]> sigrok.org Git - libsigrok.git/commitdiff
sr: Eliminate usb/serial instances from API.
authorUwe Hermann <redacted>
Sun, 29 Jan 2012 22:06:10 +0000 (23:06 +0100)
committerUwe Hermann <redacted>
Tue, 31 Jan 2012 01:04:35 +0000 (02:04 +0100)
The API should be generic and only provide sr_device_instance_new() and
friends, but not sr_usb_device_instance_new(), sr_serial_device_instance_new(),
or others for other device types we may have in the future. The
frontends shouldn't have to know or care about this implementation detail.

This also fixes the problem that parts of sigrok.h contained
'#ifdef HAVE_LIBUSB_1_0' and such, which is even less desirable for the API.

The usb/serial instance specifics are now private, and each driver that
needs them keeps a pointer in its driver-specific context.

hardware/openbench-logic-sniffer/ols.c
hardware/openbench-logic-sniffer/ols.h
hardware/saleae-logic/saleae-logic.c
hardware/saleae-logic/saleae-logic.h
hardware/zeroplus-logic-cube/zeroplus.c
hwplugin.c
sigrok-internal.h
sigrok-proto.h
sigrok.h.in

index 724aa43b613dcb89d7180ebea9cc026bcbb1d3ac..112c48d0a5b7ee069edde7c3f0f32119ea4da934 100644 (file)
@@ -218,6 +218,7 @@ static struct ols_device *ols_device_new(void)
        ols->probe_mask = 0xffffffff;
        ols->cur_samplerate = SR_KHZ(200);
        ols->period_ps = 5000000;
+       ols->serial = NULL;
 
        return ols;
 }
@@ -452,7 +453,7 @@ static int hw_init(const char *deviceinfo)
                        ols->num_probes = 32;
                        sdi->priv = ols;
                }
-               sdi->serial = sr_serial_device_instance_new(device_names[i], -1);
+               ols->serial = sr_serial_device_instance_new(device_names[i], -1);
                device_instances = g_slist_append(device_instances, sdi);
                final_devcnt++;
                serial_close(fds[i].fd);
@@ -483,12 +484,15 @@ hw_init_free_ports:
 static int hw_opendev(int device_index)
 {
        struct sr_device_instance *sdi;
+       struct ols_device *ols;
 
        if (!(sdi = sr_get_device_instance(device_instances, device_index)))
                return SR_ERR;
 
-       sdi->serial->fd = serial_open(sdi->serial->port, O_RDWR);
-       if (sdi->serial->fd == -1)
+       ols = sdi->priv;
+
+       ols->serial->fd = serial_open(ols->serial->port, O_RDWR);
+       if (ols->serial->fd == -1)
                return SR_ERR;
 
        sdi->status = SR_ST_ACTIVE;
@@ -499,16 +503,19 @@ static int hw_opendev(int device_index)
 static int hw_closedev(int device_index)
 {
        struct sr_device_instance *sdi;
+       struct ols_device *ols;
 
        if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
                sr_err("ols: %s: sdi was NULL", __func__);
                return SR_ERR; /* TODO: SR_ERR_ARG? */
        }
 
+       ols = sdi->priv;
+
        /* TODO */
-       if (sdi->serial->fd != -1) {
-               serial_close(sdi->serial->fd);
-               sdi->serial->fd = -1;
+       if (ols->serial->fd != -1) {
+               serial_close(ols->serial->fd);
+               ols->serial->fd = -1;
                sdi->status = SR_ST_INACTIVE;
        }
 
@@ -519,12 +526,15 @@ static void hw_cleanup(void)
 {
        GSList *l;
        struct sr_device_instance *sdi;
+       struct ols_device *ols;
 
        /* Properly close and free all devices. */
        for (l = device_instances; l; l = l->next) {
                sdi = l->data;
-               if (sdi->serial->fd != -1)
-                       serial_close(sdi->serial->fd);
+               ols = sdi->priv;
+               if (ols->serial->fd != -1)
+                       serial_close(ols->serial->fd);
+               sr_serial_device_instance_free(ols->serial);
                sr_device_instance_free(sdi);
        }
        g_slist_free(device_instances);
@@ -684,7 +694,7 @@ static int receive_data(int fd, int revents, void *session_data)
        ols = NULL;
        for (l = device_instances; l; l = l->next) {
                sdi = l->data;
-               if (sdi->serial->fd == fd) {
+               if (ols->serial->fd == fd) {
                        ols = sdi->priv;
                        break;
                }
@@ -906,53 +916,53 @@ static int hw_start_acquisition(int device_index, gpointer session_data)
                delaycount = readcount * (1 - ols->capture_ratio / 100.0);
                ols->trigger_at = (readcount - delaycount) * 4 - ols->num_stages;
 
-               if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_MASK_0,
+               if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_MASK_0,
                        reverse32(ols->trigger_mask[0])) != SR_OK)
                        return SR_ERR;
-               if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_VALUE_0,
+               if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_VALUE_0,
                        reverse32(ols->trigger_value[0])) != SR_OK)
                        return SR_ERR;
-               if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_CONFIG_0,
+               if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_CONFIG_0,
                        trigger_config[0]) != SR_OK)
                        return SR_ERR;
 
