]> sigrok.org Git - libsigrok.git/commitdiff
Factor out std_session_send_df_end() helper.
authorUwe Hermann <redacted>
Sat, 26 Mar 2016 18:45:04 +0000 (19:45 +0100)
committerUwe Hermann <redacted>
Fri, 29 Apr 2016 16:08:15 +0000 (18:08 +0200)
This makes the code shorter, simpler and more consistent, and also
ensures that the (same) debug messages are always emitted and the
packet.payload field is consistently set to NULL always, etc.

47 files changed:
src/hardware/asix-sigma/protocol.c
src/hardware/atten-pps3xxx/protocol.c
src/hardware/baylibre-acme/api.c
src/hardware/beaglelogic/api.c
src/hardware/beaglelogic/protocol.c
src/hardware/brymen-bm86x/api.c
src/hardware/chronovu-la/api.c
src/hardware/demo/demo.c
src/hardware/ftdi-la/api.c
src/hardware/fx2lafw/api.c
src/hardware/fx2lafw/protocol.c
src/hardware/gwinstek-gds-800/api.c
src/hardware/hameg-hmo/api.c
src/hardware/hantek-6xxx/api.c
src/hardware/hantek-dso/api.c
src/hardware/hung-chang-dso-2100/api.c
src/hardware/ikalogic-scanalogic2/protocol.c
src/hardware/ikalogic-scanaplus/api.c
src/hardware/kecheng-kc-330b/api.c
src/hardware/kecheng-kc-330b/protocol.c
src/hardware/lascar-el-usb/api.c
src/hardware/lascar-el-usb/protocol.c
src/hardware/lecroy-logicstudio/protocol.c
src/hardware/link-mso19/protocol.c
src/hardware/maynuo-m97/api.c
src/hardware/openbench-logic-sniffer/protocol.c
src/hardware/pipistrello-ols/api.c
src/hardware/rigol-ds/api.c
src/hardware/saleae-logic16/protocol.c
src/hardware/scpi-pps/api.c
src/hardware/sysclk-lwla/protocol.c
src/hardware/testo/api.c
src/hardware/uni-t-dmm/api.c
src/hardware/uni-t-ut32x/protocol.c
src/hardware/victor-dmm/api.c
src/hardware/yokogawa-dlm/api.c
src/hardware/zeroplus-logic-cube/api.c
src/input/binary.c
src/input/chronovu_la8.c
src/input/csv.c
src/input/raw_analog.c
src/input/trace32_ad.c
src/input/vcd.c
src/input/wav.c
src/libsigrok-internal.h
src/session_driver.c
src/std.c

index 03d9e3c0d7ff472cabc40fe4adbd56881345423a..0e41207af456e951362c2210bfbe072e1e55af23 100644 (file)
@@ -835,7 +835,6 @@ static int download_capture(struct sr_dev_inst *sdi)
        struct sigma_dram_line *dram_line;
        int bufsz;
        uint32_t stoppos, triggerpos;
-       struct sr_datafeed_packet packet;
        uint8_t modestatus;
 
        uint32_t i;
@@ -907,9 +906,7 @@ static int download_capture(struct sr_dev_inst *sdi)
                dl_lines_done += dl_lines_curr;
        }
 
-       /* All done. */
-       packet.type = SR_DF_END;
-       sr_session_send(sdi, &packet);
+       std_session_send_df_end(sdi, LOG_PREFIX);
 
        sdi->driver->dev_acquisition_stop(sdi, sdi);
 
index 34e0af42824ebff7fa13623c79e84bfb8ad93f9d..06a1d2e90d93546af3602e41ac399c04a9816d63 100644 (file)
@@ -133,7 +133,6 @@ SR_PRIV int atten_pps3xxx_receive_data(int fd, int revents, void *cb_data)
        struct dev_context *devc;
        const struct sr_dev_inst *sdi;
        struct sr_serial_dev_inst *serial;
-       struct sr_datafeed_packet packet;
        unsigned char c;
 
        (void)fd;
@@ -156,8 +155,7 @@ SR_PRIV int atten_pps3xxx_receive_data(int fd, int revents, void *cb_data)
                                send_config(sdi);
                        else {
                                serial_source_remove(sdi->session, serial);
-                               packet.type = SR_DF_END;
-                               sr_session_send(sdi, &packet);
+                               std_session_send_df_end(sdi, LOG_PREFIX);
                        }
                }
        }
