From: Bert Vermeulen Date: Mon, 21 Jul 2014 12:35:27 +0000 (+0200) Subject: Add struct sr_session parameter to all session source backends. X-Git-Tag: libsigrok-0.4.0~1232 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=102f12396660e0784134bccce5cc0679db325751;p=libsigrok.git Add struct sr_session parameter to all session source backends. --- diff --git a/hardware/agilent-dmm/api.c b/hardware/agilent-dmm/api.c index ccc2f65c..cb7baa60 100644 --- a/hardware/agilent-dmm/api.c +++ b/hardware/agilent-dmm/api.c @@ -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; } diff --git a/hardware/appa-55ii/api.c b/hardware/appa-55ii/api.c index 38c23b7c..de71e338 100644 --- a/hardware/appa-55ii/api.c +++ b/hardware/appa-55ii/api.c @@ -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; } diff --git a/hardware/asix-sigma/asix-sigma.c b/hardware/asix-sigma/asix-sigma.c index 26c37deb..bfd69484 100644 --- a/hardware/asix-sigma/asix-sigma.c +++ b/hardware/asix-sigma/asix-sigma.c @@ -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; } diff --git a/hardware/atten-pps3xxx/api.c b/hardware/atten-pps3xxx/api.c index 3b9f0025..5ca3dbe9 100644 --- a/hardware/atten-pps3xxx/api.c +++ b/hardware/atten-pps3xxx/api.c @@ -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. */ diff --git a/hardware/atten-pps3xxx/protocol.c b/hardware/atten-pps3xxx/protocol.c index 5658d5d5..ed4d5505 100644 --- a/hardware/atten-pps3xxx/protocol.c +++ b/hardware/atten-pps3xxx/protocol.c @@ -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); } diff --git a/hardware/brymen-bm86x/api.c b/hardware/brymen-bm86x/api.c index 169721d4..be21583b 100644 --- a/hardware/brymen-bm86x/api.c +++ b/hardware/brymen-bm86x/api.c @@ -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; } diff --git a/hardware/brymen-bm86x/protocol.c b/hardware/brymen-bm86x/protocol.c index b8fdcaab..b8e16a3f 100644 --- a/hardware/brymen-bm86x/protocol.c +++ b/hardware/brymen-bm86x/protocol.c @@ -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); } diff --git a/hardware/brymen-bm86x/protocol.h b/hardware/brymen-bm86x/protocol.h index d3d8955d..57af1552 100644 --- a/hardware/brymen-bm86x/protocol.h +++ b/hardware/brymen-bm86x/protocol.h @@ -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 */ diff --git a/hardware/brymen-dmm/api.c b/hardware/brymen-dmm/api.c index 41a31812..1ccd18af 100644 --- a/hardware/brymen-dmm/api.c +++ b/hardware/brymen-dmm/api.c @@ -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; } diff --git a/hardware/cem-dt-885x/api.c b/hardware/cem-dt-885x/api.c index 34853a0c..9aed5473 100644 --- a/hardware/cem-dt-885x/api.c +++ b/hardware/cem-dt-885x/api.c @@ -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; } diff --git a/hardware/center-3xx/api.c b/hardware/center-3xx/api.c index ddac1540..3f39b197 100644 --- a/hardware/center-3xx/api.c +++ b/hardware/center-3xx/api.c @@ -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; diff --git a/hardware/chronovu-la/api.c b/hardware/chronovu-la/api.c index 526d51cf..5a8a3d36 100644 --- a/hardware/chronovu-la/api.c +++ b/hardware/chronovu-la/api.c @@ -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; } diff --git a/hardware/colead-slm/api.c b/hardware/colead-slm/api.c index f6588272..d5fc9ac1 100644 --- a/hardware/colead-slm/api.c +++ b/hardware/colead-slm/api.c @@ -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; } diff --git a/hardware/common/scpi.c b/hardware/common/scpi.c index 21fa6b95..829a4c8c 100644 --- a/hardware/common/scpi.c +++ b/hardware/common/scpi.c @@ -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); } /** diff --git a/hardware/common/scpi_serial.c b/hardware/common/scpi_serial.c index 7000962a..feb33176 100644 --- a/hardware/common/scpi_serial.c +++ b/hardware/common/scpi_serial.c @@ -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) diff --git a/hardware/common/scpi_tcp.c b/hardware/common/scpi_tcp.c index 8ac2200f..ef3a6c75 100644 --- a/hardware/common/scpi_tcp.c +++ b/hardware/common/scpi_tcp.c @@ -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) diff --git a/hardware/common/scpi_usbtmc_libusb.c b/hardware/common/scpi_usbtmc_libusb.c index 653a0d8c..c4470b5d 100644 --- a/hardware/common/scpi_usbtmc_libusb.c +++ b/hardware/common/scpi_usbtmc_libusb.c @@ -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, diff --git a/hardware/common/scpi_visa.c b/hardware/common/scpi_visa.c index b342a91f..cf34a555 100644 --- a/hardware/common/scpi_visa.c +++ b/hardware/common/scpi_visa.c @@ -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) diff --git a/hardware/common/scpi_vxi.c b/hardware/common/scpi_vxi.c index 639b3b56..271917b0 100644 --- a/hardware/common/scpi_vxi.c +++ b/hardware/common/scpi_vxi.c @@ -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 */ diff --git a/hardware/common/serial.c b/hardware/common/serial.c index 62bbdaf9..9a9a0d94 100644 --- a/hardware/common/serial.c +++ b/hardware/common/serial.c @@ -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); diff --git a/hardware/common/usb.c b/hardware/common/usb.c index 62db385b..c3279d0a 100644 --- a/hardware/common/usb.c +++ b/hardware/common/usb.c @@ -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; diff --git a/hardware/demo/demo.c b/hardware/demo/demo.c index ea5e0b53..b2f3a509 100644 --- a/hardware/demo/demo.c +++ b/hardware/demo/demo.c @@ -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; diff --git a/hardware/fluke-dmm/api.c b/hardware/fluke-dmm/api.c index e0dee04b..3d739a18 100644 --- a/hardware/fluke-dmm/api.c +++ b/hardware/fluke-dmm/api.c @@ -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)); diff --git a/hardware/fx2lafw/api.c b/hardware/fx2lafw/api.c index 0082d228..3242afce 100644 --- a/hardware/fx2lafw/api.c +++ b/hardware/fx2lafw/api.c @@ -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); diff --git a/hardware/fx2lafw/protocol.c b/hardware/fx2lafw/protocol.c index e9b56835..433f9075 100644 --- a/hardware/fx2lafw/protocol.c +++ b/hardware/fx2lafw/protocol.c @@ -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) diff --git a/hardware/gmc-mh-1x-2x/api.c b/hardware/gmc-mh-1x-2x/api.c index 3c0a7aaf..96621bbf 100644 --- a/hardware/gmc-mh-1x-2x/api.c +++ b/hardware/gmc-mh-1x-2x/api.c @@ -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); diff --git a/hardware/hameg-hmo/api.c b/hardware/hameg-hmo/api.c index b5b3bc29..ff045f16 100644 --- a/hardware/hameg-hmo/api.c +++ b/hardware/hameg-hmo/api.c @@ -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; } diff --git a/hardware/hantek-dso/api.c b/hardware/hantek-dso/api.c index 76696d57..c948e421 100644 --- a/hardware/hantek-dso/api.c +++ b/hardware/hantek-dso/api.c @@ -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); diff --git a/hardware/ikalogic-scanalogic2/api.c b/hardware/ikalogic-scanalogic2/api.c index fd0f2176..b4c697f9 100644 --- a/hardware/ikalogic-scanalogic2/api.c +++ b/hardware/ikalogic-scanalogic2/api.c @@ -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."); diff --git a/hardware/ikalogic-scanalogic2/protocol.c b/hardware/ikalogic-scanalogic2/protocol.c index b0c33fa6..663ff527 100644 --- a/hardware/ikalogic-scanalogic2/protocol.c +++ b/hardware/ikalogic-scanalogic2/protocol.c @@ -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); diff --git a/hardware/ikalogic-scanaplus/api.c b/hardware/ikalogic-scanaplus/api.c index e8550977..3f827630 100644 --- a/hardware/ikalogic-scanaplus/api.c +++ b/hardware/ikalogic-scanaplus/api.c @@ -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; } diff --git a/hardware/kecheng-kc-330b/api.c b/hardware/kecheng-kc-330b/api.c index 57dafdfc..71bdc012 100644 --- a/hardware/kecheng-kc-330b/api.c +++ b/hardware/kecheng-kc-330b/api.c @@ -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) { diff --git a/hardware/kecheng-kc-330b/protocol.c b/hardware/kecheng-kc-330b/protocol.c index 072eb7ef..caf896ac 100644 --- a/hardware/kecheng-kc-330b/protocol.c +++ b/hardware/kecheng-kc-330b/protocol.c @@ -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; diff --git a/hardware/lascar-el-usb/api.c b/hardware/lascar-el-usb/api.c index 657d9935..04f844b3 100644 --- a/hardware/lascar-el-usb/api.c +++ b/hardware/lascar-el-usb/api.c @@ -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, diff --git a/hardware/lascar-el-usb/protocol.c b/hardware/lascar-el-usb/protocol.c index 050b42bb..49c5cd0a 100644 --- a/hardware/lascar-el-usb/protocol.c +++ b/hardware/lascar-el-usb/protocol.c @@ -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); diff --git a/hardware/link-mso19/api.c b/hardware/link-mso19/api.c index 45453efd..13c29720 100644 --- a/hardware/link-mso19/api.c +++ b/hardware/link-mso19/api.c @@ -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; } diff --git a/hardware/link-mso19/protocol.c b/hardware/link-mso19/protocol.c index 40a30b94..5f7aa719 100644 --- a/hardware/link-mso19/protocol.c +++ b/hardware/link-mso19/protocol.c @@ -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; diff --git a/hardware/manson-hcs-3xxx/api.c b/hardware/manson-hcs-3xxx/api.c index dead3085..faa093f1 100644 --- a/hardware/manson-hcs-3xxx/api.c +++ b/hardware/manson-hcs-3xxx/api.c @@ -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; } diff --git a/hardware/mic-985xx/api.c b/hardware/mic-985xx/api.c index 7b0d680c..6cfc5efd 100644 --- a/hardware/mic-985xx/api.c +++ b/hardware/mic-985xx/api.c @@ -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; diff --git a/hardware/motech-lps-30x/api.c b/hardware/motech-lps-30x/api.c index ad0fb3c4..164a9cc0 100644 --- a/hardware/motech-lps-30x/api.c +++ b/hardware/motech-lps-30x/api.c @@ -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. */ diff --git a/hardware/norma-dmm/api.c b/hardware/norma-dmm/api.c index 5dacde2e..798b60e1 100644 --- a/hardware/norma-dmm/api.c +++ b/hardware/norma-dmm/api.c @@ -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; } diff --git a/hardware/openbench-logic-sniffer/api.c b/hardware/openbench-logic-sniffer/api.c index 47a938b0..cd9d817e 100644 --- a/hardware/openbench-logic-sniffer/api.c +++ b/hardware/openbench-logic-sniffer/api.c @@ -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; } diff --git a/hardware/openbench-logic-sniffer/protocol.c b/hardware/openbench-logic-sniffer/protocol.c index d4e54bbc..1c94b7ff 100644 --- a/hardware/openbench-logic-sniffer/protocol.c +++ b/hardware/openbench-logic-sniffer/protocol.c @@ -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."); diff --git a/hardware/rigol-ds/api.c b/hardware/rigol-ds/api.c index 46500104..872531f6 100644 --- a/hardware/rigol-ds/api.c +++ b/hardware/rigol-ds/api.c @@ -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; } diff --git a/hardware/saleae-logic16/api.c b/hardware/saleae-logic16/api.c index 4cfdff12..6bd539ca 100644 --- a/hardware/saleae-logic16/api.c +++ b/hardware/saleae-logic16/api.c @@ -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); diff --git a/hardware/saleae-logic16/protocol.c b/hardware/saleae-logic16/protocol.c index 8b430d90..78583343 100644 --- a/hardware/saleae-logic16/protocol.c +++ b/hardware/saleae-logic16/protocol.c @@ -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 diff --git a/hardware/serial-dmm/api.c b/hardware/serial-dmm/api.c index 12396901..b96c7a0d 100644 --- a/hardware/serial-dmm/api.c +++ b/hardware/serial-dmm/api.c @@ -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; diff --git a/hardware/sysclk-lwla/api.c b/hardware/sysclk-lwla/api.c index d5506539..a4346a01 100644 --- a/hardware/sysclk-lwla/api.c +++ b/hardware/sysclk-lwla/api.c @@ -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."); diff --git a/hardware/sysclk-lwla/protocol.c b/hardware/sysclk-lwla/protocol.c index 5dc19b92..f1ae8b3d 100644 --- a/hardware/sysclk-lwla/protocol.c +++ b/hardware/sysclk-lwla/protocol.c @@ -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); diff --git a/hardware/teleinfo/api.c b/hardware/teleinfo/api.c index 931e5994..c4fd8467 100644 --- a/hardware/teleinfo/api.c +++ b/hardware/teleinfo/api.c @@ -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; } diff --git a/hardware/testo/api.c b/hardware/testo/api.c index 9c22893b..2b4c9634 100644 --- a/hardware/testo/api.c +++ b/hardware/testo/api.c @@ -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; diff --git a/hardware/tondaj-sl-814/api.c b/hardware/tondaj-sl-814/api.c index d112b195..7917c8d2 100644 --- a/hardware/tondaj-sl-814/api.c +++ b/hardware/tondaj-sl-814/api.c @@ -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; diff --git a/hardware/uni-t-dmm/api.c b/hardware/uni-t-dmm/api.c index ef31de04..f98c4f5e 100644 --- a/hardware/uni-t-dmm/api.c +++ b/hardware/uni-t-dmm/api.c @@ -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; } diff --git a/hardware/uni-t-ut32x/api.c b/hardware/uni-t-ut32x/api.c index b38d2fb0..81024dc7 100644 --- a/hardware/uni-t-ut32x/api.c +++ b/hardware/uni-t-ut32x/api.c @@ -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; } diff --git a/hardware/uni-t-ut32x/protocol.c b/hardware/uni-t-ut32x/protocol.c index 863f9fa8..65cb756b 100644 --- a/hardware/uni-t-ut32x/protocol.c +++ b/hardware/uni-t-ut32x/protocol.c @@ -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); diff --git a/hardware/victor-dmm/api.c b/hardware/victor-dmm/api.c index 74523ed7..56c53e50 100644 --- a/hardware/victor-dmm/api.c +++ b/hardware/victor-dmm/api.c @@ -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); diff --git a/libsigrok-internal.h b/libsigrok-internal.h index 62714a22..8c58bd9f 100644 --- a/libsigrok-internal.h +++ b/libsigrok-internal.h @@ -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, diff --git a/session.c b/session.c index 7a44a27d..4c6095e0 100644 --- 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); } /** @} */ diff --git a/session_driver.c b/session_driver.c index fd86ced1..9120ea14 100644 --- a/session_driver.c +++ b/session_driver.c @@ -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 1b9c6000..2319dfef 100644 --- 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; }