]> sigrok.org Git - libsigrok.git/commitdiff
Add struct sr_session parameter to all session source backends.
authorBert Vermeulen <redacted>
Mon, 21 Jul 2014 12:35:27 +0000 (14:35 +0200)
committerBert Vermeulen <redacted>
Mon, 21 Jul 2014 16:34:11 +0000 (18:34 +0200)
60 files changed:
hardware/agilent-dmm/api.c
hardware/appa-55ii/api.c
hardware/asix-sigma/asix-sigma.c
hardware/atten-pps3xxx/api.c
hardware/atten-pps3xxx/protocol.c
hardware/brymen-bm86x/api.c
hardware/brymen-bm86x/protocol.c
hardware/brymen-bm86x/protocol.h
hardware/brymen-dmm/api.c
hardware/cem-dt-885x/api.c
hardware/center-3xx/api.c
hardware/chronovu-la/api.c
hardware/colead-slm/api.c
hardware/common/scpi.c
hardware/common/scpi_serial.c
hardware/common/scpi_tcp.c
hardware/common/scpi_usbtmc_libusb.c
hardware/common/scpi_visa.c
hardware/common/scpi_vxi.c
hardware/common/serial.c
hardware/common/usb.c
hardware/demo/demo.c
hardware/fluke-dmm/api.c
hardware/fx2lafw/api.c
hardware/fx2lafw/protocol.c
hardware/gmc-mh-1x-2x/api.c
hardware/hameg-hmo/api.c
hardware/hantek-dso/api.c
hardware/ikalogic-scanalogic2/api.c
hardware/ikalogic-scanalogic2/protocol.c
hardware/ikalogic-scanaplus/api.c
hardware/kecheng-kc-330b/api.c
hardware/kecheng-kc-330b/protocol.c
hardware/lascar-el-usb/api.c
hardware/lascar-el-usb/protocol.c
hardware/link-mso19/api.c
hardware/link-mso19/protocol.c
hardware/manson-hcs-3xxx/api.c
hardware/mic-985xx/api.c
hardware/motech-lps-30x/api.c
hardware/norma-dmm/api.c
hardware/openbench-logic-sniffer/api.c
hardware/openbench-logic-sniffer/protocol.c
hardware/rigol-ds/api.c
hardware/saleae-logic16/api.c
hardware/saleae-logic16/protocol.c
hardware/serial-dmm/api.c
hardware/sysclk-lwla/api.c
hardware/sysclk-lwla/protocol.c
hardware/teleinfo/api.c
hardware/testo/api.c
hardware/tondaj-sl-814/api.c
hardware/uni-t-dmm/api.c
hardware/uni-t-ut32x/api.c
hardware/uni-t-ut32x/protocol.c
hardware/victor-dmm/api.c
libsigrok-internal.h
session.c
session_driver.c
std.c

index ccc2f65cd5ccaaa893c42e0f507aa6d531b0ed3d..cb7baa603a6f623f0fecb47a493ee08c41794828 100644 (file)
@@ -249,7 +249,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
 
        /* Poll every 100ms, or whenever some data comes in. */
        serial = sdi->conn;
-       serial_source_add(serial, G_IO_IN, 100, agdmm_receive_data, (void *)sdi);
+       serial_source_add(sdi->session, serial, G_IO_IN, 100,
+                       agdmm_receive_data, (void *)sdi);
 
        return SR_OK;
 }
index 38c23b7ccdaaf9f07f7d35e72d816f436a8310ab..de71e338d8f84fd22b7fd3b618ed25a633b2ebcc 100644 (file)
@@ -259,7 +259,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
        std_session_send_df_header(cb_data, LOG_PREFIX);
 
        /* Poll every 50ms, or whenever some data comes in. */
-       serial_source_add(serial, G_IO_IN, 50, appa_55ii_receive_data, (void *)sdi);
+       serial_source_add(sdi->session, serial, G_IO_IN, 50,
+                       appa_55ii_receive_data, (void *)sdi);
 
        return SR_OK;
 }
index 26c37debaf793a042f7ee60b855f74cafc9eca77..bfd69484bf8b944e8db564bc82ccab03cdb33d93 100644 (file)
@@ -1005,7 +1005,7 @@ static void sigma_decode_dram_cluster(struct sigma_dram_cluster *dram_cluster,
                 */
                if ((i == 1023) || (ts == (tsdiff - EVENTS_PER_CLUSTER))) {
                        logic.length = (i + 1) * logic.unitsize;
-                       sr_session_send(devc->cb_data, &packet);
+                       sr_session_send(sdi, &packet);
                }
        }
 
@@ -1033,14 +1033,14 @@ static void sigma_decode_dram_cluster(struct sigma_dram_cluster *dram_cluster,
                if (trigger_offset > 0) {
                        packet.type = SR_DF_LOGIC;
                        logic.length = trigger_offset * logic.unitsize;
-                       sr_session_send(devc->cb_data, &packet);
+                       sr_session_send(sdi, &packet);
                        events_in_cluster -= trigger_offset;
                }
 
                /* Only send trigger if explicitly enabled. */
                if (devc->use_triggers) {
                        packet.type = SR_DF_TRIGGER;
-                       sr_session_send(devc->cb_data, &packet);
+                       sr_session_send(sdi, &packet);
                }
        }
 
@@ -1048,7 +1048,7 @@ static void sigma_decode_dram_cluster(struct sigma_dram_cluster *dram_cluster,
                packet.type = SR_DF_LOGIC;
                logic.length = events_in_cluster * logic.unitsize;
                logic.data = samples + (trigger_offset * logic.unitsize);
-               sr_session_send(devc->cb_data, &packet);
+               sr_session_send(sdi, &packet);
        }
 
        ss->lastsample =
@@ -1069,10 +1069,9 @@ static void sigma_decode_dram_cluster(struct sigma_dram_cluster *dram_cluster,
 static int decode_chunk_ts(struct sigma_dram_line *dram_line,
                           uint16_t events_in_line,
                           uint32_t trigger_event,
-                          void *cb_data)
+                          struct sr_dev_inst *sdi)
 {
        struct sigma_dram_cluster *dram_cluster;
-       struct sr_dev_inst *sdi = cb_data;
        struct dev_context *devc = sdi->priv;
        unsigned int clusters_in_line =
                (events_in_line + (EVENTS_PER_CLUSTER - 1)) / EVENTS_PER_CLUSTER;
@@ -1510,10 +1509,10 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
        devc->cb_data = cb_data;
 
        /* Send header packet to the session bus. */
-       std_session_send_df_header(cb_data, LOG_PREFIX);
+       std_session_send_df_header(sdi, LOG_PREFIX);
 
        /* Add capture source. */
-       sr_source_add(0, G_IO_IN, 10, receive_data, (void *)sdi);
+       sr_session_source_add(sdi->session, 0, G_IO_IN, 10, receive_data, (void *)sdi);
 
        devc->state.state = SIGMA_CAPTURE;
 
@@ -1529,7 +1528,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
        devc = sdi->priv;
        devc->state.state = SIGMA_IDLE;
 
-       sr_source_remove(0);
+       sr_session_source_remove(sdi->session, 0);
 
        return SR_OK;
 }
index 3b9f002569a0706a389f09a1081cc178ce218dc9..5ca3dbe99dc9fece512c1c8afbf96a1f7f5930e2 100644 (file)
@@ -470,7 +470,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
        devc->acquisition_running = TRUE;
 
        serial = sdi->conn;
-       serial_source_add(serial, G_IO_IN, 50, atten_pps3xxx_receive_data, (void *)sdi);
+       serial_source_add(sdi->session, serial, G_IO_IN, 50,
+                       atten_pps3xxx_receive_data, (void *)sdi);
        std_session_send_df_header(cb_data, LOG_PREFIX);
 
        /* Send a "channel" configuration packet now. */
index 5658d5d576795bf1cc1c4b5a74d7fca70a4d7588..ed4d5505e6a17d7ef8edf469cd8192e20b987e07 100644 (file)
@@ -153,7 +153,7 @@ SR_PRIV int atten_pps3xxx_receive_data(int fd, int revents, void *cb_data)
                        if (devc->acquisition_running)
                                send_config(sdi);
                        else {
-                               serial_source_remove(serial);
+                               serial_source_remove(sdi->session, serial);
                                packet.type = SR_DF_END;
                                sr_session_send(sdi, &packet);
                        }
