-/**
- * @defgroup grp_session Session handling
- *
- * Starting and handling decoding sessions.
- *
- * @{
- */
-
-/**
- * Start a decoding session.
- *
- * Decoders, instances and stack must have been prepared beforehand.
- *
- * @param num_probes The number of probes which the incoming feed will contain.
- * @param unitsize The number of bytes per sample in the incoming feed.
- * @param samplerate The samplerate of the incoming feed.
- *
- * @return SRD_OK upon success, a (negative) error code otherwise.
- *
- * @since 0.1.0
- */
-SRD_API int srd_session_start(int num_probes, int unitsize, uint64_t samplerate)
-{
- PyObject *args;
- GSList *d;
- struct srd_decoder_inst *di;
- int ret;
-
- ret = SRD_OK;
-
- 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_inst_start(di, args)) != SRD_OK)
- break;
- }
-
- Py_DecRef(args);
-
- return ret;
-}
-
-/**
- * Send a chunk of logic sample data to a running decoder session.
- *
- * @param start_samplenum The sample number of the first sample in this chunk.
- * @param inbuf Pointer to sample data.
- * @param inbuflen Length in bytes of the buffer.
- *
- * @return SRD_OK upon success, a (negative) error code otherwise.
- *
- * @since 0.1.0
- */
-SRD_API int srd_session_send(uint64_t start_samplenum, const 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_inst_decode(start_samplenum, d->data, inbuf,
- inbuflen)) != SRD_OK)
- return ret;
- }
-
- return SRD_OK;
-}
-
-/**
- * Register/add a decoder output callback function.
- *
- * The function will be called when a protocol decoder sends output back
- * to the PD controller (except for Python objects, which only go up the
- * stack).
- *
- * @param output_type The output type this callback will receive. Only one
- * callback per output type can be registered.
- * @param cb The function to call. Must not be NULL.
- * @param cb_data Private data for the callback function. Can be NULL.
- *
- * @since 0.1.0
- */
-SRD_API int srd_pd_output_callback_add(int output_type,
- srd_pd_output_callback_t cb, void *cb_data)
-{
- 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)))) {
- srd_err("Failed to g_malloc() struct srd_pd_callback.");
- return SRD_ERR_MALLOC;
- }
-
- pd_cb->output_type = output_type;
- pd_cb->cb = cb;
- pd_cb->cb_data = cb_data;
- callbacks = g_slist_append(callbacks, pd_cb);
-
- return SRD_OK;
-}
-
-/** @private */
-SRD_PRIV void *srd_pd_output_callback_find(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->cb;
- break;
- }
- }
-
- return cb;
-}
-
-/* This is the backend function to Python sigrokdecode.add() call. */
-/** @private */
-SRD_PRIV int srd_inst_pd_output_add(struct srd_decoder_inst *di,
- int output_type, const char *proto_id)
-{
- struct srd_pd_output *pdo;
-
- srd_dbg("Instance %s creating new output type %d for %s.",
- di->inst_id, output_type, proto_id);
-
- if (!(pdo = g_try_malloc(sizeof(struct srd_pd_output)))) {
- srd_err("Failed to g_malloc() 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;
-}
-
-/** @} */