]> git.ipfire.org Git - collecty.git/blob - src/_collecty/_collectymodule.c
25b1979f64a7c5305f299d83a838168fd64bb825
[collecty.git] / src / _collecty / _collectymodule.c
1 /*
2 * collecty
3 * Copyright (C) 2015 IPFire Team (www.ipfire.org)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include <Python.h>
20
21 #include "_collectymodule.h"
22
23 static PyMethodDef collecty_module_methods[] = {
24 {"get_detected_sensors", (PyCFunction)_collecty_get_detected_sensors, METH_VARARGS, NULL},
25 {"get_mountpoints", (PyCFunction)_collecty_get_mountpoints, METH_NOARGS, NULL},
26 {"sensors_cleanup", (PyCFunction)_collecty_sensors_cleanup, METH_NOARGS, NULL},
27 {"sensors_init", (PyCFunction)_collecty_sensors_init, METH_NOARGS, NULL},
28 {NULL},
29 };
30
31 static struct PyModuleDef collecty_module = {
32 PyModuleDef_HEAD_INIT,
33 "_collecty", /* m_name */
34 "_collecty module", /* m_doc */
35 -1, /* m_size */
36 collecty_module_methods, /* m_methods */
37 NULL, /* m_reload */
38 NULL, /* m_traverse */
39 NULL, /* m_clear */
40 NULL, /* m_free */
41 };
42
43 PyMODINIT_FUNC PyInit__collecty(void) {
44 if (PyType_Ready(&BlockDeviceType) < 0)
45 return NULL;
46
47 if (PyType_Ready(&PingType) < 0)
48 return NULL;
49
50 if (PyType_Ready(&SensorType) < 0)
51 return NULL;
52
53 PyObject* m = PyModule_Create(&collecty_module);
54
55 Py_INCREF(&BlockDeviceType);
56 PyModule_AddObject(m, "BlockDevice", (PyObject*)&BlockDeviceType);
57
58 Py_INCREF(&PingType);
59 PyModule_AddObject(m, "Ping", (PyObject*)&PingType);
60
61 PyExc_PingError = PyErr_NewException("_collecty.PingError", NULL, NULL);
62 Py_INCREF(PyExc_PingError);
63 PyModule_AddObject(m, "PingError", PyExc_PingError);
64
65 PyExc_PingAddHostError = PyErr_NewException("_collecty.PingAddHostError", NULL, NULL);
66 Py_INCREF(PyExc_PingAddHostError);
67 PyModule_AddObject(m, "PingAddHostError", PyExc_PingAddHostError);
68
69 Py_INCREF(&SensorType);
70 PyModule_AddObject(m, "Sensor", (PyObject*)&SensorType);
71
72 return m;
73 }