fx2lafw: Keep track of our own libusb fds

This commit is contained in:
Bert Vermeulen 2013-04-30 09:55:44 +02:00
parent 0372864451
commit 0a7da5f8c9
2 changed files with 13 additions and 12 deletions

View File

@ -700,8 +700,6 @@ static void abort_acquisition(struct dev_context *devc)
static void finish_acquisition(struct dev_context *devc) static void finish_acquisition(struct dev_context *devc)
{ {
struct sr_datafeed_packet packet; struct sr_datafeed_packet packet;
struct drv_context *drvc = di->priv;
const struct libusb_pollfd **lupfd;
int i; int i;
/* Terminate session. */ /* Terminate session. */
@ -709,10 +707,9 @@ static void finish_acquisition(struct dev_context *devc)
sr_session_send(devc->cb_data, &packet); sr_session_send(devc->cb_data, &packet);
/* Remove fds from polling. */ /* Remove fds from polling. */
lupfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx); for (i = 0; devc->usbfd[i] != -1; i++)
for (i = 0; lupfd[i]; i++) sr_source_remove(devc->usbfd[i]);
sr_source_remove(lupfd[i]->fd); g_free(devc->usbfd);
free(lupfd); /* NOT g_free()! */
devc->num_transfers = 0; devc->num_transfers = 0;
g_free(devc->transfers); 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); 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, sr_source_add(lupfd[i]->fd, lupfd[i]->events,
timeout, receive_data, NULL); 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. */ /* Send header packet to the session bus. */
std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN); 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; 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) static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
{ {
(void)cb_data; (void)cb_data;

View File

@ -71,7 +71,6 @@ struct fx2lafw_profile {
struct dev_context { struct dev_context {
const struct fx2lafw_profile *profile; const struct fx2lafw_profile *profile;
/* /*
* Since we can't keep track of an fx2lafw device after upgrading * Since we can't keep track of an fx2lafw device after upgrading
* the firmware (it renumerates into a different device address * the firmware (it renumerates into a different device address
@ -84,8 +83,8 @@ struct dev_context {
uint64_t cur_samplerate; uint64_t cur_samplerate;
uint64_t limit_samples; uint64_t limit_samples;
/* Operational settings */
gboolean sample_wide; gboolean sample_wide;
uint16_t trigger_mask[NUM_TRIGGER_STAGES]; uint16_t trigger_mask[NUM_TRIGGER_STAGES];
uint16_t trigger_value[NUM_TRIGGER_STAGES]; uint16_t trigger_value[NUM_TRIGGER_STAGES];
int trigger_stage; int trigger_stage;
@ -96,9 +95,9 @@ struct dev_context {
int empty_transfer_count; int empty_transfer_count;
void *cb_data; void *cb_data;
unsigned int num_transfers; unsigned int num_transfers;
struct libusb_transfer **transfers; struct libusb_transfer **transfers;
int *usbfd;
}; };
#endif #endif