diff options
author | Uwe Hermann <uwe@hermann-uwe.de> | 2017-06-16 16:32:24 +0200 |
---|---|---|
committer | Uwe Hermann <uwe@hermann-uwe.de> | 2017-06-16 16:36:39 +0200 |
commit | eb88372396c2264948bc05586fb54dc318266973 (patch) | |
tree | a6ddaa73878fc0c5e0c891168d85e3ac7a384c09 | |
parent | b197383cfb39b39ff04644855eef57f5d3c18bc1 (diff) | |
download | libsigrokdecode-eb88372396c2264948bc05586fb54dc318266973.tar.gz libsigrokdecode-eb88372396c2264948bc05586fb54dc318266973.zip |
Drop support for PD API version 2.
All decoders must be of PD API version 3 now.
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | decoder.c | 4 | ||||
-rw-r--r-- | instance.c | 85 | ||||
-rw-r--r-- | module_sigrokdecode.c | 11 | ||||
-rw-r--r-- | type_logic.c | 97 |
5 files changed, 28 insertions, 170 deletions
diff --git a/Makefile.am b/Makefile.am index 675b460..97e5228 100644 --- a/Makefile.am +++ b/Makefile.am @@ -44,7 +44,6 @@ libsigrokdecode_la_SOURCES = \ exception.c \ module_sigrokdecode.c \ type_decoder.c \ - type_logic.c \ error.c \ version.c @@ -686,8 +686,8 @@ SRD_API int srd_decoder_load(const char *module_name) * PDs of different API versions are incompatible and cannot work. */ apiver = srd_decoder_apiver(d); - if (apiver != 2 && apiver != 3) { - srd_exception_catch("Only PD API version 2/3 is supported, " + if (apiver != 3) { + srd_exception_catch("Only PD API version 3 is supported, " "decoder %s has version %ld", module_name, apiver); fail_txt = "API version mismatch"; goto err_out; @@ -30,9 +30,6 @@ extern SRD_PRIV GSList *sessions; -/* module_sigrokdecode.c */ -extern SRD_PRIV PyObject *srd_logic_type; - static void srd_inst_join_decode_thread(struct srd_decoder_inst *di); static void srd_inst_reset_state(struct srd_decoder_inst *di); SRD_PRIV void oldpins_array_free(struct srd_decoder_inst *di); @@ -1161,10 +1158,6 @@ SRD_PRIV int srd_inst_decode(struct srd_decoder_inst *di, uint64_t abs_start_samplenum, uint64_t abs_end_samplenum, const uint8_t *inbuf, uint64_t inbuflen, uint64_t unitsize) { - PyObject *py_res; - srd_logic *logic; - long apiver; - /* Return an error upon unusable input. */ if (!di) { srd_dbg("empty decoder instance"); @@ -1199,61 +1192,33 @@ SRD_PRIV int srd_inst_decode(struct srd_decoder_inst *di, abs_end_samplenum - abs_start_samplenum, inbuflen, di->data_unitsize, di->inst_id); - apiver = srd_decoder_apiver(di->decoder); + /* If this is the first call, start the worker thread. */ + if (!di->thread_handle) { + srd_dbg("No worker thread for this decoder stack " + "exists yet, creating one: %s.", di->inst_id); + di->thread_handle = g_thread_new(di->inst_id, + di_thread, di); + } - if (apiver == 2) { - /* - * Create new srd_logic object. Each iteration around the PD's - * loop will fill one sample into this object. - */ - logic = PyObject_New(srd_logic, (PyTypeObject *)srd_logic_type); - Py_INCREF(logic); - logic->di = (struct srd_decoder_inst *)di; - logic->abs_start_samplenum = abs_start_samplenum; - logic->itercnt = 0; - logic->inbuf = (uint8_t *)inbuf; - logic->inbuflen = inbuflen; - logic->sample = PyList_New(2); - Py_INCREF(logic->sample); - - Py_IncRef(di->py_inst); - if (!(py_res = PyObject_CallMethod(di->py_inst, "decode", - "KKO", abs_start_samplenum, abs_end_samplenum, logic))) { - srd_exception_catch("Protocol decoder instance %s", - di->inst_id); - return SRD_ERR_PYTHON; - } - di->abs_cur_samplenum = abs_end_samplenum; - Py_DecRef(py_res); - } else { - /* If this is the first call, start the worker thread. */ - if (!di->thread_handle) { - srd_dbg("No worker thread for this decoder stack " - "exists yet, creating one: %s.", di->inst_id); - di->thread_handle = g_thread_new(di->inst_id, - di_thread, di); - } + /* Push the new sample chunk to the worker thread. */ + g_mutex_lock(&di->data_mutex); + di->abs_start_samplenum = abs_start_samplenum; + di->abs_end_samplenum = abs_end_samplenum; + di->inbuf = inbuf; + di->inbuflen = inbuflen; + di->got_new_samples = TRUE; + di->handled_all_samples = FALSE; + di->want_wait_terminate = FALSE; - /* Push the new sample chunk to the worker thread. */ - g_mutex_lock(&di->data_mutex); - di->abs_start_samplenum = abs_start_samplenum; - di->abs_end_samplenum = abs_end_samplenum; - di->inbuf = inbuf; - di->inbuflen = inbuflen; - di->got_new_samples = TRUE; - di->handled_all_samples = FALSE; - di->want_wait_terminate = FALSE; - - /* Signal the thread that we have new data. */ - g_cond_signal(&di->got_new_samples_cond); - g_mutex_unlock(&di->data_mutex); - - /* When all samples in this chunk were handled, return. */ - g_mutex_lock(&di->data_mutex); - while (!di->handled_all_samples && !di->want_wait_terminate) - g_cond_wait(&di->handled_all_samples_cond, &di->data_mutex); - g_mutex_unlock(&di->data_mutex); - } + /* Signal the thread that we have new data. */ + g_cond_signal(&di->got_new_samples_cond); + g_mutex_unlock(&di->data_mutex); + + /* When all samples in this chunk were handled, return. */ + g_mutex_lock(&di->data_mutex); + while (!di->handled_all_samples && !di->want_wait_terminate) + g_cond_wait(&di->handled_all_samples_cond, &di->data_mutex); + g_mutex_unlock(&di->data_mutex); return SRD_OK; } diff --git a/module_sigrokdecode.c b/module_sigrokdecode.c index 17563c1..a0d9610 100644 --- a/module_sigrokdecode.c +++ b/module_sigrokdecode.c @@ -23,8 +23,6 @@ /** @cond PRIVATE */ -SRD_PRIV PyObject *srd_logic_type = NULL; - /* * When initialized, a reference to this module inside the Python interpreter * lives here. @@ -43,7 +41,7 @@ static struct PyModuleDef sigrokdecode_module = { /** @cond PRIVATE */ PyMODINIT_FUNC PyInit_sigrokdecode(void) { - PyObject *mod, *Decoder_type, *logic_type; + PyObject *mod, *Decoder_type; mod = PyModule_Create(&sigrokdecode_module); if (!mod) @@ -55,12 +53,6 @@ PyMODINIT_FUNC PyInit_sigrokdecode(void) if (PyModule_AddObject(mod, "Decoder", Decoder_type) < 0) goto err_out; - logic_type = srd_logic_type_new(); - if (!logic_type) - goto err_out; - if (PyModule_AddObject(mod, "srd_logic", logic_type) < 0) - goto err_out; - /* Expose output types as symbols in the sigrokdecode module */ if (PyModule_AddIntConstant(mod, "OUTPUT_ANN", SRD_OUTPUT_ANN) < 0) goto err_out; @@ -74,7 +66,6 @@ PyMODINIT_FUNC PyInit_sigrokdecode(void) if (PyModule_AddIntConstant(mod, "SRD_CONF_SAMPLERATE", SRD_CONF_SAMPLERATE) < 0) goto err_out; - srd_logic_type = logic_type; mod_sigrokdecode = mod; return mod; diff --git a/type_logic.c b/type_logic.c deleted file mode 100644 index ba356c0..0000000 --- a/type_logic.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * This file is part of the libsigrokdecode project. - * - * Copyright (C) 2012 Bert Vermeulen <bert@biot.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <config.h> -#include "libsigrokdecode-internal.h" /* First, so we avoid a _POSIX_C_SOURCE warning. */ -#include "libsigrokdecode.h" -#include <inttypes.h> -#include <string.h> - -static PyObject *srd_logic_iter(PyObject *self) -{ - return self; -} - -static PyObject *srd_logic_iternext(PyObject *self) -{ - srd_logic *logic; - PyObject *py_samplenum, *py_samples; - uint8_t *sample_pos, sample; - int byte_offset, bit_offset, i; - - logic = (srd_logic *)self; - if (logic->itercnt >= logic->inbuflen / logic->di->data_unitsize) { - /* End iteration loop. */ - return NULL; - } - - /* - * Convert the bit-packed sample to an array of bytes, with only 0x01 - * and 0x00 values, so the PD doesn't need to do any bitshifting. - */ - sample_pos = logic->inbuf + logic->itercnt * logic->di->data_unitsize; - for (i = 0; i < logic->di->dec_num_channels; i++) { - /* A channelmap value of -1 means "unused optional channel". */ - if (logic->di->dec_channelmap[i] == -1) { - /* Value of unused channel is 0xff, instead of 0 or 1. */ - logic->di->channel_samples[i] = 0xff; - } else { - byte_offset = logic->di->dec_channelmap[i] / 8; - bit_offset = logic->di->dec_channelmap[i] % 8; - sample = *(sample_pos + byte_offset) & (1 << bit_offset) ? 1 : 0; - logic->di->channel_samples[i] = sample; - } - } - - /* Prepare the next samplenum/sample list in this iteration. */ - py_samplenum = - PyLong_FromUnsignedLongLong(logic->abs_start_samplenum + - logic->itercnt); - PyList_SetItem(logic->sample, 0, py_samplenum); - py_samples = PyBytes_FromStringAndSize((const char *)logic->di->channel_samples, - logic->di->dec_num_channels); - PyList_SetItem(logic->sample, 1, py_samples); - Py_INCREF(logic->sample); - logic->itercnt++; - - return logic->sample; -} - -/** Create the srd_logic type. - * @return The new type object. - * @private - */ -SRD_PRIV PyObject *srd_logic_type_new(void) -{ - PyType_Spec spec; - PyType_Slot slots[] = { - { Py_tp_doc, "sigrokdecode logic sample object" }, - { Py_tp_iter, (void *)&srd_logic_iter }, - { Py_tp_iternext, (void *)&srd_logic_iternext }, - { Py_tp_new, (void *)&PyType_GenericNew }, - { 0, NULL } - }; - spec.name = "srd_logic"; - spec.basicsize = sizeof(srd_logic); - spec.itemsize = 0; - spec.flags = Py_TPFLAGS_DEFAULT; - spec.slots = slots; - - return PyType_FromSpec(&spec); -} |