index 169721d4dfa6a4d13a2c4d26189489c35315e2a4..be21583b169b15199077e7ec975d92430ae33f2a 100644 (file)
@@ -261,17 +261,19 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
 {
        struct dev_context *devc;
 
+       (void)cb_data;
+
        if (sdi->status != SR_ST_ACTIVE)
                return SR_ERR_DEV_CLOSED;
 
        devc = sdi->priv;
-       devc->session_cb_data = cb_data;
        devc->start_time = g_get_monotonic_time();
 
        /* Send header packet to the session bus. */
-       std_session_send_df_header(cb_data, LOG_PREFIX);
+       std_session_send_df_header(sdi, LOG_PREFIX);
 
-       sr_source_add(0, 0, 10, brymen_bm86x_receive_data, (void *)sdi);
+       sr_session_source_add(sdi->session, 0, 0, 10,
+                       brymen_bm86x_receive_data, (void *)sdi);
 
        return SR_OK;
 }
@@ -280,14 +282,16 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 {
        struct sr_datafeed_packet packet;
 
+       (void)cb_data;
+
        if (sdi->status != SR_ST_ACTIVE)
                return SR_ERR_DEV_CLOSED;
 
        /* Send end packet to the session bus. */
        packet.type = SR_DF_END;
-       sr_session_send(cb_data, &packet);
+       sr_session_send(sdi, &packet);
 
-       sr_source_remove(0);
+       sr_session_source_remove(sdi->session, 0);
 
        return SR_OK;
 }
index b8fdcaab0e234778e68aa05b06e94c7f01f33ba3..b8e16a3f8d346c7f983f54a235ac764f57b7b69c 100644 (file)
@@ -211,7 +211,7 @@ static void brymen_bm86x_handle_packet(const struct sr_dev_inst *sdi,
                analog[0].channels = g_slist_append(NULL, sdi->channels->data);
                packet.type = SR_DF_ANALOG;
                packet.payload = &analog[0];
-               sr_session_send(devc->session_cb_data, &packet);
+               sr_session_send(sdi, &packet);
                g_slist_free(analog[0].channels);
        }
 
@@ -222,7 +222,7 @@ static void brymen_bm86x_handle_packet(const struct sr_dev_inst *sdi,
                analog[1].channels = g_slist_append(NULL, sdi->channels->next->data);
                packet.type = SR_DF_ANALOG;
                packet.payload = &analog[1];
-               sr_session_send(devc->session_cb_data, &packet);
+               sr_session_send(sdi, &packet);
                g_slist_free(analog[1].channels);
        }
 
index d3d8955d29779570710030b1fc4879028acfcf99..57af1552217dbdc79cff2d41f224991994f96bda 100644 (file)
@@ -32,7 +32,6 @@ struct dev_context {
        /* Acquisition settings */
        uint64_t limit_samples;    /**< The sampling limit (in number of samples).*/
        uint64_t limit_msec;       /**< The time limit (in milliseconds). */
-       void *session_cb_data;     /**< Opaque pointer passed in by the frontend. */
 
        /* Operational state */
        int detached_kernel_driver;/**< Whether kernel driver was detached or not */
index 41a318124992632fd1f696efd97a6cea40e4e7c8..1ccd18af0fa36f3eb92685d818c2fe94308b6edc 100644 (file)
@@ -230,8 +230,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
 
        /* Poll every 50ms, or whenever some data comes in. */
        serial = sdi->conn;
-       serial_source_add(serial, G_IO_IN, 50,
-                     brymen_dmm_receive_data, (void *)sdi);
+       serial_source_add(sdi->session, serial, G_IO_IN, 50,
+                       brymen_dmm_receive_data, (void *)sdi);
 
        return SR_OK;
 }
index 34853a0cbe9873c469fc536f9de09c29a4f795c3..9aed547362c59bd5933c45e56cff2e24a7fb43f8 100644 (file)
@@ -397,8 +397,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
 
        /* Poll every 100ms, or whenever some data comes in. */
        serial = sdi->conn;
-       serial_source_add(serial, G_IO_IN, 150, cem_dt_885x_receive_data,
-                       (void *)sdi);
+       serial_source_add(sdi->session, serial, G_IO_IN, 150,
+                       cem_dt_885x_receive_data, (void *)sdi);
 
        return SR_OK;
 }
index ddac1540bd4cfa62c8f14cd293d56d3f4752880e..3f39b197b03a913e4e0ef5b208ed82303fc74b39 100644 (file)
@@ -231,7 +231,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
 
        /* Poll every 500ms, or whenever some data comes in. */
        serial = sdi->conn;
-       serial_source_add(serial, G_IO_IN, 500,
+       serial_source_add(sdi->session, serial, G_IO_IN, 500,
                      center_devs[idx].receive_data, (void *)sdi);
 
        return SR_OK;
index 526d51cf3bba27f05dcd820e7c213f5fa5d9335c..5a8a3d36c959a1c4b06c7411a07e01508d6907fe 100644 (file)
@@ -507,7 +507,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
        devc->cb_data = cb_data;
 
        /* Send header packet to the session bus. */
-       std_session_send_df_header(cb_data, LOG_PREFIX);
+       std_session_send_df_header(sdi, LOG_PREFIX);
 
        /* Time when we should be done (for detecting trigger timeouts). */
        devc->done = (devc->divcount + 1) * devc->prof->trigger_constant +
@@ -516,7 +516,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
        devc->trigger_found = 0;
 
        /* Hook up a dummy handler to receive data from the device. */
-       sr_source_add(-1, G_IO_IN, 0, receive_data, (void *)sdi);
+       sr_session_source_add(sdi->session, -1, G_IO_IN, 0, receive_data, (void *)sdi);
 
        return SR_OK;
 }
@@ -525,15 +525,15 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 {
        struct sr_datafeed_packet packet;
 
-       (void)sdi;
+       (void)cb_data;
 
        sr_dbg("Stopping acquisition.");
-       sr_source_remove(-1);
+       sr_session_source_remove(sdi->session, -1);
 
        /* Send end packet to the session bus. */
        sr_dbg("Sending SR_DF_END.");
        packet.type = SR_DF_END;
-       sr_session_send(cb_data, &packet);
+       sr_session_send(sdi, &packet);
 
        return SR_OK;
 }
index f65882723cb1a37f06ebec8afeb27d9a2176b135..d5fc9ac1c28f5e4f63b68fdaa74fba6436bb53bd 100644 (file)
@@ -209,8 +209,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
 
        /* Poll every 150ms, or whenever some data comes in. */
        serial = sdi->conn;
-       serial_source_add(serial, G_IO_IN, 150, colead_slm_receive_data,
-                       (void *)sdi);
+       serial_source_add(sdi->session, serial, G_IO_IN, 150,
+                       colead_slm_receive_data, (void *)sdi);
 
        return SR_OK;
 }
index 21fa6b9592032debfdaf1197a6dd789f6559f718..829a4c8cf1828bb141ce13c159767173cc12c151 100644 (file)
@@ -216,10 +216,11 @@ SR_PRIV int sr_scpi_open(struct sr_scpi_dev_inst *scpi)
  * @return SR_OK upon success, SR_ERR_ARG upon invalid arguments, or
  *         SR_ERR_MALLOC upon memory allocation errors.
  */
-SR_PRIV int sr_scpi_source_add(struct sr_scpi_dev_inst *scpi, int events,
-               int timeout, sr_receive_data_callback cb, void *cb_data)
+SR_PRIV int sr_scpi_source_add(struct sr_session *session,
+               struct sr_scpi_dev_inst *scpi, int events, int timeout,
+               sr_receive_data_callback cb, void *cb_data)
 {
-       return scpi->source_add(scpi->priv, events, timeout, cb, cb_data);
+       return scpi->source_add(session, scpi->priv, events, timeout, cb, cb_data);
 }
 
 /**
@@ -231,9 +232,10 @@ SR_PRIV int sr_scpi_source_add(struct sr_scpi_dev_inst *scpi, int events,
  *         SR_ERR_MALLOC upon memory allocation errors, SR_ERR_BUG upon
  *         internal errors.
  */
