sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
- cg = g_malloc0(sizeof(struct sr_channel_group));
- cg->name = g_strdup("1");
- sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
+ cg = sr_channel_group_new(sdi, "1", NULL);
ch = sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "V");
cg->channels = g_slist_append(cg->channels, ch);
for (i = 0; i < MAX_CHANNELS; i++) {
snprintf(channel, 10, "CH%d", i + 1);
ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel);
- cg = g_malloc(sizeof(struct sr_channel_group));
- cg->name = g_strdup(channel);
+ cg = sr_channel_group_new(sdi, channel, NULL);
cg->channels = g_slist_append(NULL, ch);
- cg->priv = NULL;
- sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
}
devc = g_malloc0(sizeof(struct dev_context));
if (hwmon < 0)
return FALSE;
- cg = g_malloc0(sizeof(struct sr_channel_group));
cgp = g_malloc0(sizeof(struct channel_group_priv));
- cg->priv = cgp;
+ cg = sr_channel_group_new(sdi, NULL, cgp);
/*
* See if we can read the EEPROM contents. If not, assume it's
sr_err("Invalid probe type: %d.", type);
}
- sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
-
return TRUE;
}
struct channel_group_context *cgc;
size_t idx, nr;
struct sr_channel_group *cg;
+ char cg_name[24];
/*
* Get relay count from product string. Weak condition,
devc->relay_mask = (1U << relay_count) - 1;
for (idx = 0; idx < devc->relay_count; idx++) {
nr = idx + 1;
- cg = g_malloc0(sizeof(*cg));
- cg->name = g_strdup_printf("R%zu", nr);
+ snprintf(cg_name, sizeof(cg_name), "R%zu", nr);
cgc = g_malloc0(sizeof(*cgc));
- cg->priv = cgc;
cgc->number = nr;
- sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
+ cg = sr_channel_group_new(sdi, cg_name, cgc);
+ (void)cg;
}
return sdi;
if (num_logic_channels > 0) {
/* Logic channels, all in one channel group. */
- cg = g_malloc0(sizeof(struct sr_channel_group));
- cg->name = g_strdup("Logic");
+ cg = sr_channel_group_new(sdi, "Logic", NULL);
for (i = 0; i < num_logic_channels; i++) {
sprintf(channel_name, "D%d", i);
ch = sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_name);
cg->channels = g_slist_append(cg->channels, ch);
}
- sdi->channel_groups = g_slist_append(NULL, cg);
}
/* Analog channels, channel groups and pattern generators. */
pattern = 0;
/* An "Analog" channel group with all analog channels in it. */
- acg = g_malloc0(sizeof(struct sr_channel_group));
- acg->name = g_strdup("Analog");
- sdi->channel_groups = g_slist_append(sdi->channel_groups, acg);
+ acg = sr_channel_group_new(sdi, "Analog", NULL);
for (i = 0; i < num_analog_channels; i++) {
snprintf(channel_name, 16, "A%d", i);
acg->channels = g_slist_append(acg->channels, ch);
/* Every analog channel gets its own channel group as well. */
- cg = g_malloc0(sizeof(struct sr_channel_group));
- cg->name = g_strdup(channel_name);
+ cg = sr_channel_group_new(sdi, channel_name, NULL);
cg->channels = g_slist_append(NULL, ch);
- sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
/* Every channel gets a generator struct. */
ag = g_malloc(sizeof(struct analog_gen));
sdi->connection_id = g_strdup(connection_id);
/* Logic channels, all in one channel group. */
- cg = g_malloc0(sizeof(struct sr_channel_group));
- cg->name = g_strdup("Logic");
+ cg = sr_channel_group_new(sdi, "Logic", NULL);
for (j = 0; j < NUM_CHANNELS; j++) {
sprintf(channel_name, "%d", j);
ch = sr_channel_new(sdi, j, SR_CHANNEL_LOGIC,
TRUE, channel_name);
cg->channels = g_slist_append(cg->channels, ch);
}
- sdi->channel_groups = g_slist_append(NULL, cg);
devc = dslogic_dev_new();
devc->profile = prof;
num_analog_channels = prof->dev_caps & DEV_CAPS_AX_ANALOG ? 1 : 0;
/* Logic channels, all in one channel group. */
- cg = g_malloc0(sizeof(struct sr_channel_group));
- cg->name = g_strdup("Logic");
+ cg = sr_channel_group_new(sdi, "Logic", NULL);
for (j = 0; j < num_logic_channels; j++) {
sprintf(channel_name, "D%d", j);
ch = sr_channel_new(sdi, j, SR_CHANNEL_LOGIC,
TRUE, channel_name);
cg->channels = g_slist_append(cg->channels, ch);
}
- sdi->channel_groups = g_slist_append(NULL, cg);
for (j = 0; j < num_analog_channels; j++) {
snprintf(channel_name, 16, "A%d", j);
SR_CHANNEL_ANALOG, TRUE, channel_name);
/* Every analog channel gets its own channel group. */
- cg = g_malloc0(sizeof(struct sr_channel_group));
- cg->name = g_strdup(channel_name);
+ cg = sr_channel_group_new(sdi, channel_name, NULL);
cg->channels = g_slist_append(NULL, ch);
- sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
}
devc = fx2lafw_dev_new();
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "CH1");
sr_channel_new(sdi, 1, SR_CHANNEL_ANALOG, TRUE, "CH2");
- cg = g_malloc0(sizeof(struct sr_channel_group));
- cg->name = g_strdup("");
+ cg = sr_channel_group_new(sdi, "", NULL);
cg->channels = g_slist_append(cg->channels, g_slist_nth_data(sdi->channels, 0));
cg->channels = g_slist_append(cg->channels, g_slist_nth_data(sdi->channels, 1));
- cg->priv = NULL;
- sdi->channel_groups = g_slist_append(NULL, cg);
return sdi;
}
for (i = 0; i < model->num_channels; i++) {
snprintf(channel, sizeof(channel), "CH%d", i + 1);
ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel);
- cg = g_malloc(sizeof(struct sr_channel_group));
- cg->name = g_strdup(channel);
+ cg = sr_channel_group_new(sdi, channel, NULL);
cg->channels = g_slist_append(NULL, ch);
- cg->priv = NULL;
- sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
}
devc = g_malloc0(sizeof(struct dev_context));
unsigned int i, j, group;
struct sr_channel *ch;
struct dev_context *devc;
+ const char *cg_name;
int ret;
devc = sdi->priv;
ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE,
(*scope_models[model_index].analog_names)[i]);
- devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group));
-
- devc->analog_groups[i]->name = g_strdup(
- (char *)(*scope_models[model_index].analog_names)[i]);
+ cg_name = (*scope_models[model_index].analog_names)[i];
+ devc->analog_groups[i] = sr_channel_group_new(sdi, cg_name, NULL);
devc->analog_groups[i]->channels = g_slist_append(NULL, ch);
-
- sdi->channel_groups = g_slist_append(sdi->channel_groups,
- devc->analog_groups[i]);
}
/* Add digital channel groups. */
ret = SR_OK;
for (i = 0; i < scope_models[model_index].digital_pods; i++) {
- devc->digital_groups[i] = g_malloc0(sizeof(struct sr_channel_group));
+ devc->digital_groups[i] = sr_channel_group_new(sdi, NULL, NULL);
if (!devc->digital_groups[i]) {
ret = SR_ERR_MALLOC;
break;
}
devc->digital_groups[i]->name = g_strdup_printf("POD%d", i + 1);
- sdi->channel_groups = g_slist_append(sdi->channel_groups,
- devc->digital_groups[i]);
}
if (ret != SR_OK)
return ret;
struct sr_channel_group *channel_groups[2];
for (int j = 0; j < 2; j++) {
- cg = g_malloc0(sizeof(struct sr_channel_group));
+ cg = sr_channel_group_new(sdi, NULL, NULL);
cg->name = g_strdup_printf("%c", 'A' + j);
channel_groups[j] = cg;
- sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
}
/* Assemble channel list and add channel to channel groups. */
for (i = 0; i < ARRAY_SIZE(channel_names); i++) {
ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel_names[i]);
- cg = g_malloc0(sizeof(struct sr_channel_group));
- cg->name = g_strdup(channel_names[i]);
+ cg = sr_channel_group_new(sdi, channel_names[i], NULL);
cg->channels = g_slist_append(cg->channels, ch);
- sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
}
devc = g_malloc0(sizeof(struct dev_context));
*/
for (i = 0; i < ARRAY_SIZE(channel_names); i++) {
ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel_names[i]);
- cg = g_malloc0(sizeof(struct sr_channel_group));
- cg->name = g_strdup(channel_names[i]);
+ cg = sr_channel_group_new(sdi, channel_names[i], NULL);
cg->channels = g_slist_append(cg->channels, ch);
- sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
}
devc = g_malloc0(sizeof(struct dev_context));
TRUE, "Front");
channel->priv = chanc;
- front = g_malloc0(sizeof(*front));
- front->name = g_strdup("Front");
+ front = sr_channel_group_new(sdi, "Front", NULL);
front->channels = g_slist_append(front->channels, channel);
- sdi->channel_groups = g_slist_append(sdi->channel_groups, front);
-
return chan_idx;
}
if (!card)
return chan_idx;
- group = g_malloc0(sizeof(*group));
- group->priv = NULL;
- group->name = g_strdup(card->cg_name);
- sdi->channel_groups = g_slist_append(sdi->channel_groups, group);
+ group = sr_channel_group_new(sdi, card->cg_name, NULL);
for (i = 0; i < card->num_channels; i++) {
struct channel_group_context *cgc;
size_t idx, nr;
struct sr_channel_group *cg;
+ char cg_name[24];
/*
* The device cannot get identified by means of SCPI queries.
devc->channel_count = 6;
for (idx = 0; idx < devc->channel_count; idx++) {
nr = idx + 1;
-
- cg = g_malloc0(sizeof(*cg));
- cg->name = g_strdup_printf("R%zu", nr);
-
+ snprintf(cg_name, sizeof(cg_name), "R%zu", nr);
cgc = g_malloc0(sizeof(*cgc));
cgc->number = nr;
- cg->priv = cgc;
-
- sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
+ cg = sr_channel_group_new(sdi, cg_name, cgc);
+ (void)cg;
}
return sdi;
ieee1284_ref(port);
for (i = 0; i < NUM_CHANNELS; i++) {
- cg = g_malloc0(sizeof(struct sr_channel_group));
- cg->name = g_strdup(trigger_sources[i]);
+ cg = sr_channel_group_new(sdi, trigger_sources[i], NULL);
ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, FALSE, trigger_sources[i]);
cg->channels = g_slist_append(cg->channels, ch);
- sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
}
devc = g_malloc0(sizeof(struct dev_context));
sdi->version = g_strdup_printf("%x.%02x", fw_major, fw_minor);
sdi->serial_num = unit_serial;
- cg = g_malloc0(sizeof(*cg));
- cg->name = g_strdup("1");
- sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
+ cg = sr_channel_group_new(sdi, "1", NULL);
ch = sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "V1");
cg->channels = g_slist_append(cg->channels, ch);
ch = sr_channel_new(sdi, 1, SR_CHANNEL_ANALOG, TRUE, "I1");
ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, channel_enabled,
(*scope_models[model_index].analog_names)[i]);
- devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group));
-
- devc->analog_groups[i]->name = g_strdup(
- (char *)(*scope_models[model_index].analog_names)[i]);
+ devc->analog_groups[i] = sr_channel_group_new(sdi,
+ (*scope_models[model_index].analog_names)[i], NULL);
devc->analog_groups[i]->channels = g_slist_append(NULL, ch);
-
- sdi->channel_groups = g_slist_append(sdi->channel_groups,
- devc->analog_groups[i]);
}
devc->model_config = &scope_models[model_index];
sdi->driver = &maynuo_m97_driver_info;
sdi->inst_type = SR_INST_MODBUS;
- cg = g_malloc0(sizeof(struct sr_channel_group));
- cg->name = g_strdup("1");
- sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
+ cg = sr_channel_group_new(sdi, "1", NULL);
ch = sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "V1");
cg->channels = g_slist_append(cg->channels, ch);
sdi->connection_id = g_strdup(conn);
/* Create the logic channels group. */
- cg = g_malloc0(sizeof(*cg));
- sdi->channel_groups = g_slist_append(NULL, cg);
- cg->name = g_strdup("Logic");
+ cg = sr_channel_group_new(sdi, "Logic", NULL);
ch_count = ARRAY_SIZE(channel_names);
for (ch_idx = 0; ch_idx < ch_count; ch_idx++) {
ch = sr_channel_new(sdi, ch_idx, SR_CHANNEL_LOGIC,
devc->channel_status[cnt].info = g_slist_append(NULL, ch);
- cg = g_malloc(sizeof(struct sr_channel_group));
snprintf(channel, sizeof(channel), "CG%d", cnt + 1);
- cg->name = g_strdup(channel);
- cg->priv = NULL;
+ cg = sr_channel_group_new(sdi, channel, NULL);
cg->channels = g_slist_append(NULL, ch);
-
- sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
}
/* Query status */
for (i = 0; i < device->num_channels; i++) {
ch = sr_channel_new(sdi, ch_idx++, SR_CHANNEL_ANALOG, TRUE,
device->channels[i].name);
- cg = g_malloc0(sizeof(*cg));
snprintf(tmp, sizeof(tmp), "%u", i + 1);
- cg->name = g_strdup(tmp);
+ cg = sr_channel_group_new(sdi, tmp, NULL);
cg->channels = g_slist_append(cg->channels, ch);
-
- sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
}
/* Create channels for the frequency counter output. */
channel_name = g_strdup_printf("CH%d", i + 1);
ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel_name);
- devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group));
-
- devc->analog_groups[i]->name = channel_name;
+ devc->analog_groups[i] = sr_channel_group_new(sdi,
+ channel_name, NULL);
devc->analog_groups[i]->channels = g_slist_append(NULL, ch);
- sdi->channel_groups = g_slist_append(sdi->channel_groups,
- devc->analog_groups[i]);
}
if (devc->model->has_digital) {
- devc->digital_group = g_malloc0(sizeof(struct sr_channel_group));
-
+ devc->digital_group = sr_channel_group_new(sdi, "LA", NULL);
for (i = 0; i < ARRAY_SIZE(devc->digital_channels); i++) {
channel_name = g_strdup_printf("D%d", i);
ch = sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_name);
devc->digital_group->channels = g_slist_append(
devc->digital_group->channels, ch);
}
- devc->digital_group->name = g_strdup("LA");
- sdi->channel_groups = g_slist_append(sdi->channel_groups,
- devc->digital_group);
}
for (i = 0; i < ARRAY_SIZE(timebases); i++) {
for (i = 0; i < num_channel_groups; i++) {
cgs = &channel_groups[i];
- cg = g_malloc0(sizeof(struct sr_channel_group));
- cg->name = g_strdup(cgs->name);
+ cg = sr_channel_group_new(sdi, cgs->name, NULL);
for (j = 0, mask = 1; j < 64; j++, mask <<= 1) {
if (cgs->channel_index_mask & mask) {
for (l = sdi->channels; l; l = l->next) {
pcg = g_malloc0(sizeof(struct pps_channel_group));
pcg->features = cgs->features;
cg->priv = pcg;
- sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
}
sr_scpi_hw_info_free(hw_info);
channel_name = g_strdup_printf("CH%d", i + 1);
ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel_name);
- devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group));
-
- devc->analog_groups[i]->name = channel_name;
+ devc->analog_groups[i] = sr_channel_group_new(sdi,
+ channel_name, NULL);
devc->analog_groups[i]->channels = g_slist_append(NULL, ch);
- sdi->channel_groups = g_slist_append(sdi->channel_groups,
- devc->analog_groups[i]);
}
if (devc->model->has_digital) {
- devc->digital_group = g_malloc0(sizeof(struct sr_channel_group));
-
+ devc->digital_group = sr_channel_group_new(sdi, "LA", NULL);
for (i = 0; i < ARRAY_SIZE(devc->digital_channels); i++) {
channel_name = g_strdup_printf("D%d", i);
ch = sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_name);
devc->digital_group->channels = g_slist_append(
devc->digital_group->channels, ch);
}
- devc->digital_group->name = g_strdup("LA");
- sdi->channel_groups = g_slist_append(sdi->channel_groups,
- devc->digital_group);
}
for (i = 0; i < ARRAY_SIZE(timebases); i++) {
ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE,
(*scope_models[model_index].analog_names)[i]);
- devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group));
-
- devc->analog_groups[i]->name = g_strdup(
- (char *)(*scope_models[model_index].analog_names)[i]);
+ devc->analog_groups[i] = sr_channel_group_new(sdi,
+ (*scope_models[model_index].analog_names)[i], NULL);
devc->analog_groups[i]->channels = g_slist_append(NULL, ch);
-
- sdi->channel_groups = g_slist_append(sdi->channel_groups,
- devc->analog_groups[i]);
}
/* Add digital channel groups. */
for (i = 0; i < scope_models[model_index].pods; i++) {
- devc->digital_groups[i] = g_malloc0(sizeof(struct sr_channel_group));
+ devc->digital_groups[i] = sr_channel_group_new(sdi, NULL, NULL);
if (!devc->digital_groups[i])
return SR_ERR_MALLOC;
devc->digital_groups[i]->name = g_strdup_printf("POD%d", i);
- sdi->channel_groups = g_slist_append(sdi->channel_groups,
- devc->digital_groups[i]);
}
/* Add digital channels. */
g_free(vcd_ch);
}
-/* TODO Drop the local decl when this has become a common helper. */
-void sr_channel_group_free(struct sr_channel_group *cg);
-
-/* Wrapper for GDestroyNotify compatibility. */
-static void cg_free(void *p)
-{
- sr_channel_group_free(p);
-}
-
/*
* Another timestamp delta was observed, update statistics: Update the
* sorted list of minimum values, and increment the occurance counter.
if (vcd_ch->type != ch_type)
continue;
cg = NULL;
- if (vcd_ch->size != 1) {
- cg = g_malloc0(sizeof(*cg));
- cg->name = g_strdup(vcd_ch->name);
- }
+ if (vcd_ch->size != 1)
+ cg = sr_channel_group_new(sdi, vcd_ch->name, NULL);
for (size_idx = 0; size_idx < vcd_ch->size; size_idx++) {
ch_name = get_channel_name(vcd_ch, size_idx);
sr_dbg("sigrok channel idx %zu, name %s, type %s, en %d.",
if (cg)
cg->channels = g_slist_append(cg->channels, ch);
}
- if (cg)
- sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
}
}
inc = in->priv;
- g_slist_free_full(inc->prev.sr_groups, cg_free);
+ g_slist_free_full(inc->prev.sr_groups, sr_channel_group_free_cb);
inc->prev.sr_groups = in->sdi->channel_groups;
in->sdi->channel_groups = NULL;
return FALSE;
}
- g_slist_free_full(in->sdi->channel_groups, cg_free);
+ g_slist_free_full(in->sdi->channel_groups, sr_channel_group_free_cb);
in->sdi->channel_groups = inc->prev.sr_groups;
inc->prev.sr_groups = NULL;