From: Martin Ling Date: Sat, 21 Dec 2013 23:03:24 +0000 (+0000) Subject: Use common usb_source_add and usb_source_remove functions. X-Git-Tag: libsigrok-0.3.0~421 X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=6c60facc190a03c50aa66d4b1d17c825fec5d20e Use common usb_source_add and usb_source_remove functions. --- diff --git a/hardware/common/usb.c b/hardware/common/usb.c index bac420b3..249bce5a 100644 --- a/hardware/common/usb.c +++ b/hardware/common/usb.c @@ -243,3 +243,40 @@ SR_PRIV int sr_usb_open(libusb_context *usb_ctx, struct sr_usb_dev_inst *usb) return ret; } + +SR_PRIV int usb_source_add(struct sr_context *ctx, int timeout, + sr_receive_data_callback_t cb, void *cb_data) +{ +#ifdef _WIN32 + sr_err("Operation not supported on Windows yet."); + return SR_ERR; +#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); + free(lupfd); + + return SR_OK; +#endif +} + +SR_PRIV int usb_source_remove(struct sr_context *ctx) +{ +#ifdef _WIN32 + sr_err("Operation not supported on Windows yet."); + return SR_ERR; +#else + const struct libusb_pollfd **lupfd; + unsigned int i; + + lupfd = libusb_get_pollfds(ctx->libusb_ctx); + for (i = 0; lupfd[i]; i++) + sr_source_remove(lupfd[i]->fd); + free(lupfd); + + return SR_OK; +#endif +} diff --git a/hardware/fx2lafw/api.c b/hardware/fx2lafw/api.c index d10b6543..0c591428 100644 --- a/hardware/fx2lafw/api.c +++ b/hardware/fx2lafw/api.c @@ -468,7 +468,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) struct drv_context *drvc; struct sr_usb_dev_inst *usb; struct libusb_transfer *transfer; - const struct libusb_pollfd **lupfd; unsigned int i, timeout, num_transfers; int ret; unsigned char *buf; @@ -524,17 +523,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) devc->submitted_transfers++; } - lupfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx); - for (i = 0; lupfd[i]; i++); - if (!(devc->usbfd = g_try_malloc(sizeof(struct libusb_pollfd) * (i + 1)))) - return SR_ERR; - for (i = 0; lupfd[i]; i++) { - sr_source_add(lupfd[i]->fd, lupfd[i]->events, - timeout, receive_data, NULL); - devc->usbfd[i] = lupfd[i]->fd; - } - devc->usbfd[i] = -1; - free(lupfd); + devc->ctx = drvc->sr_ctx; + + usb_source_add(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 38ee13b5..303118d7 100644 --- a/hardware/fx2lafw/protocol.c +++ b/hardware/fx2lafw/protocol.c @@ -375,16 +375,13 @@ SR_PRIV void fx2lafw_abort_acquisition(struct dev_context *devc) static void finish_acquisition(struct dev_context *devc) { struct sr_datafeed_packet packet; - int i; /* Terminate session. */ packet.type = SR_DF_END; sr_session_send(devc->cb_data, &packet); /* Remove fds from polling. */ - for (i = 0; devc->usbfd[i] != -1; i++) - sr_source_remove(devc->usbfd[i]); - g_free(devc->usbfd); + usb_source_remove(devc->ctx); devc->num_transfers = 0; g_free(devc->transfers); diff --git a/hardware/fx2lafw/protocol.h b/hardware/fx2lafw/protocol.h index 5ccf8c1c..76ef63d5 100644 --- a/hardware/fx2lafw/protocol.h +++ b/hardware/fx2lafw/protocol.h @@ -103,7 +103,7 @@ struct dev_context { void *cb_data; unsigned int num_transfers; struct libusb_transfer **transfers; - int *usbfd; + struct sr_context *ctx; }; SR_PRIV int fx2lafw_command_start_acquisition(libusb_device_handle *devhdl, diff --git a/hardware/hantek-dso/api.c b/hardware/hantek-dso/api.c index f74cefdf..3da04264 100644 --- a/hardware/hantek-dso/api.c +++ b/hardware/hantek-dso/api.c @@ -805,8 +805,7 @@ static int handle_event(int fd, int revents, void *cb_data) struct timeval tv; struct dev_context *devc; struct drv_context *drvc = di->priv; - const struct libusb_pollfd **lupfd; - int num_probes, i; + int num_probes; uint32_t trigger_offset; uint8_t capturestate; @@ -822,10 +821,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. */ - lupfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx); - for (i = 0; lupfd[i]; i++) - sr_source_remove(lupfd[i]->fd); - free(lupfd); + usb_source_remove(drvc->sr_ctx); packet.type = SR_DF_END; sr_session_send(sdi, &packet); @@ -915,10 +911,8 @@ static int handle_event(int fd, int revents, void *cb_data) static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { - const struct libusb_pollfd **lupfd; struct dev_context *devc; struct drv_context *drvc = di->priv; - int i; if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; @@ -938,11 +932,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) return SR_ERR; devc->dev_state = CAPTURE; - lupfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx); - for (i = 0; lupfd[i]; i++) - sr_source_add(lupfd[i]->fd, lupfd[i]->events, TICK, - handle_event, (void *)sdi); - free(lupfd); + usb_source_add(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 1fe869c3..a91afdbb 100644 --- a/hardware/ikalogic-scanalogic2/api.c +++ b/hardware/ikalogic-scanalogic2/api.c @@ -402,7 +402,6 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { - const struct libusb_pollfd **pfd; struct drv_context *drvc; struct dev_context *devc; uint16_t trigger_bytes, tmp; @@ -473,34 +472,12 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) tmp = GUINT16_TO_LE(devc->after_trigger_delay); memcpy(devc->xfer_data_out + 10, &tmp, sizeof(tmp)); - if (!(pfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx))) { - sr_err("libusb_get_pollfds failed."); - return SR_ERR; - } - - /* Count the number of file descriptors. */ - for (devc->num_usbfd = 0; pfd[devc->num_usbfd]; devc->num_usbfd++); - - if (!(devc->usbfd = g_try_malloc(devc->num_usbfd * sizeof(int)))) { - sr_err("File descriptor array malloc failed."); - free(pfd); - return SR_ERR_MALLOC; - } - if ((ret = libusb_submit_transfer(devc->xfer_out)) != 0) { sr_err("Submit transfer failed: %s.", libusb_error_name(ret)); - g_free(devc->usbfd); return SR_ERR; } - for (i = 0; i < devc->num_usbfd; i++) { - sr_source_add(pfd[i]->fd, pfd[i]->events, 100, - ikalogic_scanalogic2_receive_data, (void *)sdi); - - devc->usbfd[i] = pfd[i]->fd; - } - - free(pfd); + usb_source_add(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 4c06e96d..87218de5 100644 --- a/hardware/ikalogic-scanalogic2/protocol.c +++ b/hardware/ikalogic-scanalogic2/protocol.c @@ -26,17 +26,14 @@ extern uint64_t sl2_samplerates[NUM_SAMPLERATES]; static void stop_acquisition(struct sr_dev_inst *sdi) { + struct drv_context *drvc = sdi->driver->priv; struct dev_context *devc; struct sr_datafeed_packet packet; - unsigned int i; devc = sdi->priv; /* Remove USB file descriptors from polling. */ - for (i = 0; i < devc->num_usbfd; i++) - sr_source_remove(devc->usbfd[i]); - - g_free(devc->usbfd); + usb_source_remove(drvc->sr_ctx); packet.type = SR_DF_END; sr_session_send(devc->cb_data, &packet); @@ -46,17 +43,14 @@ static void stop_acquisition(struct sr_dev_inst *sdi) static void abort_acquisition(struct sr_dev_inst *sdi) { + struct drv_context *drvc = sdi->driver->priv; struct dev_context *devc; struct sr_datafeed_packet packet; - unsigned int i; devc = sdi->priv; /* Remove USB file descriptors from polling. */ - for (i = 0; i < devc->num_usbfd; i++) - sr_source_remove(devc->usbfd[i]); - - g_free(devc->usbfd); + usb_source_remove(drvc->sr_ctx); packet.type = SR_DF_END; sr_session_send(devc->cb_data, &packet); diff --git a/hardware/ikalogic-scanalogic2/protocol.h b/hardware/ikalogic-scanalogic2/protocol.h index adc38592..8324204e 100644 --- a/hardware/ikalogic-scanalogic2/protocol.h +++ b/hardware/ikalogic-scanalogic2/protocol.h @@ -161,9 +161,6 @@ struct dev_context { /* Array to provide an index based access to all probes. */ const struct sr_probe *probes[NUM_PROBES]; - unsigned int num_usbfd; - int *usbfd; - struct libusb_transfer *xfer_in, *xfer_out; /* diff --git a/hardware/kecheng-kc-330b/api.c b/hardware/kecheng-kc-330b/api.c index 9355e6dc..d9e647d1 100644 --- a/hardware/kecheng-kc-330b/api.c +++ b/hardware/kecheng-kc-330b/api.c @@ -432,9 +432,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, struct sr_config *src; struct sr_usb_dev_inst *usb; GVariant *gvar, *rational[2]; - const struct libusb_pollfd **pfd; const uint64_t *si; - int stored_mqflags, req_len, buf_len, len, ret, i; + int stored_mqflags, req_len, buf_len, len, ret; unsigned char buf[9]; if (sdi->status != SR_ST_ACTIVE) @@ -494,15 +493,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, if (!(devc->xfer = libusb_alloc_transfer(0))) return SR_ERR; - pfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx); - for (i = 0; pfd[i]; i++) { - /* Handle USB events every 10ms. */ - sr_source_add(pfd[i]->fd, pfd[i]->events, 10, - kecheng_kc_330b_handle_events, (void *)sdi); - /* We'll need to remove this fd later. */ - devc->usbfd[i] = pfd[i]->fd; - } - devc->usbfd[i] = -1; + usb_source_add(drvc->sr_ctx, 10, + kecheng_kc_330b_handle_events, (void *)sdi); if (devc->data_source == DATA_SOURCE_LIVE) { buf[0] = CMD_GET_LIVE_SPL; diff --git a/hardware/kecheng-kc-330b/protocol.c b/hardware/kecheng-kc-330b/protocol.c index a3a09514..c6263cde 100644 --- a/hardware/kecheng-kc-330b/protocol.c +++ b/hardware/kecheng-kc-330b/protocol.c @@ -34,7 +34,7 @@ SR_PRIV int kecheng_kc_330b_handle_events(int fd, int revents, void *cb_data) struct timeval tv; const uint64_t *intv_entry; gint64 now, interval; - int offset, len, ret, i; + int offset, len, ret; unsigned char buf[4]; (void)fd; @@ -51,8 +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); - for (i = 0; devc->usbfd[i] != -1; i++) - sr_source_remove(devc->usbfd[i]); + usb_source_remove(drvc->sr_ctx); packet.type = SR_DF_END; sr_session_send(cb_data, &packet); sdi->status = SR_ST_ACTIVE; diff --git a/hardware/kecheng-kc-330b/protocol.h b/hardware/kecheng-kc-330b/protocol.h index 6bf86efb..eabda85b 100644 --- a/hardware/kecheng-kc-330b/protocol.h +++ b/hardware/kecheng-kc-330b/protocol.h @@ -89,7 +89,6 @@ struct dev_context { uint64_t num_samples; uint64_t stored_samples; void *cb_data; - int usbfd[10]; struct libusb_transfer *xfer; unsigned char buf[128]; diff --git a/hardware/lascar-el-usb/api.c b/hardware/lascar-el-usb/api.c index b699f283..74fd1e71 100644 --- a/hardware/lascar-el-usb/api.c +++ b/hardware/lascar-el-usb/api.c @@ -340,10 +340,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) struct drv_context *drvc; struct sr_usb_dev_inst *usb; struct libusb_transfer *xfer_in, *xfer_out; - const struct libusb_pollfd **pfd; struct timeval tv; uint64_t interval; - int ret, i; + int ret; unsigned char cmd[3], resp[4], *buf; if (sdi->status != SR_ST_ACTIVE) @@ -440,15 +439,7 @@ 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); - pfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx); - for (i = 0; pfd[i]; i++) { - /* Handle USB events every 100ms, for decent latency. */ - sr_source_add(pfd[i]->fd, pfd[i]->events, 100, - lascar_el_usb_handle_events, (void *)sdi); - /* We'll need to remove this fd later. */ - devc->usbfd[i] = pfd[i]->fd; - } - devc->usbfd[i] = -1; + usb_source_add(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 3f9cbc88..032db07e 100644 --- a/hardware/lascar-el-usb/protocol.c +++ b/hardware/lascar-el-usb/protocol.c @@ -488,22 +488,18 @@ static void lascar_el_usb_dispatch(struct sr_dev_inst *sdi, unsigned char *buf, SR_PRIV int lascar_el_usb_handle_events(int fd, int revents, void *cb_data) { - struct dev_context *devc; struct drv_context *drvc = di->priv; struct sr_datafeed_packet packet; struct sr_dev_inst *sdi; struct timeval tv; - int i; (void)fd; (void)revents; sdi = cb_data; - devc = sdi->priv; if (sdi->status == SR_ST_STOPPING) { - for (i = 0; devc->usbfd[i] != -1; i++) - sr_source_remove(devc->usbfd[i]); + usb_source_remove(drvc->sr_ctx); packet.type = SR_DF_END; sr_session_send(cb_data, &packet); diff --git a/hardware/lascar-el-usb/protocol.h b/hardware/lascar-el-usb/protocol.h index be27f69c..16e826a0 100644 --- a/hardware/lascar-el-usb/protocol.h +++ b/hardware/lascar-el-usb/protocol.h @@ -45,7 +45,6 @@ struct dev_context { void *cb_data; const struct elusb_profile *profile; - int usbfd[10]; /* Generic EL-USB */ unsigned char config[MAX_CONFIGBLOCK_SIZE]; unsigned int log_size; diff --git a/hardware/saleae-logic16/api.c b/hardware/saleae-logic16/api.c index e399729e..d2815f63 100644 --- a/hardware/saleae-logic16/api.c +++ b/hardware/saleae-logic16/api.c @@ -691,7 +691,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) struct drv_context *drvc; struct sr_usb_dev_inst *usb; struct libusb_transfer *transfer; - const struct libusb_pollfd **lupfd; unsigned int i, timeout, num_transfers; int ret; unsigned char *buf; @@ -721,7 +720,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) size = get_buffer_size(devc); convsize = (size / devc->num_channels + 2) * 16; devc->submitted_transfers = 0; - devc->usbfd = NULL; devc->convbuffer_size = convsize; if (!(devc->convbuffer = g_try_malloc(convsize))) { @@ -771,21 +769,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) devc->submitted_transfers++; } - lupfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx); - for (i = 0; lupfd[i]; i++); - devc->usbfd = g_try_malloc(sizeof(struct libusb_pollfd) * (i + 1)); - if (!devc->usbfd) { - abort_acquisition(devc); - free(lupfd); - return SR_ERR; - } - for (i = 0; lupfd[i]; i++) { - sr_source_add(lupfd[i]->fd, lupfd[i]->events, - timeout, receive_data, (void *)sdi); - devc->usbfd[i] = lupfd[i]->fd; - } - devc->usbfd[i] = -1; - free(lupfd); + devc->ctx = drvc->sr_ctx; + + usb_source_add(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 4cea180f..c7ff20c4 100644 --- a/hardware/saleae-logic16/protocol.c +++ b/hardware/saleae-logic16/protocol.c @@ -579,18 +579,13 @@ SR_PRIV int logic16_init_device(const struct sr_dev_inst *sdi) static void finish_acquisition(struct dev_context *devc) { struct sr_datafeed_packet packet; - int i; /* Terminate session. */ packet.type = SR_DF_END; sr_session_send(devc->cb_data, &packet); /* Remove fds from polling. */ - if (devc->usbfd != NULL) { - for (i = 0; devc->usbfd[i] != -1; i++) - sr_source_remove(devc->usbfd[i]); - g_free(devc->usbfd); - } + usb_source_remove(devc->ctx); devc->num_transfers = 0; g_free(devc->transfers); diff --git a/hardware/saleae-logic16/protocol.h b/hardware/saleae-logic16/protocol.h index cd8380e3..6faa8b68 100644 --- a/hardware/saleae-logic16/protocol.h +++ b/hardware/saleae-logic16/protocol.h @@ -82,7 +82,7 @@ struct dev_context { void *cb_data; unsigned int num_transfers; struct libusb_transfer **transfers; - int *usbfd; + struct sr_context *ctx; }; SR_PRIV int logic16_setup_acquisition(const struct sr_dev_inst *sdi, diff --git a/hardware/uni-t-ut32x/api.c b/hardware/uni-t-ut32x/api.c index 8d4e7221..347149e0 100644 --- a/hardware/uni-t-ut32x/api.c +++ b/hardware/uni-t-ut32x/api.c @@ -297,8 +297,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, struct drv_context *drvc; struct dev_context *devc; struct sr_usb_dev_inst *usb; - const struct libusb_pollfd **pfd; - int len, ret, i; + int len, ret; unsigned char cmd[2]; if (sdi->status != SR_ST_ACTIVE) @@ -350,15 +349,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, return SR_ERR; } - pfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx); - for (i = 0; pfd[i]; i++) { - /* Handle USB events every 10ms. */ - sr_source_add(pfd[i]->fd, pfd[i]->events, 10, - uni_t_ut32x_handle_events, (void *)sdi); - /* We'll need to remove this fd later. */ - devc->usbfd[i] = pfd[i]->fd; - } - devc->usbfd[i] = -1; + usb_source_add(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 95f512b3..52c62892 100644 --- a/hardware/uni-t-ut32x/protocol.c +++ b/hardware/uni-t-ut32x/protocol.c @@ -198,7 +198,7 @@ SR_PRIV int uni_t_ut32x_handle_events(int fd, int revents, void *cb_data) struct sr_datafeed_packet packet; struct sr_usb_dev_inst *usb; struct timeval tv; - int len, ret, i; + int len, ret; unsigned char cmd[2]; (void)fd; @@ -216,8 +216,7 @@ SR_PRIV int uni_t_ut32x_handle_events(int fd, int revents, void *cb_data) NULL); if (sdi->status == SR_ST_STOPPING) { - for (i = 0; devc->usbfd[i] != -1; i++) - sr_source_remove(devc->usbfd[i]); + usb_source_remove(drvc->sr_ctx); packet.type = SR_DF_END; sr_session_send(cb_data, &packet); diff --git a/hardware/uni-t-ut32x/protocol.h b/hardware/uni-t-ut32x/protocol.h index b070eb43..42cf01d1 100644 --- a/hardware/uni-t-ut32x/protocol.h +++ b/hardware/uni-t-ut32x/protocol.h @@ -63,7 +63,6 @@ struct dev_context { /* Operational state */ uint64_t num_samples; - int usbfd[10]; unsigned char buf[8]; struct libusb_transfer *xfer; void *cb_data; diff --git a/hardware/victor-dmm/api.c b/hardware/victor-dmm/api.c index 97e5f7bd..03462768 100644 --- a/hardware/victor-dmm/api.c +++ b/hardware/victor-dmm/api.c @@ -338,7 +338,6 @@ static int handle_events(int fd, int revents, void *cb_data) struct sr_dev_inst *sdi; struct timeval tv; gint64 now; - int i; (void)fd; (void)revents; @@ -353,8 +352,7 @@ static int handle_events(int fd, int revents, void *cb_data) } if (sdi->status == SR_ST_STOPPING) { - for (i = 0; devc->usbfd[i] != -1; i++) - sr_source_remove(devc->usbfd[i]); + usb_source_remove(drvc->sr_ctx); dev_close(sdi); @@ -373,10 +371,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { struct dev_context *devc; struct drv_context *drvc = di->priv; - const struct libusb_pollfd **pfd; struct sr_usb_dev_inst *usb; struct libusb_transfer *transfer; - int ret, i; + int ret; unsigned char *buf; if (sdi->status != SR_ST_ACTIVE) @@ -394,15 +391,7 @@ 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); - pfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx); - for (i = 0; pfd[i]; i++) { - /* Handle USB events every 100ms, for decent latency. */ - sr_source_add(pfd[i]->fd, pfd[i]->events, 100, - handle_events, (void *)sdi); - /* We'll need to remove this fd later. */ - devc->usbfd[i] = pfd[i]->fd; - } - devc->usbfd[i] = -1; + usb_source_add(drvc->sr_ctx, 100, handle_events, (void *)sdi); buf = g_try_malloc(DMM_DATA_SIZE); transfer = libusb_alloc_transfer(0); diff --git a/hardware/victor-dmm/protocol.h b/hardware/victor-dmm/protocol.h index b8573786..92539004 100644 --- a/hardware/victor-dmm/protocol.h +++ b/hardware/victor-dmm/protocol.h @@ -49,9 +49,6 @@ struct dev_context { /** The current number of already received samples. */ uint64_t num_samples; gint64 end_time; - - /* Only requires 3 really. */ - int usbfd[10]; }; SR_PRIV int victor_dmm_receive_data(struct sr_dev_inst *sdi, unsigned char *buf); diff --git a/libsigrok-internal.h b/libsigrok-internal.h index d9def32e..5c8d53de 100644 --- a/libsigrok-internal.h +++ b/libsigrok-internal.h @@ -268,6 +268,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_t cb, void *cb_data); +SR_PRIV int usb_source_remove(struct sr_context *ctx); #endif /*--- hardware/common/scpi.c ------------------------------------------------*/