-SR_PRIV int sr_scpi_source_remove(struct sr_scpi_dev_inst *scpi)
+SR_PRIV int sr_scpi_source_remove(struct sr_session *session,
+               struct sr_scpi_dev_inst *scpi)
 {
-       return scpi->source_remove(scpi->priv);
+       return scpi->source_remove(session, scpi->priv);
 }
 
 /**
index 7000962aad06bab1e6c9c648d506733be183d94b..feb3317651eb18f2d858b576bd242e4556c1e1d0 100644 (file)
@@ -102,21 +102,21 @@ static int scpi_serial_open(void *priv)
        return SR_OK;
 }
 
-static int scpi_serial_source_add(void *priv, int events, int timeout,
-                       sr_receive_data_callback cb, void *cb_data)
+static int scpi_serial_source_add(struct sr_session *session, void *priv,
+               int events, int timeout, sr_receive_data_callback cb, void *cb_data)
 {
        struct scpi_serial *sscpi = priv;
        struct sr_serial_dev_inst *serial = sscpi->serial;
 
-       return serial_source_add(serial, events, timeout, cb, cb_data);
+       return serial_source_add(session, serial, events, timeout, cb, cb_data);
 }
 
-static int scpi_serial_source_remove(void *priv)
+static int scpi_serial_source_remove(struct sr_session *session, void *priv)
 {
        struct scpi_serial *sscpi = priv;
        struct sr_serial_dev_inst *serial = sscpi->serial;
 
-       return serial_source_remove(serial);
+       return serial_source_remove(session, serial);
 }
 
 static int scpi_serial_send(void *priv, const char *command)
index 8ac2200f7f7f88b0ed104be5dcbf5687b0d76d08..ef3a6c7564e219a65e7f921a4bc72bb6f58501e1 100644 (file)
@@ -115,19 +115,20 @@ static int scpi_tcp_open(void *priv)
        return SR_OK;
 }
 
-static int scpi_tcp_source_add(void *priv, int events, int timeout,
-                       sr_receive_data_callback cb, void *cb_data)
+static int scpi_tcp_source_add(struct sr_session *session, void *priv,
+               int events, int timeout, sr_receive_data_callback cb, void *cb_data)
 {
        struct scpi_tcp *tcp = priv;
 
-       return sr_source_add(tcp->socket, events, timeout, cb, cb_data);
+       return sr_session_source_add(session, tcp->socket, events, timeout,
+                       cb, cb_data);
 }
 
-static int scpi_tcp_source_remove(void *priv)
+static int scpi_tcp_source_remove(struct sr_session *session, void *priv)
 {
        struct scpi_tcp *tcp = priv;
 
-       return sr_source_remove(tcp->socket);
+       return sr_session_source_remove(session, tcp->socket);
 }
 
 static int scpi_tcp_send(void *priv, const char *command)
index 653a0d8c9f4f79f99f76490d7d9ae5ce0131222f..c4470b5db6dee0d98b4983a8a79b2627bf9e5f08 100644 (file)
@@ -316,18 +316,20 @@ static int scpi_usbtmc_libusb_open(void *priv)
        return SR_OK;
 }
 
-static int scpi_usbtmc_libusb_source_add(void *priv, int events, int timeout,
-                       sr_receive_data_callback cb, void *cb_data)
+static int scpi_usbtmc_libusb_source_add(struct sr_session *session,
+               void *priv, int events, int timeout, sr_receive_data_callback cb,
+               void *cb_data)
 {
        struct scpi_usbtmc_libusb *uscpi = priv;
        (void)events;
-       return usb_source_add(uscpi->ctx, timeout, cb, cb_data);
+       return usb_source_add(session, uscpi->ctx, timeout, cb, cb_data);
 }
 
-static int scpi_usbtmc_libusb_source_remove(void *priv)
+static int scpi_usbtmc_libusb_source_remove(struct sr_session *session,
+               void *priv)
 {
        struct scpi_usbtmc_libusb *uscpi = priv;
-       return usb_source_remove(uscpi->ctx);
+       return usb_source_remove(session, uscpi->ctx);
 }
 
 static void usbtmc_bulk_out_header_write(void *header, uint8_t MsgID,
index b342a91f33e0e53974b16c949213b6a7d38c8867..cf34a55529aadfc7afe25f515df9c4a51c416807 100644 (file)
@@ -67,20 +67,20 @@ static int scpi_visa_open(void *priv)
        return SR_OK;
 }
 
-static int scpi_visa_source_add(void *priv, int events, int timeout,
-                       sr_receive_data_callback cb, void *cb_data)
+static int scpi_visa_source_add(struct sr_session *session, void *priv,
+               int events, int timeout, sr_receive_data_callback cb, void *cb_data)
 {
        (void) priv;
 
        /* Hook up a dummy handler to receive data from the device. */
-       return sr_source_add(-1, events, timeout, cb, cb_data);
+       return sr_session_source_add(session, -1, events, timeout, cb, cb_data);
 }
 
-static int scpi_visa_source_remove(void *priv)
+static int scpi_visa_source_remove(struct sr_session *session, void *priv)
 {
        (void) priv;
 
-       return sr_source_remove(-1);
+       return sr_session_source_remove(session, -1);
 }
 
 static int scpi_visa_send(void *priv, const char *command)
index 639b3b566ec8af7e522057f5d0d9c7f5cd198a60..271917b082dfedeaab67419d581e8806eecd9844 100644 (file)
@@ -91,20 +91,20 @@ static int scpi_vxi_open(void *priv)
        return SR_OK;
 }
 
-static int scpi_vxi_source_add(void *priv, int events, int timeout,
-                       sr_receive_data_callback cb, void *cb_data)
+static int scpi_vxi_source_add(struct sr_session *session, void *priv,
+               int events, int timeout, sr_receive_data_callback cb, void *cb_data)
 {
        (void)priv;
 
        /* Hook up a dummy handler to receive data from the device. */
-       return sr_source_add(-1, events, timeout, cb, cb_data);
+       return sr_session_source_add(session, -1, events, timeout, cb, cb_data);
 }
 
-static int scpi_vxi_source_remove(void *priv)
+static int scpi_vxi_source_remove(struct sr_session *session, void *priv)
 {
        (void)priv;
 
-       return sr_source_remove(-1);
+       return sr_session_source_remove(session, -1);
 }
 
 /* Operation Flags */
index 62bbdaf9595c052fe13d466d97a998608d9e9079..9a9a0d94fd3b3058e84ba74202db681de8397885 100644 (file)
@@ -708,8 +708,9 @@ typedef HANDLE event_handle;
 typedef int event_handle;
 #endif
 
-SR_PRIV int serial_source_add(struct sr_serial_dev_inst *serial, int events,
-               int timeout, sr_receive_data_callback cb, void *cb_data)
+SR_PRIV int serial_source_add(struct sr_session *session,
+               struct sr_serial_dev_inst *serial, int events, int timeout,
+               sr_receive_data_callback cb, void *cb_data)
 {
        enum sp_event mask = 0;
        unsigned int i;
@@ -744,20 +745,21 @@ SR_PRIV int serial_source_add(struct sr_serial_dev_inst *serial, int events,
                if (mask & SP_EVENT_ERROR)
                        serial->pollfds[i].events |= G_IO_ERR;
 
-               if (sr_source_add_pollfd(&serial->pollfds[i],
-                               timeout, cb, cb_data) != SR_OK)
+               if (sr_session_source_add_pollfd(session, &serial->pollfds[i],
+                                       timeout, cb, cb_data) != SR_OK)
                        return SR_ERR;
        }
 
        return SR_OK;
 }
 
-SR_PRIV int serial_source_remove(struct sr_serial_dev_inst *serial)
+SR_PRIV int serial_source_remove(struct sr_session *session,
+               struct sr_serial_dev_inst *serial)
 {
        unsigned int i;
 
        for (i = 0; i < serial->event_set->count; i++)
-               if (sr_source_remove_pollfd(&serial->pollfds[i]) != SR_OK)
+               if (sr_session_source_remove_pollfd(session, &serial->pollfds[i]) != SR_OK)
                        return SR_ERR;
 
        g_free(serial->pollfds);
index 62db385b273015dda825d44ddb25ff829f21a6d4..c3279d0ae1ef58640013483f9b6711deca9be15a 100644 (file)
@@ -209,8 +209,8 @@ static int usb_callback(int fd, int revents, void *cb_data)
 }
 #endif
 
