/alps/pcitool

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/pcitool
309 by Suren A. Chilingaryan
Base functions for views
1
#ifndef _PCILIB_PY_H
2
#define _PCILIB_PY_H
3
353 by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov
4
#include <pcilib.h>
5
#include <pcilib/error.h>
6
7
#define pcilib_python_error(...)	pcilib_log_python_error(__FILE__, __LINE__, PCILIB_LOG_DEFAULT, PCILIB_LOG_ERROR, __VA_ARGS__)
369 by Suren A. Chilingaryan
Make Python problems non-fatal
8
#define pcilib_python_warning(...)	pcilib_log_python_error(__FILE__, __LINE__, PCILIB_LOG_DEFAULT, PCILIB_LOG_WARNING, __VA_ARGS__)
346.1.6 by Vasilii Chernov
Merge script and transform view. Add get register and properties info to python wrap.
9
309 by Suren A. Chilingaryan
Base functions for views
10
typedef struct pcilib_py_s pcilib_py_t;
346.1.15 by Vasilii Chernov
1. Add python thread initialization to pcilib_init_py()
11
typedef void pcilib_py_object;
309 by Suren A. Chilingaryan
Base functions for views
12
13
#ifdef __cplusplus
14
extern "C" {
15
#endif
16
353 by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov
17
void pcilib_log_python_error(const char *file, int line, pcilib_log_flags_t flags, pcilib_log_priority_t prio, const char *msg, ...);
18
19
/** Initializes Python engine 
20
 *
21
 * This function will return success if Python support is disabled. Only functions
22
 * executing python call, like pcilib_py_eval_string(), return errors. Either way,
23
 * no script directories are configured. The pcilib_add_script_dir() call is used
24
 * for this purpose.
25
 * 
26
 * @param[in,out] ctx 	- pcilib context
27
 * @return 		- error or 0 on success
28
 */
309 by Suren A. Chilingaryan
Base functions for views
29
int pcilib_init_py(pcilib_t *ctx);
353 by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov
30
31
/** Cleans up memory used by various python structures 
32
 * and finalyzes python environment if pcilib is not started from python script
33
 *
34
 * @param[in] ctx 	- the pcilib_t context
35
 */
309 by Suren A. Chilingaryan
Base functions for views
36
void pcilib_free_py(pcilib_t *ctx);
37
353 by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov
38
/** Add an additional path to look for python scripts
39
 *
40
 * The default location for python files is /usr/local/share/pcilib/models/@b{model}.
41
 * This can be altered using CMake PCILIB_MODEL_DIR variable while building or using 
42
 * PCILIB_MODEL_DIR environmental variable dynamicly. The default location is added
43
 * with @b{location} = NULL. Additional directories can be added as well either 
44
 * by specifying relative path from the default directory or absolute path in the 
45
 * system.
46
 *
47
 * @param[in,out] ctx 	- pcilib context
48
 * @param[in] location 	- NULL or path to additional scripts
49
 * @return 		- error or 0 on success
50
 */
51
int pcilib_py_add_script_dir(pcilib_t *ctx, const char *location);
52
53
/** Loads the specified python script
54
 *
55
 * Once loaded the script is available until pcilib context is destryoed.
56
 * 
57
 * @param[in,out] ctx 	- pcilib context
58
 * @param[in] name	- script name, the passed variable is referenced and, hence, should have static duration
59
 * @return 		- error or 0 on success
60
 */
61
int pcilib_py_load_script(pcilib_t *ctx, const char *name);
62
63
/** Check if the specified script can be used as transform view and detects transform configuration
64
 *
65
 * @param[in,out] ctx 	- pcilib context
66
 * @param[in] name	- script name
67
 * @param[out] mode	- supported access mode (read/write/read-write)
68
 * @return 		- error or 0 on success
69
 */
70
int pcilib_py_get_transform_script_properties(pcilib_t *ctx, const char *name, pcilib_access_mode_t *mode);
71
72
/**
73
 * Get the PyObject from the polymorphic type. The returned value should be cleaned with Py_XDECREF()
74
 * @param[in] ctx	- pcilib context
75
 * @param[in] val	- initialized polymorphic value of arbitrary type
76
 * @param[out] err	- error code or 0 on sccuess
77
 * @return		- valid PyObject or NULL in the case of error
78
 */
79
pcilib_py_object *pcilib_get_value_as_pyobject(pcilib_t* ctx, pcilib_value_t *val, int *err);
80
81
/**
82
 * Initializes the polymorphic value from PyObject. If `val` already contains the value, cleans it first. 
83
 * Therefore, before first usage the value should be always initialized to 0.
84
 * @param[in] ctx       - pcilib context
85
 * @param[in,out] val   - initialized polymorphic value
86
 * @param[in] pyval     - valid PyObject* containing PyInt, PyFloat, or PyString
87
 * @return              - 0 on success or memory error
88
 */
89
int pcilib_set_value_from_pyobject(pcilib_t* ctx, pcilib_value_t *val, pcilib_py_object *pyval);
90
91
/** Evaluates the specified python code and returns result in @b{val}
92
 *
93
 * The python code may include special variables which will be substituted by pcitool before executing Python interpreter
94
 * @b{$value} 		- will be replaced by the current value of the @b{val} parameter
95
 * @b{$reg}		- will be replaced by the current value of the specified register @b{reg}
96
 * @b{${/prop/temp}}	- will be replaced by the current value of the specified property @b{/prop/temp} 
97
 * @b{${/prop/temp:C}}	- will be replaced by the current value of the specified property @b{/prop/temp} in the given units
98
99
 * @param[in,out] ctx 	- pcilib context
100
 * @param[in] codestr	- python code to evaluate
101
 * @param[in,out] val	- Should contain the value which will be substituted in place of @b{$value} and on 
102
 * 			successful execution will contain the computed value
103
 * @return 		- error or 0 on success
104
 */
105
int pcilib_py_eval_string(pcilib_t *ctx, const char *codestr, pcilib_value_t *val);
106
107
/** Execute the specified function in the Python script which was loaded with pcilib_py_load_script() call
108
 *
109
 * The function is expected to accept two paramters. The first parameter is pcipywrap context and the @b{val}
110
 * is passed as the second parameter. The return value of the script will be returned in the @b{val} as well.
111
 * If function returns Py_None, the value of @b{val} will be unchanged.
112
 *
113
 * @param[in,out] ctx 	- pcilib context
114
 * @param[in] script	- script name
115
 * @param[in] func	- function name
116
 * @param[in,out] val	- Should contain the value of second parameter of the function before call and on 
117
 * 			successful return will contain the returned value
118
 * @return 		- error or 0 on success
119
 */
120
int pcilib_py_eval_func(pcilib_t *ctx, const char *script, const char *func, pcilib_value_t *val);
346.1.7 by Vasilii Chernov
Change error logging method in Python wrap. Move functions, that converts values between PyObject and pcilib_value_t to py.c
121
309 by Suren A. Chilingaryan
Base functions for views
122
#ifdef __cplusplus
123
}
124
#endif
125
126
127
#endif /* _PCILIB_PY_H */