/alps/pcitool

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/pcitool
307 by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far)
1
#ifndef _PCILIB_VIEW_H
2
#define _PCILIB_VIEW_H
3
311 by Suren A. Chilingaryan
Implement enum view
4
#include <uthash.h>
5
307 by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far)
6
#include <pcilib.h>
7
#include <pcilib/unit.h>
8
9
#define PCILIB_VIEW_INVALID ((pcilib_view_t)-1)
10
310 by Suren A. Chilingaryan
Introduce hashes
11
typedef struct pcilib_view_context_s pcilib_view_context_t;
12
typedef struct pcilib_view_description_s pcilib_view_description_t;
307 by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far)
13
309 by Suren A. Chilingaryan
Base functions for views
14
typedef enum {
321 by Suren A. Chilingaryan
Support computed (property-based) registers
15
    PCILIB_VIEW_FLAG_PROPERTY = 1,                                              /**< Indicates that view does not depend on a value and is independent property */
16
    PCILIB_VIEW_FLAG_REGISTER = 2                                               /**< Indicates that view does not depend on a value and should be mapped to the register space */
309 by Suren A. Chilingaryan
Base functions for views
17
} pcilib_view_flags_t;
18
307 by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far)
19
typedef struct {
315 by Suren A. Chilingaryan
Support properties of arbitrary type
20
    pcilib_version_t version;                                                                                                           /**< Version */
21
    size_t description_size;                                                                                                            /**< The actual size of the description */
353 by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov
22
    pcilib_view_context_t *(*init)(pcilib_t *ctx, pcilib_view_t view);									/**< Optional function which should allocated context used by read/write functions */
315 by Suren A. Chilingaryan
Support properties of arbitrary type
23
    void (*free)(pcilib_t *ctx, pcilib_view_context_t *view);                                                                           /**< Optional function which should clean context */
24
    void (*free_description)(pcilib_t *ctx, pcilib_view_description_t *view);                                                           /**< Optional function which shoud clean required parts of the extended description if non-static memory was used to initialize it */
25
    int (*read_from_reg)(pcilib_t *ctx, pcilib_view_context_t *view, pcilib_register_value_t regval, pcilib_value_t *val);              /**< Function which computes view value based on the passed the register value (view-based properties should not use register value) */
26
    int (*write_to_reg)(pcilib_t *ctx, pcilib_view_context_t *view, pcilib_register_value_t *regval, const pcilib_value_t *val);        /**< Function which computes register value based on the passed value (view-based properties are not required to set the register value) */
307 by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far)
27
} pcilib_view_api_description_t;
28
310 by Suren A. Chilingaryan
Introduce hashes
29
struct pcilib_view_description_s {
307 by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far)
30
    const pcilib_view_api_description_t *api;
316 by Suren A. Chilingaryan
Support XML properties
31
    pcilib_view_flags_t flags;                                                  /**< Flags specifying type of the view */
309 by Suren A. Chilingaryan
Base functions for views
32
    pcilib_value_type_t type;			                                /**< The default data type returned by operation, PCILIB_VIEW_TYPE_STRING is supported by all operations */
315 by Suren A. Chilingaryan
Support properties of arbitrary type
33
    pcilib_access_mode_t mode;                                                  /**< Specifies if the view is read/write-only */
307 by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far)
34
    const char *unit;				                                /**< Returned unit (if any) */
35
    const char *name;				                                /**< Name of the view */
321 by Suren A. Chilingaryan
Support computed (property-based) registers
36
    const char *regname;                                                        /**< Specifies the register name if the view should be mapped to register space */
307 by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far)
37
    const char *description;			                                /**< Short description */
310 by Suren A. Chilingaryan
Introduce hashes
38
};
307 by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far)
39
311 by Suren A. Chilingaryan
Implement enum view
40
struct pcilib_view_context_s {
41
    const char *name;
42
    pcilib_view_t view;
318 by Suren A. Chilingaryan
Support reading/writting register views by id
43
    pcilib_xml_node_t *xml;
311 by Suren A. Chilingaryan
Implement enum view
44
    UT_hash_handle hh;
45
};
46
307 by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far)
47
#ifdef __cplusplus
48
extern "C" {
49
#endif
50
315 by Suren A. Chilingaryan
Support properties of arbitrary type
51
/**
52
 * Use this function to add new view definitions into the model. It is error to re-register
53
 * already registered view. The function will copy the context of unit description, but name, 
54
 * transform, and other strings in the structure are considered to have static duration 
55
 * and will not be copied. On error no new views are initalized.
56
 * @param[in,out] ctx - pcilib context
57
 * @param[in] n - number of views to initialize. It is OK to pass 0 if protocols variable is NULL terminated (last member of protocols array have all members set to 0)
58
 * @param[in] desc - view descriptions
59
 * @return - error or 0 on success
60
 */
307 by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far)
61
int pcilib_add_views(pcilib_t *ctx, size_t n, const pcilib_view_description_t *desc);
315 by Suren A. Chilingaryan
Support properties of arbitrary type
62
63
/**
318 by Suren A. Chilingaryan
Support reading/writting register views by id
64
 * Use this function to add new view definitions into the model. It is error to re-register
65
 * already registered view. The function will copy the context of unit description, but name, 
66
 * transform, and other strings in the structure are considered to have static duration 
67
 * and will not be copied. On error no new views are initalized.
68
 * @param[in,out] ctx - pcilib context
69
 * @param[in] n - number of views to initialize. It is OK to pass 0 if protocols variable is NULL terminated (last member of protocols array have all members set to 0)
70
 * @param[in] desc - view descriptions
71
 * @param[out] refs - fills allocated view contexts. On error context is undefined.
72
 * @return - error or 0 on success
73
 */
74
int pcilib_add_views_custom(pcilib_t *ctx, size_t n, const pcilib_view_description_t *desc, pcilib_view_context_t **refs);
75
76
/**
315 by Suren A. Chilingaryan
Support properties of arbitrary type
77
 * Destroys data associated with views. This is an internal function and will
78
 * be called during clean-up.
79
 * @param[in,out] ctx - pcilib context
80
 * @param[in] start - specifies first view to clean (used to clean only part of the views to keep the defined state if pcilib_add_views has failed)
81
 */
82
void pcilib_clean_views(pcilib_t *ctx, pcilib_view_t start);
310 by Suren A. Chilingaryan
Introduce hashes
83
84
pcilib_view_context_t *pcilib_find_view_context_by_name(pcilib_t *ctx, const char *view);
85
pcilib_view_context_t *pcilib_find_register_view_context_by_name(pcilib_t *ctx, pcilib_register_t reg, const char *name);
86
pcilib_view_context_t *pcilib_find_register_view_context(pcilib_t *ctx, pcilib_register_t reg, const char *name);
87
88
pcilib_view_t pcilib_find_view_by_name(pcilib_t *ctx, const char *name);
307 by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far)
89
90
#ifdef __cplusplus
91
}
92
#endif
93
94
#endif /* PCILIB_VIEW_H */