-SR_PRIV int usb_source_add(struct sr_context *ctx, int timeout,
-               sr_receive_data_callback cb, void *cb_data)
+SR_PRIV int usb_source_add(struct sr_session *session, struct sr_context *ctx,
+               int timeout, sr_receive_data_callback cb, void *cb_data)
 {
        if (ctx->usb_source_present) {
                sr_err("A USB event source is already present.");
@@ -226,14 +226,16 @@ SR_PRIV int usb_source_add(struct sr_context *ctx, int timeout,
        ctx->usb_pollfd.events = G_IO_IN;
        ctx->usb_cb = cb;
        ctx->usb_cb_data = cb_data;
-       sr_session_source_add_pollfd(&ctx->usb_pollfd, timeout, usb_callback, ctx);
+       sr_session_source_add_pollfd(session, &ctx->usb_pollfd, timeout,
+                       usb_callback, ctx);
 #else
        const struct libusb_pollfd **lupfd;
        unsigned int i;
 
        lupfd = libusb_get_pollfds(ctx->libusb_ctx);
        for (i = 0; lupfd[i]; i++)
-               sr_source_add(lupfd[i]->fd, lupfd[i]->events, timeout, cb, cb_data);
+               sr_session_source_add(session, lupfd[i]->fd, lupfd[i]->events,
+                               timeout, cb, cb_data);
        free(lupfd);
 #endif
        ctx->usb_source_present = TRUE;
@@ -241,7 +243,7 @@ SR_PRIV int usb_source_add(struct sr_context *ctx, int timeout,
        return SR_OK;
 }
 
-SR_PRIV int usb_source_remove(struct sr_context *ctx)
+SR_PRIV int usb_source_remove(struct sr_session *session, struct sr_context *ctx)
 {
        if (!ctx->usb_source_present)
                return SR_OK;
@@ -252,7 +254,7 @@ SR_PRIV int usb_source_remove(struct sr_context *ctx)
        libusb_unlock_events(ctx->libusb_ctx);
        g_thread_join(ctx->usb_thread);
        g_mutex_clear(&ctx->usb_mutex);
-       sr_session_source_remove_pollfd(&ctx->usb_pollfd);
+       sr_session_source_remove_pollfd(session, &ctx->usb_pollfd);
        CloseHandle(ctx->usb_event);
 #else
        const struct libusb_pollfd **lupfd;
@@ -260,7 +262,7 @@ SR_PRIV int usb_source_remove(struct sr_context *ctx)
 
        lupfd = libusb_get_pollfds(ctx->libusb_ctx);
        for (i = 0; lupfd[i]; i++)
-               sr_source_remove(lupfd[i]->fd);
+               sr_session_source_remove(session, lupfd[i]->fd);
        free(lupfd);
 #endif
        ctx->usb_source_present = FALSE;
index ea5e0b53388dc1217f630ec559faa931ab0211ed..b2f3a50915227ee4b96cd4b9dd7d45b2a0a1262f 100644 (file)
@@ -692,6 +692,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
        GSList *l;
        struct dev_context *devc;
 
+       (void)cb_data;
+
        if (sdi->status != SR_ST_ACTIVE)
                return SR_ERR_DEV_CLOSED;
 
@@ -726,11 +728,11 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
        /* Make channels to unbuffered. */
        g_io_channel_set_buffered(devc->channel, FALSE);
 
-       sr_source_add_channel(devc->channel, G_IO_IN | G_IO_ERR,
+       sr_session_source_add_channel(sdi->session, devc->channel, G_IO_IN | G_IO_ERR,
                        40, prepare_data, (void *)sdi);
 
        /* Send header packet to the session bus. */
-       std_session_send_df_header(cb_data, LOG_PREFIX);
+       std_session_send_df_header(sdi, LOG_PREFIX);
 
        /* We use this timestamp to decide how many more samples to send. */
        devc->starttime = g_get_monotonic_time();
@@ -748,7 +750,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
        devc = sdi->priv;
        sr_dbg("Stopping acquisition.");
 
-       sr_source_remove_channel(devc->channel);
+       sr_session_source_remove_channel(sdi->session, devc->channel);
        g_io_channel_shutdown(devc->channel, FALSE, NULL);
        g_io_channel_unref(devc->channel);
        devc->channel = NULL;
index e0dee04b8ec907e704b535566b9a385fb76eabd6..3d739a18d26666431793ff6f04c22d8d9af6869f 100644 (file)
@@ -283,7 +283,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
 
        /* Poll every 100ms, or whenever some data comes in. */
        serial = sdi->conn;
-       serial_source_add(serial, G_IO_IN, 50, fluke_receive_data, (void *)sdi);
+       serial_source_add(sdi->session, serial, G_IO_IN, 50,
+                       fluke_receive_data, (void *)sdi);
 
        if (serial_write(serial, "QM\r", 3) == -1) {
                sr_err("Unable to send QM: %s.", strerror(errno));
index 0082d228be5a9d2521ed94b793c05c64346ed64f..3242afcead486cb01dc4a7490d37101f6f4a4871 100644 (file)
@@ -576,7 +576,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
 
        devc->ctx = drvc->sr_ctx;
 
-       usb_source_add(devc->ctx, timeout, receive_data, NULL);
+       usb_source_add(sdi->session, devc->ctx, timeout, receive_data, NULL);
 
        /* Send header packet to the session bus. */
        std_session_send_df_header(cb_data, LOG_PREFIX);
index e9b56835dbdae8da2e51aa02a9a2be39afb56b8b..433f9075c03c2d9cf804ec8d02962ebfef28e466 100644 (file)
@@ -328,16 +328,19 @@ SR_PRIV void fx2lafw_abort_acquisition(struct dev_context *devc)
        }
 }
 
-static void finish_acquisition(struct dev_context *devc)
+static void finish_acquisition(struct sr_dev_inst *sdi)
 {
        struct sr_datafeed_packet packet;
+       struct dev_context *devc;
+
+       devc = sdi->priv;
 
        /* Terminate session. */
        packet.type = SR_DF_END;
-       sr_session_send(devc->cb_data, &packet);
+       sr_session_send(sdi, &packet);
 
        /* Remove fds from polling. */
-       usb_source_remove(devc->ctx);
+       usb_source_remove(sdi->session, devc->ctx);
 
        devc->num_transfers = 0;
        g_free(devc->transfers);
@@ -370,7 +373,7 @@ static void free_transfer(struct libusb_transfer *transfer)
 
        devc->submitted_transfers--;
        if (devc->submitted_transfers == 0)
-               finish_acquisition(devc);
+               finish_acquisition(sdi);
 }
 
 static void resubmit_transfer(struct libusb_transfer *transfer)
index 3c0a7aaff43ba13f9ed11596604dff623113f8fd..96621bbfd6636f8f52a76b36dcdca496f19e99bc 100644 (file)
@@ -529,8 +529,8 @@ static int dev_acquisition_start_1x_2x_rs232(const struct sr_dev_inst *sdi,
 
        /* Poll every 40ms, or whenever some data comes in. */
        serial = sdi->conn;
-       serial_source_add(serial, G_IO_IN, 40, gmc_mh_1x_2x_receive_data,
-                         (void *)sdi);
+       serial_source_add(sdi->session, serial, G_IO_IN, 40,
+                       gmc_mh_1x_2x_receive_data, (void *)sdi);
 
        return SR_OK;
 }
@@ -560,8 +560,8 @@ static int dev_acquisition_start_2x_bd232(const struct sr_dev_inst *sdi,
 
        /* Poll every 40ms, or whenever some data comes in. */
        serial = sdi->conn;
-       serial_source_add(serial, G_IO_IN, 40, gmc_mh_2x_receive_data,
-                         (void *)sdi);
+       serial_source_add(sdi->session, serial, G_IO_IN, 40,
+                       gmc_mh_2x_receive_data, (void *)sdi);
 
        /* Send start message */
        return req_meas14(sdi);
index b5b3bc29f0100dc588c53d3091d6031b3b2d2688..ff045f16425e61ad091be85868c2111845cb39fe 100644 (file)
@@ -749,7 +749,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
                return SR_ERR;
        }
 
-       sr_scpi_source_add(scpi, G_IO_IN, 50, hmo_receive_data, (void *)sdi);
+       sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 50,
+                       hmo_receive_data, (void *)sdi);
 
        /* Send header packet to the session bus. */
        std_session_send_df_header(cb_data, LOG_PREFIX);
@@ -780,7 +781,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
        g_slist_free(devc->enabled_channels);
        devc->enabled_channels = NULL;
        scpi = sdi->conn;
-       sr_scpi_source_remove(scpi);
+       sr_scpi_source_remove(sdi->session, scpi);
 
        return SR_OK;
 }
index 76696d57525e3b17dd75a15e41a0348985d0c482..c948e4216a8260ea591f207a5ebaf9d62feeb375 100644 (file)
@@ -822,7 +822,7 @@ static int handle_event(int fd, int revents, void *cb_data)
                 * TODO: Doesn't really cancel pending transfers so they might
                 * come in after SR_DF_END is sent.
                 */
-               usb_source_remove(drvc->sr_ctx);
+               usb_source_remove(sdi->session, drvc->sr_ctx);
 
                packet.type = SR_DF_END;
                sr_session_send(sdi, &packet);
@@ -933,7 +933,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
                return SR_ERR;
 
        devc->dev_state = CAPTURE;
-       usb_source_add(drvc->sr_ctx, TICK, handle_event, (void *)sdi);
+       usb_source_add(sdi->session, drvc->sr_ctx, TICK, handle_event, (void *)sdi);
 
        /* Send header packet to the session bus. */
        std_session_send_df_header(cb_data, LOG_PREFIX);
index fd0f217644d8538176b8f75623b9fecbd48b5238..b4c697f91a8e7b715825465bbb4c00e82c0acd78 100644 (file)
@@ -490,7 +490,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
                return SR_ERR;
        }
 
-       usb_source_add(drvc->sr_ctx, 100, ikalogic_scanalogic2_receive_data, (void *)sdi);
+       usb_source_add(sdi->session, drvc->sr_ctx, 100,
+                       ikalogic_scanalogic2_receive_data, (void *)sdi);
 
        sr_dbg("Acquisition started successfully.");
 
index b0c33fa6163cbb6fbccb7fdc67c65a8eb4215f5a..663ff527a75c42c2851448a3dd716cd983393489 100644 (file)
@@ -33,7 +33,7 @@ static void stop_acquisition(struct sr_dev_inst *sdi)
        devc = sdi->priv;
 
        /* Remove USB file descriptors from polling. */
-       usb_source_remove(drvc->sr_ctx);
+       usb_source_remove(sdi->session, drvc->sr_ctx);
 
        packet.type = SR_DF_END;
        sr_session_send(devc->cb_data, &packet);
@@ -50,7 +50,7 @@ static void abort_acquisition(struct sr_dev_inst *sdi)
        devc = sdi->priv;
 
        /* Remove USB file descriptors from polling. */
-       usb_source_remove(drvc->sr_ctx);
+       usb_source_remove(sdi->session, drvc->sr_ctx);
 
        packet.type = SR_DF_END;
        sr_session_send(devc->cb_data, &packet);
index e855097730aa51515bfb857652fbab212e1fbaab..3f8276305bbfcaa4688a0569b25ca459307c730f 100644 (file)
@@ -393,10 +393,10 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
                return ret;
 
        /* Send header packet to the session bus. */
-       std_session_send_df_header(cb_data, LOG_PREFIX);
+       std_session_send_df_header(sdi, LOG_PREFIX);
 
        /* Hook up a dummy handler to receive data from the device. */
-       sr_source_add(-1, G_IO_IN, 0, scanaplus_receive_data, (void *)sdi);
+       sr_session_source_add(sdi->session, -1, G_IO_IN, 0, scanaplus_receive_data, (void *)sdi);
 
        return SR_OK;
 }
