Bert Vermeulen | bc5f5a4 | 2012-01-05 03:31:36 +0100 | [diff] [blame] | 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. */ |
Bert Vermeulen | 1596994 | 2012-01-07 02:50:14 +0100 | [diff] [blame] | 21 | #include "sigrokdecode-internal.h" |
Bert Vermeulen | bc5f5a4 | 2012-01-05 03:31:36 +0100 | [diff] [blame] | 22 | #include "config.h" |
| 23 | |
Bert Vermeulen | 451680f | 2012-01-15 03:58:27 +0100 | [diff] [blame] | 24 | |
Bert Vermeulen | d0a0ed0 | 2012-01-15 14:44:40 +0100 | [diff] [blame^] | 25 | /* lives in type_decoder.c */ |
| 26 | extern PyTypeObject srd_Decoder_type; |
Bert Vermeulen | 451680f | 2012-01-15 03:58:27 +0100 | [diff] [blame] | 27 | |
Bert Vermeulen | bc5f5a4 | 2012-01-05 03:31:36 +0100 | [diff] [blame] | 28 | /* lives in type_logic.c */ |
| 29 | extern PyTypeObject srd_logic_type; |
| 30 | |
| 31 | |
Bert Vermeulen | d0a0ed0 | 2012-01-15 14:44:40 +0100 | [diff] [blame^] | 32 | /* When initialized, a reference to this module inside the python interpreter |
| 33 | * lives here. |
| 34 | */ |
| 35 | PyObject *mod_sigrokdecode = NULL; |
Bert Vermeulen | bc5f5a4 | 2012-01-05 03:31:36 +0100 | [diff] [blame] | 36 | |
| 37 | static struct PyModuleDef sigrokdecode_module = { |
| 38 | PyModuleDef_HEAD_INIT, |
| 39 | .m_name = "sigrokdecode", |
Bert Vermeulen | f8e4585 | 2012-01-15 03:43:01 +0100 | [diff] [blame] | 40 | .m_doc = "sigrokdecode module", |
Bert Vermeulen | bc5f5a4 | 2012-01-05 03:31:36 +0100 | [diff] [blame] | 41 | .m_size = -1, |
Bert Vermeulen | bc5f5a4 | 2012-01-05 03:31:36 +0100 | [diff] [blame] | 42 | }; |
| 43 | |
Bert Vermeulen | d0a0ed0 | 2012-01-15 14:44:40 +0100 | [diff] [blame^] | 44 | |
Bert Vermeulen | bc5f5a4 | 2012-01-05 03:31:36 +0100 | [diff] [blame] | 45 | PyMODINIT_FUNC PyInit_sigrokdecode(void) |
| 46 | { |
| 47 | PyObject *mod; |
| 48 | |
| 49 | /* tp_new needs to be assigned here for compiler portability */ |
| 50 | srd_Decoder_type.tp_new = PyType_GenericNew; |
| 51 | if (PyType_Ready(&srd_Decoder_type) < 0) |
| 52 | return NULL; |
| 53 | |
| 54 | srd_logic_type.tp_new = PyType_GenericNew; |
| 55 | if (PyType_Ready(&srd_logic_type) < 0) |
| 56 | return NULL; |
| 57 | |
| 58 | mod = PyModule_Create(&sigrokdecode_module); |
| 59 | Py_INCREF(&srd_Decoder_type); |
| 60 | if (PyModule_AddObject(mod, "Decoder", (PyObject *)&srd_Decoder_type) == -1) |
| 61 | return NULL; |
| 62 | Py_INCREF(&srd_logic_type); |
| 63 | if (PyModule_AddObject(mod, "srd_logic", (PyObject *)&srd_logic_type) == -1) |
| 64 | return NULL; |
| 65 | |
Bert Vermeulen | 3e2a9de | 2012-01-07 04:18:16 +0100 | [diff] [blame] | 66 | /* expose output types as symbols in the sigrokdecode module */ |
Uwe Hermann | 5620222 | 2012-01-11 00:52:54 +0100 | [diff] [blame] | 67 | if(PyModule_AddObject(mod, "OUTPUT_ANN", |
Uwe Hermann | 94d43b3 | 2012-01-10 20:44:22 +0100 | [diff] [blame] | 68 | PyLong_FromLong(SRD_OUTPUT_ANN)) == -1) |
Bert Vermeulen | 3e2a9de | 2012-01-07 04:18:16 +0100 | [diff] [blame] | 69 | return NULL; |
Uwe Hermann | 5620222 | 2012-01-11 00:52:54 +0100 | [diff] [blame] | 70 | if(PyModule_AddObject(mod, "OUTPUT_PROTO", |
Uwe Hermann | 94d43b3 | 2012-01-10 20:44:22 +0100 | [diff] [blame] | 71 | PyLong_FromLong(SRD_OUTPUT_PROTO)) == -1) |
Bert Vermeulen | 3e2a9de | 2012-01-07 04:18:16 +0100 | [diff] [blame] | 72 | return NULL; |
Uwe Hermann | 5620222 | 2012-01-11 00:52:54 +0100 | [diff] [blame] | 73 | if(PyModule_AddObject(mod, "OUTPUT_BINARY", |
Bert Vermeulen | 3e2a9de | 2012-01-07 04:18:16 +0100 | [diff] [blame] | 74 | PyLong_FromLong(SRD_OUTPUT_BINARY)) == -1) |
| 75 | return NULL; |
| 76 | |
Bert Vermeulen | 451680f | 2012-01-15 03:58:27 +0100 | [diff] [blame] | 77 | mod_sigrokdecode = mod; |
| 78 | |
Bert Vermeulen | bc5f5a4 | 2012-01-05 03:31:36 +0100 | [diff] [blame] | 79 | return mod; |
| 80 | } |
| 81 | |