#include "libsigrok.h"
#include "libsigrok-internal.h"
+/**
+ * @defgroup grp_session Session handling
+ *
+ * Creating, using, or destroying libsigrok sessions.
+ *
+ * @{
+ */
+
struct source {
int timeout;
sr_receive_data_callback_t cb;
static void sr_dev_close(struct sr_dev_inst *sdi)
{
- if (sdi->driver->dev_close)
+ if (sdi->driver && sdi->driver->dev_close)
sdi->driver->dev_close(sdi);
}
return SR_OK;
}
-/**
- * TODO.
- */
static int sr_session_run_poll(void)
{
unsigned int i;
int ret;
- while (session->running) {
- ret = g_poll(session->pollfds, session->num_sources, session->source_timeout);
-
+ while (session->num_sources > 0) {
+ ret = g_poll(session->pollfds, session->num_sources,
+ session->source_timeout);
for (i = 0; i < session->num_sources; i++) {
if (session->pollfds[i].revents > 0 || (ret == 0
&& session->source_timeout == session->sources[i].timeout)) {
/*
* Invoke the source's callback on an event,
- * or if the poll timeout out and this source
+ * or if the poll timed out and this source
* asked for that timeout.
*/
- if (!session->sources[i].cb(session->pollfds[i].fd, session->pollfds[i].revents,
- session->sources[i].cb_data))
+ if (!session->sources[i].cb(session->pollfds[i].fd,
+ session->pollfds[i].revents,
+ session->sources[i].cb_data))
sr_session_source_remove(session->sources[i].poll_object);
}
}
}
sr_info("session: running");
- session->running = TRUE;
/* Do we have real sources? */
if (session->num_sources == 1 && session->pollfds[0].fd == -1) {
/* Dummy source, freewheel over it. */
- while (session->running)
+ while (session->num_sources)
session->sources[0].cb(-1, 0, session->sources[0].cb_data);
} else {
/* Real sources, use g_poll() main loop. */
}
sr_info("session: stopping");
- session->running = FALSE;
for (l = session->devs; l; l = l->next) {
sdi = l->data;
sr_dbg("bus: received SR_DF_LOGIC %" PRIu64 " bytes", logic->length);
break;
case SR_DF_META_ANALOG:
- sr_dbg("bus: received SR_DF_META_LOGIC");
+ sr_dbg("bus: received SR_DF_META_ANALOG");
break;
case SR_DF_ANALOG:
analog = packet->payload;
* @param packet The datafeed packet to send to the session bus.
*
* @return SR_OK upon success, SR_ERR_ARG upon invalid arguments.
+ *
+ * @private
*/
SR_PRIV int sr_session_send(const struct sr_dev_inst *sdi,
struct sr_datafeed_packet *packet)
/* Note: cb_data can be NULL, that's not a bug. */
- new_pollfds = g_try_realloc(session->pollfds, sizeof(GPollFD) * (session->num_sources + 1));
+ new_pollfds = g_try_realloc(session->pollfds,
+ sizeof(GPollFD) * (session->num_sources + 1));
if (!new_pollfds) {
sr_err("session: %s: new_pollfds malloc failed", __func__);
return SR_ERR_MALLOC;
}
new_sources = g_try_realloc(session->sources, sizeof(struct source) *
- (session->num_sources + 1));
+ (session->num_sources + 1));
if (!new_sources) {
sr_err("session: %s: new_sources malloc failed", __func__);
return SR_ERR_MALLOC;
{
return _sr_session_source_remove((gintptr)channel);
}
+
+/** @} */