{
GHashTable *fmtargs = NULL;
struct stat st;
+ struct sr_session *session;
struct sr_input *in;
struct sr_input_format *input_format;
char *fmtspec = NULL;
if (select_channels(in->sdi) != SR_OK)
return;
- sr_session_new();
- sr_session_datafeed_callback_add(datafeed_in, NULL);
- if (sr_session_dev_add(in->sdi) != SR_OK) {
+ sr_session_new(&session);
+ sr_session_datafeed_callback_add(session, &datafeed_in, NULL);
+ if (sr_session_dev_add(session, in->sdi) != SR_OK) {
g_critical("Failed to use device.");
- sr_session_destroy();
+ sr_session_destroy(session);
return;
}
input_format->loadfile(in, opt_input_file);
- sr_session_destroy();
+ sr_session_destroy(session);
if (fmtargs)
g_hash_table_destroy(fmtargs);
void load_input_file(void)
{
- GSList *sessions;
+ GSList *devices;
+ struct sr_session *session;
struct sr_dev_inst *sdi;
int ret;
- if (sr_session_load(opt_input_file) == SR_OK) {
+ if (sr_session_load(opt_input_file, &session) == SR_OK) {
/* sigrok session file */
- ret = sr_session_dev_list(&sessions);
- if (ret != SR_OK || !sessions->data) {
+ ret = sr_session_dev_list(session, &devices);
+ if (ret != SR_OK || !devices->data) {
g_critical("Failed to access session device.");
- sr_session_destroy();
+ sr_session_destroy(session);
return;
}
- sdi = sessions->data;
+ sdi = devices->data;
if (select_channels(sdi) != SR_OK) {
- sr_session_destroy();
+ sr_session_destroy(session);
return;
}
- sr_session_datafeed_callback_add(datafeed_in, NULL);
- sr_session_start();
- sr_session_run();
- sr_session_stop();
+ sr_session_datafeed_callback_add(session, datafeed_in, NULL);
+ sr_session_start(session);
+ sr_session_run(session);
+ sr_session_stop(session);
}
else {
/* fall back on input modules */
return match;
}
-int parse_triggerstring(const struct sr_dev_inst *sdi, const char *s)
+int parse_triggerstring(const struct sr_dev_inst *sdi, const char *s,
+ struct sr_trigger **trigger)
{
struct sr_channel *ch;
- struct sr_trigger *trigger;
struct sr_trigger_stage *stage;
GVariant *gvar;
GSList *l;
}
matches = g_variant_get_fixed_array(gvar, &num_matches, sizeof(int32_t));
- trigger = sr_trigger_new(NULL);
+ *trigger = sr_trigger_new(NULL);
error = FALSE;
tokens = g_strsplit(s, ",", -1);
for (i = 0; tokens[i]; i++) {
}
/* Make sure this ends up in the right stage, creating
* them as needed. */
- while (!(stage = g_slist_nth_data(trigger->stages, t)))
- sr_trigger_stage_add(trigger);
+ while (!(stage = g_slist_nth_data((*trigger)->stages, t)))
+ sr_trigger_stage_add(*trigger);
if (sr_trigger_match_add(stage, ch, match, 0) != SR_OK) {
error = TRUE;
break;
g_variant_unref(gvar);
if (error)
- sr_trigger_free(trigger);
- else
- error = sr_session_trigger_set(trigger) != SR_OK;
+ sr_trigger_free(*trigger);
return !error;
}
const struct sr_datafeed_meta *meta;
const struct sr_datafeed_logic *logic;
const struct sr_datafeed_analog *analog;
+ struct sr_session *session;
struct sr_config *src;
struct sr_channel *ch;
static struct sr_output *o = NULL;
int i;
char **channels;
- (void) cb_data;
-
/* If the first packet to come in isn't a header, don't even try. */
if (packet->type != SR_DF_HEADER && o == NULL)
return;
+ session = cb_data;
switch (packet->type) {
case SR_DF_HEADER:
g_debug("cli: Received SR_DF_HEADER.");
channels[i++] = ch->name;
}
channels[i] = NULL;
- sr_session_save_init(opt_output_file, samplerate,
- channels);
+ sr_session_save_init(session, opt_output_file,
+ samplerate, channels);
g_free(channels);
}
- save_chunk_logic(logic->data, input_len, logic->unitsize);
+ save_chunk_logic(session, logic->data, input_len, logic->unitsize);
} else {
if (opt_pds) {
#ifdef HAVE_SRD
if (srd_session_send(srd_sess, rcvd_samples_logic, end_sample,
logic->data, input_len) != SRD_OK)
- sr_session_stop();
+ sr_session_stop(session);
#endif
}
}
if (opt_output_file && default_output_format)
/* Flush whatever is left out to the session file. */
- save_chunk_logic(NULL, 0, 0);
+ save_chunk_logic(session, NULL, 0, 0);
if (limit_samples) {
if (rcvd_samples_logic > 0 && rcvd_samples_logic < limit_samples)
GSList *devices;
GHashTable *devargs;
GVariant *gvar;
+ struct sr_session *session;
+ struct sr_trigger *trigger;
struct sr_dev_inst *sdi;
uint64_t min_samples, max_samples;
}
sdi = devices->data;
- sr_session_new();
- sr_session_datafeed_callback_add(datafeed_in, NULL);
+ sr_session_new(&session);
+ sr_session_datafeed_callback_add(session, datafeed_in, NULL);
if (sr_dev_open(sdi) != SR_OK) {
g_critical("Failed to open device.");
return;
}
- if (sr_session_dev_add(sdi) != SR_OK) {
+ if (sr_session_dev_add(session, sdi) != SR_OK) {
g_critical("Failed to add device to session.");
- sr_session_destroy();
+ sr_session_destroy(session);
return;
}
if (select_channels(sdi) != SR_OK) {
g_critical("Failed to set channels.");
- sr_session_destroy();
+ sr_session_destroy(session);
return;
}
if (opt_triggers) {
- if (!parse_triggerstring(sdi, opt_triggers)) {
- sr_session_destroy();
+ if (!parse_triggerstring(sdi, opt_triggers, &trigger)) {
+ sr_session_destroy(session);
+ return;
+ }
+ if (sr_session_trigger_set(session, trigger) != SR_OK) {
+ sr_session_destroy(session);
return;
}
}
if (opt_continuous) {
if (!sr_dev_has_option(sdi, SR_CONF_CONTINUOUS)) {
g_critical("This device does not support continuous sampling.");
- sr_session_destroy();
+ sr_session_destroy(session);
return;
}
}
if (opt_time) {
if (set_limit_time(sdi) != SR_OK) {
- sr_session_destroy();
+ sr_session_destroy(session);
return;
}
}
if (opt_samples) {
if ((sr_parse_sizestring(opt_samples, &limit_samples) != SR_OK)) {
g_critical("Invalid sample limit '%s'.", opt_samples);
- sr_session_destroy();
+ sr_session_destroy(session);
return;
}
if (sr_config_list(sdi->driver, sdi, NULL,
gvar = g_variant_new_uint64(limit_samples);
if (sr_config_set(sdi, NULL, SR_CONF_LIMIT_SAMPLES, gvar) != SR_OK) {
g_critical("Failed to configure sample limit.");
- sr_session_destroy();
+ sr_session_destroy(session);
return;
}
}
if (opt_frames) {
if ((sr_parse_sizestring(opt_frames, &limit_frames) != SR_OK)) {
g_critical("Invalid sample limit '%s'.", opt_samples);
- sr_session_destroy();
+ sr_session_destroy(session);
return;
}
gvar = g_variant_new_uint64(limit_frames);
if (sr_config_set(sdi, NULL, SR_CONF_LIMIT_FRAMES, gvar) != SR_OK) {
g_critical("Failed to configure frame limit.");
- sr_session_destroy();
+ sr_session_destroy(session);
return;
}
}
- if (sr_session_start() != SR_OK) {
+ if (sr_session_start(session) != SR_OK) {
g_critical("Failed to start session.");
- sr_session_destroy();
+ sr_session_destroy(session);
return;
}
if (opt_continuous)
- add_anykey();
+ add_anykey(session);
- sr_session_run();
+ sr_session_run(session);
if (opt_continuous)
clear_anykey();
- sr_session_datafeed_callback_remove_all();
- sr_session_destroy();
+ sr_session_datafeed_callback_remove_all(session);
+ sr_session_destroy(session);
g_slist_free(devices);
}
-void save_chunk_logic(uint8_t *data, uint64_t data_len, int unitsize)
+void save_chunk_logic(struct sr_session *session, uint8_t *data,
+ uint64_t data_len, int unitsize)
{
static uint8_t *buf = NULL;
static int buf_len = 0;
if (buf_len + data_len > SAVE_CHUNK_SIZE) {
max = (SAVE_CHUNK_SIZE - buf_len) / unitsize * unitsize;
memcpy(buf + buf_len, data, max);
- sr_session_append(opt_output_file, buf, unitsize,
+ sr_session_append(session, opt_output_file, buf, unitsize,
(buf_len + max) / unitsize);
memcpy(buf, data + max, data_len - max);
buf_len = data_len - max;
} else if (data_len == 0 && last_unitsize != 0) {
/* End of data, flush the buffer out. */
- sr_session_append(opt_output_file, buf, last_unitsize,
+ sr_session_append(session, opt_output_file, buf, last_unitsize,
buf_len / last_unitsize);
} else {
/* Buffer chunk. */