2 * This file is part of the libsigrokdecode project.
4 * Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
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.
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.
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/>.
21 #include "libsigrokdecode-internal.h" /* First, so we avoid a _POSIX_C_SOURCE warning. */
22 #include "libsigrokdecode.h"
26 SRD_PRIV PyObject *srd_logic_type = NULL;
29 * When initialized, a reference to this module inside the Python interpreter
32 SRD_PRIV PyObject *mod_sigrokdecode = NULL;
36 static struct PyModuleDef sigrokdecode_module = {
37 PyModuleDef_HEAD_INIT,
38 .m_name = "sigrokdecode",
39 .m_doc = "sigrokdecode module",
44 PyMODINIT_FUNC PyInit_sigrokdecode(void)
46 PyObject *mod, *Decoder_type, *logic_type;
48 mod = PyModule_Create(&sigrokdecode_module);
52 Decoder_type = srd_Decoder_type_new();
55 if (PyModule_AddObject(mod, "Decoder", Decoder_type) < 0)
58 logic_type = srd_logic_type_new();
61 if (PyModule_AddObject(mod, "srd_logic", logic_type) < 0)
64 /* Expose output types as symbols in the sigrokdecode module */
65 if (PyModule_AddIntConstant(mod, "OUTPUT_ANN", SRD_OUTPUT_ANN) < 0)
67 if (PyModule_AddIntConstant(mod, "OUTPUT_PYTHON", SRD_OUTPUT_PYTHON) < 0)
69 if (PyModule_AddIntConstant(mod, "OUTPUT_BINARY", SRD_OUTPUT_BINARY) < 0)
71 if (PyModule_AddIntConstant(mod, "OUTPUT_META", SRD_OUTPUT_META) < 0)
73 /* Expose meta input symbols. */
74 if (PyModule_AddIntConstant(mod, "SRD_CONF_SAMPLERATE", SRD_CONF_SAMPLERATE) < 0)
77 srd_logic_type = logic_type;
78 mod_sigrokdecode = mod;
83 srd_exception_catch("Failed to initialize module");