5
#include <pcilib/error.h>
7
#define pcilib_python_error(...) pcilib_log_python_error(__FILE__, __LINE__, PCILIB_LOG_DEFAULT, PCILIB_LOG_ERROR, __VA_ARGS__)
4
9
typedef struct pcilib_py_s pcilib_py_t;
10
typedef void pcilib_py_object;
16
void pcilib_log_python_error(const char *file, int line, pcilib_log_flags_t flags, pcilib_log_priority_t prio, const char *msg, ...);
18
/** Initializes Python engine
20
* This function will return success if Python support is disabled. Only functions
21
* executing python call, like pcilib_py_eval_string(), return errors. Either way,
22
* no script directories are configured. The pcilib_add_script_dir() call is used
25
* @param[in,out] ctx - pcilib context
26
* @return - error or 0 on success
10
28
int pcilib_init_py(pcilib_t *ctx);
11
int pcilib_py_eval_string(pcilib_t *ctx, const char *codestr, pcilib_value_t *value);
30
/** Cleans up memory used by various python structures
31
* and finalyzes python environment if pcilib is not started from python script
33
* @param[in] ctx - the pcilib_t context
12
35
void pcilib_free_py(pcilib_t *ctx);
37
/** Add an additional path to look for python scripts
39
* The default location for python files is /usr/local/share/pcilib/models/@b{model}.
40
* This can be altered using CMake PCILIB_MODEL_DIR variable while building or using
41
* PCILIB_MODEL_DIR environmental variable dynamicly. The default location is added
42
* with @b{location} = NULL. Additional directories can be added as well either
43
* by specifying relative path from the default directory or absolute path in the
46
* @param[in,out] ctx - pcilib context
47
* @param[in] location - NULL or path to additional scripts
48
* @return - error or 0 on success
50
int pcilib_py_add_script_dir(pcilib_t *ctx, const char *location);
52
/** Loads the specified python script
54
* Once loaded the script is available until pcilib context is destryoed.
56
* @param[in,out] ctx - pcilib context
57
* @param[in] name - script name, the passed variable is referenced and, hence, should have static duration
58
* @return - error or 0 on success
60
int pcilib_py_load_script(pcilib_t *ctx, const char *name);
62
/** Check if the specified script can be used as transform view and detects transform configuration
64
* @param[in,out] ctx - pcilib context
65
* @param[in] name - script name
66
* @param[out] mode - supported access mode (read/write/read-write)
67
* @return - error or 0 on success
69
int pcilib_py_get_transform_script_properties(pcilib_t *ctx, const char *name, pcilib_access_mode_t *mode);
72
* Get the PyObject from the polymorphic type. The returned value should be cleaned with Py_XDECREF()
73
* @param[in] ctx - pcilib context
74
* @param[in] val - initialized polymorphic value of arbitrary type
75
* @param[out] err - error code or 0 on sccuess
76
* @return - valid PyObject or NULL in the case of error
78
pcilib_py_object *pcilib_get_value_as_pyobject(pcilib_t* ctx, pcilib_value_t *val, int *err);
81
* Initializes the polymorphic value from PyObject. If `val` already contains the value, cleans it first.
82
* Therefore, before first usage the value should be always initialized to 0.
83
* @param[in] ctx - pcilib context
84
* @param[in,out] val - initialized polymorphic value
85
* @param[in] pyval - valid PyObject* containing PyInt, PyFloat, or PyString
86
* @return - 0 on success or memory error
88
int pcilib_set_value_from_pyobject(pcilib_t* ctx, pcilib_value_t *val, pcilib_py_object *pyval);
90
/** Evaluates the specified python code and returns result in @b{val}
92
* The python code may include special variables which will be substituted by pcitool before executing Python interpreter
93
* @b{$value} - will be replaced by the current value of the @b{val} parameter
94
* @b{$reg} - will be replaced by the current value of the specified register @b{reg}
95
* @b{${/prop/temp}} - will be replaced by the current value of the specified property @b{/prop/temp}
96
* @b{${/prop/temp:C}} - will be replaced by the current value of the specified property @b{/prop/temp} in the given units
98
* @param[in,out] ctx - pcilib context
99
* @param[in] codestr - python code to evaluate
100
* @param[in,out] val - Should contain the value which will be substituted in place of @b{$value} and on
101
* successful execution will contain the computed value
102
* @return - error or 0 on success
104
int pcilib_py_eval_string(pcilib_t *ctx, const char *codestr, pcilib_value_t *val);
106
/** Execute the specified function in the Python script which was loaded with pcilib_py_load_script() call
108
* The function is expected to accept two paramters. The first parameter is pcipywrap context and the @b{val}
109
* is passed as the second parameter. The return value of the script will be returned in the @b{val} as well.
110
* If function returns Py_None, the value of @b{val} will be unchanged.
112
* @param[in,out] ctx - pcilib context
113
* @param[in] script - script name
114
* @param[in] func - function name
115
* @param[in,out] val - Should contain the value of second parameter of the function before call and on
116
* successful return will contain the returned value
117
* @return - error or 0 on success
119
int pcilib_py_eval_func(pcilib_t *ctx, const char *script, const char *func, pcilib_value_t *val);
14
121
#ifdef __cplusplus