-int srd_session_start(int num_probes, int unitsize, uint64_t samplerate)
-{
- PyObject *args;
- GSList *d;
- struct srd_decoder_instance *di;
- int ret;
-
- srd_dbg("Calling start() on all instances with %d probes, "
- "unitsize %d samplerate %d.", num_probes, unitsize, samplerate);
-
- /* Currently only one item of metadata is passed along to decoders,
- * samplerate. This can be extended as needed.
- */
- if (!(args = Py_BuildValue("{s:l}", "samplerate", (long)samplerate))) {
- srd_err("Unable to build python object for metadata.");
- return SRD_ERR_PYTHON;
- }
-
- /* Run the start() method on all decoders receiving frontend data. */
- for (d = di_list; d; d = d->next) {
- di = d->data;
- di->data_num_probes = num_probes;
- di->data_unitsize = unitsize;
- di->data_samplerate = samplerate;
- if ((ret = srd_instance_start(di, args) != SRD_OK))
- break;
- }
-
- Py_DecRef(args);
-
- return ret;
-}
-
-/* Feed logic samples to decoder session. */
-int srd_session_feed(uint64_t start_samplenum, uint8_t *inbuf, uint64_t inbuflen)
-{
- GSList *d;
- int ret;
-
- srd_dbg("Calling decode() on all instances with starting sample "
- "number %"PRIu64", %"PRIu64" bytes at 0x%p", start_samplenum,
- inbuflen, inbuf);
-
- for (d = di_list; d; d = d->next) {
- if ((ret = srd_instance_decode(start_samplenum, d->data, inbuf,
- inbuflen)) != SRD_OK)
- return ret;
- }
-
- return SRD_OK;
-}
-
-
-int srd_register_callback(int output_type, void *cb)
-{
- struct srd_pd_callback *pd_cb;
-
- srd_dbg("Registering new callback for output type %d.", output_type);
-
- if (!(pd_cb = g_try_malloc(sizeof(struct srd_pd_callback))))
- return SRD_ERR_MALLOC;
-
- pd_cb->output_type = output_type;
- pd_cb->callback = cb;
- callbacks = g_slist_append(callbacks, pd_cb);
-
- return SRD_OK;
-}
-
-void *srd_find_callback(int output_type)
-{
- GSList *l;
- struct srd_pd_callback *pd_cb;
- void *(cb);
-
- cb = NULL;
- for (l = callbacks; l; l = l->next) {
- pd_cb = l->data;
- if (pd_cb->output_type == output_type) {
- cb = pd_cb->callback;
- break;
- }
- }
-
- return cb;
-}
-
-
-/* This is the backend function to python sigrokdecode.add() call. */
-int pd_add(struct srd_decoder_instance *di, int output_type, char *proto_id)
-{
- struct srd_pd_output *pdo;
-
- srd_dbg("Instance %s creating new output type %d for %s.",
- di->instance_id, output_type, proto_id);
-
- if (!(pdo = g_try_malloc(sizeof(struct srd_pd_output))))
- return -1;
-
- /* pdo_id is just a simple index, nothing is deleted from this list anyway. */
- pdo->pdo_id = g_slist_length(di->pd_output);
- pdo->output_type = output_type;
- pdo->di = di;
- pdo->proto_id = g_strdup(proto_id);
- di->pd_output = g_slist_append(di->pd_output, pdo);
-
- return pdo->pdo_id;
-}