Bert Vermeulen | bc5f5a4 | 2012-01-05 03:31:36 +0100 | [diff] [blame] | 1 | /* |
Uwe Hermann | 50bd5d2 | 2013-04-23 22:27:20 +0200 | [diff] [blame^] | 2 | * This file is part of the libsigrokdecode project. |
Bert Vermeulen | bc5f5a4 | 2012-01-05 03:31:36 +0100 | [diff] [blame] | 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 | |
Uwe Hermann | 57790bc | 2013-02-09 21:44:11 +0100 | [diff] [blame] | 24 | /** @cond PRIVATE */ |
| 25 | |
Uwe Hermann | c9bfccc | 2012-02-08 22:39:30 +0100 | [diff] [blame] | 26 | /* type_decoder.c */ |
Uwe Hermann | 55c3c5f | 2012-02-09 19:11:53 +0100 | [diff] [blame] | 27 | extern SRD_PRIV PyTypeObject srd_Decoder_type; |
Bert Vermeulen | 451680f | 2012-01-15 03:58:27 +0100 | [diff] [blame] | 28 | |
Uwe Hermann | c9bfccc | 2012-02-08 22:39:30 +0100 | [diff] [blame] | 29 | /* type_logic.c */ |
Uwe Hermann | 55c3c5f | 2012-02-09 19:11:53 +0100 | [diff] [blame] | 30 | extern SRD_PRIV PyTypeObject srd_logic_type; |
Bert Vermeulen | bc5f5a4 | 2012-01-05 03:31:36 +0100 | [diff] [blame] | 31 | |
Uwe Hermann | c9bfccc | 2012-02-08 22:39:30 +0100 | [diff] [blame] | 32 | /* |
Uwe Hermann | 511e212 | 2012-02-10 09:29:38 +0100 | [diff] [blame] | 33 | * When initialized, a reference to this module inside the Python interpreter |
Bert Vermeulen | d0a0ed0 | 2012-01-15 14:44:40 +0100 | [diff] [blame] | 34 | * lives here. |
| 35 | */ |
Uwe Hermann | 55c3c5f | 2012-02-09 19:11:53 +0100 | [diff] [blame] | 36 | SRD_PRIV PyObject *mod_sigrokdecode = NULL; |
Bert Vermeulen | bc5f5a4 | 2012-01-05 03:31:36 +0100 | [diff] [blame] | 37 | |
Uwe Hermann | 57790bc | 2013-02-09 21:44:11 +0100 | [diff] [blame] | 38 | /** @endcond */ |
| 39 | |
Bert Vermeulen | bc5f5a4 | 2012-01-05 03:31:36 +0100 | [diff] [blame] | 40 | static struct PyModuleDef sigrokdecode_module = { |
| 41 | PyModuleDef_HEAD_INIT, |
| 42 | .m_name = "sigrokdecode", |
Bert Vermeulen | f8e4585 | 2012-01-15 03:43:01 +0100 | [diff] [blame] | 43 | .m_doc = "sigrokdecode module", |
Bert Vermeulen | bc5f5a4 | 2012-01-05 03:31:36 +0100 | [diff] [blame] | 44 | .m_size = -1, |
Bert Vermeulen | bc5f5a4 | 2012-01-05 03:31:36 +0100 | [diff] [blame] | 45 | }; |
| 46 | |
Uwe Hermann | 57790bc | 2013-02-09 21:44:11 +0100 | [diff] [blame] | 47 | /** @cond PRIVATE */ |
Uwe Hermann | 53a07a6 | 2012-04-16 23:10:26 +0200 | [diff] [blame] | 48 | /* FIXME: SRD_PRIV causes issues on MinGW. Investigate. */ |
| 49 | PyMODINIT_FUNC PyInit_sigrokdecode(void) |
Bert Vermeulen | bc5f5a4 | 2012-01-05 03:31:36 +0100 | [diff] [blame] | 50 | { |
| 51 | PyObject *mod; |
| 52 | |
Uwe Hermann | 361fdca | 2012-03-15 22:00:24 +0100 | [diff] [blame] | 53 | /* tp_new needs to be assigned here for compiler portability. */ |
Bert Vermeulen | bc5f5a4 | 2012-01-05 03:31:36 +0100 | [diff] [blame] | 54 | srd_Decoder_type.tp_new = PyType_GenericNew; |
| 55 | if (PyType_Ready(&srd_Decoder_type) < 0) |
| 56 | return NULL; |
| 57 | |
| 58 | srd_logic_type.tp_new = PyType_GenericNew; |
| 59 | if (PyType_Ready(&srd_logic_type) < 0) |
| 60 | return NULL; |
| 61 | |
| 62 | mod = PyModule_Create(&sigrokdecode_module); |
| 63 | Py_INCREF(&srd_Decoder_type); |
Uwe Hermann | c9bfccc | 2012-02-08 22:39:30 +0100 | [diff] [blame] | 64 | if (PyModule_AddObject(mod, "Decoder", |
| 65 | (PyObject *)&srd_Decoder_type) == -1) |
Bert Vermeulen | bc5f5a4 | 2012-01-05 03:31:36 +0100 | [diff] [blame] | 66 | return NULL; |
| 67 | Py_INCREF(&srd_logic_type); |
Uwe Hermann | c9bfccc | 2012-02-08 22:39:30 +0100 | [diff] [blame] | 68 | if (PyModule_AddObject(mod, "srd_logic", |
| 69 | (PyObject *)&srd_logic_type) == -1) |
Bert Vermeulen | bc5f5a4 | 2012-01-05 03:31:36 +0100 | [diff] [blame] | 70 | return NULL; |
| 71 | |
Bert Vermeulen | 3e2a9de | 2012-01-07 04:18:16 +0100 | [diff] [blame] | 72 | /* expose output types as symbols in the sigrokdecode module */ |
Uwe Hermann | c9bfccc | 2012-02-08 22:39:30 +0100 | [diff] [blame] | 73 | if (PyModule_AddIntConstant(mod, "OUTPUT_ANN", SRD_OUTPUT_ANN) == -1) |
Bert Vermeulen | 3e2a9de | 2012-01-07 04:18:16 +0100 | [diff] [blame] | 74 | return NULL; |
Uwe Hermann | c9bfccc | 2012-02-08 22:39:30 +0100 | [diff] [blame] | 75 | if (PyModule_AddIntConstant(mod, "OUTPUT_PROTO", |
| 76 | SRD_OUTPUT_PROTO) == -1) |
Bert Vermeulen | 3e2a9de | 2012-01-07 04:18:16 +0100 | [diff] [blame] | 77 | return NULL; |
Uwe Hermann | c9bfccc | 2012-02-08 22:39:30 +0100 | [diff] [blame] | 78 | if (PyModule_AddIntConstant(mod, "OUTPUT_BINARY", |
| 79 | SRD_OUTPUT_BINARY) == -1) |
Bert Vermeulen | 3e2a9de | 2012-01-07 04:18:16 +0100 | [diff] [blame] | 80 | return NULL; |
| 81 | |
Bert Vermeulen | 451680f | 2012-01-15 03:58:27 +0100 | [diff] [blame] | 82 | mod_sigrokdecode = mod; |
| 83 | |
Bert Vermeulen | bc5f5a4 | 2012-01-05 03:31:36 +0100 | [diff] [blame] | 84 | return mod; |
| 85 | } |
Uwe Hermann | 57790bc | 2013-02-09 21:44:11 +0100 | [diff] [blame] | 86 | /** @endcond */ |