-               if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_MASK_1,
+               if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_MASK_1,
                        reverse32(ols->trigger_mask[1])) != SR_OK)
                        return SR_ERR;
-               if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_VALUE_1,
+               if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_VALUE_1,
                        reverse32(ols->trigger_value[1])) != SR_OK)
                        return SR_ERR;
-               if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_CONFIG_1,
+               if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_CONFIG_1,
                        trigger_config[1]) != SR_OK)
                        return SR_ERR;
 
-               if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_MASK_2,
+               if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_MASK_2,
                        reverse32(ols->trigger_mask[2])) != SR_OK)
                        return SR_ERR;
-               if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_VALUE_2,
+               if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_VALUE_2,
                        reverse32(ols->trigger_value[2])) != SR_OK)
                        return SR_ERR;
-               if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_CONFIG_2,
+               if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_CONFIG_2,
                        trigger_config[2]) != SR_OK)
                        return SR_ERR;
 
-               if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_MASK_3,
+               if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_MASK_3,
                        reverse32(ols->trigger_mask[3])) != SR_OK)
                        return SR_ERR;
-               if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_VALUE_3,
+               if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_VALUE_3,
                        reverse32(ols->trigger_value[3])) != SR_OK)
                        return SR_ERR;
-               if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_CONFIG_3,
+               if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_CONFIG_3,
                        trigger_config[3]) != SR_OK)
                        return SR_ERR;
        } else {
-               if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_MASK_0,
+               if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_MASK_0,
                                ols->trigger_mask[0]) != SR_OK)
                        return SR_ERR;
-               if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_VALUE_0,
+               if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_VALUE_0,
                                ols->trigger_value[0]) != SR_OK)
                        return SR_ERR;
