From: Uwe Hermann Date: Sat, 26 Mar 2016 18:45:04 +0000 (+0100) Subject: Factor out std_session_send_df_end() helper. X-Git-Tag: libsigrok-0.5.0~484 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=3be42bc22f8b36599a448273c12a76d3e0f7a940;p=libsigrok.git Factor out std_session_send_df_end() helper. 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. --- diff --git a/src/hardware/asix-sigma/protocol.c b/src/hardware/asix-sigma/protocol.c index 03d9e3c0..0e41207a 100644 --- a/src/hardware/asix-sigma/protocol.c +++ b/src/hardware/asix-sigma/protocol.c @@ -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); diff --git a/src/hardware/atten-pps3xxx/protocol.c b/src/hardware/atten-pps3xxx/protocol.c index 34e0af42..06a1d2e9 100644 --- a/src/hardware/atten-pps3xxx/protocol.c +++ b/src/hardware/atten-pps3xxx/protocol.c @@ -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); } } } diff --git a/src/hardware/baylibre-acme/api.c b/src/hardware/baylibre-acme/api.c index c116cbbb..0dd6fdba 100644 --- a/src/hardware/baylibre-acme/api.c +++ b/src/hardware/baylibre-acme/api.c @@ -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); diff --git a/src/hardware/beaglelogic/api.c b/src/hardware/beaglelogic/api.c index b9740104..6e881889 100644 --- a/src/hardware/beaglelogic/api.c +++ b/src/hardware/beaglelogic/api.c @@ -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; } diff --git a/src/hardware/beaglelogic/protocol.c b/src/hardware/beaglelogic/protocol.c index 55e2b647..f440592f 100644 --- a/src/hardware/beaglelogic/protocol.c +++ b/src/hardware/beaglelogic/protocol.c @@ -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); } diff --git a/src/hardware/brymen-bm86x/api.c b/src/hardware/brymen-bm86x/api.c index 64e492c6..d252208d 100644 --- a/src/hardware/brymen-bm86x/api.c +++ b/src/hardware/brymen-bm86x/api.c @@ -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); diff --git a/src/hardware/chronovu-la/api.c b/src/hardware/chronovu-la/api.c index 14104581..976180ac 100644 --- a/src/hardware/chronovu-la/api.c +++ b/src/hardware/chronovu-la/api.c @@ -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; } diff --git a/src/hardware/demo/demo.c b/src/hardware/demo/demo.c index e7948cdc..f1b97d21 100644 --- a/src/hardware/demo/demo.c +++ b/src/hardware/demo/demo.c @@ -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; } diff --git a/src/hardware/ftdi-la/api.c b/src/hardware/ftdi-la/api.c index 68d60e0b..c9ab6f6a 100644 --- a/src/hardware/ftdi-la/api.c +++ b/src/hardware/ftdi-la/api.c @@ -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; } diff --git a/src/hardware/fx2lafw/api.c b/src/hardware/fx2lafw/api.c index c6b14565..171ec166 100644 --- a/src/hardware/fx2lafw/api.c +++ b/src/hardware/fx2lafw/api.c @@ -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) diff --git a/src/hardware/fx2lafw/protocol.c b/src/hardware/fx2lafw/protocol.c index fce69ac4..513fd0e2 100644 --- a/src/hardware/fx2lafw/protocol.c +++ b/src/hardware/fx2lafw/protocol.c @@ -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); diff --git a/src/hardware/gwinstek-gds-800/api.c b/src/hardware/gwinstek-gds-800/api.c index cfec15ee..89d6a07a 100644 --- a/src/hardware/gwinstek-gds-800/api.c +++ b/src/hardware/gwinstek-gds-800/api.c @@ -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; } diff --git a/src/hardware/hameg-hmo/api.c b/src/hardware/hameg-hmo/api.c index 370b6314..c293d2b4 100644 --- a/src/hardware/hameg-hmo/api.c +++ b/src/hardware/hameg-hmo/api.c @@ -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; diff --git a/src/hardware/hantek-6xxx/api.c b/src/hardware/hantek-6xxx/api.c index 480eb1c4..83992ff6 100644 --- a/src/hardware/hantek-6xxx/api.c +++ b/src/hardware/hantek-6xxx/api.c @@ -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; diff --git a/src/hardware/hantek-dso/api.c b/src/hardware/hantek-dso/api.c index 5fe431d5..52d5fe64 100644 --- a/src/hardware/hantek-dso/api.c +++ b/src/hardware/hantek-dso/api.c @@ -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; diff --git a/src/hardware/hung-chang-dso-2100/api.c b/src/hardware/hung-chang-dso-2100/api.c index 45fff2bc..e76b9a51 100644 --- a/src/hardware/hung-chang-dso-2100/api.c +++ b/src/hardware/hung-chang-dso-2100/api.c @@ -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; diff --git a/src/hardware/ikalogic-scanalogic2/protocol.c b/src/hardware/ikalogic-scanalogic2/protocol.c index 03d5d1bf..f8833806 100644 --- a/src/hardware/ikalogic-scanalogic2/protocol.c +++ b/src/hardware/ikalogic-scanalogic2/protocol.c @@ -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); } diff --git a/src/hardware/ikalogic-scanaplus/api.c b/src/hardware/ikalogic-scanaplus/api.c index ba4652ec..dcd773dd 100644 --- a/src/hardware/ikalogic-scanaplus/api.c +++ b/src/hardware/ikalogic-scanaplus/api.c @@ -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; } diff --git a/src/hardware/kecheng-kc-330b/api.c b/src/hardware/kecheng-kc-330b/api.c index d294bf02..7fcb562e 100644 --- a/src/hardware/kecheng-kc-330b/api.c +++ b/src/hardware/kecheng-kc-330b/api.c @@ -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; } diff --git a/src/hardware/kecheng-kc-330b/protocol.c b/src/hardware/kecheng-kc-330b/protocol.c index e4550d21..bcc68469 100644 --- a/src/hardware/kecheng-kc-330b/protocol.c +++ b/src/hardware/kecheng-kc-330b/protocol.c @@ -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; } diff --git a/src/hardware/lascar-el-usb/api.c b/src/hardware/lascar-el-usb/api.c index c8938f21..1934c9e2 100644 --- a/src/hardware/lascar-el-usb/api.c +++ b/src/hardware/lascar-el-usb/api.c @@ -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; } diff --git a/src/hardware/lascar-el-usb/protocol.c b/src/hardware/lascar-el-usb/protocol.c index 2584e8b0..9fd9b696 100644 --- a/src/hardware/lascar-el-usb/protocol.c +++ b/src/hardware/lascar-el-usb/protocol.c @@ -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)); diff --git a/src/hardware/lecroy-logicstudio/protocol.c b/src/hardware/lecroy-logicstudio/protocol.c index 9c825991..11d3ce2c 100644 --- a/src/hardware/lecroy-logicstudio/protocol.c +++ b/src/hardware/lecroy-logicstudio/protocol.c @@ -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, diff --git a/src/hardware/link-mso19/protocol.c b/src/hardware/link-mso19/protocol.c index 69551fe0..0c28585e 100644 --- a/src/hardware/link-mso19/protocol.c +++ b/src/hardware/link-mso19/protocol.c @@ -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) diff --git a/src/hardware/maynuo-m97/api.c b/src/hardware/maynuo-m97/api.c index b2f7e11f..090bae3e 100644 --- a/src/hardware/maynuo-m97/api.c +++ b/src/hardware/maynuo-m97/api.c @@ -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); diff --git a/src/hardware/openbench-logic-sniffer/protocol.c b/src/hardware/openbench-logic-sniffer/protocol.c index 6fb6b44f..7f274258 100644 --- a/src/hardware/openbench-logic-sniffer/protocol.c +++ b/src/hardware/openbench-logic-sniffer/protocol.c @@ -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) diff --git a/src/hardware/pipistrello-ols/api.c b/src/hardware/pipistrello-ols/api.c index 44af4017..d5ec1ef6 100644 --- a/src/hardware/pipistrello-ols/api.c +++ b/src/hardware/pipistrello-ols/api.c @@ -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; } diff --git a/src/hardware/rigol-ds/api.c b/src/hardware/rigol-ds/api.c index 1f784cfc..97757ecf 100644 --- a/src/hardware/rigol-ds/api.c +++ b/src/hardware/rigol-ds/api.c @@ -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; diff --git a/src/hardware/saleae-logic16/protocol.c b/src/hardware/saleae-logic16/protocol.c index 5566b859..d75be36d 100644 --- a/src/hardware/saleae-logic16/protocol.c +++ b/src/hardware/saleae-logic16/protocol.c @@ -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); diff --git a/src/hardware/scpi-pps/api.c b/src/hardware/scpi-pps/api.c index a29744ed..475cdca3 100644 --- a/src/hardware/scpi-pps/api.c +++ b/src/hardware/scpi-pps/api.c @@ -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; } diff --git a/src/hardware/sysclk-lwla/protocol.c b/src/hardware/sysclk-lwla/protocol.c index 20cf10f9..d7f8da83 100644 --- a/src/hardware/sysclk-lwla/protocol.c +++ b/src/hardware/sysclk-lwla/protocol.c @@ -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; } diff --git a/src/hardware/testo/api.c b/src/hardware/testo/api.c index 0c37886e..97aa7ac4 100644 --- a/src/hardware/testo/api.c +++ b/src/hardware/testo/api.c @@ -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)); diff --git a/src/hardware/uni-t-dmm/api.c b/src/hardware/uni-t-dmm/api.c index f74d10d6..250e92fc 100644 --- a/src/hardware/uni-t-dmm/api.c +++ b/src/hardware/uni-t-dmm/api.c @@ -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; diff --git a/src/hardware/uni-t-ut32x/protocol.c b/src/hardware/uni-t-ut32x/protocol.c index 7fd1a02a..14e70cf2 100644 --- a/src/hardware/uni-t-ut32x/protocol.c +++ b/src/hardware/uni-t-ut32x/protocol.c @@ -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; diff --git a/src/hardware/victor-dmm/api.c b/src/hardware/victor-dmm/api.c index 8e8f0276..19539ede 100644 --- a/src/hardware/victor-dmm/api.c +++ b/src/hardware/victor-dmm/api.c @@ -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)); diff --git a/src/hardware/yokogawa-dlm/api.c b/src/hardware/yokogawa-dlm/api.c index 21fa1657..2a3d2e55 100644 --- a/src/hardware/yokogawa-dlm/api.c +++ b/src/hardware/yokogawa-dlm/api.c @@ -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; diff --git a/src/hardware/zeroplus-logic-cube/api.c b/src/hardware/zeroplus-logic-cube/api.c index 657e5eb2..3681352e 100644 --- a/src/hardware/zeroplus-logic-cube/api.c +++ b/src/hardware/zeroplus-logic-cube/api.c @@ -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__); diff --git a/src/input/binary.c b/src/input/binary.c index f58af58d..51b9f6bf 100644 --- a/src/input/binary.c +++ b/src/input/binary.c @@ -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; } diff --git a/src/input/chronovu_la8.c b/src/input/chronovu_la8.c index f42886ed..0afd8ea2 100644 --- a/src/input/chronovu_la8.c +++ b/src/input/chronovu_la8.c @@ -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; } diff --git a/src/input/csv.c b/src/input/csv.c index ed2b4940..984a58c7 100644 --- a/src/input/csv.c +++ b/src/input/csv.c @@ -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; } diff --git a/src/input/raw_analog.c b/src/input/raw_analog.c index e0b5ceda..f05ca5b8 100644 --- a/src/input/raw_analog.c +++ b/src/input/raw_analog.c @@ -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; } diff --git a/src/input/trace32_ad.c b/src/input/trace32_ad.c index 81df295a..4ac06cf5 100644 --- a/src/input/trace32_ad.c +++ b/src/input/trace32_ad.c @@ -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; } diff --git a/src/input/vcd.c b/src/input/vcd.c index b25c7381..253e76f6 100644 --- a/src/input/vcd.c +++ b/src/input/vcd.c @@ -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; } diff --git a/src/input/wav.c b/src/input/wav.c index f7574334..a887fb74 100644 --- a/src/input/wav.c +++ b/src/input/wav.c @@ -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; } diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index 0cf52884..63234153 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -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); diff --git a/src/session_driver.c b/src/session_driver.c index cfa1da9d..1db2cdff 100644 --- a/src/session_driver.c +++ b/src/session_driver.c @@ -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; } diff --git a/src/std.c b/src/std.c index 55952240..adbd2e52 100644 --- 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; }