blob: 0992ea20fdee0a25d3442b7a48dfc0709a21e1bd [file] [log] [blame]
Bert Vermeulenbc5f5a42012-01-05 03:31:36 +01001/*
2 * This file is part of the sigrok 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 "sigrokdecode.h" /* First, so we avoid a _POSIX_C_SOURCE warning. */
Bert Vermeulen15969942012-01-07 02:50:14 +010021#include "sigrokdecode-internal.h"
Bert Vermeulenbc5f5a42012-01-05 03:31:36 +010022#include "config.h"
23
Uwe Hermannc9bfccc2012-02-08 22:39:30 +010024/* type_decoder.c */
Bert Vermeulend0a0ed02012-01-15 14:44:40 +010025extern PyTypeObject srd_Decoder_type;
Bert Vermeulen451680f2012-01-15 03:58:27 +010026
Uwe Hermannc9bfccc2012-02-08 22:39:30 +010027/* type_logic.c */
Bert Vermeulenbc5f5a42012-01-05 03:31:36 +010028extern PyTypeObject srd_logic_type;
29
Uwe Hermannc9bfccc2012-02-08 22:39:30 +010030/*
31 * When initialized, a reference to this module inside the python interpreter
Bert Vermeulend0a0ed02012-01-15 14:44:40 +010032 * lives here.
33 */
34PyObject *mod_sigrokdecode = NULL;
Bert Vermeulenbc5f5a42012-01-05 03:31:36 +010035
36static struct PyModuleDef sigrokdecode_module = {
37 PyModuleDef_HEAD_INIT,
38 .m_name = "sigrokdecode",
Bert Vermeulenf8e45852012-01-15 03:43:01 +010039 .m_doc = "sigrokdecode module",
Bert Vermeulenbc5f5a42012-01-05 03:31:36 +010040 .m_size = -1,
Bert Vermeulenbc5f5a42012-01-05 03:31:36 +010041};
42
43PyMODINIT_FUNC PyInit_sigrokdecode(void)
44{
45 PyObject *mod;
46
47 /* tp_new needs to be assigned here for compiler portability */
48 srd_Decoder_type.tp_new = PyType_GenericNew;
49 if (PyType_Ready(&srd_Decoder_type) < 0)
50 return NULL;
51
52 srd_logic_type.tp_new = PyType_GenericNew;
53 if (PyType_Ready(&srd_logic_type) < 0)
54 return NULL;
55
56 mod = PyModule_Create(&sigrokdecode_module);
57 Py_INCREF(&srd_Decoder_type);
Uwe Hermannc9bfccc2012-02-08 22:39:30 +010058 if (PyModule_AddObject(mod, "Decoder",
59 (PyObject *)&srd_Decoder_type) == -1)
Bert Vermeulenbc5f5a42012-01-05 03:31:36 +010060 return NULL;
61 Py_INCREF(&srd_logic_type);
Uwe Hermannc9bfccc2012-02-08 22:39:30 +010062 if (PyModule_AddObject(mod, "srd_logic",
63 (PyObject *)&srd_logic_type) == -1)
Bert Vermeulenbc5f5a42012-01-05 03:31:36 +010064 return NULL;
65
Bert Vermeulen3e2a9de2012-01-07 04:18:16 +010066 /* expose output types as symbols in the sigrokdecode module */
Uwe Hermannc9bfccc2012-02-08 22:39:30 +010067 if (PyModule_AddIntConstant(mod, "OUTPUT_ANN", SRD_OUTPUT_ANN) == -1)
Bert Vermeulen3e2a9de2012-01-07 04:18:16 +010068 return NULL;
Uwe Hermannc9bfccc2012-02-08 22:39:30 +010069 if (PyModule_AddIntConstant(mod, "OUTPUT_PROTO",
70 SRD_OUTPUT_PROTO) == -1)
Bert Vermeulen3e2a9de2012-01-07 04:18:16 +010071 return NULL;
Uwe Hermannc9bfccc2012-02-08 22:39:30 +010072 if (PyModule_AddIntConstant(mod, "OUTPUT_BINARY",
73 SRD_OUTPUT_BINARY) == -1)
Bert Vermeulen3e2a9de2012-01-07 04:18:16 +010074 return NULL;
75
Bert Vermeulen451680f2012-01-15 03:58:27 +010076 mod_sigrokdecode = mod;
77
Bert Vermeulenbc5f5a42012-01-05 03:31:36 +010078 return mod;
79}