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. */
13 #define CPY_LOCK_THREADS {\
14 PyGILState_STATE gil_state;\
15 gil_state = PyGILState_Ensure();
17 #define CPY_RETURN_FROM_THREADS \
18 PyGILState_Release(gil_state);\
19 return
21 #define CPY_RELEASE_THREADS \
22 PyGILState_Release(gil_state);\
23 }
25 /* Python 2.4 has this macro, older versions do not. */
26 #ifndef Py_VISIT
27 #define Py_VISIT(o) do {\
28 int _vret;\
29 if ((o) != NULL) {\
30 _vret = visit((o), arg);\
31 if (_vret != 0)\
32 return _vret;\
33 }\
34 } while (0)
35 #endif
37 /* Python 2.4 has this macro, older versions do not. */
38 #ifndef Py_CLEAR
39 #define Py_CLEAR(o) do {\
40 PyObject *tmp = o;\
41 (o) = NULL;\
42 Py_XDECREF(tmp);\
43 } while (0)
44 #endif
46 /* Python 2.4 has this macro, older versions do not. */
47 #ifndef Py_RETURN_NONE
48 # define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
49 #endif
51 typedef struct {
52 PyObject_HEAD /* No semicolon! */
53 PyObject *parent; /* Config */
54 PyObject *key; /* String */
55 PyObject *values; /* Sequence */
56 PyObject *children; /* Sequence */
57 } Config;
59 PyTypeObject ConfigType;
61 typedef struct {
62 PyObject_HEAD /* No semicolon! */
63 double time;
64 char host[DATA_MAX_NAME_LEN];
65 char plugin[DATA_MAX_NAME_LEN];
66 char plugin_instance[DATA_MAX_NAME_LEN];
67 char type[DATA_MAX_NAME_LEN];
68 char type_instance[DATA_MAX_NAME_LEN];
69 } PluginData;
71 PyTypeObject PluginDataType;
73 typedef struct {
74 PluginData data;
75 PyObject *values; /* Sequence */
76 int interval;
77 } Values;
79 PyTypeObject ValuesType;
81 typedef struct {
82 PluginData data;
83 int severity;
84 char message[NOTIF_MAX_MSG_LEN];
85 } Notification;
87 PyTypeObject NotificationType;