]> sigrok.org Git - libsigrokdecode.git/blame_incremental - module_sigrokdecode.c
type_decoder: update and extend Decoder base class doc strings
[libsigrokdecode.git] / module_sigrokdecode.c
... / ...
CommitLineData
1/*
2 * This file is part of the libsigrokdecode project.
3 *
4 * Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <config.h>
21#include "libsigrokdecode-internal.h" /* First, so we avoid a _POSIX_C_SOURCE warning. */
22#include "libsigrokdecode.h"
23
24/** @cond PRIVATE */
25
26/*
27 * When initialized, a reference to this module inside the Python interpreter
28 * lives here.
29 */
30SRD_PRIV PyObject *mod_sigrokdecode = NULL;
31
32/** @endcond */
33
34static struct PyModuleDef sigrokdecode_module = {
35 PyModuleDef_HEAD_INIT,
36 .m_name = "sigrokdecode",
37 .m_doc = "sigrokdecode module",
38 .m_size = -1,
39};
40
41/** @cond PRIVATE */
42PyMODINIT_FUNC PyInit_sigrokdecode(void)
43{
44 PyObject *mod, *Decoder_type;
45 PyGILState_STATE gstate;
46
47 gstate = PyGILState_Ensure();
48
49 mod = PyModule_Create(&sigrokdecode_module);
50 if (!mod)
51 goto err_out;
52
53 Decoder_type = srd_Decoder_type_new();
54 if (!Decoder_type)
55 goto err_out;
56 if (PyModule_AddObject(mod, "Decoder", Decoder_type) < 0)
57 goto err_out;
58
59 /* Expose output types as symbols in the sigrokdecode module */
60 if (PyModule_AddIntConstant(mod, "OUTPUT_ANN", SRD_OUTPUT_ANN) < 0)
61 goto err_out;
62 if (PyModule_AddIntConstant(mod, "OUTPUT_PYTHON", SRD_OUTPUT_PYTHON) < 0)
63 goto err_out;
64 if (PyModule_AddIntConstant(mod, "OUTPUT_BINARY", SRD_OUTPUT_BINARY) < 0)
65 goto err_out;
66 if (PyModule_AddIntConstant(mod, "OUTPUT_LOGIC", SRD_OUTPUT_LOGIC) < 0)
67 goto err_out;
68 if (PyModule_AddIntConstant(mod, "OUTPUT_META", SRD_OUTPUT_META) < 0)
69 goto err_out;
70 /* Expose meta input symbols. */
71 if (PyModule_AddIntConstant(mod, "SRD_CONF_SAMPLERATE", SRD_CONF_SAMPLERATE) < 0)
72 goto err_out;
73
74 mod_sigrokdecode = mod;
75
76 PyGILState_Release(gstate);
77
78 return mod;
79
80err_out:
81 Py_XDECREF(mod);
82 srd_exception_catch("Failed to initialize module");
83 PyGILState_Release(gstate);
84
85 return NULL;
86}
87
88/** @endcond */