]> sigrok.org Git - libsigrok.git/blobdiff - session.c
device: Make some parameters const.
[libsigrok.git] / session.c
index 6e597ab34dd87065a0fc3bd23e16d2b4c45abb11..549666375ad5923e5889de906740f10ce7880daa 100644 (file)
--- a/session.c
+++ b/session.c
@@ -54,6 +54,7 @@ struct sr_session *sr_session_new(void)
 
 void sr_session_destroy(void)
 {
+
        g_slist_free(session->devices);
 
        /* TODO: Loop over protocol decoders and free them. */
@@ -71,8 +72,8 @@ 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;
        }
@@ -144,8 +145,9 @@ static void sr_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);
                        }
                }
        }
@@ -210,6 +212,33 @@ void sr_session_stop(void)
 
 }
 
+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 sr_session_bus(struct sr_device *device, struct sr_datafeed_packet *packet)
 {
        GSList *l;
@@ -221,6 +250,7 @@ void sr_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);
        }
 }
@@ -260,7 +290,7 @@ void sr_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));