summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGareth McMullin <gareth@blacksphere.co.nz>2011-11-28 22:54:18 +1300
committerGareth McMullin <gareth@blacksphere.co.nz>2011-11-28 22:54:18 +1300
commit60b928b2c9d3fa31f42c25613f2f07bc9e44fff5 (patch)
tree2497bf69d5070421384047bf810aaf3e68c82c64
parent73e542a4611411411a6df4843d62576e25ddeb7c (diff)
downloadlibsigrokdecode-60b928b2c9d3fa31f42c25613f2f07bc9e44fff5.tar.gz
libsigrokdecode-60b928b2c9d3fa31f42c25613f2f07bc9e44fff5.zip
srd: Moved instance list to libsigrokdecode.
Functions changed to srd_session_start() to initialise the session, and srd_session_feed() to feed sample data to the decoders.
-rw-r--r--decode.c64
-rw-r--r--sigrokdecode.h9
2 files changed, 46 insertions, 27 deletions
diff --git a/decode.c b/decode.c
index fed9fa7..6a86b34 100644
--- a/decode.c
+++ b/decode.c
@@ -33,6 +33,8 @@
/* The list of protocol decoders. */
static GSList *list_pds = NULL;
+/* The list of protocol decoder instances: struct srd_decoder_instance */
+static GSList *decoders;
/*
* Here's a quick overview of Python/C API reference counting.
@@ -308,6 +310,7 @@ static int srd_load_decoder(const char *name, struct srd_decoder **dec)
return SRD_OK;
}
+/** Create a new decoder instance and add to session. */
struct srd_decoder_instance *srd_instance_new(const char *id)
{
struct srd_decoder *dec;
@@ -337,6 +340,9 @@ struct srd_decoder_instance *srd_instance_new(const char *id)
return NULL; /* TODO: More specific error? */
}
+ /* Append to list of PD instances */
+ decoders = g_slist_append(decoders, di);
+
Py_XDECREF(py_args);
return di;
@@ -364,24 +370,29 @@ int srd_instance_set_probe(struct srd_decoder_instance *di,
return SRD_OK;
}
-int srd_instance_start(struct srd_decoder_instance *di,
- const char *driver, int unitsize, uint64_t starttime,
+/** Start decoding session. Feed metadata to decoder instances. */
+int srd_session_start(const char *driver, int unitsize, uint64_t starttime,
uint64_t samplerate)
{
PyObject *py_res;
-
- if (!(py_res = PyObject_CallMethod(di->py_instance, "start",
- "{s:s,s:l,s:l,s:l}",
- "driver", driver,
- "unitsize", (long)unitsize,
- "starttime", (long)starttime,
- "samplerate", (long)samplerate))) {
- if (PyErr_Occurred())
- PyErr_Print(); /* Returns void. */
-
- return SRD_ERR_PYTHON; /* TODO: More specific error? */
+ GSList *d;
+ for (d = decoders; d; d = d->next) {
+ struct srd_decoder_instance *di = d->data;
+ /* TODO: Error handling. */
+ if (!(py_res = PyObject_CallMethod(di->py_instance, "start",
+ "{s:s,s:l,s:l,s:l}",
+ "driver", driver,
+ "unitsize", (long)unitsize,
+ "starttime", (long)starttime,
+ "samplerate", (long)samplerate))) {
+ if (PyErr_Occurred())
+ PyErr_Print(); /* Returns void. */
+
+ return SRD_ERR_PYTHON; /* TODO: More specific error? */
+ }
+ Py_XDECREF(py_res);
}
- Py_XDECREF(py_res);
+
return SRD_OK;
}
@@ -396,9 +407,8 @@ int srd_instance_start(struct srd_decoder_instance *di,
*
* @return SRD_OK upon success, a (negative) error code otherwise.
*/
-int srd_run_decoder(struct srd_decoder_instance *dec,
- uint8_t *inbuf, uint64_t inbuflen,
- uint8_t **outbuf, uint64_t *outbuflen)
+static int srd_run_decoder(struct srd_decoder_instance *dec,
+ uint8_t *inbuf, uint64_t inbuflen)
{
PyObject *py_instance, *py_res;
/* FIXME: Don't have a timebase available here. Make one up. */
@@ -415,10 +425,6 @@ int srd_run_decoder(struct srd_decoder_instance *dec,
return SRD_ERR_ARGS; /* TODO: More specific error? */
if (inbuflen == 0) /* No point in working on empty buffers. */
return SRD_ERR_ARGS; /* TODO: More specific error? */
- if (outbuf == NULL)
- return SRD_ERR_ARGS; /* TODO: More specific error? */
- if (outbuflen == NULL)
- return SRD_ERR_ARGS; /* TODO: More specific error? */
/* TODO: Error handling. */
py_instance = dec->py_instance;
@@ -439,6 +445,22 @@ int srd_run_decoder(struct srd_decoder_instance *dec,
return SRD_OK;
}
+/* Feed logic samples to decoder session. */
+int srd_session_feed(uint8_t *inbuf, uint64_t inbuflen)
+{
+ GSList *d;
+ for (d = decoders; d; d = d->next) {
+ /* TODO: Error handling. */
+
+ int ret = srd_run_decoder(d->data, inbuf, inbuflen);
+
+ if (ret != SRD_OK) {
+ fprintf(stderr, "Decoder runtime error (%d)\n", ret);
+ exit(1);
+ }
+ }
+}
+
/**
* TODO
*/
diff --git a/sigrokdecode.h b/sigrokdecode.h
index 27f2734..b7ed2dc 100644
--- a/sigrokdecode.h
+++ b/sigrokdecode.h
@@ -102,15 +102,12 @@ struct srd_decoder_instance {
int srd_init(void);
GSList *srd_list_decoders(void);
struct srd_decoder *srd_get_decoder_by_id(const char *id);
-int srd_run_decoder(struct srd_decoder_instance *dec,
- uint8_t *inbuf, uint64_t inbuflen,
- uint8_t **outbuf, uint64_t *outbuflen);
struct srd_decoder_instance *srd_instance_new(const char *id);
int srd_instance_set_probe(struct srd_decoder_instance *di,
const char *probename, int num);
-int srd_instance_start(struct srd_decoder_instance *di,
- const char *driver, int unitsize, uint64_t starttime,
- uint64_t samplerate);
+int srd_session_start(const char *driver, int unitsize, uint64_t starttime,
+ uint64_t samplerate);
+int srd_session_feed(uint8_t *inbuf, uint64_t inbuflen);
int srd_exit(void);
#ifdef __cplusplus