X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=session.c;h=caa794a142377ca75953ba032ee53dd08984ba3c;hb=5e59cfbfc736aab9e79caef4ab6bdcbc500e254f;hp=7732629131c1a0f4957ef71546a643c571c6a9cd;hpb=22b02383442ec55a11cc6dd2b4c467d1de0b5bd2;p=libsigrok.git diff --git a/session.c b/session.c index 77326291..caa794a1 100644 --- a/session.c +++ b/session.c @@ -23,7 +23,8 @@ #include #include #include -#include +#include "sigrok.h" +#include "sigrok-internal.h" /* demo.c */ extern GIOChannel channels[2]; @@ -32,26 +33,26 @@ struct source { int fd; int events; int timeout; - receive_data_callback cb; + sr_receive_data_callback cb; void *user_data; }; /* There can only be one session at a time. */ -struct session *session; -int num_sources = 0; +/* 'session' is not static, it's used elsewhere (via 'extern'). */ +struct sr_session *session; +static int num_sources = 0; -struct source *sources = NULL; -int source_timeout = -1; +static struct source *sources = NULL; +static int source_timeout = -1; - -struct session *session_new(void) +struct sr_session *sr_session_new(void) { - session = calloc(1, sizeof(struct session)); + session = calloc(1, sizeof(struct sr_session)); return session; } -void session_destroy(void) +void sr_session_destroy(void) { g_slist_free(session->devices); @@ -60,18 +61,18 @@ void session_destroy(void) g_free(session); } -void session_device_clear(void) +void sr_session_device_clear(void) { g_slist_free(session->devices); session->devices = NULL; } -int session_device_add(struct sr_device *device) +int sr_session_device_add(struct sr_device *device) { int ret; - if (device->plugin && device->plugin->open) { - ret = device->plugin->open(device->plugin_index); + if (device->plugin && device->plugin->opendev) { + ret = device->plugin->opendev(device->plugin_index); if (ret != SR_OK) return ret; } @@ -81,7 +82,8 @@ int session_device_add(struct sr_device *device) return SR_OK; } -void session_pa_clear(void) +#if 0 +void sr_session_pa_clear(void) { /* * The protocols are pointers to the global set of PA plugins, @@ -91,24 +93,25 @@ void session_pa_clear(void) session->analyzers = NULL; } -void session_pa_add(struct analyzer *an) +void sr_session_pa_add(struct sr_analyzer *an) { session->analyzers = g_slist_append(session->analyzers, an); } +#endif -void session_datafeed_callback_clear(void) +void sr_session_datafeed_callback_clear(void) { g_slist_free(session->datafeed_callbacks); session->datafeed_callbacks = NULL; } -void session_datafeed_callback_add(datafeed_callback callback) +void sr_session_datafeed_callback_add(sr_datafeed_callback callback) { session->datafeed_callbacks = g_slist_append(session->datafeed_callbacks, callback); } -static void session_run_poll() +static void sr_session_run_poll() { GPollFD *fds, my_gpollfd; int ret, i; @@ -141,22 +144,22 @@ static void session_run_poll() * or if the poll timeout out and this source * asked for that timeout. */ - sources[i].cb(fds[i].fd, fds[i].revents, - sources[i].user_data); + if (!sources[i].cb(fds[i].fd, fds[i].revents, + sources[i].user_data)) + sr_session_source_remove(sources[i].fd); } } } free(fds); - } -int session_start(void) +int sr_session_start(void) { struct sr_device *device; GSList *l; int ret; - g_message("session: starting"); + sr_info("session: starting"); for (l = session->devices; l; l = l->next) { device = l->data; if ((ret = device->plugin->start_acquisition( @@ -167,10 +170,9 @@ int session_start(void) return ret; } -void session_run(void) +void sr_session_run(void) { - - g_message("session: running"); + sr_info("session: running"); session->running = TRUE; /* do we have real sources? */ @@ -180,37 +182,59 @@ void session_run(void) sources[0].cb(-1, 0, sources[0].user_data); else /* real sources, use g_poll() main loop */ - session_run_poll(); - + sr_session_run_poll(); } -void session_halt(void) +void sr_session_halt(void) { - - g_message("session: halting"); + sr_info("session: halting"); session->running = FALSE; - } -void session_stop(void) +void sr_session_stop(void) { struct sr_device *device; GSList *l; - g_message("session: stopping"); + sr_info("session: stopping"); session->running = FALSE; for (l = session->devices; l; l = l->next) { device = l->data; if (device->plugin && device->plugin->stop_acquisition) device->plugin->stop_acquisition(device->plugin_index, device); } +} +static void datafeed_dump(struct sr_datafeed_packet *packet) +{ + struct sr_datafeed_logic *logic; + + switch (packet->type) { + case SR_DF_HEADER: + sr_dbg("bus: received SR_DF_HEADER"); + break; + case SR_DF_TRIGGER: + sr_dbg("bus: received SR_DF_TRIGGER at %lu ms", + packet->timeoffset / 1000000); + break; + case SR_DF_LOGIC: + logic = packet->payload; + sr_dbg("bus: received SR_DF_LOGIC at %f ms duration %f ms, %"PRIu64" bytes", + packet->timeoffset / 1000000.0, packet->duration / 1000000.0, + logic->length); + break; + case SR_DF_END: + sr_dbg("bus: received SR_DF_END"); + break; + default: + sr_dbg("bus: received unknown packet type %d", packet->type); + } } -void session_bus(struct sr_device *device, struct sr_datafeed_packet *packet) +void sr_session_bus(struct sr_device *device, struct sr_datafeed_packet *packet) { GSList *l; - datafeed_callback cb; + sr_datafeed_callback cb; /* * TODO: Send packet through PD pipe, and send the output of that to @@ -218,12 +242,13 @@ void session_bus(struct sr_device *device, struct sr_datafeed_packet *packet) */ for (l = session->datafeed_callbacks; l; l = l->next) { cb = l->data; + datafeed_dump(packet); cb(device, packet); } } -void session_source_add(int fd, int events, int timeout, - receive_data_callback callback, void *user_data) +void sr_session_source_add(int fd, int events, int timeout, + sr_receive_data_callback callback, void *user_data) { struct source *new_sources, *s; @@ -248,7 +273,7 @@ void session_source_add(int fd, int events, int timeout, source_timeout = timeout; } -void session_source_remove(int fd) +void sr_session_source_remove(int fd) { struct source *new_sources; int old, new; @@ -257,7 +282,7 @@ void session_source_remove(int fd) return; new_sources = calloc(1, sizeof(struct source) * num_sources); - for (old = 0; old < num_sources; old++) + for (old = 0, new = 0; old < num_sources; old++) if (sources[old].fd != fd) memcpy(&new_sources[new++], &sources[old], sizeof(struct source)); @@ -271,4 +296,3 @@ void session_source_remove(int fd) free(new_sources); } } -