blob: a76645c582c6e205912d03d6f4299eb069551303 [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 */
Uwe Hermann55c3c5f2012-02-09 19:11:53 +010025extern SRD_PRIV PyTypeObject srd_Decoder_type;
Bert Vermeulen451680f2012-01-15 03:58:27 +010026
Uwe Hermannc9bfccc2012-02-08 22:39:30 +010027/* type_logic.c */
Uwe Hermann55c3c5f2012-02-09 19:11:53 +010028extern SRD_PRIV PyTypeObject srd_logic_type;
Bert Vermeulenbc5f5a42012-01-05 03:31:36 +010029
Uwe Hermannc9bfccc2012-02-08 22:39:30 +010030/*
Uwe Hermann511e2122012-02-10 09:29:38 +010031 * When initialized, a reference to this module inside the Python interpreter
Bert Vermeulend0a0ed02012-01-15 14:44:40 +010032 * lives here.
33 */
Uwe Hermann55c3c5f2012-02-09 19:11:53 +010034SRD_PRIV PyObject *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
Uwe Hermann53a07a62012-04-16 23:10:26 +020043/* FIXME: SRD_PRIV causes issues on MinGW. Investigate. */
44PyMODINIT_FUNC PyInit_sigrokdecode(void)
Bert Vermeulenbc5f5a42012-01-05 03:31:36 +010045{
46 PyObject *mod;
47
Uwe Hermann361fdca2012-03-15 22:00:24 +010048 /* tp_new needs to be assigned here for compiler portability. */
Bert Vermeulenbc5f5a42012-01-05 03:31:36 +010049 srd_Decoder_type.tp_new = PyType_GenericNew;
50 if (PyType_Ready(&srd_Decoder_type) < 0)
51 return NULL;
52
53 srd_logic_type.tp_new = PyType_GenericNew;
54 if (PyType_Ready(&srd_logic_type) < 0)
55 return NULL;
56
57 mod = PyModule_Create(&sigrokdecode_module);
58 Py_INCREF(&srd_Decoder_type);
Uwe Hermannc9bfccc2012-02-08 22:39:30 +010059 if (PyModule_AddObject(mod, "Decoder",
60 (PyObject *)&srd_Decoder_type) == -1)
Bert Vermeulenbc5f5a42012-01-05 03:31:36 +010061 return NULL;
62 Py_INCREF(&srd_logic_type);
Uwe Hermannc9bfccc2012-02-08 22:39:30 +010063 if (PyModule_AddObject(mod, "srd_logic",
64 (PyObject *)&srd_logic_type) == -1)
Bert Vermeulenbc5f5a42012-01-05 03:31:36 +010065 return NULL;
66
Bert Vermeulen3e2a9de2012-01-07 04:18:16 +010067 /* expose output types as symbols in the sigrokdecode module */
Uwe Hermannc9bfccc2012-02-08 22:39:30 +010068 if (PyModule_AddIntConstant(mod, "OUTPUT_ANN", SRD_OUTPUT_ANN) == -1)
Bert Vermeulen3e2a9de2012-01-07 04:18:16 +010069 return NULL;
Uwe Hermannc9bfccc2012-02-08 22:39:30 +010070 if (PyModule_AddIntConstant(mod, "OUTPUT_PROTO",
71 SRD_OUTPUT_PROTO) == -1)
Bert Vermeulen3e2a9de2012-01-07 04:18:16 +010072 return NULL;
Uwe Hermannc9bfccc2012-02-08 22:39:30 +010073 if (PyModule_AddIntConstant(mod, "OUTPUT_BINARY",
74 SRD_OUTPUT_BINARY) == -1)
Bert Vermeulen3e2a9de2012-01-07 04:18:16 +010075 return NULL;
76
Bert Vermeulen451680f2012-01-15 03:58:27 +010077 mod_sigrokdecode = mod;
78
Bert Vermeulenbc5f5a42012-01-05 03:31:36 +010079 return mod;
80}