/* Poll every 100ms, or whenever some data comes in. */
serial = sdi->conn;
- serial_source_add(serial, G_IO_IN, 100, agdmm_receive_data, (void *)sdi);
+ serial_source_add(sdi->session, serial, G_IO_IN, 100,
+ agdmm_receive_data, (void *)sdi);
return SR_OK;
}
std_session_send_df_header(cb_data, LOG_PREFIX);
/* Poll every 50ms, or whenever some data comes in. */
- serial_source_add(serial, G_IO_IN, 50, appa_55ii_receive_data, (void *)sdi);
+ serial_source_add(sdi->session, serial, G_IO_IN, 50,
+ appa_55ii_receive_data, (void *)sdi);
return SR_OK;
}
*/
if ((i == 1023) || (ts == (tsdiff - EVENTS_PER_CLUSTER))) {
logic.length = (i + 1) * logic.unitsize;
- sr_session_send(devc->cb_data, &packet);
+ sr_session_send(sdi, &packet);
}
}
if (trigger_offset > 0) {
packet.type = SR_DF_LOGIC;
logic.length = trigger_offset * logic.unitsize;
- sr_session_send(devc->cb_data, &packet);
+ sr_session_send(sdi, &packet);
events_in_cluster -= trigger_offset;
}
/* Only send trigger if explicitly enabled. */
if (devc->use_triggers) {
packet.type = SR_DF_TRIGGER;
- sr_session_send(devc->cb_data, &packet);
+ sr_session_send(sdi, &packet);
}
}
packet.type = SR_DF_LOGIC;
logic.length = events_in_cluster * logic.unitsize;
logic.data = samples + (trigger_offset * logic.unitsize);
- sr_session_send(devc->cb_data, &packet);
+ sr_session_send(sdi, &packet);
}
ss->lastsample =
static int decode_chunk_ts(struct sigma_dram_line *dram_line,
uint16_t events_in_line,
uint32_t trigger_event,
- void *cb_data)
+ struct sr_dev_inst *sdi)
{
struct sigma_dram_cluster *dram_cluster;
- struct sr_dev_inst *sdi = cb_data;
struct dev_context *devc = sdi->priv;
unsigned int clusters_in_line =
(events_in_line + (EVENTS_PER_CLUSTER - 1)) / EVENTS_PER_CLUSTER;
devc->cb_data = cb_data;
/* Send header packet to the session bus. */
- std_session_send_df_header(cb_data, LOG_PREFIX);
+ std_session_send_df_header(sdi, LOG_PREFIX);
/* Add capture source. */
- sr_source_add(0, G_IO_IN, 10, receive_data, (void *)sdi);
+ sr_session_source_add(sdi->session, 0, G_IO_IN, 10, receive_data, (void *)sdi);
devc->state.state = SIGMA_CAPTURE;
devc = sdi->priv;
devc->state.state = SIGMA_IDLE;
- sr_source_remove(0);
+ sr_session_source_remove(sdi->session, 0);
return SR_OK;
}
devc->acquisition_running = TRUE;
serial = sdi->conn;
- serial_source_add(serial, G_IO_IN, 50, atten_pps3xxx_receive_data, (void *)sdi);
+ serial_source_add(sdi->session, serial, G_IO_IN, 50,
+ atten_pps3xxx_receive_data, (void *)sdi);
std_session_send_df_header(cb_data, LOG_PREFIX);
/* Send a "channel" configuration packet now. */
if (devc->acquisition_running)
send_config(sdi);
else {
- serial_source_remove(serial);
+ serial_source_remove(sdi->session, serial);
packet.type = SR_DF_END;
sr_session_send(sdi, &packet);
}
{
struct dev_context *devc;
+ (void)cb_data;
+
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
devc = sdi->priv;
- devc->session_cb_data = cb_data;
devc->start_time = g_get_monotonic_time();
/* Send header packet to the session bus. */
- std_session_send_df_header(cb_data, LOG_PREFIX);
+ std_session_send_df_header(sdi, LOG_PREFIX);
- sr_source_add(0, 0, 10, brymen_bm86x_receive_data, (void *)sdi);
+ sr_session_source_add(sdi->session, 0, 0, 10,
+ brymen_bm86x_receive_data, (void *)sdi);
return SR_OK;
}
{
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(cb_data, &packet);
+ sr_session_send(sdi, &packet);
- sr_source_remove(0);
+ sr_session_source_remove(sdi->session, 0);
return SR_OK;
}
analog[0].channels = g_slist_append(NULL, sdi->channels->data);
packet.type = SR_DF_ANALOG;
packet.payload = &analog[0];
- sr_session_send(devc->session_cb_data, &packet);
+ sr_session_send(sdi, &packet);
g_slist_free(analog[0].channels);
}
analog[1].channels = g_slist_append(NULL, sdi->channels->next->data);
packet.type = SR_DF_ANALOG;
packet.payload = &analog[1];
- sr_session_send(devc->session_cb_data, &packet);
+ sr_session_send(sdi, &packet);
g_slist_free(analog[1].channels);
}
/* Acquisition settings */
uint64_t limit_samples; /**< The sampling limit (in number of samples).*/
uint64_t limit_msec; /**< The time limit (in milliseconds). */
- void *session_cb_data; /**< Opaque pointer passed in by the frontend. */
/* Operational state */
int detached_kernel_driver;/**< Whether kernel driver was detached or not */
/* Poll every 50ms, or whenever some data comes in. */
serial = sdi->conn;
- serial_source_add(serial, G_IO_IN, 50,
- brymen_dmm_receive_data, (void *)sdi);
+ serial_source_add(sdi->session, serial, G_IO_IN, 50,
+ brymen_dmm_receive_data, (void *)sdi);
return SR_OK;
}
/* Poll every 100ms, or whenever some data comes in. */
serial = sdi->conn;
- serial_source_add(serial, G_IO_IN, 150, cem_dt_885x_receive_data,
- (void *)sdi);
+ serial_source_add(sdi->session, serial, G_IO_IN, 150,
+ cem_dt_885x_receive_data, (void *)sdi);
return SR_OK;
}
/* Poll every 500ms, or whenever some data comes in. */
serial = sdi->conn;
- serial_source_add(serial, G_IO_IN, 500,
+ serial_source_add(sdi->session, serial, G_IO_IN, 500,
center_devs[idx].receive_data, (void *)sdi);
return SR_OK;
devc->cb_data = cb_data;
/* Send header packet to the session bus. */
- std_session_send_df_header(cb_data, LOG_PREFIX);
+ std_session_send_df_header(sdi, LOG_PREFIX);
/* Time when we should be done (for detecting trigger timeouts). */
devc->done = (devc->divcount + 1) * devc->prof->trigger_constant +
devc->trigger_found = 0;
/* Hook up a dummy handler to receive data from the device. */
- sr_source_add(-1, G_IO_IN, 0, receive_data, (void *)sdi);
+ sr_session_source_add(sdi->session, -1, G_IO_IN, 0, receive_data, (void *)sdi);
return SR_OK;
}
{
struct sr_datafeed_packet packet;
- (void)sdi;
+ (void)cb_data;
sr_dbg("Stopping acquisition.");
- sr_source_remove(-1);
+ 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);
+ sr_session_send(sdi, &packet);
return SR_OK;
}
/* Poll every 150ms, or whenever some data comes in. */
serial = sdi->conn;
- serial_source_add(serial, G_IO_IN, 150, colead_slm_receive_data,
- (void *)sdi);
+ serial_source_add(sdi->session, serial, G_IO_IN, 150,
+ colead_slm_receive_data, (void *)sdi);
return SR_OK;
}
* @return SR_OK upon success, SR_ERR_ARG upon invalid arguments, or
* SR_ERR_MALLOC upon memory allocation errors.
*/
-SR_PRIV int sr_scpi_source_add(struct sr_scpi_dev_inst *scpi, int events,
- int timeout, sr_receive_data_callback cb, void *cb_data)
+SR_PRIV int sr_scpi_source_add(struct sr_session *session,
+ struct sr_scpi_dev_inst *scpi, int events, int timeout,
+ sr_receive_data_callback cb, void *cb_data)
{
- return scpi->source_add(scpi->priv, events, timeout, cb, cb_data);
+ return scpi->source_add(session, scpi->priv, events, timeout, cb, cb_data);
}
/**
* SR_ERR_MALLOC upon memory allocation errors, SR_ERR_BUG upon
* internal errors.
*/
-SR_PRIV int sr_scpi_source_remove(struct sr_scpi_dev_inst *scpi)
+SR_PRIV int sr_scpi_source_remove(struct sr_session *session,
+ struct sr_scpi_dev_inst *scpi)
{
- return scpi->source_remove(scpi->priv);
+ return scpi->source_remove(session, scpi->priv);
}
/**
return SR_OK;
}
-static int scpi_serial_source_add(void *priv, int events, int timeout,
- sr_receive_data_callback cb, void *cb_data)
+static int scpi_serial_source_add(struct sr_session *session, void *priv,
+ int events, int timeout, sr_receive_data_callback cb, void *cb_data)
{
struct scpi_serial *sscpi = priv;
struct sr_serial_dev_inst *serial = sscpi->serial;
- return serial_source_add(serial, events, timeout, cb, cb_data);
+ return serial_source_add(session, serial, events, timeout, cb, cb_data);
}
-static int scpi_serial_source_remove(void *priv)
+static int scpi_serial_source_remove(struct sr_session *session, void *priv)
{
struct scpi_serial *sscpi = priv;
struct sr_serial_dev_inst *serial = sscpi->serial;
- return serial_source_remove(serial);
+ return serial_source_remove(session, serial);
}
static int scpi_serial_send(void *priv, const char *command)
return SR_OK;
}
-static int scpi_tcp_source_add(void *priv, int events, int timeout,
- sr_receive_data_callback cb, void *cb_data)
+static int scpi_tcp_source_add(struct sr_session *session, void *priv,
+ int events, int timeout, sr_receive_data_callback cb, void *cb_data)
{
struct scpi_tcp *tcp = priv;
- return sr_source_add(tcp->socket, events, timeout, cb, cb_data);
+ return sr_session_source_add(session, tcp->socket, events, timeout,
+ cb, cb_data);
}
-static int scpi_tcp_source_remove(void *priv)
+static int scpi_tcp_source_remove(struct sr_session *session, void *priv)
{
struct scpi_tcp *tcp = priv;
- return sr_source_remove(tcp->socket);
+ return sr_session_source_remove(session, tcp->socket);
}
static int scpi_tcp_send(void *priv, const char *command)
return SR_OK;
}
-static int scpi_usbtmc_libusb_source_add(void *priv, int events, int timeout,
- sr_receive_data_callback cb, void *cb_data)
+static int scpi_usbtmc_libusb_source_add(struct sr_session *session,
+ void *priv, int events, int timeout, sr_receive_data_callback cb,
+ void *cb_data)
{
struct scpi_usbtmc_libusb *uscpi = priv;
(void)events;
- return usb_source_add(uscpi->ctx, timeout, cb, cb_data);
+ return usb_source_add(session, uscpi->ctx, timeout, cb, cb_data);
}
-static int scpi_usbtmc_libusb_source_remove(void *priv)
+static int scpi_usbtmc_libusb_source_remove(struct sr_session *session,
+ void *priv)
{
struct scpi_usbtmc_libusb *uscpi = priv;
- return usb_source_remove(uscpi->ctx);
+ return usb_source_remove(session, uscpi->ctx);
}
static void usbtmc_bulk_out_header_write(void *header, uint8_t MsgID,
return SR_OK;
}
-static int scpi_visa_source_add(void *priv, int events, int timeout,
- sr_receive_data_callback cb, void *cb_data)
+static int scpi_visa_source_add(struct sr_session *session, void *priv,
+ int events, int timeout, sr_receive_data_callback cb, void *cb_data)
{
(void) priv;
/* Hook up a dummy handler to receive data from the device. */
- return sr_source_add(-1, events, timeout, cb, cb_data);
+ return sr_session_source_add(session, -1, events, timeout, cb, cb_data);
}
-static int scpi_visa_source_remove(void *priv)
+static int scpi_visa_source_remove(struct sr_session *session, void *priv)
{
(void) priv;
- return sr_source_remove(-1);
+ return sr_session_source_remove(session, -1);
}
static int scpi_visa_send(void *priv, const char *command)
return SR_OK;
}
-static int scpi_vxi_source_add(void *priv, int events, int timeout,
- sr_receive_data_callback cb, void *cb_data)
+static int scpi_vxi_source_add(struct sr_session *session, void *priv,
+ int events, int timeout, sr_receive_data_callback cb, void *cb_data)
{
(void)priv;
/* Hook up a dummy handler to receive data from the device. */
- return sr_source_add(-1, events, timeout, cb, cb_data);
+ return sr_session_source_add(session, -1, events, timeout, cb, cb_data);
}
-static int scpi_vxi_source_remove(void *priv)
+static int scpi_vxi_source_remove(struct sr_session *session, void *priv)
{
(void)priv;
- return sr_source_remove(-1);
+ return sr_session_source_remove(session, -1);
}
/* Operation Flags */
typedef int event_handle;
#endif
-SR_PRIV int serial_source_add(struct sr_serial_dev_inst *serial, int events,
- int timeout, sr_receive_data_callback cb, void *cb_data)
+SR_PRIV int serial_source_add(struct sr_session *session,
+ struct sr_serial_dev_inst *serial, int events, int timeout,
+ sr_receive_data_callback cb, void *cb_data)
{
enum sp_event mask = 0;
unsigned int i;
if (mask & SP_EVENT_ERROR)
serial->pollfds[i].events |= G_IO_ERR;
- if (sr_source_add_pollfd(&serial->pollfds[i],
- timeout, cb, cb_data) != SR_OK)
+ if (sr_session_source_add_pollfd(session, &serial->pollfds[i],
+ timeout, cb, cb_data) != SR_OK)
return SR_ERR;
}
return SR_OK;
}
-SR_PRIV int serial_source_remove(struct sr_serial_dev_inst *serial)
+SR_PRIV int serial_source_remove(struct sr_session *session,
+ struct sr_serial_dev_inst *serial)
{
unsigned int i;
for (i = 0; i < serial->event_set->count; i++)
- if (sr_source_remove_pollfd(&serial->pollfds[i]) != SR_OK)
+ if (sr_session_source_remove_pollfd(session, &serial->pollfds[i]) != SR_OK)
return SR_ERR;
g_free(serial->pollfds);
}
#endif
-SR_PRIV int usb_source_add(struct sr_context *ctx, int timeout,
- sr_receive_data_callback cb, void *cb_data)
+SR_PRIV int usb_source_add(struct sr_session *session, struct sr_context *ctx,
+ int timeout, sr_receive_data_callback cb, void *cb_data)
{
if (ctx->usb_source_present) {
sr_err("A USB event source is already present.");
ctx->usb_pollfd.events = G_IO_IN;
ctx->usb_cb = cb;
ctx->usb_cb_data = cb_data;
- sr_session_source_add_pollfd(&ctx->usb_pollfd, timeout, usb_callback, ctx);
+ sr_session_source_add_pollfd(session, &ctx->usb_pollfd, timeout,
+ usb_callback, ctx);
#else
const struct libusb_pollfd **lupfd;
unsigned int i;
lupfd = libusb_get_pollfds(ctx->libusb_ctx);
for (i = 0; lupfd[i]; i++)
- sr_source_add(lupfd[i]->fd, lupfd[i]->events, timeout, cb, cb_data);
+ sr_session_source_add(session, lupfd[i]->fd, lupfd[i]->events,
+ timeout, cb, cb_data);
free(lupfd);
#endif
ctx->usb_source_present = TRUE;
return SR_OK;
}
-SR_PRIV int usb_source_remove(struct sr_context *ctx)
+SR_PRIV int usb_source_remove(struct sr_session *session, struct sr_context *ctx)
{
if (!ctx->usb_source_present)
return SR_OK;
libusb_unlock_events(ctx->libusb_ctx);
g_thread_join(ctx->usb_thread);
g_mutex_clear(&ctx->usb_mutex);
- sr_session_source_remove_pollfd(&ctx->usb_pollfd);
+ sr_session_source_remove_pollfd(session, &ctx->usb_pollfd);
CloseHandle(ctx->usb_event);
#else
const struct libusb_pollfd **lupfd;
lupfd = libusb_get_pollfds(ctx->libusb_ctx);
for (i = 0; lupfd[i]; i++)
- sr_source_remove(lupfd[i]->fd);
+ sr_session_source_remove(session, lupfd[i]->fd);
free(lupfd);
#endif
ctx->usb_source_present = FALSE;
GSList *l;
struct dev_context *devc;
+ (void)cb_data;
+
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
/* Make channels to unbuffered. */
g_io_channel_set_buffered(devc->channel, FALSE);
- sr_source_add_channel(devc->channel, G_IO_IN | G_IO_ERR,
+ sr_session_source_add_channel(sdi->session, devc->channel, G_IO_IN | G_IO_ERR,
40, prepare_data, (void *)sdi);
/* Send header packet to the session bus. */
- std_session_send_df_header(cb_data, LOG_PREFIX);
+ std_session_send_df_header(sdi, LOG_PREFIX);
/* We use this timestamp to decide how many more samples to send. */
devc->starttime = g_get_monotonic_time();
devc = sdi->priv;
sr_dbg("Stopping acquisition.");
- sr_source_remove_channel(devc->channel);
+ sr_session_source_remove_channel(sdi->session, devc->channel);
g_io_channel_shutdown(devc->channel, FALSE, NULL);
g_io_channel_unref(devc->channel);
devc->channel = NULL;
/* Poll every 100ms, or whenever some data comes in. */
serial = sdi->conn;
- serial_source_add(serial, G_IO_IN, 50, fluke_receive_data, (void *)sdi);
+ serial_source_add(sdi->session, serial, G_IO_IN, 50,
+ fluke_receive_data, (void *)sdi);
if (serial_write(serial, "QM\r", 3) == -1) {
sr_err("Unable to send QM: %s.", strerror(errno));
devc->ctx = drvc->sr_ctx;
- usb_source_add(devc->ctx, timeout, receive_data, NULL);
+ usb_source_add(sdi->session, devc->ctx, timeout, receive_data, NULL);
/* Send header packet to the session bus. */
std_session_send_df_header(cb_data, LOG_PREFIX);
}
}
-static void finish_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(devc->cb_data, &packet);
+ sr_session_send(sdi, &packet);
/* Remove fds from polling. */
- usb_source_remove(devc->ctx);
+ usb_source_remove(sdi->session, devc->ctx);
devc->num_transfers = 0;
g_free(devc->transfers);
devc->submitted_transfers--;
if (devc->submitted_transfers == 0)
- finish_acquisition(devc);
+ finish_acquisition(sdi);
}
static void resubmit_transfer(struct libusb_transfer *transfer)
/* Poll every 40ms, or whenever some data comes in. */
serial = sdi->conn;
- serial_source_add(serial, G_IO_IN, 40, gmc_mh_1x_2x_receive_data,
- (void *)sdi);
+ serial_source_add(sdi->session, serial, G_IO_IN, 40,
+ gmc_mh_1x_2x_receive_data, (void *)sdi);
return SR_OK;
}
/* Poll every 40ms, or whenever some data comes in. */
serial = sdi->conn;
- serial_source_add(serial, G_IO_IN, 40, gmc_mh_2x_receive_data,
- (void *)sdi);
+ serial_source_add(sdi->session, serial, G_IO_IN, 40,
+ gmc_mh_2x_receive_data, (void *)sdi);
/* Send start message */
return req_meas14(sdi);
return SR_ERR;
}
- sr_scpi_source_add(scpi, G_IO_IN, 50, hmo_receive_data, (void *)sdi);
+ sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 50,
+ hmo_receive_data, (void *)sdi);
/* Send header packet to the session bus. */
std_session_send_df_header(cb_data, LOG_PREFIX);
g_slist_free(devc->enabled_channels);
devc->enabled_channels = NULL;
scpi = sdi->conn;
- sr_scpi_source_remove(scpi);
+ sr_scpi_source_remove(sdi->session, scpi);
return SR_OK;
}
* TODO: Doesn't really cancel pending transfers so they might
* come in after SR_DF_END is sent.
*/
- usb_source_remove(drvc->sr_ctx);
+ usb_source_remove(sdi->session, drvc->sr_ctx);
packet.type = SR_DF_END;
sr_session_send(sdi, &packet);
return SR_ERR;
devc->dev_state = CAPTURE;
- usb_source_add(drvc->sr_ctx, TICK, handle_event, (void *)sdi);
+ usb_source_add(sdi->session, drvc->sr_ctx, TICK, handle_event, (void *)sdi);
/* Send header packet to the session bus. */
std_session_send_df_header(cb_data, LOG_PREFIX);
return SR_ERR;
}
- usb_source_add(drvc->sr_ctx, 100, ikalogic_scanalogic2_receive_data, (void *)sdi);
+ usb_source_add(sdi->session, drvc->sr_ctx, 100,
+ ikalogic_scanalogic2_receive_data, (void *)sdi);
sr_dbg("Acquisition started successfully.");
devc = sdi->priv;
/* Remove USB file descriptors from polling. */
- usb_source_remove(drvc->sr_ctx);
+ usb_source_remove(sdi->session, drvc->sr_ctx);
packet.type = SR_DF_END;
sr_session_send(devc->cb_data, &packet);
devc = sdi->priv;
/* Remove USB file descriptors from polling. */
- usb_source_remove(drvc->sr_ctx);
+ usb_source_remove(sdi->session, drvc->sr_ctx);
packet.type = SR_DF_END;
sr_session_send(devc->cb_data, &packet);
return ret;
/* Send header packet to the session bus. */
- std_session_send_df_header(cb_data, LOG_PREFIX);
+ std_session_send_df_header(sdi, LOG_PREFIX);
/* Hook up a dummy handler to receive data from the device. */
- sr_source_add(-1, G_IO_IN, 0, scanaplus_receive_data, (void *)sdi);
+ sr_session_source_add(sdi->session, -1, G_IO_IN, 0, scanaplus_receive_data, (void *)sdi);
return SR_OK;
}
{
struct sr_datafeed_packet packet;
- (void)sdi;
+ (void)cb_data;
sr_dbg("Stopping acquisition.");
- sr_source_remove(-1);
+ 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);
+ sr_session_send(sdi, &packet);
return SR_OK;
}
if (!(devc->xfer = libusb_alloc_transfer(0)))
return SR_ERR;
- usb_source_add(drvc->sr_ctx, 10,
+ usb_source_add(sdi->session, drvc->sr_ctx, 10,
kecheng_kc_330b_handle_events, (void *)sdi);
if (devc->data_source == DATA_SOURCE_LIVE) {
if (sdi->status == SR_ST_STOPPING) {
libusb_free_transfer(devc->xfer);
- usb_source_remove(drvc->sr_ctx);
+ usb_source_remove(sdi->session, drvc->sr_ctx);
packet.type = SR_DF_END;
sr_session_send(cb_data, &packet);
sdi->status = SR_ST_ACTIVE;
devc->log_size = xfer_in->buffer[1] + (xfer_in->buffer[2] << 8);
libusb_free_transfer(xfer_out);
- usb_source_add(drvc->sr_ctx, 100, lascar_el_usb_handle_events, (void *)sdi);
+ usb_source_add(sdi->session, drvc->sr_ctx, 100,
+ lascar_el_usb_handle_events, (void *)sdi);
buf = g_try_malloc(4096);
libusb_fill_bulk_transfer(xfer_in, usb->devhdl, LASCAR_EP_IN,
sdi = cb_data;
if (sdi->status == SR_ST_STOPPING) {
- usb_source_remove(drvc->sr_ctx);
+ usb_source_remove(sdi->session, drvc->sr_ctx);
packet.type = SR_DF_END;
sr_session_send(cb_data, &packet);
/* Our first channel is analog, the other 8 are of type 'logic'. */
/* TODO. */
- serial_source_add(devc->serial, G_IO_IN, -1, mso_receive_data, cb_data);
+ serial_source_add(sdi->session, devc->serial, G_IO_IN, -1,
+ mso_receive_data, cb_data);
return SR_OK;
}
struct dev_context *devc;
devc = sdi->priv;
- serial_source_remove(devc->serial);
+ serial_source_remove(sdi->session, devc->serial);
/* Terminate session */
packet.type = SR_DF_END;
/* Poll every 10ms, or whenever some data comes in. */
serial = sdi->conn;
- serial_source_add(serial, G_IO_IN, 10, hcs_receive_data, (void *)sdi);
+ serial_source_add(sdi->session, serial, G_IO_IN, 10,
+ hcs_receive_data, (void *)sdi);
return SR_OK;
}
/* Poll every 100ms, or whenever some data comes in. */
serial = sdi->conn;
- serial_source_add(serial, G_IO_IN, 100,
+ serial_source_add(sdi->session, serial, G_IO_IN, 100,
mic_devs[idx].receive_data, (void *)sdi);
return SR_OK;
devc->acq_running = TRUE;
serial = sdi->conn;
- serial_source_add(serial, G_IO_IN, 50, motech_lps_30x_receive_data, (void *)sdi);
+ serial_source_add(sdi->session, serial, G_IO_IN, 50,
+ motech_lps_30x_receive_data, (void *)sdi);
std_session_send_df_header(cb_data, LOG_PREFIX);
/* Start timer, if required. */
/* Poll every 100ms, or whenever some data comes in. */
serial = sdi->conn;
- serial_source_add(serial, G_IO_IN, 100, norma_dmm_receive_data,
- (void *)sdi);
+ serial_source_add(sdi->session, serial, G_IO_IN, 100,
+ norma_dmm_receive_data, (void *)sdi);
return SR_OK;
}
/* Send header packet to the session bus. */
std_session_send_df_header(cb_data, LOG_PREFIX);
- serial_source_add(serial, G_IO_IN, -1, ols_receive_data, cb_data);
+ serial_source_add(sdi->session, serial, G_IO_IN, -1,
+ ols_receive_data, cb_data);
return SR_OK;
}
struct sr_serial_dev_inst *serial;
serial = sdi->conn;
- serial_source_remove(serial);
+ serial_source_remove(sdi->session, serial);
/* Terminate session */
packet.type = SR_DF_END;
* longer than it takes to send a byte, that means it's
* finished. We'll double that to 30ms to be sure...
*/
- serial_source_remove(serial);
- serial_source_add(serial, G_IO_IN, 30, ols_receive_data, cb_data);
+ serial_source_remove(sdi->session, serial);
+ serial_source_add(sdi->session, serial, G_IO_IN, 30,
+ ols_receive_data, cb_data);
devc->raw_sample_buf = g_try_malloc(devc->limit_samples * 4);
if (!devc->raw_sample_buf) {
sr_err("Sample buffer malloc failed.");
if (rigol_ds_config_set(sdi, ":RUN") != SR_OK)
return SR_ERR;
- sr_scpi_source_add(scpi, G_IO_IN, 50, rigol_ds_receive, (void *)sdi);
+ sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 50,
+ rigol_ds_receive, (void *)sdi);
/* Send header packet to the session bus. */
std_session_send_df_header(cb_data, LOG_PREFIX);
devc->enabled_analog_channels = NULL;
devc->enabled_digital_channels = NULL;
scpi = sdi->conn;
- sr_scpi_source_remove(scpi);
+ sr_scpi_source_remove(sdi->session, scpi);
return SR_OK;
}
transfer = libusb_alloc_transfer(0);
libusb_fill_bulk_transfer(transfer, usb->devhdl,
2 | LIBUSB_ENDPOINT_IN, buf, size,
- logic16_receive_transfer, devc, timeout);
+ logic16_receive_transfer, (void *)sdi, timeout);
if ((ret = libusb_submit_transfer(transfer)) != 0) {
sr_err("Failed to submit transfer: %s.",
libusb_error_name(ret));
devc->ctx = drvc->sr_ctx;
- usb_source_add(devc->ctx, timeout, receive_data, (void *)sdi);
+ usb_source_add(sdi->session, devc->ctx, timeout, receive_data, (void *)sdi);
/* Send header packet to the session bus. */
std_session_send_df_header(cb_data, LOG_PREFIX);
return SR_OK;
}
-static void finish_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(devc->cb_data, &packet);
/* Remove fds from polling. */
- usb_source_remove(devc->ctx);
+ usb_source_remove(sdi->session, devc->ctx);
devc->num_transfers = 0;
g_free(devc->transfers);
static void free_transfer(struct libusb_transfer *transfer)
{
+ struct sr_dev_inst *sdi;
struct dev_context *devc;
unsigned int i;
- devc = transfer->user_data;
+ sdi = transfer->user_data;
+ devc = sdi->priv;
g_free(transfer->buffer);
transfer->buffer = NULL;
devc->submitted_transfers--;
if (devc->submitted_transfers == 0)
- finish_acquisition(devc);
+ finish_acquisition(sdi);
}
static void resubmit_transfer(struct libusb_transfer *transfer)
gboolean packet_has_error = FALSE;
struct sr_datafeed_packet packet;
struct sr_datafeed_logic logic;
+ struct sr_dev_inst *sdi;
struct dev_context *devc;
size_t new_samples, num_samples;
int trigger_offset;
- devc = transfer->user_data;
+ sdi = transfer->user_data;
+ devc = sdi->priv;
/*
* If acquisition has already ended, just free any queued up
/* Poll every 50ms, or whenever some data comes in. */
serial = sdi->conn;
- serial_source_add(serial, G_IO_IN, 50,
+ serial_source_add(sdi->session, serial, G_IO_IN, 50,
dmms[dmm].receive_data, (void *)sdi);
return SR_OK;
lwla_free_acquisition_state(acq);
return ret;
}
- usb_source_add(drvc->sr_ctx, 100, &lwla_receive_data,
+ usb_source_add(sdi->session, drvc->sr_ctx, 100, &lwla_receive_data,
(struct sr_dev_inst *)sdi);
sr_info("Waiting for data.");
devc->state = STATE_IDLE;
/* Remove USB file descriptors from polling. */
- usb_source_remove(drvc->sr_ctx);
+ usb_source_remove(sdi->session, drvc->sr_ctx);
packet.type = SR_DF_END;
sr_session_send(sdi, &packet);
std_session_send_df_header(cb_data, LOG_PREFIX);
/* Poll every 50ms, or whenever some data comes in. */
- serial_source_add(serial, G_IO_IN, 50, teleinfo_receive_data, (void *)sdi);
+ serial_source_add(sdi->session, serial, G_IO_IN, 50,
+ teleinfo_receive_data, (void *)sdi);
return SR_OK;
}
}
if (sdi->status == SR_ST_STOPPING) {
- usb_source_remove(drvc->sr_ctx);
+ usb_source_remove(sdi->session, drvc->sr_ctx);
dev_close(sdi);
/* Send header packet to the session bus. */
std_session_send_df_header(cb_data, LOG_PREFIX);
- usb_source_add(drvc->sr_ctx, 100, handle_events, (void *)sdi);
+ usb_source_add(sdi->session, drvc->sr_ctx, 100,
+ handle_events, (void *)sdi);
if (testo_set_serial_params(usb) != SR_OK)
return SR_ERR;
/* Poll every 500ms, or whenever some data comes in. */
serial = sdi->conn;
- serial_source_add(serial, G_IO_IN, 500,
+ serial_source_add(sdi->session, serial, G_IO_IN, 500,
tondaj_sl_814_receive_data, (void *)sdi);
return SR_OK;
devc->starttime = g_get_monotonic_time();
/* Send header packet to the session bus. */
- std_session_send_df_header(cb_data, LOG_PREFIX);
+ std_session_send_df_header(sdi, LOG_PREFIX);
- sr_source_add(0, 0, 10 /* poll_timeout */,
+ sr_session_source_add(sdi->session, 0, 0, 10 /* poll_timeout */,
udmms[dmm].receive_data, (void *)sdi);
return SR_OK;
{
struct sr_datafeed_packet packet;
- (void)sdi;
+ (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(cb_data, &packet);
+ sr_session_send(sdi, &packet);
- /* TODO? */
- sr_source_remove(0);
+ sr_session_source_remove(sdi->session, 0);
return SR_OK;
}
return SR_ERR;
}
- usb_source_add(drvc->sr_ctx, 10, uni_t_ut32x_handle_events, (void *)sdi);
+ usb_source_add(sdi->session, drvc->sr_ctx, 10,
+ uni_t_ut32x_handle_events, (void *)sdi);
return SR_OK;
}
NULL);
if (sdi->status == SR_ST_STOPPING) {
- usb_source_remove(drvc->sr_ctx);
+ usb_source_remove(sdi->session, drvc->sr_ctx);
packet.type = SR_DF_END;
sr_session_send(cb_data, &packet);
}
if (sdi->status == SR_ST_STOPPING) {
- usb_source_remove(drvc->sr_ctx);
+ usb_source_remove(sdi->session, drvc->sr_ctx);
dev_close(sdi);
/* Send header packet to the session bus. */
std_session_send_df_header(cb_data, LOG_PREFIX);
- usb_source_add(drvc->sr_ctx, 100, handle_events, (void *)sdi);
+ usb_source_add(sdi->session, drvc->sr_ctx, 100,
+ handle_events, (void *)sdi);
buf = g_try_malloc(DMM_DATA_SIZE);
transfer = libusb_alloc_transfer(0);
uint64_t timeout_ms, int baudrate);
SR_PRIV int sr_serial_extract_options(GSList *options, const char **serial_device,
const char **serial_options);
-SR_PRIV int serial_source_add(struct sr_serial_dev_inst *serial, int events,
- int timeout, sr_receive_data_callback cb, void *cb_data);
-SR_PRIV int serial_source_remove(struct sr_serial_dev_inst *serial);
+SR_PRIV int serial_source_add(struct sr_session *session,
+ struct sr_serial_dev_inst *serial, int events, int timeout,
+ sr_receive_data_callback cb, void *cb_data);
+SR_PRIV int serial_source_remove(struct sr_session *session,
+ struct sr_serial_dev_inst *serial);
SR_PRIV GSList *sr_serial_find_usb(uint16_t vendor_id, uint16_t product_id);
#endif
#ifdef HAVE_LIBUSB_1_0
SR_PRIV GSList *sr_usb_find(libusb_context *usb_ctx, const char *conn);
SR_PRIV int sr_usb_open(libusb_context *usb_ctx, struct sr_usb_dev_inst *usb);
-SR_PRIV int usb_source_add(struct sr_context *ctx, int timeout,
- sr_receive_data_callback cb, void *cb_data);
-SR_PRIV int usb_source_remove(struct sr_context *ctx);
+SR_PRIV int usb_source_add(struct sr_session *session, struct sr_context *ctx,
+ int timeout, sr_receive_data_callback cb, void *cb_data);
+SR_PRIV int usb_source_remove(struct sr_session *session, struct sr_context *ctx);
#endif
/*--- hardware/common/scpi.c ------------------------------------------------*/
int (*dev_inst_new)(void *priv, struct drv_context *drvc,
const char *resource, char **params, const char *serialcomm);
int (*open)(void *priv);
- int (*source_add)(void *priv, int events,
+ int (*source_add)(struct sr_session *session, void *priv, int events,
int timeout, sr_receive_data_callback cb, void *cb_data);
- int (*source_remove)(void *priv);
+ int (*source_remove)(struct sr_session *session, void *priv);
int (*send)(void *priv, const char *command);
int (*read_begin)(void *priv);
int (*read_data)(void *priv, char *buf, int maxlen);
SR_PRIV struct sr_scpi_dev_inst *scpi_dev_inst_new(struct drv_context *drvc,
const char *resource, const char *serialcomm);
SR_PRIV int sr_scpi_open(struct sr_scpi_dev_inst *scpi);
-SR_PRIV int sr_scpi_source_add(struct sr_scpi_dev_inst *scpi, int events,
- int timeout, sr_receive_data_callback cb, void *cb_data);
-SR_PRIV int sr_scpi_source_remove(struct sr_scpi_dev_inst *scpi);
+SR_PRIV int sr_scpi_source_add(struct sr_session *session,
+ struct sr_scpi_dev_inst *scpi, int events, int timeout,
+ sr_receive_data_callback cb, void *cb_data);
+SR_PRIV int sr_scpi_source_remove(struct sr_session *session,
+ struct sr_scpi_dev_inst *scpi);
SR_PRIV int sr_scpi_send(struct sr_scpi_dev_inst *scpi,
const char *format, ...);
SR_PRIV int sr_scpi_send_variadic(struct sr_scpi_dev_inst *scpi,
* @retval SR_ERR_ARG Invalid argument.
* @retval SR_ERR_MALLOC Memory allocation error.
*/
-static int _sr_session_source_add(GPollFD *pollfd, int timeout,
- sr_receive_data_callback cb, void *cb_data, gintptr poll_object)
+static int _sr_session_source_add(struct sr_session *session, GPollFD *pollfd,
+ int timeout, sr_receive_data_callback cb, void *cb_data, gintptr poll_object)
{
- struct sr_session *session = sr_current_session;
struct source *new_sources, *s;
GPollFD *new_pollfds;
p.fd = fd;
p.events = events;
- return _sr_session_source_add(&p, timeout, cb, cb_data, (gintptr)fd);
+ return _sr_session_source_add(session, &p, timeout, cb, cb_data, (gintptr)fd);
}
/**
{
(void) session;
- return _sr_session_source_add(pollfd, timeout, cb,
+ return _sr_session_source_add(session, pollfd, timeout, cb,
cb_data, (gintptr)pollfd);
}
p.events = events;
#endif
- return _sr_session_source_add(&p, timeout, cb, cb_data, (gintptr)channel);
+ return _sr_session_source_add(session, &p, timeout, cb, cb_data, (gintptr)channel);
}
/**
* @retval SR_ERR_MALLOC Memory allocation error
* @retval SR_ERR_BUG Internal error
*/
-static int _sr_session_source_remove(gintptr poll_object)
+static int _sr_session_source_remove(struct sr_session *session, gintptr poll_object)
{
- struct sr_session *session = sr_current_session;
struct source *new_sources;
GPollFD *new_pollfds;
unsigned int old;
{
(void) session;
- return _sr_session_source_remove((gintptr)fd);
+ return _sr_session_source_remove(session, (gintptr)fd);
}
/**
{
(void) session;
- return _sr_session_source_remove((gintptr)pollfd);
+ return _sr_session_source_remove(session, (gintptr)pollfd);
}
/**
{
(void) session;
- return _sr_session_source_remove((gintptr)channel);
+ return _sr_session_source_remove(session, (gintptr)channel);
}
/** @} */
#define CHUNKSIZE (512 * 1024)
/** @endcond */
+SR_PRIV struct sr_dev_driver session_driver_info;
+static struct sr_dev_driver *di = &session_driver_info;
+
struct session_vdev {
char *sessionfile;
char *capturefile;
gboolean finished;
};
-static GSList *dev_insts = NULL;
static const int hwcaps[] = {
SR_CONF_CAPTUREFILE,
SR_CONF_CAPTURE_UNITSIZE,
SR_CONF_SAMPLERATE,
};
-extern struct sr_session *sr_current_session;
-
static int receive_data(int fd, int revents, void *cb_data)
{
struct sr_dev_inst *sdi;
struct sr_datafeed_packet packet;
struct sr_datafeed_logic logic;
struct zip_stat zs;
- GSList *l;
int ret, got_data;
char capturefile[16];
void *buf;
(void)fd;
(void)revents;
+ sdi = cb_data;
got_data = FALSE;
- for (l = dev_insts; l; l = l->next) {
- sdi = l->data;
- vdev = sdi->priv;
- if (vdev->finished)
- /* Already done with this instance. */
- continue;
-
+ vdev = sdi->priv;
+ if (!vdev->finished) {
if (!vdev->capfile) {
/* No capture file opened yet, or finished with the last
* chunked one. */
} else {
/* We got all the chunks, finish up. */
vdev->finished = TRUE;
- continue;
+ return TRUE;
}
}
}
logic.unitsize = vdev->unitsize;
logic.data = buf;
vdev->bytes_read += ret;
- sr_session_send(cb_data, &packet);
+ sr_session_send(sdi, &packet);
} else {
/* done with this capture file */
zip_fclose(vdev->capfile);
if (!got_data) {
packet.type = SR_DF_END;
- sr_session_send(cb_data, &packet);
- sr_session_source_remove(sr_current_session, -1);
+ sr_session_send(sdi, &packet);
+ sr_session_source_remove(sdi->session, -1);
}
return TRUE;
static int init(struct sr_context *sr_ctx)
{
- (void)sr_ctx;
-
- return SR_OK;
+ return std_init(sr_ctx, di, LOG_PREFIX);
}
static int dev_clear(void)
{
+ struct drv_context *drvc;
GSList *l;
- for (l = dev_insts; l; l = l->next)
+ drvc = di->priv;
+ for (l = drvc->instances; l; l = l->next)
sr_dev_inst_free(l->data);
- g_slist_free(dev_insts);
- dev_insts = NULL;
+ g_slist_free(drvc->instances);
+ drvc->instances = NULL;
return SR_OK;
}
static int dev_open(struct sr_dev_inst *sdi)
{
+ struct drv_context *drvc;
struct session_vdev *vdev;
- vdev = g_try_malloc0(sizeof(struct session_vdev));
+ drvc = di->priv;
+ vdev = g_malloc0(sizeof(struct session_vdev));
sdi->priv = vdev;
- dev_insts = g_slist_append(dev_insts, sdi);
+ drvc->instances = g_slist_append(drvc->instances, sdi);
return SR_OK;
}
struct session_vdev *vdev;
int ret;
- vdev = sdi->priv;
+ (void)cb_data;
+ vdev = sdi->priv;
vdev->bytes_read = 0;
vdev->cur_chunk = 0;
vdev->finished = FALSE;
}
/* Send header packet to the session bus. */
- std_session_send_df_header(cb_data, LOG_PREFIX);
+ std_session_send_df_header(sdi, LOG_PREFIX);
/* freewheeling source */
- sr_session_source_add(sr_current_session, -1, 0, 0, receive_data, cb_data);
+ sr_session_source_add(sdi->session, -1, 0, 0, receive_data, (void *)sdi);
return SR_OK;
}
sr_dbg("%s: Stopping acquisition.", prefix);
- if ((ret = serial_source_remove(serial)) < 0) {
+ if ((ret = serial_source_remove(sdi->session, serial)) < 0) {
sr_err("%s: Failed to remove source: %d.", prefix, ret);
return ret;
}