]>
Commit | Line | Data |
---|---|---|
bc5f5a43 BV |
1 | /* |
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. */ | |
15969949 | 21 | #include "sigrokdecode-internal.h" |
bc5f5a43 BV |
22 | #include "config.h" |
23 | ||
c9bfccc6 | 24 | /* type_decoder.c */ |
55c3c5f4 | 25 | extern SRD_PRIV PyTypeObject srd_Decoder_type; |
451680f1 | 26 | |
c9bfccc6 | 27 | /* type_logic.c */ |
55c3c5f4 | 28 | extern SRD_PRIV PyTypeObject srd_logic_type; |
bc5f5a43 | 29 | |
c9bfccc6 UH |
30 | /* |
31 | * When initialized, a reference to this module inside the python interpreter | |
d0a0ed03 BV |
32 | * lives here. |
33 | */ | |
55c3c5f4 | 34 | SRD_PRIV PyObject *mod_sigrokdecode = NULL; |
bc5f5a43 BV |
35 | |
36 | static struct PyModuleDef sigrokdecode_module = { | |
37 | PyModuleDef_HEAD_INIT, | |
38 | .m_name = "sigrokdecode", | |
f8e45857 | 39 | .m_doc = "sigrokdecode module", |
bc5f5a43 | 40 | .m_size = -1, |
bc5f5a43 BV |
41 | }; |
42 | ||
55c3c5f4 | 43 | SRD_PRIV PyMODINIT_FUNC PyInit_sigrokdecode(void) |
bc5f5a43 BV |
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); | |
c9bfccc6 UH |
58 | if (PyModule_AddObject(mod, "Decoder", |
59 | (PyObject *)&srd_Decoder_type) == -1) | |
bc5f5a43 BV |
60 | return NULL; |
61 | Py_INCREF(&srd_logic_type); | |
c9bfccc6 UH |
62 | if (PyModule_AddObject(mod, "srd_logic", |
63 | (PyObject *)&srd_logic_type) == -1) | |
bc5f5a43 BV |
64 | return NULL; |
65 | ||
3e2a9de2 | 66 | /* expose output types as symbols in the sigrokdecode module */ |
c9bfccc6 | 67 | if (PyModule_AddIntConstant(mod, "OUTPUT_ANN", SRD_OUTPUT_ANN) == -1) |
3e2a9de2 | 68 | return NULL; |
c9bfccc6 UH |
69 | if (PyModule_AddIntConstant(mod, "OUTPUT_PROTO", |
70 | SRD_OUTPUT_PROTO) == -1) | |
3e2a9de2 | 71 | return NULL; |
c9bfccc6 UH |
72 | if (PyModule_AddIntConstant(mod, "OUTPUT_BINARY", |
73 | SRD_OUTPUT_BINARY) == -1) | |
3e2a9de2 BV |
74 | return NULL; |
75 | ||
451680f1 BV |
76 | mod_sigrokdecode = mod; |
77 | ||
bc5f5a43 BV |
78 | return mod; |
79 | } |