+ 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;
+ unsigned char *buf;
+
+ if (sdi->status != SR_ST_ACTIVE)
+ return SR_ERR_DEV_CLOSED;
+
+ if (!di->priv) {
+ sr_err("Driver was not initialized.");
+ return SR_ERR;
+ }
+
+ devc = sdi->priv;
+ usb = sdi->conn;
+ devc->cb_data = 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;
+
+ buf = g_try_malloc(DMM_DATA_SIZE);
+ transfer = libusb_alloc_transfer(0);
+ /* Each transfer request gets 100ms to arrive before it's restarted.
+ * The device only sends 1 transfer/second no matter how many
+ * times you ask, but we want to keep step with the USB events
+ * handling above. */
+ libusb_fill_interrupt_transfer(transfer, usb->devhdl,
+ VICTOR_ENDPOINT, buf, DMM_DATA_SIZE, receive_transfer,
+ cb_data, 100);
+ if ((ret = libusb_submit_transfer(transfer) != 0)) {
+ sr_err("Unable to submit transfer: %s.", libusb_error_name(ret));
+ libusb_free_transfer(transfer);
+ g_free(buf);
+ return SR_ERR;
+ }