-               if (send_longcommand(sdi->serial->fd, CMD_SET_TRIGGER_CONFIG_0,
+               if (send_longcommand(ols->serial->fd, CMD_SET_TRIGGER_CONFIG_0,
                     0x00000008) != SR_OK)
                        return SR_ERR;
                delaycount = readcount;
@@ -961,14 +971,14 @@ static int hw_start_acquisition(int device_index, gpointer session_data)
        sr_info("ols: setting samplerate to %" PRIu64 " Hz (divider %u, "
                "demux %s)", ols->cur_samplerate, ols->cur_samplerate_divider,
                ols->flag_reg & FLAG_DEMUX ? "on" : "off");
-       if (send_longcommand(sdi->serial->fd, CMD_SET_DIVIDER,
+       if (send_longcommand(ols->serial->fd, CMD_SET_DIVIDER,
                        reverse32(ols->cur_samplerate_divider)) != SR_OK)
                return SR_ERR;
 
        /* Send sample limit and pre/post-trigger capture ratio. */
        data = ((readcount - 1) & 0xffff) << 16;
        data |= (delaycount - 1) & 0xffff;
-       if (send_longcommand(sdi->serial->fd, CMD_CAPTURE_SIZE, reverse16(data)) != SR_OK)
+       if (send_longcommand(ols->serial->fd, CMD_CAPTURE_SIZE, reverse16(data)) != SR_OK)
                return SR_ERR;
 
        /* The flag register wants them here, and 1 means "disable channel". */
@@ -976,14 +986,14 @@ static int hw_start_acquisition(int device_index, gpointer session_data)
        ols->flag_reg |= FLAG_FILTER;
        ols->rle_count = 0;
        data = (ols->flag_reg << 24) | ((ols->flag_reg << 8) & 0xff0000);
-       if (send_longcommand(sdi->serial->fd, CMD_SET_FLAGS, data) != SR_OK)
+       if (send_longcommand(ols->serial->fd, CMD_SET_FLAGS, data) != SR_OK)
                return SR_ERR;
 
        /* Start acquisition on the device. */
-       if (send_shortcommand(sdi->serial->fd, CMD_RUN) != SR_OK)
+       if (send_shortcommand(ols->serial->fd, CMD_RUN) != SR_OK)
                return SR_ERR;
 
-       sr_source_add(sdi->serial->fd, G_IO_IN, -1, receive_data,
+       sr_source_add(ols->serial->fd, G_IO_IN, -1, receive_data,
                      session_data);
 
        if (!(packet = g_try_malloc(sizeof(struct sr_datafeed_packet)))) {
index a954605e7f23d278a84a46a971244ba8095209f9..d8b00b47c149f6c1bf317977e0cd7ebb9aafd7a6 100644 (file)
@@ -88,6 +88,8 @@ struct ols_device {
        unsigned char sample[4];
        unsigned char tmp_sample[4];
        unsigned char *raw_sample_buf;
+
+       struct sr_serial_device_instance *serial;
 };
 
 #endif /* OLS_H_ */
index 70721ea5213755d7caf8e44836e3e2b8cc6225f8..27938a51bc18623efa3caa25d1f8b0feb5771c58 100644 (file)
@@ -192,24 +192,24 @@ static int sl_open_device(int device_index)
                         * This device is fully enumerated, so we need to find this
                         * device by vendor, product, bus and address.
                         */
-                       if (libusb_get_bus_number(devlist[i]) != sdi->usb->bus
-                               || libusb_get_device_address(devlist[i]) != sdi->usb->address)
+                       if (libusb_get_bus_number(devlist[i]) != fx2->usb->bus
+                               || libusb_get_device_address(devlist[i]) != fx2->usb->address)
                                /* this is not the one */
                                continue;
                }
 
-               if (!(err = libusb_open(devlist[i], &sdi->usb->devhdl))) {
-                       if (sdi->usb->address == 0xff)
+               if (!(err = libusb_open(devlist[i], &fx2->usb->devhdl))) {
+                       if (fx2->usb->address == 0xff)
                                /*
                                 * first time we touch this device after firmware upload,
                                 * so we don't know the address yet.
                                 */
-                               sdi->usb->address = libusb_get_device_address(devlist[i]);
+                               fx2->usb->address = libusb_get_device_address(devlist[i]);
 
                        sdi->status = SR_ST_ACTIVE;
                        sr_info("saleae: opened device %d on %d.%d interface %d",
-                                 sdi->index, sdi->usb->bus,
-                                 sdi->usb->address, USB_INTERFACE);
+                                 sdi->index, fx2->usb->bus,
+                                 fx2->usb->address, USB_INTERFACE);
                } else {
                        sr_warn("failed to open device: %d", err);
                }
@@ -227,14 +227,18 @@ static int sl_open_device(int device_index)
 
 static void close_device(struct sr_device_instance *sdi)
 {
-       if (sdi->usb->devhdl == NULL)
+       struct fx2_device *fx2;
+
+       fx2 = sdi->priv;
+
+       if (fx2->usb->devhdl == NULL)
                return;
 
        sr_info("saleae: closing device %d on %d.%d interface %d", sdi->index,
-               sdi->usb->bus, sdi->usb->address, USB_INTERFACE);
-       libusb_release_interface(sdi->usb->devhdl, USB_INTERFACE);
-       libusb_close(sdi->usb->devhdl);
-       sdi->usb->devhdl = NULL;
+               fx2->usb->bus, fx2->usb->address, USB_INTERFACE);
+       libusb_release_interface(fx2->usb->devhdl, USB_INTERFACE);
+       libusb_close(fx2->usb->devhdl);
+       fx2->usb->devhdl = NULL;
        sdi->status = SR_ST_INACTIVE;
 }
 
@@ -289,10 +293,11 @@ static struct fx2_device *fx2_device_new(void)
        struct fx2_device *fx2;
 
        if (!(fx2 = g_try_malloc0(sizeof(struct fx2_device)))) {
-               sr_err("saleae: %s: saleae malloc failed", __func__);
+               sr_err("saleae: %s: fx2 malloc failed", __func__);
                return NULL;
        }
        fx2->trigger_stage = TRIGGER_FIRED;
+       fx2->usb = NULL;
 
        return fx2;
 }
@@ -353,7 +358,7 @@ static int hw_init(const char *deviceinfo)
                if (check_conf_profile(devlist[i])) {
                        /* Already has the firmware, so fix the new address. */
                        sdi->status = SR_ST_INACTIVE;
-                       sdi->usb = sr_usb_device_instance_new
+                       fx2->usb = sr_usb_device_instance_new
                            (libusb_get_bus_number(devlist[i]),
                             libusb_get_device_address(devlist[i]), NULL);
                } else {
@@ -362,7 +367,7 @@ static int hw_init(const char *deviceinfo)
                                g_get_current_time(&fx2->fw_updated);
                        else
                                sr_warn("firmware upload failed for device %d", devcnt);
-                       sdi->usb = sr_usb_device_instance_new
+                       fx2->usb = sr_usb_device_instance_new
                                (libusb_get_bus_number(devlist[i]), 0xff, NULL);
                }
                devcnt++;
@@ -411,7 +416,7 @@ static int hw_opendev(int device_index)
        }
        fx2 = sdi->priv;
 
-       err = libusb_claim_interface(sdi->usb->devhdl, USB_INTERFACE);
+       err = libusb_claim_interface(fx2->usb->devhdl, USB_INTERFACE);
        if (err != 0) {
                sr_warn("Unable to claim interface: %d", err);
                return SR_ERR;
@@ -445,14 +450,18 @@ static int hw_closedev(int device_index)
 static void hw_cleanup(void)
 {
        GSList *l;
+       struct sr_device_instance *sdi;
+       struct fx2_device *fx2;
 
-       /* Properly close all devices... */
-       for (l = device_instances; l; l = l->next)
-               close_device((struct sr_device_instance *)l->data);
+       /* Properly close and free all devices. */
+       for (l = device_instances; l; l = l->next) {
+               sdi = l->data;
+               fx2 = sdi->priv;
+               close_device(sdi);
+               sr_usb_device_instance_free(fx2->usb);
+               sr_device_instance_free(sdi);
+       }
 
-       /* ...and free all their memory. */
-       for (l = device_instances; l; l = l->next)
-               g_free(l->data);
        g_slist_free(device_instances);
        device_instances = NULL;
 
@@ -533,7 +542,7 @@ static int set_configuration_samplerate(struct sr_device_instance *sdi,
                samplerate, divider);
        buf[0] = 0x01;
        buf[1] = divider;
-       ret = libusb_bulk_transfer(sdi->usb->devhdl, 1 | LIBUSB_ENDPOINT_OUT,
+       ret = libusb_bulk_transfer(fx2->usb->devhdl, 1 | LIBUSB_ENDPOINT_OUT,
                                   buf, 2, &result, 500);
        if (ret != 0) {
                sr_warn("failed to set samplerate: %d", ret);
@@ -765,7 +774,7 @@ static int hw_start_acquisition(int device_index, gpointer session_data)
                        return SR_ERR_MALLOC;
                }
                transfer = libusb_alloc_transfer(0);
-               libusb_fill_bulk_transfer(transfer, sdi->usb->devhdl,
+               libusb_fill_bulk_transfer(transfer, fx2->usb->devhdl,
                                2 | LIBUSB_ENDPOINT_IN, buf, size,
                                receive_transfer, fx2, 40);
                if (libusb_submit_transfer(transfer) != 0) {
index 1dfc39d9f562201ab01508e858a4aed0cbc5ba3a..50cca6280bc47990644a4a0591f28ab2077f0689 100644 (file)
@@ -71,6 +71,8 @@ struct fx2_device {
         * on the session bus along with samples.
         */
        void *session_data;
+
+       struct sr_usb_device_instance *usb;
 };
 
 #endif /* SALEAE_LOGIC_H_ */
index 6966ff83f103dba8cbe9870ab045fb265679775c..54f4d08315e0fac1c6a85c1cda8ab817ba752630 100644 (file)
@@ -163,6 +163,8 @@ struct zp {
        uint8_t trigger_mask[NUM_TRIGGER_STAGES];
        uint8_t trigger_value[NUM_TRIGGER_STAGES];
        // uint8_t trigger_buffer[NUM_TRIGGER_STAGES];
+
+       struct sr_usb_device_instance *usb;
 };
 
 static int hw_set_configuration(int device_index, int capability, void *value);
@@ -203,8 +205,8 @@ static int opendev4(struct sr_device_instance **sdi, libusb_device *dev,
        if (des->idVendor != USB_VENDOR)
                return 0;
 
-       if (libusb_get_bus_number(dev) == (*sdi)->usb->bus
-           && libusb_get_device_address(dev) == (*sdi)->usb->address) {
+       if (libusb_get_bus_number(dev) == zp->usb->bus
+           && libusb_get_device_address(dev) == zp->usb->address) {
 
                for (i = 0; i < ARRAY_SIZE(zeroplus_models); i++) {
                        if (!(des->idProduct == zeroplus_models[i].pid))
@@ -223,11 +225,11 @@ static int opendev4(struct sr_device_instance **sdi, libusb_device *dev,
                }
 
                /* Found it. */
-               if (!(err = libusb_open(dev, &((*sdi)->usb->devhdl)))) {
+               if (!(err = libusb_open(dev, &(zp->usb->devhdl)))) {
                        (*sdi)->status = SR_ST_ACTIVE;
                        sr_info("opened device %d on %d.%d interface %d",
-                               (*sdi)->index, (*sdi)->usb->bus,
-                               (*sdi)->usb->address, USB_INTERFACE);
+                               (*sdi)->index, zp->usb->bus,
+                               zp->usb->address, USB_INTERFACE);
                } else {
                        sr_warn("failed to open device: %d", err);
                        *sdi = NULL;
@@ -269,14 +271,21 @@ static struct sr_device_instance *zp_open_device(int device_index)
 
 static void close_device(struct sr_device_instance *sdi)
 {
-       if (!sdi->usb->devhdl)
+       struct zp *zp;
+
+       if (!(zp = sdi->priv)) {
+               sr_err("zp: %s: sdi->priv was NULL", __func__);
+               return; /* FIXME */
+       }
+
+       if (!zp->usb->devhdl)
                return;
 
        sr_info("closing device %d on %d.%d interface %d", sdi->index,
-               sdi->usb->bus, sdi->usb->address, USB_INTERFACE);
-       libusb_release_interface(sdi->usb->devhdl, USB_INTERFACE);
-       libusb_close(sdi->usb->devhdl);
-       sdi->usb->devhdl = NULL;
+               zp->usb->bus, zp->usb->address, USB_INTERFACE);
+       libusb_release_interface(zp->usb->devhdl, USB_INTERFACE);
+       libusb_close(zp->usb->devhdl);
+       zp->usb->devhdl = NULL;
        sdi->status = SR_ST_INACTIVE;
 }
 
@@ -389,7 +398,7 @@ static int hw_init(const char *deviceinfo)
 
                        device_instances =
                            g_slist_append(device_instances, sdi);
-                       sdi->usb = sr_usb_device_instance_new(
+                       zp->usb = sr_usb_device_instance_new(
                                libusb_get_bus_number(devlist[i]),
                                libusb_get_device_address(devlist[i]), NULL);
                        devcnt++;
@@ -418,13 +427,13 @@ static int hw_opendev(int device_index)
                return SR_ERR_ARG;
        }
 
-       err = libusb_claim_interface(sdi->usb->devhdl, USB_INTERFACE);
+       err = libusb_claim_interface(zp->usb->devhdl, USB_INTERFACE);
        if (err != 0) {
                sr_warn("Unable to claim interface: %d", err);
                return SR_ERR;
        }
-       analyzer_reset(sdi->usb->devhdl);
-       analyzer_initialize(sdi->usb->devhdl);
+       analyzer_reset(zp->usb->devhdl);
+       analyzer_initialize(zp->usb->devhdl);
 
        analyzer_set_memory_size(MEMORY_SIZE_512K);
        // analyzer_set_freq(g_freq, g_freq_scale);
@@ -632,15 +641,15 @@ static int hw_start_acquisition(int device_index, gpointer session_data)
        }
 
        /* push configured settings to device */
-       analyzer_configure(sdi->usb->devhdl);
+       analyzer_configure(zp->usb->devhdl);
 
-       analyzer_start(sdi->usb->devhdl);
+       analyzer_start(zp->usb->devhdl);
        sr_info("Waiting for data");
-       analyzer_wait_data(sdi->usb->devhdl);
+       analyzer_wait_data(zp->usb->devhdl);
 
-       sr_info("Stop address    = 0x%x", analyzer_get_stop_address(sdi->usb->devhdl));
-       sr_info("Now address     = 0x%x", analyzer_get_now_address(sdi->usb->devhdl));
-       sr_info("Trigger address = 0x%x", analyzer_get_trigger_address(sdi->usb->devhdl));
+       sr_info("Stop address    = 0x%x", analyzer_get_stop_address(zp->usb->devhdl));
+       sr_info("Now address     = 0x%x", analyzer_get_now_address(zp->usb->devhdl));
+       sr_info("Trigger address = 0x%x", analyzer_get_trigger_address(zp->usb->devhdl));
 
        packet.type = SR_DF_HEADER;
        packet.payload = &header;
@@ -657,11 +666,11 @@ static int hw_start_acquisition(int device_index, gpointer session_data)
        }
 
        samples_read = 0;
-       analyzer_read_start(sdi->usb->devhdl);
+       analyzer_read_start(zp->usb->devhdl);
        /* Send the incoming transfer to the session bus. */
        for (packet_num = 0; packet_num < (zp->memory_size * 4 / PACKET_SIZE);
             packet_num++) {
-               res = analyzer_read_data(sdi->usb->devhdl, buf, PACKET_SIZE);
+               res = analyzer_read_data(zp->usb->devhdl, buf, PACKET_SIZE);
                sr_info("Tried to read %llx bytes, actually read %x bytes",
                        PACKET_SIZE, res);
 
@@ -675,7 +684,7 @@ static int hw_start_acquisition(int device_index, gpointer session_data)
                sr_session_bus(session_data, &packet);
                samples_read += res / 4;
        }
-       analyzer_read_stop(sdi->usb->devhdl);
+       analyzer_read_stop(zp->usb->devhdl);
        g_free(buf);
 
        packet.type = SR_DF_END;
@@ -689,14 +698,22 @@ static void hw_stop_acquisition(int device_index, gpointer session_device_id)
 {
        struct sr_datafeed_packet packet;
        struct sr_device_instance *sdi;
+       struct zp *zp;
 
        packet.type = SR_DF_END;
        sr_session_bus(session_device_id, &packet);
 
-       if (!(sdi = sr_get_device_instance(device_instances, device_index)))
-               return; /* TODO: Cry? */
+       if (!(sdi = sr_get_device_instance(device_instances, device_index))) {
+               sr_err("zp: %s: sdi was NULL", __func__);
+               return; /* FIXME */
+       }
+
+       if (!(zp = sdi->priv)) {
+               sr_err("zp: %s: sdi->priv was NULL", __func__);
+               return; /* FIXME */
+       }
 
-       analyzer_reset(sdi->usb->devhdl);
+       analyzer_reset(zp->usb->devhdl);
        /* TODO: Need to cancel and free any queued up transfers. */
 }
 
index 23bbef4455463503ceb49f35bde6659b8e3a06b2..8ec8c30c6008049225b178a04beeeb463ce492ca 100644 (file)
@@ -163,7 +163,6 @@ struct sr_device_instance *sr_device_instance_new(int index, int status,
        sdi->model = model ? g_strdup(model) : NULL;
        sdi->version = version ? g_strdup(version) : NULL;
        sdi->priv = NULL;
-       sdi->usb = NULL;
 
        return sdi;
 }
@@ -186,20 +185,6 @@ struct sr_device_instance *sr_get_device_instance(GSList *device_instances,
 
 void sr_device_instance_free(struct sr_device_instance *sdi)
 {
-       switch (sdi->instance_type) {
-#ifdef HAVE_LIBUSB_1_0
-       case SR_USB_INSTANCE:
-               sr_usb_device_instance_free(sdi->usb);
-               break;
-#endif
-       case SR_SERIAL_INSTANCE:
-               sr_serial_device_instance_free(sdi->serial);
-               break;
-       default:
-               /* No specific type, nothing extra to free. */
-               break;
-       }
-
        g_free(sdi->priv);
        g_free(sdi->vendor);
        g_free(sdi->model);
index 4ea5d475c39d87973ced6c864b44961d9f0228fb..4ec9339c2900e90cc9866258af85d27455445f64 100644 (file)
@@ -22,6 +22,9 @@
 
 #include <stdarg.h>
 #include <glib.h>
+#ifdef HAVE_LIBUSB_1_0
+#include <libusb.h>
+#endif
 
 /*--- Macros ----------------------------------------------------------------*/
 
 
 int load_hwplugins(void);
 
+#ifdef HAVE_LIBUSB_1_0
+struct sr_usb_device_instance {
+       uint8_t bus;
+       uint8_t address;
+       struct libusb_device_handle *devhdl;
+};
+#endif
+
+struct sr_serial_device_instance {
+       char *port;
+       int fd;
+};
+
+#ifdef HAVE_LIBUSB_1_0
+/* USB-specific instances */
+struct sr_usb_device_instance *sr_usb_device_instance_new(uint8_t bus,
+               uint8_t address, struct libusb_device_handle *hdl);
+void sr_usb_device_instance_free(struct sr_usb_device_instance *usb);
+#endif
+
+/* Serial-specific instances */
+struct sr_serial_device_instance *sr_serial_device_instance_new(
+                                       const char *port, int fd);
+void sr_serial_device_instance_free(struct sr_serial_device_instance *serial);
+
 /*--- log.c -----------------------------------------------------------------*/
 
 int sr_log(int loglevel, const char *format, ...);
index 80c48948a312ee075527ad53c969577155a49ecc..2d32354cda417599ec196406990584621742ef70 100644 (file)
@@ -76,18 +76,6 @@ struct sr_device_instance *sr_get_device_instance(GSList *device_instances,
                                                  int device_index);
 void sr_device_instance_free(struct sr_device_instance *sdi);
 
-/* USB-specific instances */
-#ifdef HAVE_LIBUSB_1_0
-struct sr_usb_device_instance *sr_usb_device_instance_new(uint8_t bus,
-               uint8_t address, struct libusb_device_handle *hdl);
-void sr_usb_device_instance_free(struct sr_usb_device_instance *usb);
-#endif
-
-/* Serial-specific instances */
-struct sr_serial_device_instance *sr_serial_device_instance_new(
-                                       const char *port, int fd);
-void sr_serial_device_instance_free(struct sr_serial_device_instance *serial);
-
 int sr_find_hwcap(int *capabilities, int hwcap);
 struct sr_hwcap_option *sr_find_hwcap_option(int hwcap);
 void sr_source_remove(int fd);
index fb8e0d53b732dffb501abe29244e0599e9c1a75c..401e94fbeec2c7e0a4f2b428732f2fce069ac316 100644 (file)
@@ -25,9 +25,6 @@
 #include <stdint.h>
 #include <inttypes.h>
 #include <glib.h>
-#ifdef HAVE_LIBUSB_1_0
-#include <libusb.h>
-#endif
 
 #ifdef __cplusplus
 extern "C" {
@@ -275,10 +272,6 @@ struct sr_device_instance {
        char *model;
        char *version;
        void *priv;
-       union {
-               struct sr_usb_device_instance *usb;
-               struct sr_serial_device_instance *serial;
-       };
 };
 
 /* sr_device_instance types */
@@ -287,19 +280,6 @@ enum {
        SR_SERIAL_INSTANCE,
 };
 
-#ifdef HAVE_LIBUSB_1_0
-struct sr_usb_device_instance {
-       uint8_t bus;
-       uint8_t address;
-       struct libusb_device_handle *devhdl;
-};
-#endif
-
-struct sr_serial_device_instance {
-       char *port;
-       int fd;
-};
-
 /* Device instance status */
 enum {
        SR_ST_NOT_FOUND,