Added new python class "Values". Only "dispatch" is implemented right now.
[collectd.git] / src / cpython.h
1 /* These two macros are basicly Py_BEGIN_ALLOW_THREADS and Py_BEGIN_ALLOW_THREADS
2  * from the other direction. If a Python thread calls a C function
3  * Py_BEGIN_ALLOW_THREADS is used to allow other python threads to run because
4  * we don't intend to call any Python functions.
5  *
6  * These two macros are used whenever a C thread intends to call some Python
7  * function, usually because some registered callback was triggered.
8  * Just like Py_BEGIN_ALLOW_THREADS it opens a block so these macros have to be
9  * used in pairs. They aquire the GIL, create a new Python thread state and swap
10  * the current thread state with the new one. This means this thread is now allowed
11  * to execute Python code. */
12
13 #define CPY_LOCK_THREADS {\
14         PyGILState_STATE gil_state;\
15         gil_state = PyGILState_Ensure();
16
17 #define CPY_RELEASE_THREADS \
18         PyGILState_Release(gil_state);\
19 }
20
21 /* Python 2.4 has this macro, older versions do not. */
22 #ifndef Py_VISIT
23 #define Py_VISIT(o) do {\
24         int _vret;\
25         if ((o) != NULL) {\
26                 _vret = visit((o), arg);\
27                 if (_vret != 0)\
28                 return _vret;\
29         }\
30 } while (0)
31 #endif
32
33 /* Python 2.4 has this macro, older versions do not. */
34 #ifndef Py_CLEAR
35 #define Py_CLEAR(o) do {\
36         PyObject *tmp = o;\
37         (o) = NULL;\
38         Py_XDECREF(tmp);\
39 } while (0)
40 #endif
41
42 typedef struct {
43         PyObject_HEAD        /* No semicolon! */
44         PyObject *parent;    /* Config */
45         PyObject *key;       /* String */
46         PyObject *values;    /* Sequence */
47         PyObject *children;  /* Sequence */
48 } Config;
49
50 PyTypeObject ConfigType;
51
52 typedef struct {
53         PyObject_HEAD        /* No semicolon! */
54         PyObject *values;    /* Sequence */
55         double time;
56         int interval;
57         char host[DATA_MAX_NAME_LEN];
58         char plugin[DATA_MAX_NAME_LEN];
59         char plugin_instance[DATA_MAX_NAME_LEN];
60         char type[DATA_MAX_NAME_LEN];
61         char type_instance[DATA_MAX_NAME_LEN];
62 } Values;
63
64 PyTypeObject ValuesType;