summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerhard Sittig <gerhard.sittig@gmx.net>2018-01-26 21:02:25 +0100
committerUwe Hermann <uwe@hermann-uwe.de>2018-03-31 20:44:21 +0200
commit7d82e3c1ec96ac8a9ef358de1e9c87715dcb8f43 (patch)
tree5504e0838196e3fc27e576d9c696b264132f9eb6
parentcd8d918846a00847f2e8e15ba1642882c34a1ff3 (diff)
downloadlibsigrokdecode-7d82e3c1ec96ac8a9ef358de1e9c87715dcb8f43.tar.gz
libsigrokdecode-7d82e3c1ec96ac8a9ef358de1e9c87715dcb8f43.zip
Decoder: check for duplicate register() calls in common backend code
Future implementations might call decoders' start() routine several times, which makes them call register() again. It's desirable that the common backend code copes with this condition, such that (the multitude of) decoder implementations need not work around a specific constraint.
-rw-r--r--type_decoder.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/type_decoder.c b/type_decoder.c
index 7c71132..06842f9 100644
--- a/type_decoder.c
+++ b/type_decoder.c
@@ -361,6 +361,9 @@ static PyObject *Decoder_register(PyObject *self, PyObject *args,
char *proto_id, *meta_name, *meta_descr;
char *keywords[] = {"output_type", "proto_id", "meta", NULL};
PyGILState_STATE gstate;
+ gboolean is_meta;
+ GSList *l;
+ struct srd_pd_output *cmp;
gstate = PyGILState_Ensure();
@@ -383,7 +386,8 @@ static PyObject *Decoder_register(PyObject *self, PyObject *args,
}
/* Check if the meta value's type is supported. */
- if (output_type == SRD_OUTPUT_META) {
+ is_meta = output_type == SRD_OUTPUT_META;
+ if (is_meta) {
if (meta_type_py == &PyLong_Type)
meta_type_gv = G_VARIANT_TYPE_INT64;
else if (meta_type_py == &PyFloat_Type)
@@ -394,6 +398,30 @@ static PyObject *Decoder_register(PyObject *self, PyObject *args,
}
}
+ srd_dbg("Instance %s checking registration type %d for %s.",
+ di->inst_id, output_type, proto_id);
+ pdo = NULL;
+ for (l = di->pd_output; l; l = l->next) {
+ cmp = l->data;
+ if (cmp->output_type != output_type)
+ continue;
+ if (strcmp(cmp->proto_id, proto_id) != 0)
+ continue;
+ if (is_meta && cmp->meta_type != meta_type_gv)
+ continue;
+ if (is_meta && strcmp(cmp->meta_name, meta_name) != 0)
+ continue;
+ if (is_meta && strcmp(cmp->meta_descr, meta_descr) != 0)
+ continue;
+ pdo = cmp;
+ break;
+ }
+ if (pdo) {
+ py_new_output_id = Py_BuildValue("i", pdo->pdo_id);
+ PyGILState_Release(gstate);
+ return py_new_output_id;
+ }
+
srd_dbg("Instance %s creating new output type %d for %s.",
di->inst_id, output_type, proto_id);