@@ -405,15 +405,15 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 {
        struct sr_datafeed_packet packet;
 
-       (void)sdi;
+       (void)cb_data;
 
        sr_dbg("Stopping acquisition.");
-       sr_source_remove(-1);
+       sr_session_source_remove(sdi->session, -1);
 
        /* Send end packet to the session bus. */
        sr_dbg("Sending SR_DF_END.");
        packet.type = SR_DF_END;
-       sr_session_send(cb_data, &packet);
+       sr_session_send(sdi, &packet);
 
        return SR_OK;
 }
index 57dafdfc6d6df4d4d8f7228a8c2bee1f6dae3d36..71bdc012f690c202f5812cac7d8ca86b380a590f 100644 (file)
@@ -489,7 +489,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
        if (!(devc->xfer = libusb_alloc_transfer(0)))
                return SR_ERR;
 
-       usb_source_add(drvc->sr_ctx, 10,
+       usb_source_add(sdi->session, drvc->sr_ctx, 10,
                kecheng_kc_330b_handle_events, (void *)sdi);
 
        if (devc->data_source == DATA_SOURCE_LIVE) {
index 072eb7efa45454234a6aa281a6e01cbf6d7e91bb..caf896ac051204e62dfab51e8eeba6137efd536c 100644 (file)
@@ -51,7 +51,7 @@ SR_PRIV int kecheng_kc_330b_handle_events(int fd, int revents, void *cb_data)
 
        if (sdi->status == SR_ST_STOPPING) {
                libusb_free_transfer(devc->xfer);
-               usb_source_remove(drvc->sr_ctx);
+               usb_source_remove(sdi->session, drvc->sr_ctx);
                packet.type = SR_DF_END;
                sr_session_send(cb_data, &packet);
                sdi->status = SR_ST_ACTIVE;
index 657d9935b541ee0d6264c2831c159a29291d4d78..04f844b3318b1d575a4eec0a8f23708e59a162a9 100644 (file)
@@ -434,7 +434,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
        devc->log_size = xfer_in->buffer[1] + (xfer_in->buffer[2] << 8);
        libusb_free_transfer(xfer_out);
 
-       usb_source_add(drvc->sr_ctx, 100, lascar_el_usb_handle_events, (void *)sdi);
+       usb_source_add(sdi->session, drvc->sr_ctx, 100,
+                       lascar_el_usb_handle_events, (void *)sdi);
 
        buf = g_try_malloc(4096);
        libusb_fill_bulk_transfer(xfer_in, usb->devhdl, LASCAR_EP_IN,
index 050b42bb1eb8494655f9072beac43272511769e0..49c5cd0a3687e3416c8585edd72c1634cca7e204 100644 (file)
@@ -499,7 +499,7 @@ SR_PRIV int lascar_el_usb_handle_events(int fd, int revents, void *cb_data)
        sdi = cb_data;
 
        if (sdi->status == SR_ST_STOPPING) {
-               usb_source_remove(drvc->sr_ctx);
+               usb_source_remove(sdi->session, drvc->sr_ctx);
 
                packet.type = SR_DF_END;
                sr_session_send(cb_data, &packet);
index 45453efdf3f49571dce0545643d2734d9ba3f724..13c2972001a506627ea325f1c35467606d751a14 100644 (file)
@@ -461,7 +461,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
        /* Our first channel is analog, the other 8 are of type 'logic'. */
        /* TODO. */
 
-       serial_source_add(devc->serial, G_IO_IN, -1, mso_receive_data, cb_data);
+       serial_source_add(sdi->session, devc->serial, G_IO_IN, -1,
+                       mso_receive_data, cb_data);
 
        return SR_OK;
 }
index 40a30b944a3f5711181e59f945877c12bee44a88..5f7aa719876b11c9bd0eab0096f90e5a8d9102f2 100644 (file)
@@ -294,7 +294,7 @@ SR_PRIV void stop_acquisition(const struct sr_dev_inst *sdi)
        struct dev_context *devc;
 
        devc = sdi->priv;
-       serial_source_remove(devc->serial);
+       serial_source_remove(sdi->session, devc->serial);
 
        /* Terminate session */
        packet.type = SR_DF_END;
index dead308546e5685aed85164c1c25d5d297b12d13..faa093f1187e4da73951e81ae875d7564567a287 100644 (file)
@@ -398,7 +398,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
 
        /* Poll every 10ms, or whenever some data comes in. */
        serial = sdi->conn;
-       serial_source_add(serial, G_IO_IN, 10, hcs_receive_data, (void *)sdi);
+       serial_source_add(sdi->session, serial, G_IO_IN, 10,
+                       hcs_receive_data, (void *)sdi);
 
        return SR_OK;
 }
index 7b0d680c38f403b011a55d5f912c05b9d33fd476..6cfc5efde05dbcbb58ecb6ec1424796a8ded1db2 100644 (file)
@@ -233,7 +233,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
 
        /* Poll every 100ms, or whenever some data comes in. */
        serial = sdi->conn;
-       serial_source_add(serial, G_IO_IN, 100,
+       serial_source_add(sdi->session, serial, G_IO_IN, 100,
                      mic_devs[idx].receive_data, (void *)sdi);
 
        return SR_OK;
index ad0fb3c4212ecc3840dfcf8ce399399f2f5682a6..164a9cc02321d88656018a93e0879cf765f6dc17 100644 (file)
@@ -814,7 +814,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
        devc->acq_running = TRUE;
 
        serial = sdi->conn;
-       serial_source_add(serial, G_IO_IN, 50, motech_lps_30x_receive_data, (void *)sdi);
+       serial_source_add(sdi->session, serial, G_IO_IN, 50,
+                       motech_lps_30x_receive_data, (void *)sdi);
        std_session_send_df_header(cb_data, LOG_PREFIX);
 
        /* Start timer, if required. */
index 5dacde2ea4a4d24119dde53813eeeefa98d62319..798b60e151b7082ab8dfc1d1804b0d3db8397edd 100644 (file)
@@ -317,8 +317,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
 
        /* Poll every 100ms, or whenever some data comes in. */
        serial = sdi->conn;
-       serial_source_add(serial, G_IO_IN, 100, norma_dmm_receive_data,
-                     (void *)sdi);
+       serial_source_add(sdi->session, serial, G_IO_IN, 100,
+                       norma_dmm_receive_data, (void *)sdi);
 
        return SR_OK;
 }
index 47a938b0f5c6f840afad7eb81046e8bec96dfec3..cd9d817e22c17c2de8e87cc562c91ff68d5d7182 100644 (file)
@@ -565,7 +565,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
        /* Send header packet to the session bus. */
        std_session_send_df_header(cb_data, LOG_PREFIX);
 
-       serial_source_add(serial, G_IO_IN, -1, ols_receive_data, cb_data);
+       serial_source_add(sdi->session, serial, G_IO_IN, -1,
+                       ols_receive_data, cb_data);
 
        return SR_OK;
 }
index d4e54bbc83040cadcb40bdb694792d00c9759aa5..1c94b7ff6948e9103d7caa7cb66878b0f6a76bdd 100644 (file)
@@ -318,7 +318,7 @@ SR_PRIV void abort_acquisition(const struct sr_dev_inst *sdi)
        struct sr_serial_dev_inst *serial;
 
        serial = sdi->conn;
-       serial_source_remove(serial);
+       serial_source_remove(sdi->session, serial);
 
        /* Terminate session */
        packet.type = SR_DF_END;
@@ -350,8 +350,9 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
                 * longer than it takes to send a byte, that means it's
                 * finished. We'll double that to 30ms to be sure...
                 */
-               serial_source_remove(serial);
-               serial_source_add(serial, G_IO_IN, 30, ols_receive_data, cb_data);
+               serial_source_remove(sdi->session, serial);
+               serial_source_add(sdi->session, serial, G_IO_IN, 30,
+                               ols_receive_data, cb_data);
                devc->raw_sample_buf = g_try_malloc(devc->limit_samples * 4);
                if (!devc->raw_sample_buf) {
                        sr_err("Sample buffer malloc failed.");
index 465001048ac5af4a93c87d6db478a35f86140467..872531f694159b3c0d57d9ad7f2b5df584efd7de 100644 (file)
@@ -970,7 +970,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
                if (rigol_ds_config_set(sdi, ":RUN") != SR_OK)
                        return SR_ERR;
 
-       sr_scpi_source_add(scpi, G_IO_IN, 50, rigol_ds_receive, (void *)sdi);
+       sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 50,
+                       rigol_ds_receive, (void *)sdi);
 
        /* Send header packet to the session bus. */
        std_session_send_df_header(cb_data, LOG_PREFIX);
@@ -1014,7 +1015,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
        devc->enabled_analog_channels = NULL;
        devc->enabled_digital_channels = NULL;
        scpi = sdi->conn;
-       sr_scpi_source_remove(scpi);
+       sr_scpi_source_remove(sdi->session, scpi);
 
        return SR_OK;
 }
index 4cfdff12439e0674c260b2641ea77f41eb0f73fa..6bd539ca29d10d29b64d65b5528c9c14a526ca11 100644 (file)
@@ -773,7 +773,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
                transfer = libusb_alloc_transfer(0);
                libusb_fill_bulk_transfer(transfer, usb->devhdl,
                                2 | LIBUSB_ENDPOINT_IN, buf, size,
-                               logic16_receive_transfer, devc, timeout);
+                               logic16_receive_transfer, (void *)sdi, timeout);
                if ((ret = libusb_submit_transfer(transfer)) != 0) {
                        sr_err("Failed to submit transfer: %s.",
                               libusb_error_name(ret));
@@ -788,7 +788,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
 
        devc->ctx = drvc->sr_ctx;
 
-       usb_source_add(devc->ctx, timeout, receive_data, (void *)sdi);
+       usb_source_add(sdi->session, devc->ctx, timeout, receive_data, (void *)sdi);
 
        /* Send header packet to the session bus. */
        std_session_send_df_header(cb_data, LOG_PREFIX);
index 8b430d90c01e91e5d62ce2c87af853faaa19376f..785833432749f2f71f772a841699197e5d56da41 100644 (file)
@@ -576,16 +576,19 @@ SR_PRIV int logic16_init_device(const struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-static void finish_acquisition(struct dev_context *devc)
+static void finish_acquisition(struct sr_dev_inst *sdi)
 {
        struct sr_datafeed_packet packet;
+       struct dev_context *devc;
+
+       devc = sdi->priv;
 
        /* Terminate session. */
        packet.type = SR_DF_END;
        sr_session_send(devc->cb_data, &packet);
 
        /* Remove fds from polling. */
-       usb_source_remove(devc->ctx);
+       usb_source_remove(sdi->session, devc->ctx);
 
        devc->num_transfers = 0;
        g_free(devc->transfers);
@@ -598,10 +601,12 @@ static void finish_acquisition(struct dev_context *devc)
 
 static void free_transfer(struct libusb_transfer *transfer)
 {
+       struct sr_dev_inst *sdi;
        struct dev_context *devc;
        unsigned int i;
 
-       devc = transfer->user_data;
+       sdi = transfer->user_data;
+       devc = sdi->priv;
 
        g_free(transfer->buffer);
        transfer->buffer = NULL;
@@ -616,7 +621,7 @@ static void free_transfer(struct libusb_transfer *transfer)
 
        devc->submitted_transfers--;
        if (devc->submitted_transfers == 0)
-               finish_acquisition(devc);
+               finish_acquisition(sdi);
 }
 
 static void resubmit_transfer(struct libusb_transfer *transfer)
@@ -679,11 +684,13 @@ SR_PRIV void logic16_receive_transfer(struct libusb_transfer *transfer)
        gboolean packet_has_error = FALSE;
        struct sr_datafeed_packet packet;
        struct sr_datafeed_logic logic;
+       struct sr_dev_inst *sdi;
        struct dev_context *devc;
        size_t new_samples, num_samples;
        int trigger_offset;
 
-       devc = transfer->user_data;
+       sdi = transfer->user_data;
+       devc = sdi->priv;
 
        /*
         * If acquisition has already ended, just free any queued up
index 123969011a61db63d73a830261fef159be61dea7..b96c7a0da982c18431a2b02697843bbf71f77e38 100644 (file)
@@ -543,7 +543,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
 
        /* Poll every 50ms, or whenever some data comes in. */
        serial = sdi->conn;
-       serial_source_add(serial, G_IO_IN, 50,
+       serial_source_add(sdi->session, serial, G_IO_IN, 50,
                      dmms[dmm].receive_data, (void *)sdi);
 
        return SR_OK;
index d55065399f3e05a42795d6a46ce015bf98240cdd..a4346a012329c083349fd40a80831c1e504f02c9 100644 (file)
@@ -537,7 +537,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
                lwla_free_acquisition_state(acq);
                return ret;
        }
-       usb_source_add(drvc->sr_ctx, 100, &lwla_receive_data,
+       usb_source_add(sdi->session, drvc->sr_ctx, 100, &lwla_receive_data,
                       (struct sr_dev_inst *)sdi);
 
        sr_info("Waiting for data.");
index 5dc19b92b45a05f219e09616ff28a0a84ac8d6fd..f1ae8b3d5d1fe1c1b146fa5d41ddb3eeb0f7ad50 100644 (file)
@@ -587,7 +587,7 @@ static void end_acquisition(struct sr_dev_inst *sdi)
        devc->state = STATE_IDLE;
 
        /* Remove USB file descriptors from polling. */
-       usb_source_remove(drvc->sr_ctx);
+       usb_source_remove(sdi->session, drvc->sr_ctx);
 
        packet.type = SR_DF_END;
        sr_session_send(sdi, &packet);
index 931e5994cd40927bbd490b30a3be3c9d3701b9cd..c4fd846716878241d1151bba3679e8e5cc7a8e1b 100644 (file)
@@ -257,7 +257,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
        std_session_send_df_header(cb_data, LOG_PREFIX);
 
        /* Poll every 50ms, or whenever some data comes in. */
-       serial_source_add(serial, G_IO_IN, 50, teleinfo_receive_data, (void *)sdi);
+       serial_source_add(sdi->session, serial, G_IO_IN, 50,
+                       teleinfo_receive_data, (void *)sdi);
 
        return SR_OK;
 }
index 9c22893b23084a8da72331d312c01d7350dbcbbb..2b4c9634c09a75b83019e53a95b1e144bb83b941 100644 (file)
@@ -430,7 +430,7 @@ static int handle_events(int fd, int revents, void *cb_data)
        }
 
        if (sdi->status == SR_ST_STOPPING) {
-               usb_source_remove(drvc->sr_ctx);
+               usb_source_remove(sdi->session, drvc->sr_ctx);
 
                dev_close(sdi);
 
@@ -473,7 +473,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
        /* Send header packet to the session bus. */
        std_session_send_df_header(cb_data, LOG_PREFIX);
 
-       usb_source_add(drvc->sr_ctx, 100, handle_events, (void *)sdi);
+       usb_source_add(sdi->session, drvc->sr_ctx, 100,
+                       handle_events, (void *)sdi);
 
        if (testo_set_serial_params(usb) != SR_OK)
                return SR_ERR;
index d112b19598b7c3d5b4f8ac3dd4ae9e0f03ecbdbd..7917c8d2606bc24dac697b5964a776787bde5265 100644 (file)
@@ -192,7 +192,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
 
        /* Poll every 500ms, or whenever some data comes in. */
        serial = sdi->conn;
-       serial_source_add(serial, G_IO_IN, 500,
+       serial_source_add(sdi->session, serial, G_IO_IN, 500,
                      tondaj_sl_814_receive_data, (void *)sdi);
 
        return SR_OK;
index ef31de040b0df57d019446b902b919121b906d91..f98c4f5e39e32654fc2fd3e87a1b99577e2dab7e 100644 (file)
@@ -338,9 +338,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
        devc->starttime = g_get_monotonic_time();
 
        /* Send header packet to the session bus. */
-       std_session_send_df_header(cb_data, LOG_PREFIX);
+       std_session_send_df_header(sdi, LOG_PREFIX);
 
-       sr_source_add(0, 0, 10 /* poll_timeout */,
+       sr_session_source_add(sdi->session, 0, 0, 10 /* poll_timeout */,
                      udmms[dmm].receive_data, (void *)sdi);
 
        return SR_OK;
@@ -350,17 +350,16 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 {
        struct sr_datafeed_packet packet;
 
-       (void)sdi;
+       (void)cb_data;
 
        sr_dbg("Stopping acquisition.");
 
        /* Send end packet to the session bus. */
        sr_dbg("Sending SR_DF_END.");
        packet.type = SR_DF_END;
-       sr_session_send(cb_data, &packet);
+       sr_session_send(sdi, &packet);
 
-       /* TODO? */
-       sr_source_remove(0);
+       sr_session_source_remove(sdi->session, 0);
 
        return SR_OK;
 }
index b38d2fb0d52a42c77f4bc486730c366750787d60..81024dc7cc0548afb6d2515d636bc96519c9f4db 100644 (file)
@@ -345,7 +345,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
                return SR_ERR;
        }
 
-       usb_source_add(drvc->sr_ctx, 10, uni_t_ut32x_handle_events, (void *)sdi);
+       usb_source_add(sdi->session, drvc->sr_ctx, 10,
+                       uni_t_ut32x_handle_events, (void *)sdi);
 
        return SR_OK;
 }
index 863f9fa82aab7bae3a7e370d1c94eb5aee27d6f0..65cb756bd87774dc4b275d5673710507d9654d94 100644 (file)
@@ -217,7 +217,7 @@ SR_PRIV int uni_t_ut32x_handle_events(int fd, int revents, void *cb_data)
                        NULL);
 
        if (sdi->status == SR_ST_STOPPING) {
-               usb_source_remove(drvc->sr_ctx);
+               usb_source_remove(sdi->session, drvc->sr_ctx);
                packet.type = SR_DF_END;
                sr_session_send(cb_data, &packet);
 
index 74523ed7aabbfd4cef6e0baab92a0f917e3f4ce2..56c53e503c90d98ab60338e56198071c8bd4f789 100644 (file)
@@ -348,7 +348,7 @@ static int handle_events(int fd, int revents, void *cb_data)
        }
 
        if (sdi->status == SR_ST_STOPPING) {
-               usb_source_remove(drvc->sr_ctx);
+               usb_source_remove(sdi->session, drvc->sr_ctx);
 
                dev_close(sdi);
 
@@ -387,7 +387,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
        /* Send header packet to the session bus. */
        std_session_send_df_header(cb_data, LOG_PREFIX);
 
-       usb_source_add(drvc->sr_ctx, 100, handle_events, (void *)sdi);
+       usb_source_add(sdi->session, drvc->sr_ctx, 100,
+                       handle_events, (void *)sdi);
 
        buf = g_try_malloc(DMM_DATA_SIZE);
        transfer = libusb_alloc_transfer(0);
index 62714a22f238eaf2fd0bc6f91abb3d4538646245..8c58bd9f1e53e61c49985207cca5b2472321f699 100644 (file)
@@ -393,9 +393,11 @@ SR_PRIV int serial_stream_detect(struct sr_serial_dev_inst *serial,
                                 uint64_t timeout_ms, int baudrate);
 SR_PRIV int sr_serial_extract_options(GSList *options, const char **serial_device,
                                      const char **serial_options);
-SR_PRIV int serial_source_add(struct sr_serial_dev_inst *serial, int events,
-               int timeout, sr_receive_data_callback cb, void *cb_data);
-SR_PRIV int serial_source_remove(struct sr_serial_dev_inst *serial);
+SR_PRIV int serial_source_add(struct sr_session *session,
+               struct sr_serial_dev_inst *serial, int events, int timeout,
+               sr_receive_data_callback cb, void *cb_data);
+SR_PRIV int serial_source_remove(struct sr_session *session,
+               struct sr_serial_dev_inst *serial);
 SR_PRIV GSList *sr_serial_find_usb(uint16_t vendor_id, uint16_t product_id);
 #endif
 
@@ -414,9 +416,9 @@ SR_PRIV int ezusb_upload_firmware(libusb_device *dev, int configuration,
 #ifdef HAVE_LIBUSB_1_0
 SR_PRIV GSList *sr_usb_find(libusb_context *usb_ctx, const char *conn);
 SR_PRIV int sr_usb_open(libusb_context *usb_ctx, struct sr_usb_dev_inst *usb);
-SR_PRIV int usb_source_add(struct sr_context *ctx, int timeout,
-               sr_receive_data_callback cb, void *cb_data);
-SR_PRIV int usb_source_remove(struct sr_context *ctx);
+SR_PRIV int usb_source_add(struct sr_session *session, struct sr_context *ctx,
+               int timeout, sr_receive_data_callback cb, void *cb_data);
+SR_PRIV int usb_source_remove(struct sr_session *session, struct sr_context *ctx);
 #endif
 
 /*--- hardware/common/scpi.c ------------------------------------------------*/
@@ -465,9 +467,9 @@ struct sr_scpi_dev_inst {
        int (*dev_inst_new)(void *priv, struct drv_context *drvc,
                const char *resource, char **params, const char *serialcomm);
        int (*open)(void *priv);
-       int (*source_add)(void *priv, int events,
+       int (*source_add)(struct sr_session *session, void *priv, int events,
                int timeout, sr_receive_data_callback cb, void *cb_data);
-       int (*source_remove)(void *priv);
+       int (*source_remove)(struct sr_session *session, void *priv);
        int (*send)(void *priv, const char *command);
        int (*read_begin)(void *priv);
        int (*read_data)(void *priv, char *buf, int maxlen);
@@ -482,9 +484,11 @@ SR_PRIV GSList *sr_scpi_scan(struct drv_context *drvc, GSList *options,
 SR_PRIV struct sr_scpi_dev_inst *scpi_dev_inst_new(struct drv_context *drvc,
                const char *resource, const char *serialcomm);
 SR_PRIV int sr_scpi_open(struct sr_scpi_dev_inst *scpi);
-SR_PRIV int sr_scpi_source_add(struct sr_scpi_dev_inst *scpi, int events,
-               int timeout, sr_receive_data_callback cb, void *cb_data);
-SR_PRIV int sr_scpi_source_remove(struct sr_scpi_dev_inst *scpi);
+SR_PRIV int sr_scpi_source_add(struct sr_session *session,
+               struct sr_scpi_dev_inst *scpi, int events, int timeout,
+               sr_receive_data_callback cb, void *cb_data);
+SR_PRIV int sr_scpi_source_remove(struct sr_session *session,
+               struct sr_scpi_dev_inst *scpi);
 SR_PRIV int sr_scpi_send(struct sr_scpi_dev_inst *scpi,
                const char *format, ...);
 SR_PRIV int sr_scpi_send_variadic(struct sr_scpi_dev_inst *scpi,
index 7a44a27d31a0361c572e912727a3d558d96c42f9..4c6095e00481777234c7255cb6789b1c9acb2896 100644 (file)
--- a/session.c
+++ b/session.c
@@ -673,10 +673,9 @@ SR_PRIV int sr_session_send(const struct sr_dev_inst *sdi,
  * @retval SR_ERR_ARG Invalid argument.
  * @retval SR_ERR_MALLOC Memory allocation error.
  */
-static int _sr_session_source_add(GPollFD *pollfd, int timeout,
-       sr_receive_data_callback cb, void *cb_data, gintptr poll_object)
+static int _sr_session_source_add(struct sr_session *session, GPollFD *pollfd,
+               int timeout, sr_receive_data_callback cb, void *cb_data, gintptr poll_object)
 {
-       struct sr_session *session = sr_current_session;
        struct source *new_sources, *s;
        GPollFD *new_pollfds;
 
@@ -742,7 +741,7 @@ SR_API int sr_session_source_add(struct sr_session *session, int fd,
        p.fd = fd;
        p.events = events;
 
-       return _sr_session_source_add(&p, timeout, cb, cb_data, (gintptr)fd);
+       return _sr_session_source_add(session, &p, timeout, cb, cb_data, (gintptr)fd);
 }
 
 /**
@@ -765,7 +764,7 @@ SR_API int sr_session_source_add_pollfd(struct sr_session *session,
 {
        (void) session;
 
-       return _sr_session_source_add(pollfd, timeout, cb,
+       return _sr_session_source_add(session, pollfd, timeout, cb,
                                      cb_data, (gintptr)pollfd);
 }
 
@@ -799,7 +798,7 @@ SR_API int sr_session_source_add_channel(struct sr_session *session,
        p.events = events;
 #endif
 
-       return _sr_session_source_add(&p, timeout, cb, cb_data, (gintptr)channel);
+       return _sr_session_source_add(session, &p, timeout, cb, cb_data, (gintptr)channel);
 }
 
 /**
@@ -814,9 +813,8 @@ SR_API int sr_session_source_add_channel(struct sr_session *session,
  * @retval SR_ERR_MALLOC Memory allocation error
  * @retval SR_ERR_BUG Internal error
  */
-static int _sr_session_source_remove(gintptr poll_object)
+static int _sr_session_source_remove(struct sr_session *session, gintptr poll_object)
 {
-       struct sr_session *session = sr_current_session;
        struct source *new_sources;
        GPollFD *new_pollfds;
        unsigned int old;
@@ -878,7 +876,7 @@ SR_API int sr_session_source_remove(struct sr_session *session, int fd)
 {
        (void) session;
 
-       return _sr_session_source_remove((gintptr)fd);
+       return _sr_session_source_remove(session, (gintptr)fd);
 }
 
 /**
@@ -897,7 +895,7 @@ SR_API int sr_session_source_remove_pollfd(struct sr_session *session,
 {
        (void) session;
 
-       return _sr_session_source_remove((gintptr)pollfd);
+       return _sr_session_source_remove(session, (gintptr)pollfd);
 }
 
 /**
@@ -917,7 +915,7 @@ SR_API int sr_session_source_remove_channel(struct sr_session *session,
 {
        (void) session;
 
-       return _sr_session_source_remove((gintptr)channel);
+       return _sr_session_source_remove(session, (gintptr)channel);
 }
 
 /** @} */
index fd86ced1655a39298e190b4027766501a0dc991d..9120ea14575b4f2e71fbfa3d0fcdfc28100b8467 100644 (file)
@@ -33,6 +33,9 @@
 #define CHUNKSIZE (512 * 1024)
 /** @endcond */
 
+SR_PRIV struct sr_dev_driver session_driver_info;
+static struct sr_dev_driver *di = &session_driver_info;
+
 struct session_vdev {
        char *sessionfile;
        char *capturefile;
@@ -46,15 +49,12 @@ struct session_vdev {
        gboolean finished;
 };
 
-static GSList *dev_insts = NULL;
 static const int hwcaps[] = {
        SR_CONF_CAPTUREFILE,
        SR_CONF_CAPTURE_UNITSIZE,
        SR_CONF_SAMPLERATE,
 };
 
-extern struct sr_session *sr_current_session;
-
 static int receive_data(int fd, int revents, void *cb_data)
 {
        struct sr_dev_inst *sdi;
@@ -62,7 +62,6 @@ static int receive_data(int fd, int revents, void *cb_data)
        struct sr_datafeed_packet packet;
        struct sr_datafeed_logic logic;
        struct zip_stat zs;
-       GSList *l;
        int ret, got_data;
        char capturefile[16];
        void *buf;
@@ -70,14 +69,10 @@ static int receive_data(int fd, int revents, void *cb_data)
        (void)fd;
        (void)revents;
 
+       sdi = cb_data;
        got_data = FALSE;
-       for (l = dev_insts; l; l = l->next) {
-               sdi = l->data;
-               vdev = sdi->priv;
-               if (vdev->finished)
-                       /* Already done with this instance. */
-                       continue;
-
+       vdev = sdi->priv;
+       if (!vdev->finished) {
                if (!vdev->capfile) {
                        /* No capture file opened yet, or finished with the last
                         * chunked one. */
@@ -118,7 +113,7 @@ static int receive_data(int fd, int revents, void *cb_data)
                                } else {
                                        /* We got all the chunks, finish up. */
                                        vdev->finished = TRUE;
-                                       continue;
+                                       return TRUE;
                                }
                        }
                }
@@ -141,7 +136,7 @@ static int receive_data(int fd, int revents, void *cb_data)
                        logic.unitsize = vdev->unitsize;
                        logic.data = buf;
                        vdev->bytes_read += ret;
-                       sr_session_send(cb_data, &packet);
+                       sr_session_send(sdi, &packet);
                } else {
                        /* done with this capture file */
                        zip_fclose(vdev->capfile);
@@ -161,8 +156,8 @@ static int receive_data(int fd, int revents, void *cb_data)
 
        if (!got_data) {
                packet.type = SR_DF_END;
-               sr_session_send(cb_data, &packet);
-               sr_session_source_remove(sr_current_session, -1);
+               sr_session_send(sdi, &packet);
+               sr_session_source_remove(sdi->session, -1);
        }
 
        return TRUE;
@@ -172,30 +167,32 @@ static int receive_data(int fd, int revents, void *cb_data)
 
 static int init(struct sr_context *sr_ctx)
 {
-       (void)sr_ctx;
-
-       return SR_OK;
+       return std_init(sr_ctx, di, LOG_PREFIX);
 }
 
 static int dev_clear(void)
 {
+       struct drv_context *drvc;
        GSList *l;
 
-       for (l = dev_insts; l; l = l->next)
+       drvc = di->priv;
+       for (l = drvc->instances; l; l = l->next)
                sr_dev_inst_free(l->data);
-       g_slist_free(dev_insts);
-       dev_insts = NULL;
+       g_slist_free(drvc->instances);
+       drvc->instances = NULL;
 
        return SR_OK;
 }
 
 static int dev_open(struct sr_dev_inst *sdi)
 {
+       struct drv_context *drvc;
        struct session_vdev *vdev;
 
-       vdev = g_try_malloc0(sizeof(struct session_vdev));
+       drvc = di->priv;
+       vdev = g_malloc0(sizeof(struct session_vdev));
        sdi->priv = vdev;
-       dev_insts = g_slist_append(dev_insts, sdi);
+       drvc->instances = g_slist_append(drvc->instances, sdi);
 
        return SR_OK;
 }
@@ -294,8 +291,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
        struct session_vdev *vdev;
        int ret;
 
-       vdev = sdi->priv;
+       (void)cb_data;
 
+       vdev = sdi->priv;
        vdev->bytes_read = 0;
        vdev->cur_chunk = 0;
        vdev->finished = FALSE;
@@ -310,10 +308,10 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
        }
 
        /* Send header packet to the session bus. */
-       std_session_send_df_header(cb_data, LOG_PREFIX);
+       std_session_send_df_header(sdi, LOG_PREFIX);
 
        /* freewheeling source */
-       sr_session_source_add(sr_current_session, -1, 0, 0, receive_data, cb_data);
+       sr_session_source_add(sdi->session, -1, 0, 0, receive_data, (void *)sdi);
 
        return SR_OK;
 }
diff --git a/std.c b/std.c
index 1b9c600077d1928bd569ff76d3d11ed464a032b0..2319dfef9273f47524fd61bcebb7535f8f21135b 100644 (file)
--- a/std.c
+++ b/std.c
@@ -200,7 +200,7 @@ SR_PRIV int std_serial_dev_acquisition_stop(struct sr_dev_inst *sdi,
 
        sr_dbg("%s: Stopping acquisition.", prefix);
 
-       if ((ret = serial_source_remove(serial)) < 0) {
+       if ((ret = serial_source_remove(sdi->session, serial)) < 0) {
                sr_err("%s: Failed to remove source: %d.", prefix, ret);
                return ret;
        }