]> sigrok.org Git - libsigrok.git/commitdiff
salae: Only terminate session after all transfers have been aborted
authorJoel Holdsworth <redacted>
Sun, 25 Mar 2012 17:53:54 +0000 (18:53 +0100)
committerJoel Holdsworth <redacted>
Sun, 25 Mar 2012 18:42:37 +0000 (19:42 +0100)
hardware/saleae-logic/saleae-logic.c
hardware/saleae-logic/saleae-logic.h

index d1b2e11a73bad34df16168b07038c4b53d80af7f..7e8c4b10e3ae0316cbccb674b7beb03c4984a54d 100644 (file)
@@ -673,15 +673,25 @@ static int receive_data(int fd, int revents, void *cb_data)
 }
 
 static void abort_acquisition(struct context *ctx)
+{
+       ctx->num_samples = -1;
+}
+
+static void finish_acquisition(struct context *ctx)
 {
        struct sr_datafeed_packet packet;
+       int i;
 
+       /* Terminate session */
        packet.type = SR_DF_END;
        sr_session_send(ctx->session_dev_id, &packet);
 
-       ctx->num_samples = -1;
-
-       /* TODO: Need to cancel and free any queued up transfers. */
+       /* Remove fds from polling */
+       const struct libusb_pollfd **const lupfd =
+               libusb_get_pollfds(usb_context);
+       for (i = 0; lupfd[i]; i++)
+               sr_source_remove(lupfd[i]->fd);
+       free(lupfd); /* NOT g_free()! */
 }
 
 static void receive_transfer(struct libusb_transfer *transfer)
@@ -701,6 +711,11 @@ static void receive_transfer(struct libusb_transfer *transfer)
        if (ctx->num_samples == -1) {
                if (transfer)
                        libusb_free_transfer(transfer);
+
+               ctx->submitted_transfers--;
+               if (ctx->submitted_transfers == 0)
+                       finish_acquisition(ctx);
+
                return;
        }
 
@@ -861,6 +876,8 @@ static int hw_dev_acquisition_start(int dev_index, void *cb_data)
                        g_free(buf);
                        return SR_ERR;
                }
+
+               ctx->submitted_transfers++;
                size = 4096;
        }
 
index 5378616e4b8c511b88a38ee1a7796cfbb829a87d..6a96d458b93f40cb2fc1e621b975182aeab390b1 100644 (file)
@@ -66,6 +66,8 @@ struct context {
        int trigger_stage;
        uint8_t trigger_buffer[NUM_TRIGGER_STAGES];
        int num_samples;
+       int submitted_transfers;
+
        /*
         * opaque session data passed in by the frontend, will be passed back
         * on the session bus along with samples.