From: Bert Vermeulen Date: Tue, 30 Apr 2013 07:55:44 +0000 (+0200) Subject: fx2lafw: Keep track of our own libusb fds X-Git-Tag: dsupstream~27 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=0a7da5f8c9f1c6656672152ad48d76b5a4cd7ecd;p=libsigrok.git fx2lafw: Keep track of our own libusb fds --- diff --git a/hardware/fx2lafw/fx2lafw.c b/hardware/fx2lafw/fx2lafw.c index c55c0ed1..02ddbb96 100644 --- a/hardware/fx2lafw/fx2lafw.c +++ b/hardware/fx2lafw/fx2lafw.c @@ -700,8 +700,6 @@ static void abort_acquisition(struct dev_context *devc) static void finish_acquisition(struct dev_context *devc) { struct sr_datafeed_packet packet; - struct drv_context *drvc = di->priv; - const struct libusb_pollfd **lupfd; int i; /* Terminate session. */ @@ -709,10 +707,9 @@ static void finish_acquisition(struct dev_context *devc) sr_session_send(devc->cb_data, &packet); /* Remove fds from polling. */ - lupfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx); - for (i = 0; lupfd[i]; i++) - sr_source_remove(lupfd[i]->fd); - free(lupfd); /* NOT g_free()! */ + for (i = 0; devc->usbfd[i] != -1; i++) + sr_source_remove(devc->usbfd[i]); + g_free(devc->usbfd); devc->num_transfers = 0; g_free(devc->transfers); @@ -1002,10 +999,16 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, } lupfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx); - for (i = 0; lupfd[i]; i++) + 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); - free(lupfd); /* NOT g_free()! */ + devc->usbfd[i] = lupfd[i]->fd; + } + devc->usbfd[i] = -1; + free(lupfd); /* Send header packet to the session bus. */ std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN); @@ -1019,7 +1022,6 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, return SR_OK; } -/* TODO: This stops acquisition on ALL devices, ignoring dev_index. */ static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { (void)cb_data; diff --git a/hardware/fx2lafw/fx2lafw.h b/hardware/fx2lafw/fx2lafw.h index bb936627..a77c94ae 100644 --- a/hardware/fx2lafw/fx2lafw.h +++ b/hardware/fx2lafw/fx2lafw.h @@ -71,7 +71,6 @@ struct fx2lafw_profile { struct dev_context { const struct fx2lafw_profile *profile; - /* * Since we can't keep track of an fx2lafw device after upgrading * the firmware (it renumerates into a different device address @@ -84,8 +83,8 @@ struct dev_context { uint64_t cur_samplerate; uint64_t limit_samples; + /* Operational settings */ gboolean sample_wide; - uint16_t trigger_mask[NUM_TRIGGER_STAGES]; uint16_t trigger_value[NUM_TRIGGER_STAGES]; int trigger_stage; @@ -96,9 +95,9 @@ struct dev_context { int empty_transfer_count; void *cb_data; - unsigned int num_transfers; struct libusb_transfer **transfers; + int *usbfd; }; #endif