/* 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.
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;
return NULL; /* TODO: More specific error? */
}
+ /* Append to list of PD instances */
+ decoders = g_slist_append(decoders, di);
+
Py_XDECREF(py_args);
return 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;
}
*
* @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. */
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;
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
*/
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