]> sigrok.org Git - libsigrok.git/blobdiff - src/session.c
Enable loading of session files without total probes defined
[libsigrok.git] / src / session.c
index c84edcbfdb27ed0c9119727dbf00ba2c5db40b07..5a68c8df4e142081c704cd56771efdadc51bc66b 100644 (file)
@@ -117,21 +117,12 @@ static gboolean fd_source_dispatch(GSource *source,
                GSourceFunc callback, void *user_data)
 {
        struct fd_source *fsource;
-       const char *name;
        unsigned int revents;
        gboolean keep;
 
        fsource = (struct fd_source *)source;
-       name = g_source_get_name(source);
        revents = fsource->pollfd.revents;
 
-       if (revents != 0) {
-               sr_spew("%s: %s " G_POLLFD_FORMAT ", revents 0x%.2X",
-                       __func__, name, fsource->pollfd.fd, revents);
-       } else {
-               sr_spew("%s: %s " G_POLLFD_FORMAT ", timed out",
-                       __func__, name, fsource->pollfd.fd);
-       }
        if (!callback) {
                sr_err("Callback not set, cannot dispatch event.");
                return G_SOURCE_REMOVE;
@@ -265,6 +256,8 @@ SR_API int sr_session_destroy(struct sr_session *session)
        sr_session_dev_remove_all(session);
        g_slist_free_full(session->owned_devs, (GDestroyNotify)sr_dev_inst_free);
 
+       sr_session_datafeed_callback_remove_all(session);
+
        g_hash_table_unref(session->event_sources);
 
        g_mutex_clear(&session->main_mutex);
@@ -412,6 +405,45 @@ SR_API int sr_session_dev_list(struct sr_session *session, GSList **devlist)
        return SR_OK;
 }
 
+/**
+ * Remove a device instance from a session.
+ *
+ * @param session The session to remove from. Must not be NULL.
+ * @param sdi The device instance to remove from a session. Must not
+ *            be NULL. Also, sdi->driver and sdi->driver->dev_open must
+ *            not be NULL.
+ *
+ * @retval SR_OK Success.
+ * @retval SR_ERR_ARG Invalid argument.
+ *
+ * @since 0.4.0
+ */
+SR_API int sr_session_dev_remove(struct sr_session *session,
+               struct sr_dev_inst *sdi)
+{
+       if (!sdi) {
+               sr_err("%s: sdi was NULL", __func__);
+               return SR_ERR_ARG;
+       }
+
+       if (!session) {
+               sr_err("%s: session was NULL", __func__);
+               return SR_ERR_ARG;
+       }
+
+       /* If sdi->session is not session, the device is not in this
+        * session. */
+       if (sdi->session != session) {
+               sr_err("%s: not assigned to this session", __func__);
+               return SR_ERR_ARG;
+       }
+
+       session->devs = g_slist_remove(session->devs, sdi);
+       sdi->session = NULL;
+
+       return SR_OK;
+}
+
 /**
  * Remove all datafeed callbacks in a session.
  *
@@ -1493,7 +1525,7 @@ SR_PRIV int sr_packet_copy(const struct sr_datafeed_packet *packet,
                break;
        case SR_DF_LOGIC:
                logic = packet->payload;
-               logic_copy = g_malloc(sizeof(logic));
+               logic_copy = g_malloc(sizeof(*logic_copy));
                logic_copy->length = logic->length;
                logic_copy->unitsize = logic->unitsize;
                memcpy(logic_copy->data, logic->data, logic->length * logic->unitsize);
@@ -1501,7 +1533,7 @@ SR_PRIV int sr_packet_copy(const struct sr_datafeed_packet *packet,
                break;
        case SR_DF_ANALOG_OLD:
                analog_old = packet->payload;
-               analog_old_copy = g_malloc(sizeof(analog_old));
+               analog_old_copy = g_malloc(sizeof(*analog_old_copy));
                analog_old_copy->channels = g_slist_copy(analog_old->channels);
                analog_old_copy->num_samples = analog_old->num_samples;
                analog_old_copy->mq = analog_old->mq;
@@ -1514,7 +1546,7 @@ SR_PRIV int sr_packet_copy(const struct sr_datafeed_packet *packet,
                break;
        case SR_DF_ANALOG:
                analog = packet->payload;
-               analog_copy = g_malloc(sizeof(analog));
+               analog_copy = g_malloc(sizeof(*analog_copy));
                analog_copy->data = g_malloc(
                                analog->encoding->unitsize * analog->num_samples);
                memcpy(analog_copy->data, analog->data,