Add struct sr_session parameter to all session source backends.

This commit is contained in:
Bert Vermeulen 2014-07-21 14:35:27 +02:00
parent 85b69c2b64
commit 102f123966
60 changed files with 230 additions and 191 deletions

View File

@ -249,7 +249,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
/* 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;
}

View File

@ -259,7 +259,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
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;
}

View File

@ -1005,7 +1005,7 @@ static void sigma_decode_dram_cluster(struct sigma_dram_cluster *dram_cluster,
*/
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);
}
}
@ -1033,14 +1033,14 @@ static void sigma_decode_dram_cluster(struct sigma_dram_cluster *dram_cluster,
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);
}
}
@ -1048,7 +1048,7 @@ static void sigma_decode_dram_cluster(struct sigma_dram_cluster *dram_cluster,
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 =
@ -1069,10 +1069,9 @@ static void sigma_decode_dram_cluster(struct sigma_dram_cluster *dram_cluster,
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;
@ -1510,10 +1509,10 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
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;
@ -1529,7 +1528,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
devc = sdi->priv;
devc->state.state = SIGMA_IDLE;
sr_source_remove(0);
sr_session_source_remove(sdi->session, 0);
return SR_OK;
}

View File

@ -470,7 +470,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
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. */

View File

@ -153,7 +153,7 @@ SR_PRIV int atten_pps3xxx_receive_data(int fd, int revents, void *cb_data)
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);
}

View File

@ -261,17 +261,19 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
{
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;
}
@ -280,14 +282,16 @@ 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(cb_data, &packet);
sr_session_send(sdi, &packet);
sr_source_remove(0);
sr_session_source_remove(sdi->session, 0);
return SR_OK;
}

View File

@ -211,7 +211,7 @@ static void brymen_bm86x_handle_packet(const struct sr_dev_inst *sdi,
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);
}
@ -222,7 +222,7 @@ static void brymen_bm86x_handle_packet(const struct sr_dev_inst *sdi,
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);
}

View File