index c116cbbb6ef10ec1f105a33f3f77753aa63b6ffa..0dd6fdba51f9134b981f892d5b97391ff77f7dcf 100644 (file)
@@ -401,7 +401,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
 
 static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 {
-       struct sr_datafeed_packet packet;
        struct dev_context *devc;
 
        (void)cb_data;
@@ -417,9 +416,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
        g_io_channel_unref(devc->channel);
        devc->channel = NULL;
 
-       /* Send last packet. */
-       packet.type = SR_DF_END;
-       sr_session_send(sdi, &packet);
+       std_session_send_df_end(sdi, LOG_PREFIX);
 
        if (devc->samples_missed > 0)
                sr_warn("%" PRIu64 " samples missed", devc->samples_missed);
index b974010468f38dfb440198c150fe6bcb7e486286..6e88188918eb34af70c8f374c25d5b13dec7db0a 100644 (file)
@@ -384,7 +384,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
 static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 {
        struct dev_context *devc = sdi->priv;
-       struct sr_datafeed_packet pkt;
 
        (void)cb_data;
 
@@ -399,9 +398,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 
        /* Remove session source and send EOT packet */
        sr_session_source_remove_pollfd(sdi->session, &devc->pollfd);
-       pkt.type = SR_DF_END;
-       pkt.payload = NULL;
-       sr_session_send(sdi, &pkt);
+       std_session_send_df_end(sdi, LOG_PREFIX);
 
        return SR_OK;
 }
index 55e2b647deefd5f11dcbb86da9483a08e1beaeac..f440592f30a3c571ade26cf4f43a9a25f721e1eb 100644 (file)
@@ -101,10 +101,7 @@ SR_PRIV int beaglelogic_receive_data(int fd, int revents, void *cb_data)
        if (devc->bytes_read >= devc->limit_samples * logic.unitsize ||
                        packetsize == 0) {
                /* Send EOA Packet, stop polling */
-               packet.type = SR_DF_END;
-               packet.payload = NULL;
-               sr_session_send(devc->cb_data, &packet);
-
+               std_session_send_df_end(devc->cb_data, LOG_PREFIX);
                sr_session_source_remove_pollfd(sdi->session, &devc->pollfd);
        }
 
index 64e492c6384175582016aa3e2bf44d806c02d933..d252208dc7272d14f377802eb0d53f88a405f601 100644 (file)
@@ -273,16 +273,12 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
 
 static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 {
-       struct sr_datafeed_packet packet;
-
        (void)cb_data;
 
        if (sdi->status != SR_ST_ACTIVE)
                return SR_ERR_DEV_CLOSED;
 
-       /* Send end packet to the session bus. */
-       packet.type = SR_DF_END;
-       sr_session_send(sdi, &packet);
+       std_session_send_df_end(sdi, LOG_PREFIX);
 
        sr_session_source_remove(sdi->session, -1);
 
index 141045819980b3e4b950a3b3560e23d531556fa0..976180ac6b034af4bf3198d7fd617adbbfe3108e 100644 (file)
@@ -584,17 +584,11 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
 
 static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 {
-       struct sr_datafeed_packet packet;
-
        (void)cb_data;
 
        sr_dbg("Stopping acquisition.");
        sr_session_source_remove(sdi->session, -1);
-
-       /* Send end packet to the session bus. */
-       sr_dbg("Sending SR_DF_END.");
-       packet.type = SR_DF_END;
-       sr_session_send(sdi, &packet);
+       std_session_send_df_end(sdi, LOG_PREFIX);
 
        return SR_OK;
 }
index e7948cdc4a89f7e175506f86683c6e2ae6d2e79f..f1b97d21829bbf26ddfcaf954d05c23a67ac53b6 100644 (file)
@@ -880,17 +880,11 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
 
 static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 {
-       struct sr_datafeed_packet packet;
-
        (void)cb_data;
 
        sr_dbg("Stopping acquisition.");
-
        sr_session_source_remove(sdi->session, -1);
-
-       /* Send last packet. */
-       packet.type = SR_DF_END;
-       sr_session_send(sdi, &packet);
+       std_session_send_df_end(sdi, LOG_PREFIX);
 
        return SR_OK;
 }
index 68d60e0b2f0a8defa4659b622811ea32090a8daf..c9ab6f6a2165262a16d9c0b57acd00928bf1f67e 100644 (file)
@@ -491,8 +491,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
 
 static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 {
-       struct sr_datafeed_packet packet;
-
        (void)cb_data;
 
        if (sdi->status != SR_ST_ACTIVE)
@@ -501,10 +499,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
        sr_dbg("Stopping acquisition.");
        sr_session_source_remove(sdi->session, -1);
 
-       /* Send end packet to the session bus. */
-       sr_dbg("Sending SR_DF_END.");
-       packet.type = SR_DF_END;
-       sr_session_send(sdi, &packet);
+       std_session_send_df_end(sdi, LOG_PREFIX);
 
        return SR_OK;
 }
index c6b14565b04735a96065938281384bdb1973ccae..171ec1666ff7622b1c06801c1bc028919f5553f6 100644 (file)
@@ -748,7 +748,6 @@ static int start_transfers(const struct sr_dev_inst *sdi)
 static void LIBUSB_CALL dslogic_trigger_receive(struct libusb_transfer *transfer)
 {
        const struct sr_dev_inst *sdi;
-       struct sr_datafeed_packet packet;
        struct dslogic_trigger_pos *tpos;
        struct dev_context *devc;
 
@@ -757,8 +756,7 @@ static void LIBUSB_CALL dslogic_trigger_receive(struct libusb_transfer *transfer
        if (transfer->status == LIBUSB_TRANSFER_CANCELLED) {
                sr_dbg("Trigger transfer canceled.");
                /* Terminate session. */
-               packet.type = SR_DF_END;
-               sr_session_send(sdi, &packet);
+               std_session_send_df_end(sdi, LOG_PREFIX);
                usb_source_remove(sdi->session, devc->ctx);
                devc->num_transfers = 0;
                g_free(devc->transfers);
@@ -775,7 +773,6 @@ static void LIBUSB_CALL dslogic_trigger_receive(struct libusb_transfer *transfer
        }
 
        libusb_free_transfer(transfer);
-
 }
 
 static int dslogic_trigger_request(const struct sr_dev_inst *sdi)
index fce69ac486fa6c5e101d9927331f9c391639d8f5..513fd0e2821f8fe039b45b4e58a33423ea152ac0 100644 (file)
@@ -326,14 +326,11 @@ SR_PRIV void fx2lafw_abort_acquisition(struct dev_context *devc)
 
 static void finish_acquisition(struct sr_dev_inst *sdi)
 {
-       struct sr_datafeed_packet packet;
        struct dev_context *devc;
 
        devc = sdi->priv;
 
-       /* Terminate session. */
-       packet.type = SR_DF_END;
-       sr_session_send(sdi, &packet);
+       std_session_send_df_end(sdi, LOG_PREFIX);
 
        /* Remove fds from polling. */
        usb_source_remove(sdi->session, devc->ctx);
index cfec15ee2236381c48af3d64bf4ed46ad0585270..89d6a07a21bd8150afda02806a6d469abd534c71 100644 (file)
@@ -251,8 +251,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
                packet.type = SR_DF_FRAME_END;
                sr_session_send(sdi, &packet);
 
-               packet.type = SR_DF_END;
-               sr_session_send(sdi, &packet);
+               std_session_send_df_end(sdi, LOG_PREFIX);
 
                devc->df_started = FALSE;
        }
index 370b6314059fb5dd0a0375f4dfe8a1e000103440..c293d2b44dd9e7024a06e8e9e7cee7d68d2b2d21 100644 (file)
@@ -769,13 +769,10 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 {
        struct dev_context *devc;
        struct sr_scpi_dev_inst *scpi;
-       struct sr_datafeed_packet packet;
 
        (void)cb_data;
 
-       packet.type = SR_DF_END;
-       packet.payload = NULL;
-       sr_session_send(sdi, &packet);
+       std_session_send_df_end(sdi, LOG_PREFIX);
 
        if (sdi->status != SR_ST_ACTIVE)
                return SR_ERR_DEV_CLOSED;
index 480eb1c4f8aed4e5e8381a69d336b155198a9ec1..83992ff64f4f1490452b3491a59289c0de9600d3 100644 (file)
@@ -732,7 +732,6 @@ static int read_channel(const struct sr_dev_inst *sdi, uint32_t amount)
 static int handle_event(int fd, int revents, void *cb_data)
 {
        const struct sr_dev_inst *sdi;
-       struct sr_datafeed_packet packet;
        struct timeval tv;
        struct sr_dev_driver *di;
        struct dev_context *devc;
@@ -761,9 +760,7 @@ static int handle_event(int fd, int revents, void *cb_data)
                 */
                usb_source_remove(sdi->session, drvc->sr_ctx);
 
-               packet.type = SR_DF_END;
-               packet.payload = NULL;
-               sr_session_send(sdi, &packet);
+               std_session_send_df_end(sdi, LOG_PREFIX);
 
                devc->dev_state = IDLE;
 
index 5fe431d5be7c468f219ce8b81b32431fbd1b88b9..52d5fe64950253efa827eb7eadc004b7cf9b1f99 100644 (file)
@@ -883,8 +883,7 @@ static int handle_event(int fd, int revents, void *cb_data)
                 */
                usb_source_remove(sdi->session, drvc->sr_ctx);
 
-               packet.type = SR_DF_END;
-               sr_session_send(sdi, &packet);
+               std_session_send_df_end(sdi, LOG_PREFIX);
 
                devc->dev_state = IDLE;
 
index 45fff2bc3b417f411385cbfd3302094d6d1cbcc1..e76b9a517d8daa2e40391bb7f5f07387a5df34e1 100644 (file)
@@ -724,14 +724,11 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
 SR_PRIV int hung_chang_dso_2100_dev_acquisition_stop(const struct sr_dev_inst *sdi,
                void *cb_data)
 {
-       struct sr_datafeed_packet packet = { .type = SR_DF_END };
-
        if (sdi->status != SR_ST_ACTIVE)
                return SR_ERR_DEV_CLOSED;
 
-       sr_session_send(cb_data, &packet);
+       std_session_send_df_end(cb_data, LOG_PREFIX);
        sr_session_source_remove(sdi->session, -1);
-
        hung_chang_dso_2100_move_to(sdi, 1);
 
        return SR_OK;
index 03d5d1bf32df778c0f824b29a8fb5fbc672d1933..f8833806dda30973a8ba63535402d9f46ff4b5f1 100644 (file)
@@ -28,15 +28,13 @@ static void stop_acquisition(struct sr_dev_inst *sdi)
 {
        struct drv_context *drvc = sdi->driver->context;
        struct dev_context *devc;
-       struct sr_datafeed_packet packet;
 
        devc = sdi->priv;
 
        /* Remove USB file descriptors from polling. */
        usb_source_remove(sdi->session, drvc->sr_ctx);
 
-       packet.type = SR_DF_END;
-       sr_session_send(devc->cb_data, &packet);
+       std_session_send_df_end(devc->cb_data, LOG_PREFIX);
 
        sdi->status = SR_ST_ACTIVE;
 }
@@ -45,15 +43,13 @@ static void abort_acquisition(struct sr_dev_inst *sdi)
 {
        struct drv_context *drvc = sdi->driver->context;
        struct dev_context *devc;
-       struct sr_datafeed_packet packet;
 
        devc = sdi->priv;
 
        /* Remove USB file descriptors from polling. */
        usb_source_remove(sdi->session, drvc->sr_ctx);
 
-       packet.type = SR_DF_END;
-       sr_session_send(devc->cb_data, &packet);
+       std_session_send_df_end(devc->cb_data, LOG_PREFIX);
 
        sdi->driver->dev_close(sdi);
 }
index ba4652ec060d83f698ff1102312aa8c510e7e3d1..dcd773dd674a9c94bd76f890d40523bb9fa0a568 100644 (file)
@@ -390,17 +390,11 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
 
 static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 {
-       struct sr_datafeed_packet packet;
-
        (void)cb_data;
 
        sr_dbg("Stopping acquisition.");
        sr_session_source_remove(sdi->session, -1);
-
-       /* Send end packet to the session bus. */
-       sr_dbg("Sending SR_DF_END.");
-       packet.type = SR_DF_END;
-       sr_session_send(sdi, &packet);
+       std_session_send_df_end(sdi, LOG_PREFIX);
 
        return SR_OK;
 }
index d294bf02ac11414df743e3d22776cf2874fb301c..7fcb562e6ab34ceec788b847161e1455170365a2 100644 (file)
@@ -462,8 +462,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
                devc->stored_samples = (buf[7] << 8) | buf[8];
                if (devc->stored_samples == 0) {
                        /* Notify frontend of empty log by sending start/end packets. */
-                       packet.type = SR_DF_END;
-                       sr_session_send(cb_data, &packet);
+                       std_session_send_df_end(cb_data, LOG_PREFIX);
                        return SR_OK;
                }
 
index e4550d2133220f9661d2c973f36e0644a9b9f826..bcc6846988c6a6856503f1ebeee9084b0e09fe33 100644 (file)
@@ -29,7 +29,6 @@ SR_PRIV int kecheng_kc_330b_handle_events(int fd, int revents, void *cb_data)
        struct sr_dev_driver *di;
        struct drv_context *drvc;
        struct dev_context *devc;
-       struct sr_datafeed_packet packet;
        struct sr_dev_inst *sdi;
        struct sr_usb_dev_inst *usb;
        struct timeval tv;
@@ -54,8 +53,7 @@ SR_PRIV int kecheng_kc_330b_handle_events(int fd, int revents, void *cb_data)
        if (sdi->status == SR_ST_STOPPING) {
                libusb_free_transfer(devc->xfer);
                usb_source_remove(sdi->session, drvc->sr_ctx);
-               packet.type = SR_DF_END;
-               sr_session_send(cb_data, &packet);
+               std_session_send_df_end(cb_data, LOG_PREFIX);
                sdi->status = SR_ST_ACTIVE;
                return TRUE;
        }
index c8938f21ac3e9d36d1edb81821f0c1b164fdf5a0..1934c9e21ca77792cae6a7d7cef69ae5f147c532 100644 (file)
@@ -369,8 +369,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
 
        if (devc->logged_samples == 0) {
                /* This ensures the frontend knows the session is done. */
-               packet.type = SR_DF_END;
-               sr_session_send(devc->cb_data, &packet);
+               std_session_send_df_end(devc->cb_data, LOG_PREFIX);
                return SR_OK;
        }
 
index 2584e8b09830015b5b22940712d4baeb06cb1c8e..9fd9b696466a09eac8921d0d26c263bde7b46d10 100644 (file)
@@ -477,7 +477,6 @@ static void lascar_el_usb_dispatch(struct sr_dev_inst *sdi, unsigned char *buf,
 SR_PRIV int lascar_el_usb_handle_events(int fd, int revents, void *cb_data)
 {
        struct drv_context *drvc = di->context;
-       struct sr_datafeed_packet packet;
        struct sr_dev_inst *sdi;
        struct timeval tv;
 
@@ -488,9 +487,7 @@ SR_PRIV int lascar_el_usb_handle_events(int fd, int revents, void *cb_data)
 
        if (sdi->status == SR_ST_STOPPING) {
                usb_source_remove(sdi->session, drvc->sr_ctx);
-
-               packet.type = SR_DF_END;
-               sr_session_send(cb_data, &packet);
+               std_session_send_df_end(cb_data, LOG_PREFIX);
        }
 
        memset(&tv, 0, sizeof(struct timeval));
index 9c825991b69427e6494457608dc3e8494db05cd2..11d3ce2c201cb2100f65b3bd06c5603f9623c59b 100644 (file)
@@ -912,15 +912,13 @@ static void LIBUSB_CALL recv_intr_transfer(struct libusb_transfer *xfer)
        const struct sr_dev_inst *sdi;
        struct drv_context *drvc;
        struct dev_context *devc;
-       struct sr_datafeed_packet packet;
 
        sdi = xfer->user_data;
        drvc = sdi->driver->context;
        devc = sdi->priv;
 
        if (devc->abort_acquisition) {
-               packet.type = SR_DF_END;
-               sr_session_send(sdi, &packet);
+               std_session_send_df_end(sdi, LOG_PREFIX);
                usb_source_remove(sdi->session, drvc->sr_ctx);
                return;
        }
@@ -1091,8 +1089,7 @@ static void LIBUSB_CALL recv_bulk_transfer(struct libusb_transfer *xfer)
                read_offset %= SAMPLE_BUF_SIZE;
        }
 
-       packet.type = SR_DF_END;
-       sr_session_send(sdi, &packet);
+       std_session_send_df_end(sdi, LOG_PREFIX);
 }
 
 static uint32_t transform_sample_count(struct dev_context *devc,
index 69551fe0f8244360ae7a3ebac6787f26ae568695..0c28585e774bcf69fd1eb263c6885332ed3d90d6 100644 (file)
@@ -286,15 +286,12 @@ SR_PRIV int mso_toggle_led(struct sr_dev_inst *sdi, int state)
 
 SR_PRIV void stop_acquisition(const struct sr_dev_inst *sdi)
 {
-       struct sr_datafeed_packet packet;
        struct dev_context *devc;
 
        devc = sdi->priv;
        serial_source_remove(sdi->session, devc->serial);
 
-       /* Terminate session */
-       packet.type = SR_DF_END;
-       sr_session_send(sdi, &packet);
+       std_session_send_df_end(sdi, LOG_PREFIX);
 }
 
 SR_PRIV int mso_clkrate_out(struct sr_serial_dev_inst *serial, uint16_t val)
index b2f7e11fa2da57c79eeb334ba1f3f8bcb845e09f..090bae3e1fcd91433b92ad8a56250277366675ad 100644 (file)
@@ -484,16 +484,13 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
 static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 {
        struct sr_modbus_dev_inst *modbus;
-       struct sr_datafeed_packet packet;
 
        (void)cb_data;
 
        if (sdi->status != SR_ST_ACTIVE)
                return SR_ERR_DEV_CLOSED;
 
-       /* End of last frame. */
-       packet.type = SR_DF_END;
-       sr_session_send(sdi, &packet);
+       std_session_send_df_end(sdi, LOG_PREFIX);
 
        modbus = sdi->conn;
        sr_modbus_source_remove(sdi->session, modbus);
index 6fb6b44fb087be9f3321f9d049c245d7854ae39d..7f274258ddafe8b1245ff887fc663d55394db9db 100644 (file)
@@ -315,15 +315,12 @@ SR_PRIV int ols_set_samplerate(const struct sr_dev_inst *sdi,
 
 SR_PRIV void abort_acquisition(const struct sr_dev_inst *sdi)
 {
-       struct sr_datafeed_packet packet;
        struct sr_serial_dev_inst *serial;
 
        serial = sdi->conn;
        serial_source_remove(sdi->session, serial);
 
-       /* Terminate session */
-       packet.type = SR_DF_END;
-       sr_session_send(sdi, &packet);
+       std_session_send_df_end(sdi, LOG_PREFIX);
 }
 
 SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
index 44af4017077d8d79f4503fa1d720ed0678381cc6..d5ec1ef6070f82df7bbc3ccf8f8389a23f5ab636 100644 (file)
@@ -702,7 +702,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
 static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 {
        struct dev_context *devc;
-       struct sr_datafeed_packet packet;
 
        devc = sdi->priv;
 
@@ -715,10 +714,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 
        sr_session_source_remove(sdi->session, -1);
 
-       /* Send end packet to the session bus. */
-       sr_dbg("Sending SR_DF_END.");
-       packet.type = SR_DF_END;
-       sr_session_send(cb_data, &packet);
+       std_session_send_df_end(cb_data, LOG_PREFIX);
 
        return SR_OK;
 }
index 1f784cfce344177d997a08d5fc73e5a8f0f8e76a..97757ecf1668a653ebb48fb9bba72e6a209ab4ec 100644 (file)
@@ -1050,7 +1050,6 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 {
        struct dev_context *devc;
        struct sr_scpi_dev_inst *scpi;
-       struct sr_datafeed_packet packet;
 
        (void)cb_data;
 
@@ -1061,9 +1060,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
                return SR_ERR;
        }
 
-       /* End of last frame. */
-       packet.type = SR_DF_END;
-       sr_session_send(sdi, &packet);
+       std_session_send_df_end(sdi, LOG_PREFIX);
 
        g_slist_free(devc->enabled_channels);
        devc->enabled_channels = NULL;
index 5566b85972f64d890543e7764e20f5442970af21..d75be36dda6c2d00d4398f4dc3cb23a7755cdc37 100644 (file)
@@ -757,14 +757,11 @@ SR_PRIV int logic16_init_device(const struct sr_dev_inst *sdi)
 
 static void finish_acquisition(struct sr_dev_inst *sdi)
 {
-       struct sr_datafeed_packet packet;
        struct dev_context *devc;
 
        devc = sdi->priv;
 
-       /* Terminate session. */
-       packet.type = SR_DF_END;
-       sr_session_send(devc->cb_data, &packet);
+       std_session_send_df_end(sdi, LOG_PREFIX);
 
        /* Remove fds from polling. */
        usb_source_remove(sdi->session, devc->ctx);
index a29744edefa0b79e6744906b414121511de0a37d..475cdca3eb9064bbb8cfac3b90b2d8c1b07a3196 100644 (file)
@@ -618,7 +618,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
 
 static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 {
-       struct sr_datafeed_packet packet;
        struct sr_scpi_dev_inst *scpi;
        float f;
 
@@ -637,8 +636,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
        sr_scpi_get_float(scpi, NULL, &f);
        sr_scpi_source_remove(sdi->session, scpi);
 
-       packet.type = SR_DF_END;
-       sr_session_send(sdi, &packet);
+       std_session_send_df_end(sdi, LOG_PREFIX);
 
        return SR_OK;
 }
index 20cf10f9c5fabc81b2cf9329e8babc778ae3a6e4..d7f8da83adb0e07beb37c2801d4e166602644b3f 100644 (file)
@@ -277,7 +277,6 @@ static int transfer_event(int fd, int revents, void *cb_data)
        struct dev_context *devc;
        struct drv_context *drvc;
        struct timeval tv;
-       struct sr_datafeed_packet packet;
        int ret;
 
        (void)fd;
@@ -317,10 +316,7 @@ static int transfer_event(int fd, int revents, void *cb_data)
 
        /* We are done, clean up and send end packet to session bus. */
        clear_acquisition_state(sdi);
-
-       packet.type = SR_DF_END;
-       packet.payload = NULL;
-       sr_session_send(sdi, &packet);
+       std_session_send_df_end(sdi, LOG_PREFIX);
 
        return G_SOURCE_REMOVE;
 }
index 0c37886e30c9d995e17c1a9c95eeee59c24e3679..97aa7ac4fc9206b98ee95342a903e86319371729 100644 (file)
@@ -413,7 +413,6 @@ static int handle_events(int fd, int revents, void *cb_data)
        struct sr_dev_driver *di;
        struct dev_context *devc;
        struct drv_context *drvc;
-       struct sr_datafeed_packet packet;
        struct sr_dev_inst *sdi;
        struct timeval tv;
        gint64 now;
@@ -434,11 +433,8 @@ static int handle_events(int fd, int revents, void *cb_data)
 
        if (sdi->status == SR_ST_STOPPING) {
                usb_source_remove(sdi->session, drvc->sr_ctx);
-
                dev_close(sdi);
-
-               packet.type = SR_DF_END;
-               sr_session_send(sdi, &packet);
+               std_session_send_df_end(sdi, LOG_PREFIX);
        }
 
        memset(&tv, 0, sizeof(struct timeval));
index f74d10d69887d69431edaa909e9b35b550da5619..250e92fc42bb812d5cff7678edd1197fdde3dd04 100644 (file)
@@ -210,17 +210,10 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
 
 static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 {
-       struct sr_datafeed_packet packet;
-
        (void)cb_data;
 
        sr_dbg("Stopping acquisition.");
-
-       /* Send end packet to the session bus. */
-       sr_dbg("Sending SR_DF_END.");
-       packet.type = SR_DF_END;
-       sr_session_send(sdi, &packet);
-
+       std_session_send_df_end(sdi, LOG_PREFIX);
        sr_session_source_remove(sdi->session, -1);
 
        return SR_OK;
index 7fd1a02aef393c2960f60b902d566a3d53d28515..14e70cf221ed13f9d41adf1082098ce215f8648e 100644 (file)
@@ -195,7 +195,6 @@ SR_PRIV int uni_t_ut32x_handle_events(int fd, int revents, void *cb_data)
        struct dev_context *devc;
        struct sr_dev_driver *di;
        struct sr_dev_inst *sdi;
-       struct sr_datafeed_packet packet;
        struct sr_usb_dev_inst *usb;
        struct timeval tv;
        int len, ret;
@@ -219,8 +218,7 @@ SR_PRIV int uni_t_ut32x_handle_events(int fd, int revents, void *cb_data)
 
        if (sdi->status == SR_ST_STOPPING) {
                usb_source_remove(sdi->session, drvc->sr_ctx);
-               packet.type = SR_DF_END;
-               sr_session_send(cb_data, &packet);
+               std_session_send_df_header(cb_data, LOG_PREFIX);
 
                /* Tell the device to stop sending USB packets. */
                usb = sdi->conn;
index 8e8f0276e60c8a97b8fd7f0083966004da19e10c..19539ede87bffc81f9c4f88f15155bb6b61f6a26 100644 (file)
@@ -327,7 +327,6 @@ static int handle_events(int fd, int revents, void *cb_data)
 {
        struct dev_context *devc;
        struct drv_context *drvc;
-       struct sr_datafeed_packet packet;
        struct sr_dev_inst *sdi;
        struct sr_dev_driver *di;
        struct timeval tv;
@@ -349,11 +348,8 @@ static int handle_events(int fd, int revents, void *cb_data)
 
        if (sdi->status == SR_ST_STOPPING) {
                usb_source_remove(sdi->session, drvc->sr_ctx);
-
                dev_close(sdi);
-
-               packet.type = SR_DF_END;
-               sr_session_send(cb_data, &packet);
+               std_session_send_df_end(sdi, LOG_PREFIX);
        }
 
        memset(&tv, 0, sizeof(struct timeval));
index 21fa1657acb7779ee461114cb422f71a35a09daa..2a3d2e55f00a6a39eb6385d199a128a3a236caea 100644 (file)
@@ -676,13 +676,10 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
 static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 {
        struct dev_context *devc;
-       struct sr_datafeed_packet packet;
 
        (void)cb_data;
 
-       packet.type = SR_DF_END;
-       packet.payload = NULL;
-       sr_session_send(sdi, &packet);
+       std_session_send_df_end(sdi, LOG_PREFIX);
 
        if (sdi->status != SR_ST_ACTIVE)
                return SR_ERR_DEV_CLOSED;
index 657e5eb25ae87fa59c148c3ac5bd1dfcf5893a20..3681352e73e058828ec03e4cb7b800b80e554eef 100644 (file)
@@ -583,8 +583,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
 
        /* Check for empty capture */
        if ((status & STATUS_READY) && !stop_address) {
-               packet.type = SR_DF_END;
-               sr_session_send(cb_data, &packet);
+               std_session_send_df_end(cb_data, LOG_PREFIX);
                return SR_OK;
        }
 
@@ -692,8 +691,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
        analyzer_read_stop(usb->devhdl);
        g_free(buf);
 
-       packet.type = SR_DF_END;
-       sr_session_send(cb_data, &packet);
+       std_session_send_df_end(cb_data, LOG_PREFIX);
 
        return SR_OK;
 }
@@ -703,10 +701,8 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 {
        struct dev_context *devc;
        struct sr_usb_dev_inst *usb;
-       struct sr_datafeed_packet packet;
 
-       packet.type = SR_DF_END;
-       sr_session_send(cb_data, &packet);
+       std_session_send_df_end(cb_data, LOG_PREFIX);
 
        if (!(devc = sdi->priv)) {
                sr_err("%s: sdi->priv was NULL", __func__);
index f58af58d16ac1d35e649a1db7761a0cf3fe495ec..51b9f6bfc4c2fbcff0487e257f0a9a0164ac3b60 100644 (file)
@@ -128,7 +128,6 @@ static int receive(struct sr_input *in, GString *buf)
 static int end(struct sr_input *in)
 {
        struct context *inc;
-       struct sr_datafeed_packet packet;
        int ret;
 
        if (in->sdi_ready)
@@ -137,10 +136,8 @@ static int end(struct sr_input *in)
                ret = SR_OK;
 
        inc = in->priv;
-       if (inc->started) {
-               packet.type = SR_DF_END;
-               sr_session_send(in->sdi, &packet);
-       }
+       if (inc->started)
+               std_session_send_df_end(in->sdi, LOG_PREFIX);
 
        return ret;
 }
index f42886ed87e21037b83efc443856952a9dfe3033..0afd8ea286cbb7b87dd10ecf077b725c57d995ed 100644 (file)
@@ -140,7 +140,6 @@ static int receive(struct sr_input *in, GString *buf)
 static int end(struct sr_input *in)
 {
        struct context *inc;
-       struct sr_datafeed_packet packet;
        int ret;
 
        if (in->sdi_ready)
@@ -149,10 +148,8 @@ static int end(struct sr_input *in)
                ret = SR_OK;
 
        inc = in->priv;
-       if (inc->started) {
-               packet.type = SR_DF_END;
-               sr_session_send(in->sdi, &packet);
-       }
+       if (inc->started)
+               std_session_send_df_end(in->sdi, LOG_PREFIX);
 
        return ret;
 }
index ed2b49409b43d9b25c611ce47090c435d90cb5a2..984a58c7d9753ae1d11869d829ad2e5507e9d686 100644 (file)
@@ -738,7 +738,6 @@ static int receive(struct sr_input *in, GString *buf)
 static int end(struct sr_input *in)
 {
        struct context *inc;
-       struct sr_datafeed_packet packet;
        int ret;
 
        if (in->sdi_ready)
@@ -747,11 +746,8 @@ static int end(struct sr_input *in)
                ret = SR_OK;
 
        inc = in->priv;
-       if (inc->started) {
-               /* End of stream. */
-               packet.type = SR_DF_END;
-               sr_session_send(in->sdi, &packet);
-       }
+       if (inc->started)
+               std_session_send_df_end(in->sdi, LOG_PREFIX);
 
        return ret;
 }
index e0b5cedaeffc6726b892705fc44b86e0a20451d0..f05ca5b8c50116a85e48f081263e7640634593f3 100644 (file)
@@ -217,7 +217,6 @@ static int receive(struct sr_input *in, GString *buf)
 
 static int end(struct sr_input *in)
 {
-       struct sr_datafeed_packet packet;
        struct context *inc;
        int ret;
 
@@ -227,10 +226,8 @@ static int end(struct sr_input *in)
                ret = SR_OK;
 
        inc = in->priv;
-       if (inc->started) {
-               packet.type = SR_DF_END;
-               sr_session_send(in->sdi, &packet);
-       }
+       if (inc->started)
+               std_session_send_df_end(in->sdi, LOG_PREFIX);
 
        return ret;
 }
index 81df295a238ebf79b188720e787976f4fe41248a..4ac06cf565c1792b2df0c0b7437e166d8e8f6d80 100644 (file)
@@ -731,7 +731,6 @@ static int receive(struct sr_input *in, GString *buf)
 static int end(struct sr_input *in)
 {
        struct context *inc;
-       struct sr_datafeed_packet packet;
        int ret;
 
        inc = in->priv;
@@ -743,10 +742,8 @@ static int end(struct sr_input *in)
 
        flush_output_buffer(in);
 
-       if (inc->meta_sent) {
-               packet.type = SR_DF_END;
-               sr_session_send(in->sdi, &packet);
-       }
+       if (inc->meta_sent)
+               std_session_send_df_end(in->sdi, LOG_PREFIX);
 
        return ret;
 }
index b25c7381b7d32ab1830070c2c80fafc76ab03cab..253e76f67d25a78a5b381a08e2cd841ca8bdc723 100644 (file)
@@ -582,7 +582,6 @@ static int receive(struct sr_input *in, GString *buf)
 
 static int end(struct sr_input *in)
 {
-       struct sr_datafeed_packet packet;
        struct context *inc;
        int ret;
 
@@ -596,10 +595,8 @@ static int end(struct sr_input *in)
        /* Send any samples that haven't been sent yet. */
        send_buffer(in);
 
-       if (inc->started) {
-               packet.type = SR_DF_END;
-               sr_session_send(in->sdi, &packet);
-       }
+       if (inc->started)
+               std_session_send_df_end(in->sdi, LOG_PREFIX);
 
        return ret;
 }
index f7574334da78e045c287a16f18e1f036da74a904..a887fb743396e57ae83d3ecfd1707f83a0b76c89 100644 (file)
@@ -341,7 +341,6 @@ static int receive(struct sr_input *in, GString *buf)
 
 static int end(struct sr_input *in)
 {
-       struct sr_datafeed_packet packet;
        struct context *inc;
        int ret;
 
@@ -351,10 +350,8 @@ static int end(struct sr_input *in)
                ret = SR_OK;
 
        inc = in->priv;
-       if (inc->started) {
-               packet.type = SR_DF_END;
-               sr_session_send(in->sdi, &packet);
-       }
+       if (inc->started)
+               std_session_send_df_end(in->sdi, LOG_PREFIX);
 
        return ret;
 }
index 0cf52884a93c6e3082b9f537630e7569c8236b8c..63234153d44da4051a8d9ff35b48fcd21f54cca0 100644 (file)
@@ -857,6 +857,8 @@ SR_PRIV int std_serial_dev_acquisition_stop(struct sr_dev_inst *sdi,
 #endif
 SR_PRIV int std_session_send_df_header(const struct sr_dev_inst *sdi,
                const char *prefix);
+SR_PRIV int std_session_send_df_end(const struct sr_dev_inst *sdi,
+               const char *prefix);
 SR_PRIV int std_dev_clear(const struct sr_dev_driver *driver,
                std_dev_clear_callback clear_private);
 SR_PRIV int std_serial_dev_close(struct sr_dev_inst *sdi);
index cfa1da9d2ac0beaf24c182bf0d1614e0a30e5395..1db2cdff255ca26d14a3d9509d174ff04ecb16c2 100644 (file)
@@ -178,7 +178,6 @@ static int receive_data(int fd, int revents, void *cb_data)
 {
        struct sr_dev_inst *sdi;
        struct session_vdev *vdev;
-       struct sr_datafeed_packet packet;
 
        (void)fd;
        (void)revents;
@@ -199,9 +198,8 @@ static int receive_data(int fd, int revents, void *cb_data)
                zip_discard(vdev->archive);
                vdev->archive = NULL;
        }
-       packet.type = SR_DF_END;
-       packet.payload = NULL;
-       sr_session_send(sdi, &packet);
+
+       std_session_send_df_end(sdi, LOG_PREFIX);
 
        return G_SOURCE_REMOVE;
 }
index 55952240fefe94e018e4a6b654477c0eab4b220f..adbd2e52b6fa14d0c34554d8f9f4b62fe43090c9 100644 (file)
--- a/src/std.c
+++ b/src/std.c
@@ -105,6 +105,38 @@ SR_PRIV int std_session_send_df_header(const struct sr_dev_inst *sdi,
        return SR_OK;
 }
 
+/**
+ * Standard API helper for sending an SR_DF_END packet.
+ *
+ * @param sdi The device instance to use. Must not be NULL.
+ * @param prefix A driver-specific prefix string used for log messages.
+ *              Must not be NULL. An empty string is allowed.
+ *
+ * @return SR_OK upon success, SR_ERR_ARG upon invalid arguments, or
+ *         SR_ERR upon other errors.
+ */
+SR_PRIV int std_session_send_df_end(const struct sr_dev_inst *sdi,
+                                   const char *prefix)
+{
+       int ret;
+       struct sr_datafeed_packet packet;
+
+       if (!sdi || !prefix)
+               return SR_ERR_ARG;
+
+       sr_dbg("%s: Sending SR_DF_END packet.", prefix);
+
+       packet.type = SR_DF_END;
+       packet.payload = NULL;
+
+       if ((ret = sr_session_send(sdi, &packet)) < 0) {
+               sr_err("%s: Failed to send SR_DF_END packet: %d.", prefix, ret);
+               return ret;
+       }
+
+       return SR_OK;
+}
+
 #ifdef HAVE_LIBSERIALPORT
 
 /**
@@ -183,7 +215,6 @@ SR_PRIV int std_serial_dev_acquisition_stop(struct sr_dev_inst *sdi,
                        struct sr_serial_dev_inst *serial, const char *prefix)
 {
        int ret;
-       struct sr_datafeed_packet packet;
 
        if (!prefix) {
                sr_err("Invalid prefix.");
@@ -207,14 +238,7 @@ SR_PRIV int std_serial_dev_acquisition_stop(struct sr_dev_inst *sdi,
                return ret;
        }
 
-       /* Send SR_DF_END packet to the session bus. */
-       sr_dbg("%s: Sending SR_DF_END packet.", prefix);
-       packet.type = SR_DF_END;
-       packet.payload = NULL;
-       if ((ret = sr_session_send(cb_data, &packet)) < 0) {
-               sr_err("%s: Failed to send SR_DF_END packet: %d.", prefix, ret);
-               return ret;
-       }
+       std_session_send_df_end(cb_data, prefix);
 
        return SR_OK;
 }