/alps/pcitool

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/pcitool

« back to all changes in this revision

Viewing changes to pcilib/py.h

  • Committer: Suren A. Chilingaryan
  • Date: 2016-02-23 06:20:33 UTC
  • mfrom: (346.1.18 pcitool)
  • Revision ID: csa@suren.me-20160223062033-mz8qkpm1a2oioveb
Merge Python scripting support from Vasiliy Chernov

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#ifndef _PCILIB_PY_H
2
2
#define _PCILIB_PY_H
3
3
 
 
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__)
 
8
 
4
9
typedef struct pcilib_py_s pcilib_py_t;
 
10
typedef void pcilib_py_object;
5
11
 
6
12
#ifdef __cplusplus
7
13
extern "C" {
8
14
#endif
9
15
 
 
16
void pcilib_log_python_error(const char *file, int line, pcilib_log_flags_t flags, pcilib_log_priority_t prio, const char *msg, ...);
 
17
 
 
18
/** Initializes Python engine 
 
19
 *
 
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
 
23
 * for this purpose.
 
24
 * 
 
25
 * @param[in,out] ctx   - pcilib context
 
26
 * @return              - error or 0 on success
 
27
 */
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);
 
29
 
 
30
/** Cleans up memory used by various python structures 
 
31
 * and finalyzes python environment if pcilib is not started from python script
 
32
 *
 
33
 * @param[in] ctx       - the pcilib_t context
 
34
 */
12
35
void pcilib_free_py(pcilib_t *ctx);
13
36
 
 
37
/** Add an additional path to look for python scripts
 
38
 *
 
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 
 
44
 * system.
 
45
 *
 
46
 * @param[in,out] ctx   - pcilib context
 
47
 * @param[in] location  - NULL or path to additional scripts
 
48
 * @return              - error or 0 on success
 
49
 */
 
50
int pcilib_py_add_script_dir(pcilib_t *ctx, const char *location);
 
51
 
 
52
/** Loads the specified python script
 
53
 *
 
54
 * Once loaded the script is available until pcilib context is destryoed.
 
55
 * 
 
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
 
59
 */
 
60
int pcilib_py_load_script(pcilib_t *ctx, const char *name);
 
61
 
 
62
/** Check if the specified script can be used as transform view and detects transform configuration
 
63
 *
 
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
 
68
 */
 
69
int pcilib_py_get_transform_script_properties(pcilib_t *ctx, const char *name, pcilib_access_mode_t *mode);
 
70
 
 
71
/**
 
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
 
77
 */
 
78
pcilib_py_object *pcilib_get_value_as_pyobject(pcilib_t* ctx, pcilib_value_t *val, int *err);
 
79
 
 
80
/**
 
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
 
87
 */
 
88
int pcilib_set_value_from_pyobject(pcilib_t* ctx, pcilib_value_t *val, pcilib_py_object *pyval);
 
89
 
 
90
/** Evaluates the specified python code and returns result in @b{val}
 
91
 *
 
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
 
97
 
 
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
 
103
 */
 
104
int pcilib_py_eval_string(pcilib_t *ctx, const char *codestr, pcilib_value_t *val);
 
105
 
 
106
/** Execute the specified function in the Python script which was loaded with pcilib_py_load_script() call
 
107
 *
 
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.
 
111
 *
 
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
 
118
 */
 
119
int pcilib_py_eval_func(pcilib_t *ctx, const char *script, const char *func, pcilib_value_t *val);
 
120
 
14
121
#ifdef __cplusplus
15
122
}
16
123
#endif