@ -32,7 +32,6 @@ struct dev_context {
/* 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 */

View File

@ -230,8 +230,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
/* 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;
}

View File

@ -397,8 +397,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
/* 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;
}

View File

@ -231,7 +231,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
/* 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;

View File

@ -507,7 +507,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
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 +
@ -516,7 +516,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
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;
}
@ -525,15 +525,15 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
{
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;
}

View File

@ -209,8 +209,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
/* 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;
}

View File

@ -216,10 +216,11 @@ SR_PRIV int sr_scpi_open(struct sr_scpi_dev_inst *scpi)
* @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);
}
/**
@ -231,9 +232,10 @@ SR_PRIV int sr_scpi_source_add(struct sr_scpi_dev_inst *scpi, int events,
* 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);
}
/**

View File

@ -102,21 +102,21 @@ static int scpi_serial_open(void *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)

View File

@ -115,19 +115,20 @@ static int scpi_tcp_open(void *priv)
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)

View File

@ -316,18 +316,20 @@ static int scpi_usbtmc_libusb_open(void *priv)
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,

View File

@ -67,20 +67,20 @@ static int scpi_visa_open(void *priv)
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)

View File

@ -91,20 +91,20 @@ static int scpi_vxi_open(void *priv)
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 */

View File

@ -708,8 +708,9 @@ typedef HANDLE event_handle;
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;
@ -744,20 +745,21 @@ SR_PRIV int serial_source_add(struct sr_serial_dev_inst *serial, int events,
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);

View File

@ -209,8 +209,8 @@ static int usb_callback(int fd, int revents, void *cb_data)
}
#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.");
@ -226,14 +226,16 @@ SR_PRIV int usb_source_add(struct sr_context *ctx, int timeout,
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;
@ -241,7 +243,7 @@ SR_PRIV int usb_source_add(struct sr_context *ctx, int timeout,
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;
@ -252,7 +254,7 @@ SR_PRIV int usb_source_remove(struct sr_context *ctx)
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;
@ -260,7 +262,7 @@ SR_PRIV int usb_source_remove(struct sr_context *ctx)
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;

View File

@ -692,6 +692,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
GSList *l;
struct dev_context *devc;
(void)cb_data;
if (sdi->status != SR_ST_ACTIVE)
return SR_ERR_DEV_CLOSED;
@ -726,11 +728,11 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
/* 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();
@ -748,7 +750,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
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;

View File

@ -283,7 +283,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
/* 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));

View File

@ -576,7 +576,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
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);

View File

@ -328,16 +328,19 @@ SR_PRIV void fx2lafw_abort_acquisition(struct dev_context *devc)
}
}
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);
@ -370,7 +373,7 @@ static void free_transfer(struct libusb_transfer *transfer)
devc->submitted_transfers--;
if (devc->submitted_transfers == 0)
finish_acquisition(devc);
finish_acquisition(sdi);
}
static void resubmit_transfer(struct libusb_transfer *transfer)

View File

@ -529,8 +529,8 @@ static int dev_acquisition_start_1x_2x_rs232(const struct sr_dev_inst *sdi,
/* 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;
}
@ -560,8 +560,8 @@ static int dev_acquisition_start_2x_bd232(const struct sr_dev_inst *sdi,
/* 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);

View File

@ -749,7 +749,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
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);
@ -780,7 +781,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
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;
}

View File

@ -822,7 +822,7 @@ static int handle_event(int fd, int revents, void *cb_data)
* 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);
@ -933,7 +933,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
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);

View File

@ -490,7 +490,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
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.");

View File

@ -33,7 +33,7 @@ static void stop_acquisition(struct sr_dev_inst *sdi)
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);
@ -50,7 +50,7 @@ static void abort_acquisition(struct sr_dev_inst *sdi)
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);

View File

@ -393,10 +393,10 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
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;
}
@ -405,15 +405,15 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
{
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;
}

View File

@ -489,7 +489,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
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) {

View File

@ -51,7 +51,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(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;

View File

@ -434,7 +434,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
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,

View File

@ -499,7 +499,7 @@ SR_PRIV int lascar_el_usb_handle_events(int fd, int revents, void *cb_data)
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);

View File

@ -461,7 +461,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
/* 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;
}

View File

@ -294,7 +294,7 @@ SR_PRIV void stop_acquisition(const struct sr_dev_inst *sdi)
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;

View File

@ -398,7 +398,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
/* 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;
}

View File

@ -233,7 +233,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
/* 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;

View File

@ -814,7 +814,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
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. */

View File

@ -317,8 +317,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
/* 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;
}

View File

@ -565,7 +565,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
/* 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;
}

View File

@ -318,7 +318,7 @@ SR_PRIV void abort_acquisition(const struct sr_dev_inst *sdi)
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;
@ -350,8 +350,9 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
* 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.");

View File

@ -970,7 +970,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
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);
@ -1014,7 +1015,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
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;
}

View File

@ -773,7 +773,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
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));
@ -788,7 +788,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
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);

View File

@ -576,16 +576,19 @@ SR_PRIV int logic16_init_device(const struct sr_dev_inst *sdi)
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);
@ -598,10 +601,12 @@ static void finish_acquisition(struct dev_context *devc)
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;
@ -616,7 +621,7 @@ static void free_transfer(struct libusb_transfer *transfer)
devc->submitted_transfers--;
if (devc->submitted_transfers == 0)
finish_acquisition(devc);
finish_acquisition(sdi);
}
static void resubmit_transfer(struct libusb_transfer *transfer)
@ -679,11 +684,13 @@ SR_PRIV void logic16_receive_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

View File

@ -543,7 +543,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
/* 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;

View File

@ -537,7 +537,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
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.");

View File

@ -587,7 +587,7 @@ static void end_acquisition(struct sr_dev_inst *sdi)
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);

View File

@ -257,7 +257,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
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;
}

View File

@ -430,7 +430,7 @@ static int handle_events(int fd, int revents, void *cb_data)
}
if (sdi->status == SR_ST_STOPPING) {
usb_source_remove(drvc->sr_ctx);
usb_source_remove(sdi->session, drvc->sr_ctx);
dev_close(sdi);
@ -473,7 +473,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
/* 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;

View File

@ -192,7 +192,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
/* 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;

View File

@ -338,9 +338,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
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;
@ -350,17 +350,16 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
{
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;
}

View File

@ -345,7 +345,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
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;
}

View File

@ -217,7 +217,7 @@ SR_PRIV int uni_t_ut32x_handle_events(int fd, int revents, void *cb_data)
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);

View File

@ -348,7 +348,7 @@ static int handle_events(int fd, int revents, void *cb_data)
}
if (sdi->status == SR_ST_STOPPING) {
usb_source_remove(drvc->sr_ctx);
usb_source_remove(sdi->session, drvc->sr_ctx);
dev_close(sdi);
@ -387,7 +387,8 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
/* 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);

View File

@ -393,9 +393,11 @@ SR_PRIV int serial_stream_detect(struct sr_serial_dev_inst *serial,
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
@ -414,9 +416,9 @@ SR_PRIV int ezusb_upload_firmware(libusb_device *dev, int configuration,
#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 ------------------------------------------------*/
@ -465,9 +467,9 @@ struct sr_scpi_dev_inst {
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);
@ -482,9 +484,11 @@ SR_PRIV GSList *sr_scpi_scan(struct drv_context *drvc, GSList *options,
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,

View File

@ -673,10 +673,9 @@ SR_PRIV int sr_session_send(const struct sr_dev_inst *sdi,
* @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;
@ -742,7 +741,7 @@ SR_API int sr_session_source_add(struct sr_session *session, int fd,
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);
}
/**
@ -765,7 +764,7 @@ SR_API int sr_session_source_add_pollfd(struct sr_session *session,
{
(void) session;
return _sr_session_source_add(pollfd, timeout, cb,
return _sr_session_source_add(session, pollfd, timeout, cb,
cb_data, (gintptr)pollfd);
}
@ -799,7 +798,7 @@ SR_API int sr_session_source_add_channel(struct sr_session *session,
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);
}
/**
@ -814,9 +813,8 @@ SR_API int sr_session_source_add_channel(struct sr_session *session,
* @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;
@ -878,7 +876,7 @@ SR_API int sr_session_source_remove(struct sr_session *session, int fd)
{
(void) session;
return _sr_session_source_remove((gintptr)fd);
return _sr_session_source_remove(session, (gintptr)fd);
}
/**
@ -897,7 +895,7 @@ SR_API int sr_session_source_remove_pollfd(struct sr_session *session,
{
(void) session;
return _sr_session_source_remove((gintptr)pollfd);
return _sr_session_source_remove(session, (gintptr)pollfd);
}
/**
@ -917,7 +915,7 @@ SR_API int sr_session_source_remove_channel(struct sr_session *session,
{
(void) session;
return _sr_session_source_remove((gintptr)channel);
return _sr_session_source_remove(session, (gintptr)channel);
}
/** @} */

View File

@ -33,6 +33,9 @@
#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;
@ -46,15 +49,12 @@ struct session_vdev {
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;
@ -62,7 +62,6 @@ static int receive_data(int fd, int revents, void *cb_data)
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;
@ -70,14 +69,10 @@ static int receive_data(int fd, int revents, void *cb_data)
(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. */
@ -118,7 +113,7 @@ static int receive_data(int fd, int revents, void *cb_data)
} else {
/* We got all the chunks, finish up. */
vdev->finished = TRUE;
continue;
return TRUE;
}
}
}
@ -141,7 +136,7 @@ static int receive_data(int fd, int revents, void *cb_data)
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);
@ -161,8 +156,8 @@ static int receive_data(int fd, int revents, void *cb_data)
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;
@ -172,30 +167,32 @@ static int receive_data(int fd, int revents, void *cb_data)
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;
}
@ -294,8 +291,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data)
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;
@ -310,10 +308,10 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *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);
/* 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;
}

2
std.c
View File

@ -200,7 +200,7 @@ SR_PRIV int std_serial_dev_acquisition_stop(struct sr_dev_inst *sdi,
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;
}