Skip to content

Commit

Permalink
Use getters now that 'struct sr_dev_inst' is opaque.
Browse files Browse the repository at this point in the history
  • Loading branch information
uwehermann committed Nov 11, 2014
1 parent d75c852 commit c6fa2b2
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 57 deletions.
6 changes: 5 additions & 1 deletion decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,13 @@ static void map_pd_inst_channels(void *key, void *value, void *user_data)

void map_pd_channels(struct sr_dev_inst *sdi)
{
GSList *channels;

channels = sr_dev_inst_channels_get(sdi);

if (pd_channel_maps) {
g_hash_table_foreach(pd_channel_maps, &map_pd_inst_channels,
sdi->channels);
channels);
g_hash_table_destroy(pd_channel_maps);
pd_channel_maps = NULL;
}
Expand Down
8 changes: 5 additions & 3 deletions device.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,19 @@ GSList *device_scan(void)
struct sr_channel_group *select_channel_group(struct sr_dev_inst *sdi)
{
struct sr_channel_group *cg;
GSList *l;
GSList *l, *channel_groups;

if (!opt_channel_group)
return NULL;

if (!sdi->channel_groups) {
channel_groups = sr_dev_inst_channel_groups_get(sdi);

if (!channel_groups) {
g_critical("This device does not have any channel groups.");
return NULL;
}

for (l = sdi->channel_groups; l; l = l->next) {
for (l = channel_groups; l; l = l->next) {
cg = l->data;
if (!strcasecmp(opt_channel_group, cg->name)) {
return cg;
Expand Down
11 changes: 8 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ static void logger(const gchar *log_domain, GLogLevelFlags log_level,
int select_channels(struct sr_dev_inst *sdi)
{
struct sr_channel *ch;
GSList *selected_channels, *l;
GSList *selected_channels, *l, *channels;

channels = sr_dev_inst_channels_get(sdi);

if (opt_channels) {
if (!(selected_channels = parse_channelstring(sdi, opt_channels)))
return SR_ERR;

for (l = sdi->channels; l; l = l->next) {
for (l = channels; l; l = l->next) {
ch = l->data;
if (g_slist_find(selected_channels, ch))
ch->enabled = TRUE;
Expand All @@ -81,6 +83,7 @@ static void get_option(void)
GHashTable *devargs;
int ret;
char *s;
struct sr_dev_driver *driver;

if (!(devices = device_scan())) {
g_critical("No devices found.");
Expand All @@ -89,6 +92,8 @@ static void get_option(void)
sdi = devices->data;
g_slist_free(devices);

driver = sr_dev_inst_driver_get(sdi);

if (sr_dev_open(sdi) != SR_OK) {
g_critical("Failed to open device.");
return;
Expand All @@ -102,7 +107,7 @@ static void get_option(void)
set_dev_options(sdi, devargs);
else devargs = NULL;

if ((ret = sr_config_get(sdi->driver, sdi, cg, ci->key, &gvar)) != SR_OK)
if ((ret = sr_config_get(driver, sdi, cg, ci->key, &gvar)) != SR_OK)
g_critical("Failed to get '%s': %s", opt_get, sr_strerror(ret));
s = g_variant_print(gvar, FALSE);
printf("%s\n", s);
Expand Down
20 changes: 13 additions & 7 deletions parsers.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ struct sr_channel *find_channel(GSList *channellist, const char *channelname)
GSList *parse_channelstring(struct sr_dev_inst *sdi, const char *channelstring)
{
struct sr_channel *ch;
GSList *channellist;
GSList *channellist, *channels;
int ret, n, b, e, i;
char **tokens, **range, **names, *eptr, str[8];

channels = sr_dev_inst_channels_get(sdi);

if (!channelstring || !channelstring[0])
/* Use all channels by default. */
return g_slist_copy(sdi->channels);
return g_slist_copy(channels);

ret = SR_OK;
range = NULL;
Expand Down Expand Up @@ -102,7 +104,7 @@ GSList *parse_channelstring(struct sr_dev_inst *sdi, const char *channelstring)
ret = SR_ERR;
break;
}
ch = find_channel(sdi->channels, str);
ch = find_channel(channels, str);
if (!ch) {
g_critical("unknown channel '%d'.", b);
ret = SR_ERR;
Expand All @@ -127,7 +129,7 @@ GSList *parse_channelstring(struct sr_dev_inst *sdi, const char *channelstring)
break;
}

ch = find_channel(sdi->channels, names[0]);
ch = find_channel(channels, names[0]);
if (!ch) {
g_critical("unknown channel '%s'.", names[0]);
g_strfreev(names);
Expand Down Expand Up @@ -185,16 +187,20 @@ int parse_triggerstring(const struct sr_dev_inst *sdi, const char *s,
struct sr_channel *ch;
struct sr_trigger_stage *stage;
GVariant *gvar;
GSList *l;
GSList *l, *channels;
gsize num_matches;
gboolean found_match, error;
const int32_t *matches;
int32_t match;
unsigned int j;
int t, i;
char **tokens, *sep;
struct sr_dev_driver *driver;

driver = sr_dev_inst_driver_get(sdi);
channels = sr_dev_inst_channels_get(sdi);

if (sr_config_list(sdi->driver, sdi, NULL, SR_CONF_TRIGGER_MATCH,
if (sr_config_list(driver, sdi, NULL, SR_CONF_TRIGGER_MATCH,
&gvar) != SR_OK) {
g_critical("Device doesn't support any triggers.");
return FALSE;
Expand All @@ -212,7 +218,7 @@ int parse_triggerstring(const struct sr_dev_inst *sdi, const char *s,
}
*sep++ = 0;
ch = NULL;
for (l = sdi->channels; l; l = l->next) {
for (l = channels; l; l = l->next) {
ch = l->data;
if (ch->enabled && !strcmp(ch->name, tokens[i]))
break;
Expand Down
24 changes: 17 additions & 7 deletions session.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ static int set_limit_time(const struct sr_dev_inst *sdi)
GVariant *gvar;
uint64_t time_msec;
uint64_t samplerate;
struct sr_dev_driver *driver;

driver = sr_dev_inst_driver_get(sdi);

if (!(time_msec = sr_parse_timestring(opt_time))) {
g_critical("Invalid time '%s'", opt_time);
Expand All @@ -50,7 +53,7 @@ static int set_limit_time(const struct sr_dev_inst *sdi)
}
} else if (sr_dev_has_option(sdi, SR_CONF_SAMPLERATE)) {
/* Convert to samples based on the samplerate. */
sr_config_get(sdi->driver, sdi, NULL, SR_CONF_SAMPLERATE, &gvar);
sr_config_get(driver, sdi, NULL, SR_CONF_SAMPLERATE, &gvar);
samplerate = g_variant_get_uint64(gvar);
g_variant_unref(gvar);
limit_samples = (samplerate) * time_msec / (uint64_t)1000;
Expand Down Expand Up @@ -130,13 +133,17 @@ void datafeed_in(const struct sr_dev_inst *sdi,
static uint64_t samplerate = 0;
static int triggered = 0;
static FILE *outfile = NULL;
GSList *l;
GSList *l, *channels_sdi;
GString *out;
GVariant *gvar;
uint64_t end_sample;
uint64_t input_len;
int i;
char **channels;
struct sr_dev_driver *driver;

driver = sr_dev_inst_driver_get(sdi);
channels_sdi = sr_dev_inst_channels_get(sdi);

/* If the first packet to come in isn't a header, don't even try. */
if (packet->type != SR_DF_HEADER && o == NULL)
Expand Down Expand Up @@ -165,7 +172,7 @@ void datafeed_in(const struct sr_dev_inst *sdi,
}
rcvd_samples_logic = rcvd_samples_analog = 0;

if (sr_config_get(sdi->driver, sdi, NULL, SR_CONF_SAMPLERATE,
if (sr_config_get(driver, sdi, NULL, SR_CONF_SAMPLERATE,
&gvar) == SR_OK) {
samplerate = g_variant_get_uint64(gvar);
g_variant_unref(gvar);
Expand Down Expand Up @@ -246,8 +253,8 @@ void datafeed_in(const struct sr_dev_inst *sdi,
/* Saving to a session file. */
if (rcvd_samples_logic == 0) {
/* First packet with logic data, init session file. */
channels = g_malloc(sizeof(char *) * g_slist_length(sdi->channels));
for (i = 0, l = sdi->channels; l; l = l->next) {
channels = g_malloc(sizeof(char *) * g_slist_length(channels_sdi));
for (i = 0, l = channels_sdi; l; l = l->next) {
ch = l->data;
if (ch->type == SR_CHANNEL_LOGIC)
channels[i++] = ch->name;
Expand Down Expand Up @@ -468,6 +475,7 @@ void run_session(void)
gsize n_elements, i;
const uint32_t *dev_opts;
int is_demo_dev;
struct sr_dev_driver *driver;

devices = device_scan();
if (!devices) {
Expand All @@ -479,7 +487,9 @@ void run_session(void)
for (sd = devices; sd; sd = sd->next) {
sdi = sd->data;

if (sr_config_list(sdi->driver, sdi, NULL, SR_CONF_DEVICE_OPTIONS, &gvar) != SR_OK) {
driver = sr_dev_inst_driver_get(sdi);

if (sr_config_list(driver, sdi, NULL, SR_CONF_DEVICE_OPTIONS, &gvar) != SR_OK) {
g_critical("Failed to query sr_config_list(SR_CONF_DEVICE_OPTIONS).");
return;
}
Expand Down Expand Up @@ -574,7 +584,7 @@ void run_session(void)
sr_session_destroy(session);
return;
}
if (sr_config_list(sdi->driver, sdi, NULL,
if (sr_config_list(driver, sdi, NULL,
SR_CONF_LIMIT_SAMPLES, &gvar) == SR_OK) {
/* The device has no compression, or compression is turned
* off, and publishes its sample memory size. */
Expand Down
Loading

0 comments on commit c6fa2b2

Please sign in to comment.