]> sigrok.org Git - libsigrokdecode.git/blame - module_sigrokdecode.c
Move session-specific functionality into session.c
[libsigrokdecode.git] / module_sigrokdecode.c
CommitLineData
bc5f5a43 1/*
50bd5d25 2 * This file is part of the libsigrokdecode project.
bc5f5a43
BV
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
c1f86f02
UH
20#include "libsigrokdecode.h" /* First, so we avoid a _POSIX_C_SOURCE warning. */
21#include "libsigrokdecode-internal.h"
bc5f5a43
BV
22#include "config.h"
23
57790bc8
UH
24/** @cond PRIVATE */
25
c9bfccc6 26/* type_decoder.c */
55c3c5f4 27extern SRD_PRIV PyTypeObject srd_Decoder_type;
451680f1 28
c9bfccc6 29/* type_logic.c */
55c3c5f4 30extern SRD_PRIV PyTypeObject srd_logic_type;
bc5f5a43 31
c9bfccc6 32/*
511e2123 33 * When initialized, a reference to this module inside the Python interpreter
d0a0ed03
BV
34 * lives here.
35 */
55c3c5f4 36SRD_PRIV PyObject *mod_sigrokdecode = NULL;
bc5f5a43 37
57790bc8
UH
38/** @endcond */
39
bc5f5a43
BV
40static struct PyModuleDef sigrokdecode_module = {
41 PyModuleDef_HEAD_INIT,
42 .m_name = "sigrokdecode",
f8e45857 43 .m_doc = "sigrokdecode module",
bc5f5a43 44 .m_size = -1,
bc5f5a43
BV
45};
46
57790bc8 47/** @cond PRIVATE */
53a07a6d 48PyMODINIT_FUNC PyInit_sigrokdecode(void)
bc5f5a43
BV
49{
50 PyObject *mod;
51
361fdcaa 52 /* tp_new needs to be assigned here for compiler portability. */
bc5f5a43
BV
53 srd_Decoder_type.tp_new = PyType_GenericNew;
54 if (PyType_Ready(&srd_Decoder_type) < 0)
55 return NULL;
56
57 srd_logic_type.tp_new = PyType_GenericNew;
58 if (PyType_Ready(&srd_logic_type) < 0)
59 return NULL;
60
61 mod = PyModule_Create(&sigrokdecode_module);
62 Py_INCREF(&srd_Decoder_type);
c9bfccc6
UH
63 if (PyModule_AddObject(mod, "Decoder",
64 (PyObject *)&srd_Decoder_type) == -1)
bc5f5a43
BV
65 return NULL;
66 Py_INCREF(&srd_logic_type);
c9bfccc6
UH
67 if (PyModule_AddObject(mod, "srd_logic",
68 (PyObject *)&srd_logic_type) == -1)
bc5f5a43
BV
69 return NULL;
70
7ee0c40b 71 /* Expose output types as symbols in the sigrokdecode module */
c9bfccc6 72 if (PyModule_AddIntConstant(mod, "OUTPUT_ANN", SRD_OUTPUT_ANN) == -1)
3e2a9de2 73 return NULL;
7ee0c40b 74 if (PyModule_AddIntConstant(mod, "OUTPUT_PYTHON", SRD_OUTPUT_PYTHON) == -1)
3e2a9de2 75 return NULL;
7ee0c40b 76 if (PyModule_AddIntConstant(mod, "OUTPUT_BINARY", SRD_OUTPUT_BINARY) == -1)
3e2a9de2 77 return NULL;
7ee0c40b
BV
78 if (PyModule_AddIntConstant(mod, "OUTPUT_META", SRD_OUTPUT_META) == -1)
79 return NULL;
80 /* Expose meta input symbols. */
81 if (PyModule_AddIntConstant(mod, "SRD_CONF_SAMPLERATE", SRD_CONF_SAMPLERATE) == -1)
ed416497 82 return NULL;
3e2a9de2 83
451680f1
BV
84 mod_sigrokdecode = mod;
85
bc5f5a43
BV
86 return mod;
87}
57790bc8 88/** @endcond */