+static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi)
+{
+
+ (void)sdi;
+
+ switch (key) {
+ case SR_CONF_SCAN_OPTIONS:
+ *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
+ hwopts, ARRAY_SIZE(hwopts), sizeof(int32_t));
+ break;
+ case SR_CONF_DEVICE_OPTIONS:
+ *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32,
+ hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t));
+ break;
+ default:
+ return SR_ERR_NA;
+ }
+
+ return SR_OK;
+}
+
+static void receive_transfer(struct libusb_transfer *transfer)
+{
+ struct dev_context *devc;
+ struct sr_dev_inst *sdi;
+ int ret;
+
+ sdi = transfer->user_data;
+ devc = sdi->priv;
+ if (transfer->status == LIBUSB_TRANSFER_NO_DEVICE) {
+ /* USB device was unplugged. */
+ hw_dev_acquisition_stop(sdi, sdi);
+ } else if (transfer->status == LIBUSB_TRANSFER_COMPLETED) {
+ sr_dbg("Got %d-byte packet.", transfer->actual_length);
+ if (transfer->actual_length == DMM_DATA_SIZE) {
+ victor_dmm_receive_data(sdi, transfer->buffer);
+ if (devc->limit_samples) {
+ if (devc->num_samples >= devc->limit_samples)
+ hw_dev_acquisition_stop(sdi, sdi);
+ }
+ }
+ }
+ /* Anything else is either an error or a timeout, which is fine:
+ * we were just going to send another transfer request anyway. */
+
+ if (sdi->status == SR_ST_ACTIVE) {
+ /* Send the same request again. */
+ if ((ret = libusb_submit_transfer(transfer) != 0)) {
+ sr_err("Unable to resubmit transfer: %s.",
+ libusb_error_name(ret));
+ g_free(transfer->buffer);
+ libusb_free_transfer(transfer);
+ hw_dev_acquisition_stop(sdi, sdi);
+ }
+ } else {
+ /* This was the last transfer we're going to receive, so
+ * clean up now. */
+ g_free(transfer->buffer);
+ libusb_free_transfer(transfer);
+ }
+}
+
+static int 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;
+ gint64 now;
+ int i;
+
+ (void)fd;
+ (void)revents;
+
+ sdi = cb_data;
+ devc = sdi->priv;
+
+ if (devc->limit_msec) {
+ now = g_get_monotonic_time() / 1000;
+ if (now > devc->end_time)
+ hw_dev_acquisition_stop(sdi, sdi);
+ }
+
+ if (sdi->status == SR_ST_STOPPING) {
+ for (i = 0; devc->usbfd[i] != -1; i++)
+ sr_source_remove(devc->usbfd[i]);
+
+ hw_dev_close(sdi);
+
+ packet.type = SR_DF_END;
+ sr_session_send(cb_data, &packet);
+ }
+
+ memset(&tv, 0, sizeof(struct timeval));
+ libusb_handle_events_timeout_completed(drvc->sr_ctx->libusb_ctx, &tv,
+ NULL);
+
+ return TRUE;
+}
+