From: Martin Ling Date: Thu, 19 Mar 2015 21:37:33 +0000 (+0000) Subject: Simplify channel creation. X-Git-Tag: libsigrok-0.4.0~600 X-Git-Url: http://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=5e23fcab889c62864b92aa3ad6902ce3e9f5be49 Simplify channel creation. We always follow sr_channel_new() with a call to add the channel to the sdi. Tidy up a bit by adding this functionality to sr_channel_new() instead. --- diff --git a/src/device.c b/src/device.c index 9dd2201e..1c84a7df 100644 --- a/src/device.c +++ b/src/device.c @@ -42,7 +42,8 @@ */ /** @private - * Allocate and initialize new struct sr_channel + * Allocate and initialize new struct sr_channel and add to sdi. + * @param[in] sdi The device instance the channel is connected to. * @param[in] index @copydoc sr_channel::index * @param[in] type @copydoc sr_channel::type * @param[in] enabled @copydoc sr_channel::enabled @@ -50,8 +51,8 @@ * * @return A new struct sr_channel*. */ -SR_PRIV struct sr_channel *sr_channel_new(int index, int type, - gboolean enabled, const char *name) +SR_PRIV struct sr_channel *sr_channel_new(struct sr_dev_inst *sdi, + int index, int type, gboolean enabled, const char *name) { struct sr_channel *ch; @@ -62,6 +63,8 @@ SR_PRIV struct sr_channel *sr_channel_new(int index, int type, if (name) ch->name = g_strdup(name); + sdi->channels = g_slist_append(sdi->channels, ch); + return ch; } @@ -227,13 +230,10 @@ SR_API struct sr_dev_inst *sr_dev_inst_user_new(const char *vendor, */ SR_API int sr_dev_inst_channel_add(struct sr_dev_inst *sdi, int index, int type, const char *name) { - struct sr_channel *ch; - if (!sdi || sdi->inst_type != SR_INST_USER || index < 0) return SR_ERR_ARG; - ch = sr_channel_new(index, type, TRUE, name); - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, index, type, TRUE, name); return SR_OK; } diff --git a/src/hardware/agilent-dmm/api.c b/src/hardware/agilent-dmm/api.c index 374c206a..7cfb69d8 100644 --- a/src/hardware/agilent-dmm/api.c +++ b/src/hardware/agilent-dmm/api.c @@ -84,7 +84,6 @@ static GSList *scan(GSList *options) struct drv_context *drvc; struct dev_context *devc; struct sr_config *src; - struct sr_channel *ch; struct sr_serial_dev_inst *serial; GSList *l, *devices; int len, i; @@ -150,8 +149,7 @@ static GSList *scan(GSList *options) sdi->conn = serial; sdi->priv = devc; sdi->driver = di; - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"); - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1"); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); break; diff --git a/src/hardware/appa-55ii/api.c b/src/hardware/appa-55ii/api.c index 771a686c..b9f767d2 100644 --- a/src/hardware/appa-55ii/api.c +++ b/src/hardware/appa-55ii/api.c @@ -55,7 +55,6 @@ static GSList *scan(GSList *options) struct dev_context *devc; struct sr_serial_dev_inst *serial; struct sr_dev_inst *sdi; - struct sr_channel *ch; struct sr_config *src; GSList *devices, *l; const char *conn, *serialcomm; @@ -110,10 +109,8 @@ static GSList *scan(GSList *options) sdi->priv = devc; sdi->driver = di; - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "T1"); - sdi->channels = g_slist_append(sdi->channels, ch); - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "T2"); - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "T1"); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "T2"); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); diff --git a/src/hardware/asix-sigma/asix-sigma.c b/src/hardware/asix-sigma/asix-sigma.c index 0e6180cb..e1355e9f 100644 --- a/src/hardware/asix-sigma/asix-sigma.c +++ b/src/hardware/asix-sigma/asix-sigma.c @@ -325,7 +325,6 @@ static int init(struct sr_context *sr_ctx) static GSList *scan(GSList *options) { struct sr_dev_inst *sdi; - struct sr_channel *ch; struct drv_context *drvc; struct dev_context *devc; GSList *devices; @@ -383,11 +382,9 @@ static GSList *scan(GSList *options) sdi->model = g_strdup(USB_MODEL_NAME); sdi->driver = di; - for (i = 0; i < ARRAY_SIZE(channel_names); i++) { - ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, + for (i = 0; i < ARRAY_SIZE(channel_names); i++) + sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_names[i]); - sdi->channels = g_slist_append(sdi->channels, ch); - } devices = g_slist_append(devices, sdi); drvc->instances = g_slist_append(drvc->instances, sdi); diff --git a/src/hardware/atten-pps3xxx/api.c b/src/hardware/atten-pps3xxx/api.c index b72eeb4a..1eafaaff 100644 --- a/src/hardware/atten-pps3xxx/api.c +++ b/src/hardware/atten-pps3xxx/api.c @@ -173,8 +173,7 @@ static GSList *scan(GSList *options, int modelid) sdi->conn = serial; for (i = 0; i < MAX_CHANNELS; i++) { snprintf(channel, 10, "CH%d", i + 1); - ch = sr_channel_new(i, SR_CHANNEL_ANALOG, TRUE, channel); - sdi->channels = g_slist_append(sdi->channels, ch); + 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->channels = g_slist_append(NULL, ch); diff --git a/src/hardware/baylibre-acme/protocol.c b/src/hardware/baylibre-acme/protocol.c index 3ceee6c1..461a7b5e 100644 --- a/src/hardware/baylibre-acme/protocol.c +++ b/src/hardware/baylibre-acme/protocol.c @@ -201,13 +201,12 @@ static void append_channel(struct sr_dev_inst *sdi, struct sr_channel_group *cg, cp->ch_type = type; cp->probe = cg->priv; - ch = sr_channel_new(devc->num_channels++, + ch = sr_channel_new(sdi, devc->num_channels++, SR_CHANNEL_ANALOG, TRUE, name); g_free(name); ch->priv = cp; cg->channels = g_slist_append(cg->channels, ch); - sdi->channels = g_slist_append(sdi->channels, ch); } SR_PRIV gboolean bl_acme_register_probe(struct sr_dev_inst *sdi, int type, diff --git a/src/hardware/beaglelogic/api.c b/src/hardware/beaglelogic/api.c index 098efa06..e6668ae6 100644 --- a/src/hardware/beaglelogic/api.c +++ b/src/hardware/beaglelogic/api.c @@ -86,7 +86,6 @@ static GSList *scan(GSList *options) struct sr_config *src; struct sr_dev_inst *sdi; struct dev_context *devc; - struct sr_channel *ch; int i, maxch; devices = NULL; @@ -136,11 +135,9 @@ static GSList *scan(GSList *options) sr_info("BeagleLogic device found at "BEAGLELOGIC_DEV_NODE); /* Fill the channels */ - for (i = 0; i < maxch; i++) { - ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, + for (i = 0; i < maxch; i++) + sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, beaglelogic_channel_names[i]); - sdi->channels = g_slist_append(sdi->channels, ch); - } sdi->priv = devc; drvc->instances = g_slist_append(drvc->instances, sdi); diff --git a/src/hardware/brymen-bm86x/api.c b/src/hardware/brymen-bm86x/api.c index 65fcb428..87d2e5af 100644 --- a/src/hardware/brymen-bm86x/api.c +++ b/src/hardware/brymen-bm86x/api.c @@ -48,7 +48,6 @@ static GSList *scan(GSList *options) struct sr_dev_inst *sdi; struct sr_usb_dev_inst *usb; struct sr_config *src; - struct sr_channel *ch; const char *conn; drvc = di->priv; @@ -80,10 +79,8 @@ static GSList *scan(GSList *options) devc = g_malloc0(sizeof(struct dev_context)); sdi->priv = devc; sdi->driver = di; - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"); - sdi->channels = g_slist_append(sdi->channels, ch); - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P2"); - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1"); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P2"); sdi->inst_type = SR_INST_USB; sdi->conn = usb; diff --git a/src/hardware/brymen-dmm/api.c b/src/hardware/brymen-dmm/api.c index aef784e8..058835ee 100644 --- a/src/hardware/brymen-dmm/api.c +++ b/src/hardware/brymen-dmm/api.c @@ -44,7 +44,6 @@ static GSList *brymen_scan(const char *conn, const char *serialcomm) struct sr_dev_inst *sdi; struct dev_context *devc; struct drv_context *drvc; - struct sr_channel *ch; struct sr_serial_dev_inst *serial; GSList *devices; int ret; @@ -84,8 +83,7 @@ static GSList *brymen_scan(const char *conn, const char *serialcomm) drvc = di->priv; sdi->priv = devc; sdi->driver = di; - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"); - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1"); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); diff --git a/src/hardware/cem-dt-885x/api.c b/src/hardware/cem-dt-885x/api.c index d91c5509..5c259542 100644 --- a/src/hardware/cem-dt-885x/api.c +++ b/src/hardware/cem-dt-885x/api.c @@ -82,7 +82,6 @@ static GSList *scan(GSList *options) struct sr_config *src; struct sr_serial_dev_inst *serial; struct sr_dev_inst *sdi; - struct sr_channel *ch; GSList *l, *devices; gint64 start; const char *conn; @@ -122,8 +121,7 @@ static GSList *scan(GSList *options) sdi->inst_type = SR_INST_SERIAL; sdi->priv = devc; sdi->driver = di; - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "SPL"); - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "SPL"); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); break; diff --git a/src/hardware/center-3xx/api.c b/src/hardware/center-3xx/api.c index c4008d48..cc9e3d7a 100644 --- a/src/hardware/center-3xx/api.c +++ b/src/hardware/center-3xx/api.c @@ -72,7 +72,6 @@ static GSList *center_scan(const char *conn, const char *serialcomm, int idx) struct sr_dev_inst *sdi; struct drv_context *drvc; struct dev_context *devc; - struct sr_channel *ch; struct sr_serial_dev_inst *serial; GSList *devices; @@ -98,9 +97,8 @@ static GSList *center_scan(const char *conn, const char *serialcomm, int idx) sdi->driver = center_devs[idx].di; for (i = 0; i < center_devs[idx].num_channels; i++) { - ch = sr_channel_new(i, SR_CHANNEL_ANALOG, + sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel_names[i]); - sdi->channels = g_slist_append(sdi->channels, ch); } drvc->instances = g_slist_append(drvc->instances, sdi); diff --git a/src/hardware/chronovu-la/api.c b/src/hardware/chronovu-la/api.c index c9d7ec11..14f1066e 100644 --- a/src/hardware/chronovu-la/api.c +++ b/src/hardware/chronovu-la/api.c @@ -80,7 +80,6 @@ static int add_device(int idx, int model, GSList **devices) struct sr_dev_inst *sdi; struct drv_context *drvc; struct dev_context *devc; - struct sr_channel *ch; ret = SR_OK; @@ -127,11 +126,9 @@ static int add_device(int idx, int model, GSList **devices) sdi->driver = di; sdi->priv = devc; - for (i = 0; i < devc->prof->num_channels; i++) { - ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, + for (i = 0; i < devc->prof->num_channels; i++) + sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, cv_channel_names[i]); - sdi->channels = g_slist_append(sdi->channels, ch); - } *devices = g_slist_append(*devices, sdi); drvc->instances = g_slist_append(drvc->instances, sdi); diff --git a/src/hardware/colead-slm/api.c b/src/hardware/colead-slm/api.c index 34bebd8e..6e907cec 100644 --- a/src/hardware/colead-slm/api.c +++ b/src/hardware/colead-slm/api.c @@ -56,7 +56,6 @@ static GSList *scan(GSList *options) struct dev_context *devc; struct sr_dev_inst *sdi; struct sr_config *src; - struct sr_channel *ch; GSList *devices, *l; const char *conn, *serialcomm; @@ -91,8 +90,7 @@ static GSList *scan(GSList *options) sdi->inst_type = SR_INST_SERIAL; sdi->priv = devc; sdi->driver = di; - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"); - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1"); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); diff --git a/src/hardware/conrad-digi-35-cpu/api.c b/src/hardware/conrad-digi-35-cpu/api.c index ed7378ee..dc524264 100644 --- a/src/hardware/conrad-digi-35-cpu/api.c +++ b/src/hardware/conrad-digi-35-cpu/api.c @@ -51,7 +51,6 @@ static GSList *scan(GSList *options) struct sr_dev_inst *sdi; struct drv_context *drvc; struct sr_config *src; - struct sr_channel *ch; struct sr_serial_dev_inst *serial; GSList *l, *devices; const char *conn, *serialcomm; @@ -100,8 +99,7 @@ static GSList *scan(GSList *options) sdi->conn = serial; sdi->priv = NULL; sdi->driver = di; - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "CH1"); - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "CH1"); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); diff --git a/src/hardware/demo/demo.c b/src/hardware/demo/demo.c index 95c9fcfe..fb1bb05f 100644 --- a/src/hardware/demo/demo.c +++ b/src/hardware/demo/demo.c @@ -320,8 +320,7 @@ static GSList *scan(GSList *options) cg->name = g_strdup("Logic"); for (i = 0; i < num_logic_channels; i++) { sprintf(channel_name, "D%d", i); - ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, channel_name); - sdi->channels = g_slist_append(sdi->channels, ch); + 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); @@ -336,9 +335,8 @@ static GSList *scan(GSList *options) devc->ch_ag = g_hash_table_new(g_direct_hash, g_direct_equal); for (i = 0; i < num_analog_channels; i++) { snprintf(channel_name, 16, "A%d", i); - ch = sr_channel_new(i + num_logic_channels, SR_CHANNEL_ANALOG, + ch = sr_channel_new(sdi, i + num_logic_channels, SR_CHANNEL_ANALOG, TRUE, channel_name); - sdi->channels = g_slist_append(sdi->channels, ch); acg->channels = g_slist_append(acg->channels, ch); /* Every analog channel gets its own channel group as well. */ diff --git a/src/hardware/fluke-dmm/api.c b/src/hardware/fluke-dmm/api.c index e590a4cc..bb903d2f 100644 --- a/src/hardware/fluke-dmm/api.c +++ b/src/hardware/fluke-dmm/api.c @@ -69,7 +69,6 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm) struct sr_dev_inst *sdi; struct drv_context *drvc; struct dev_context *devc; - struct sr_channel *ch; struct sr_serial_dev_inst *serial; GSList *devices; int retry, len, i, s; @@ -132,8 +131,7 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm) sdi->conn = serial; sdi->priv = devc; sdi->driver = di; - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"); - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1"); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); break; diff --git a/src/hardware/fx2lafw/api.c b/src/hardware/fx2lafw/api.c index 46520eb4..8e9b5be4 100644 --- a/src/hardware/fx2lafw/api.c +++ b/src/hardware/fx2lafw/api.c @@ -171,7 +171,6 @@ static GSList *scan(GSList *options) struct dev_context *devc; struct sr_dev_inst *sdi; struct sr_usb_dev_inst *usb; - struct sr_channel *ch; struct sr_config *src; const struct fx2lafw_profile *prof; GSList *l, *devices, *conn_devices; @@ -288,11 +287,9 @@ static GSList *scan(GSList *options) /* Fill in channellist according to this device's profile. */ num_logic_channels = prof->dev_caps & DEV_CAPS_16BIT ? 16 : 8; - for (j = 0; j < num_logic_channels; j++) { - ch = sr_channel_new(j, SR_CHANNEL_LOGIC, TRUE, + for (j = 0; j < num_logic_channels; j++) + sr_channel_new(sdi, j, SR_CHANNEL_LOGIC, TRUE, channel_names[j]); - sdi->channels = g_slist_append(sdi->channels, ch); - } devc = fx2lafw_dev_new(); devc->profile = prof; diff --git a/src/hardware/gmc-mh-1x-2x/api.c b/src/hardware/gmc-mh-1x-2x/api.c index 91267d98..96d7656c 100644 --- a/src/hardware/gmc-mh-1x-2x/api.c +++ b/src/hardware/gmc-mh-1x-2x/api.c @@ -162,7 +162,6 @@ static GSList *scan_1x_2x_rs232(GSList *options) struct drv_context *drvc; struct dev_context *devc; struct sr_config *src; - struct sr_channel *ch; struct sr_serial_dev_inst *serial; GSList *l, *devices; const char *conn, *serialcomm; @@ -236,8 +235,7 @@ static GSList *scan_1x_2x_rs232(GSList *options) sdi->conn = serial; sdi->priv = devc; sdi->driver = &gmc_mh_1x_2x_rs232_driver_info; - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"); - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1"); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); } @@ -254,7 +252,6 @@ static GSList *scan_2x_bd232(GSList *options) struct drv_context *drvc; struct dev_context *devc; struct sr_config *src; - struct sr_channel *ch; struct sr_serial_dev_inst *serial; GSList *l, *devices; const char *conn, *serialcomm; @@ -332,8 +329,7 @@ static GSList *scan_2x_bd232(GSList *options) sdi->conn = serial; sdi->priv = devc; sdi->driver = &gmc_mh_2x_bd232_driver_info; - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"); - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1"); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); devc = g_malloc0(sizeof(struct dev_context)); diff --git a/src/hardware/hameg-hmo/protocol.c b/src/hardware/hameg-hmo/protocol.c index 28c9fd61..783c3ebc 100644 --- a/src/hardware/hameg-hmo/protocol.c +++ b/src/hardware/hameg-hmo/protocol.c @@ -616,9 +616,8 @@ SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi) /* Add analog channels. */ for (i = 0; i < scope_models[model_index].analog_channels; i++) { - ch = sr_channel_new(i, SR_CHANNEL_ANALOG, TRUE, + ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, (*scope_models[model_index].analog_names)[i]); - sdi->channels = g_slist_append(sdi->channels, ch); devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group)); @@ -643,9 +642,8 @@ SR_PRIV int hmo_init_device(struct sr_dev_inst *sdi) /* Add digital channels. */ for (i = 0; i < scope_models[model_index].digital_channels; i++) { - ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, + ch = sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, (*scope_models[model_index].digital_names)[i]); - sdi->channels = g_slist_append(sdi->channels, ch); devc->digital_groups[i < 8 ? 0 : 1]->channels = g_slist_append( devc->digital_groups[i < 8 ? 0 : 1]->channels, ch); diff --git a/src/hardware/hantek-dso/api.c b/src/hardware/hantek-dso/api.c index d375c2aa..e2d09142 100644 --- a/src/hardware/hantek-dso/api.c +++ b/src/hardware/hantek-dso/api.c @@ -183,8 +183,7 @@ static struct sr_dev_inst *dso_dev_new(const struct dso_profile *prof) * a trigger source internal to the device. */ for (i = 0; channel_names[i]; i++) { - ch = sr_channel_new(i, SR_CHANNEL_ANALOG, TRUE, channel_names[i]); - sdi->channels = g_slist_append(sdi->channels, ch); + 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->channels = g_slist_append(cg->channels, ch); diff --git a/src/hardware/ikalogic-scanalogic2/api.c b/src/hardware/ikalogic-scanalogic2/api.c index 798ae8bd..b9418db2 100644 --- a/src/hardware/ikalogic-scanalogic2/api.c +++ b/src/hardware/ikalogic-scanalogic2/api.c @@ -65,7 +65,6 @@ static GSList *scan(GSList *options) GSList *usb_devices, *devices, *l; struct drv_context *drvc; struct sr_dev_inst *sdi; - struct sr_channel *ch; struct dev_context *devc; struct sr_usb_dev_inst *usb; struct device_info dev_info; @@ -119,12 +118,9 @@ static GSList *scan(GSList *options) sdi->inst_type = SR_INST_USB; sdi->conn = usb; - for (i = 0; channel_names[i]; i++) { - ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, - channel_names[i]); - sdi->channels = g_slist_append(sdi->channels, ch); - devc->channels[i] = ch; - } + for (i = 0; channel_names[i]; i++) + devc->channels[i] = sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, + TRUE, channel_names[i]); devc->state = STATE_IDLE; devc->next_state = STATE_IDLE; diff --git a/src/hardware/ikalogic-scanaplus/api.c b/src/hardware/ikalogic-scanaplus/api.c index ea508c09..3bd1b273 100644 --- a/src/hardware/ikalogic-scanaplus/api.c +++ b/src/hardware/ikalogic-scanaplus/api.c @@ -74,7 +74,6 @@ static int init(struct sr_context *sr_ctx) static GSList *scan(GSList *options) { struct sr_dev_inst *sdi; - struct sr_channel *ch; struct drv_context *drvc; struct dev_context *devc; GSList *devices; @@ -127,11 +126,9 @@ static GSList *scan(GSList *options) sdi->driver = di; sdi->priv = devc; - for (i = 0; channel_names[i]; i++) { - ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, + for (i = 0; channel_names[i]; i++) + sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_names[i]); - sdi->channels = g_slist_append(sdi->channels, ch); - } devices = g_slist_append(devices, sdi); drvc->instances = g_slist_append(drvc->instances, sdi); diff --git a/src/hardware/kecheng-kc-330b/api.c b/src/hardware/kecheng-kc-330b/api.c index 0f8304fc..7f49364a 100644 --- a/src/hardware/kecheng-kc-330b/api.c +++ b/src/hardware/kecheng-kc-330b/api.c @@ -113,7 +113,6 @@ static GSList *scan(GSList *options) struct drv_context *drvc; struct dev_context *devc; struct sr_dev_inst *sdi; - struct sr_channel *ch; GSList *usb_devices, *devices, *l; char *model; @@ -136,8 +135,7 @@ static GSList *scan(GSList *options) sdi->driver = di; sdi->inst_type = SR_INST_USB; sdi->conn = l->data; - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "SPL"); - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "SPL"); devc = g_malloc0(sizeof(struct dev_context)); sdi->priv = devc; devc->limit_samples = 0; diff --git a/src/hardware/lascar-el-usb/protocol.c b/src/hardware/lascar-el-usb/protocol.c index 801f83b0..576d9749 100644 --- a/src/hardware/lascar-el-usb/protocol.c +++ b/src/hardware/lascar-el-usb/protocol.c @@ -293,7 +293,6 @@ static struct sr_dev_inst *lascar_identify(unsigned char *config) struct dev_context *devc; const struct elusb_profile *profile; struct sr_dev_inst *sdi; - struct sr_channel *ch; int modelid, i; char firmware[5]; @@ -332,16 +331,12 @@ static struct sr_dev_inst *lascar_identify(unsigned char *config) if (profile->logformat == LOG_TEMP_RH) { /* Model this as two channels: temperature and humidity. */ - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "Temp"); - sdi->channels = g_slist_append(NULL, ch); - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "Hum"); - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "Temp"); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "Hum"); } else if (profile->logformat == LOG_CO) { - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "CO"); - sdi->channels = g_slist_append(NULL, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "CO"); } else { - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"); - sdi->channels = g_slist_append(NULL, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1"); } devc = g_malloc0(sizeof(struct dev_context)); diff --git a/src/hardware/link-mso19/api.c b/src/hardware/link-mso19/api.c index 451cc934..aa8cb778 100644 --- a/src/hardware/link-mso19/api.c +++ b/src/hardware/link-mso19/api.c @@ -215,11 +215,9 @@ static GSList *scan(GSList *options) sdi->priv = devc; for (i = 0; i < NUM_CHANNELS; i++) { - struct sr_channel *ch; chtype = (i == 0) ? SR_CHANNEL_ANALOG : SR_CHANNEL_LOGIC; - ch = sr_channel_new(i, chtype, TRUE, + sr_channel_new(sdi, i, chtype, TRUE, mso19_channel_names[i]); - sdi->channels = g_slist_append(sdi->channels, ch); } //Add the driver diff --git a/src/hardware/manson-hcs-3xxx/api.c b/src/hardware/manson-hcs-3xxx/api.c index d3e5f8fa..d3bd5e1f 100644 --- a/src/hardware/manson-hcs-3xxx/api.c +++ b/src/hardware/manson-hcs-3xxx/api.c @@ -92,7 +92,6 @@ static GSList *scan(GSList *options) struct dev_context *devc; struct sr_dev_inst *sdi; struct sr_config *src; - struct sr_channel *ch; GSList *devices, *l; const char *conn, *serialcomm; struct sr_serial_dev_inst *serial; @@ -162,8 +161,7 @@ static GSList *scan(GSList *options) sdi->conn = serial; sdi->driver = di; - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "CH1"); - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "CH1"); devc = g_malloc0(sizeof(struct dev_context)); devc->model = &models[model_id]; diff --git a/src/hardware/mic-985xx/api.c b/src/hardware/mic-985xx/api.c index 3bc65faa..737febaf 100644 --- a/src/hardware/mic-985xx/api.c +++ b/src/hardware/mic-985xx/api.c @@ -71,7 +71,6 @@ static GSList *mic_scan(const char *conn, const char *serialcomm, int idx) struct sr_dev_inst *sdi; struct drv_context *drvc; struct dev_context *devc; - struct sr_channel *ch; struct sr_serial_dev_inst *serial; GSList *devices; @@ -100,13 +99,10 @@ static GSList *mic_scan(const char *conn, const char *serialcomm, int idx) sdi->priv = devc; sdi->driver = mic_devs[idx].di; - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "Temperature"); - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "Temperature"); - if (mic_devs[idx].has_humidity) { - ch = sr_channel_new(1, SR_CHANNEL_ANALOG, TRUE, "Humidity"); - sdi->channels = g_slist_append(sdi->channels, ch); - } + if (mic_devs[idx].has_humidity) + sr_channel_new(sdi, 1, SR_CHANNEL_ANALOG, TRUE, "Humidity"); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); diff --git a/src/hardware/motech-lps-30x/api.c b/src/hardware/motech-lps-30x/api.c index f118ebe3..d54b267c 100644 --- a/src/hardware/motech-lps-30x/api.c +++ b/src/hardware/motech-lps-30x/api.c @@ -470,8 +470,7 @@ static GSList *do_scan(lps_modelid modelid, struct sr_dev_driver *drv, GSList *o /* Setup channels and channel groups. */ for (cnt = 0; cnt < models[modelid].num_channels; cnt++) { snprintf(channel, sizeof(channel), "CH%d", cnt + 1); - ch = sr_channel_new(cnt, SR_CHANNEL_ANALOG, TRUE, channel); - sdi->channels = g_slist_append(sdi->channels, ch); + ch = sr_channel_new(sdi, cnt, SR_CHANNEL_ANALOG, TRUE, channel); devc->channel_status[cnt].info = g_slist_append(NULL, ch); diff --git a/src/hardware/norma-dmm/api.c b/src/hardware/norma-dmm/api.c index 83e11351..174425b7 100644 --- a/src/hardware/norma-dmm/api.c +++ b/src/hardware/norma-dmm/api.c @@ -82,7 +82,6 @@ static GSList *do_scan(struct sr_dev_driver* drv, GSList *options) struct drv_context *drvc; struct dev_context *devc; struct sr_config *src; - struct sr_channel *ch; struct sr_serial_dev_inst *serial; GSList *l, *devices; int len, cnt; @@ -155,8 +154,7 @@ static GSList *do_scan(struct sr_dev_driver* drv, GSList *options) sdi->conn = serial; sdi->priv = devc; sdi->driver = drv; - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"); - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1"); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); break; diff --git a/src/hardware/openbench-logic-sniffer/api.c b/src/hardware/openbench-logic-sniffer/api.c index ca5f4799..487f5b2e 100644 --- a/src/hardware/openbench-logic-sniffer/api.c +++ b/src/hardware/openbench-logic-sniffer/api.c @@ -98,7 +98,6 @@ static GSList *scan(GSList *options) struct sr_dev_inst *sdi; struct drv_context *drvc; struct dev_context *devc; - struct sr_channel *ch; struct sr_serial_dev_inst *serial; GSList *l, *devices; int ret, i; @@ -194,11 +193,9 @@ static GSList *scan(GSList *options) sdi->model = g_strdup("Logic Analyzer"); sdi->version = g_strdup("v1.0"); sdi->driver = di; - for (i = 0; i < 32; i++) { - ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, + for (i = 0; i < 32; i++) + sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, ols_channel_names[i]); - sdi->channels = g_slist_append(sdi->channels, ch); - } devc = ols_dev_new(); sdi->priv = devc; } diff --git a/src/hardware/openbench-logic-sniffer/protocol.c b/src/hardware/openbench-logic-sniffer/protocol.c index b732da59..d9c2c2bb 100644 --- a/src/hardware/openbench-logic-sniffer/protocol.c +++ b/src/hardware/openbench-logic-sniffer/protocol.c @@ -142,7 +142,6 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial) { struct sr_dev_inst *sdi; struct dev_context *devc; - struct sr_channel *ch; uint32_t tmp_int, ui; uint8_t key, type, token; int delay_ms; @@ -215,11 +214,9 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial) switch (token) { case 0x00: /* Number of usable channels */ - for (ui = 0; ui < tmp_int; ui++) { - ch = sr_channel_new(ui, SR_CHANNEL_LOGIC, TRUE, + for (ui = 0; ui < tmp_int; ui++) + sr_channel_new(sdi, ui, SR_CHANNEL_LOGIC, TRUE, ols_channel_names[ui]); - sdi->channels = g_slist_append(sdi->channels, ch); - } break; case 0x01: /* Amount of sample memory available (bytes) */ @@ -253,11 +250,9 @@ SR_PRIV struct sr_dev_inst *get_metadata(struct sr_serial_dev_inst *serial) switch (token) { case 0x00: /* Number of usable channels */ - for (ui = 0; ui < tmp_c; ui++) { - ch = sr_channel_new(ui, SR_CHANNEL_LOGIC, TRUE, + for (ui = 0; ui < tmp_c; ui++) + sr_channel_new(sdi, ui, SR_CHANNEL_LOGIC, TRUE, ols_channel_names[ui]); - sdi->channels = g_slist_append(sdi->channels, ch); - } break; case 0x01: /* protocol version */ diff --git a/src/hardware/pipistrello-ols/protocol.c b/src/hardware/pipistrello-ols/protocol.c index 272c8a8c..1d0c9f20 100644 --- a/src/hardware/pipistrello-ols/protocol.c +++ b/src/hardware/pipistrello-ols/protocol.c @@ -219,7 +219,6 @@ SR_PRIV int pols_convert_trigger(const struct sr_dev_inst *sdi) SR_PRIV struct sr_dev_inst *p_ols_get_metadata(uint8_t *buf, int bytes_read, struct dev_context *devc) { struct sr_dev_inst *sdi; - struct sr_channel *ch; uint32_t tmp_int, ui; uint8_t key, type, token; GString *tmp_str, *devname, *version; @@ -288,11 +287,9 @@ SR_PRIV struct sr_dev_inst *p_ols_get_metadata(uint8_t *buf, int bytes_read, str switch (token) { case 0x00: /* Number of usable channels */ - for (ui = 0; ui < tmp_int; ui++) { - ch = sr_channel_new(ui, SR_CHANNEL_LOGIC, TRUE, + for (ui = 0; ui < tmp_int; ui++) + sr_channel_new(sdi, ui, SR_CHANNEL_LOGIC, TRUE, p_ols_channel_names[ui]); - sdi->channels = g_slist_append(sdi->channels, ch); - } break; case 0x01: /* Amount of sample memory available (bytes) */ @@ -324,11 +321,9 @@ SR_PRIV struct sr_dev_inst *p_ols_get_metadata(uint8_t *buf, int bytes_read, str switch (token) { case 0x00: /* Number of usable channels */ - for (ui = 0; ui < tmp_c; ui++) { - ch = sr_channel_new(ui, SR_CHANNEL_LOGIC, TRUE, + for (ui = 0; ui < tmp_c; ui++) + sr_channel_new(sdi, ui, SR_CHANNEL_LOGIC, TRUE, p_ols_channel_names[ui]); - sdi->channels = g_slist_append(sdi->channels, ch); - } break; case 0x01: /* protocol version */ diff --git a/src/hardware/rigol-ds/api.c b/src/hardware/rigol-ds/api.c index a8f8bcde..5da9a5ea 100644 --- a/src/hardware/rigol-ds/api.c +++ b/src/hardware/rigol-ds/api.c @@ -345,8 +345,7 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) for (i = 0; i < model->analog_channels; i++) { if (!(channel_name = g_strdup_printf("CH%d", i + 1))) return NULL; - ch = sr_channel_new(i, SR_CHANNEL_ANALOG, TRUE, channel_name); - sdi->channels = g_slist_append(sdi->channels, ch); + ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel_name); devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group)); @@ -362,9 +361,8 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) for (i = 0; i < ARRAY_SIZE(devc->digital_channels); i++) { if (!(channel_name = g_strdup_printf("D%d", i))) return NULL; - ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, channel_name); + ch = sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_name); g_free(channel_name); - sdi->channels = g_slist_append(sdi->channels, ch); devc->digital_group->channels = g_slist_append( devc->digital_group->channels, ch); } diff --git a/src/hardware/saleae-logic16/api.c b/src/hardware/saleae-logic16/api.c index f33894ea..cf6063af 100644 --- a/src/hardware/saleae-logic16/api.c +++ b/src/hardware/saleae-logic16/api.c @@ -145,7 +145,6 @@ static GSList *scan(GSList *options) struct dev_context *devc; struct sr_dev_inst *sdi; struct sr_usb_dev_inst *usb; - struct sr_channel *ch; struct sr_config *src; GSList *l, *devices, *conn_devices; struct libusb_device_descriptor des; @@ -206,11 +205,9 @@ static GSList *scan(GSList *options) sdi->driver = di; sdi->connection_id = g_strdup(connection_id); - for (j = 0; channel_names[j]; j++) { - ch = sr_channel_new(j, SR_CHANNEL_LOGIC, TRUE, + for (j = 0; channel_names[j]; j++) + sr_channel_new(sdi, j, SR_CHANNEL_LOGIC, TRUE, channel_names[j]); - sdi->channels = g_slist_append(sdi->channels, ch); - } devc = g_malloc0(sizeof(struct dev_context)); devc->selected_voltage_range = VOLTAGE_RANGE_18_33_V; diff --git a/src/hardware/scpi-pps/api.c b/src/hardware/scpi-pps/api.c index c8070a06..4647031c 100644 --- a/src/hardware/scpi-pps/api.c +++ b/src/hardware/scpi-pps/api.c @@ -133,13 +133,13 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) continue; g_snprintf(ch_name, 16, "%s%s", pci[i].prefix, channels[ch_num].name); - ch = sr_channel_new(ch_idx++, SR_CHANNEL_ANALOG, TRUE, ch_name); + ch = sr_channel_new(sdi, ch_idx++, SR_CHANNEL_ANALOG, TRUE, + ch_name); pch = g_malloc0(sizeof(struct pps_channel)); pch->hw_output_idx = ch_num; pch->hwname = channels[ch_num].name; pch->mq = pci[i].mq; ch->priv = pch; - sdi->channels = g_slist_append(sdi->channels, ch); } } diff --git a/src/hardware/serial-dmm/api.c b/src/hardware/serial-dmm/api.c index 4bbf230f..0387c95a 100644 --- a/src/hardware/serial-dmm/api.c +++ b/src/hardware/serial-dmm/api.c @@ -410,7 +410,6 @@ static GSList *sdmm_scan(const char *conn, const char *serialcomm, int dmm) struct sr_dev_inst *sdi; struct drv_context *drvc; struct dev_context *devc; - struct sr_channel *ch; struct sr_serial_dev_inst *serial; GSList *devices; int dropped, ret; @@ -472,8 +471,7 @@ static GSList *sdmm_scan(const char *conn, const char *serialcomm, int dmm) sdi->conn = serial; sdi->priv = devc; sdi->driver = dmms[dmm].di; - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"); - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1"); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); diff --git a/src/hardware/sysclk-lwla/api.c b/src/hardware/sysclk-lwla/api.c index 1e3dd1d2..959b566d 100644 --- a/src/hardware/sysclk-lwla/api.c +++ b/src/hardware/sysclk-lwla/api.c @@ -79,30 +79,12 @@ static int init(struct sr_context *sr_ctx) return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *gen_channel_list(int num_channels) -{ - GSList *list; - struct sr_channel *ch; - int i; - char name[8]; - - list = NULL; - - for (i = num_channels; i > 0; --i) { - /* The LWLA series simply number channels from CH1 to CHxx. */ - g_snprintf(name, sizeof(name), "CH%d", i); - - ch = sr_channel_new(i - 1, SR_CHANNEL_LOGIC, TRUE, name); - list = g_slist_prepend(list, ch); - } - - return list; -} - static struct sr_dev_inst *dev_inst_new(void) { struct sr_dev_inst *sdi; struct dev_context *devc; + int i; + char name[8]; /* Allocate memory for our private driver context. */ devc = g_malloc0(sizeof(struct dev_context)); @@ -118,7 +100,11 @@ static struct sr_dev_inst *dev_inst_new(void) devc->samplerate = DEFAULT_SAMPLERATE; sdi->priv = devc; - sdi->channels = gen_channel_list(NUM_CHANNELS); + for (i = NUM_CHANNELS; i > 0; --i) { + /* The LWLA series simply number channels from CH1 to CHxx. */ + g_snprintf(name, sizeof(name), "CH%d", i); + sr_channel_new(sdi, i - 1, SR_CHANNEL_LOGIC, TRUE, name); + } return sdi; } diff --git a/src/hardware/teleinfo/api.c b/src/hardware/teleinfo/api.c index 5e1dfba1..c1d9b040 100644 --- a/src/hardware/teleinfo/api.c +++ b/src/hardware/teleinfo/api.c @@ -49,7 +49,6 @@ static GSList *scan(GSList *options) struct dev_context *devc; struct sr_serial_dev_inst *serial; struct sr_dev_inst *sdi; - struct sr_channel *ch; GSList *devices = NULL, *l; const char *conn = NULL, *serialcomm = NULL; uint8_t buf[292]; @@ -103,42 +102,27 @@ static GSList *scan(GSList *options) sdi->priv = devc; sdi->driver = di; - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P"); - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P"); if (devc->optarif == OPTARIF_BASE) { - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "BASE"); - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "BASE"); } else if (devc->optarif == OPTARIF_HC) { - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HP"); - sdi->channels = g_slist_append(sdi->channels, ch); - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HC"); - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "HP"); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "HC"); } else if (devc->optarif == OPTARIF_EJP) { - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HN"); - sdi->channels = g_slist_append(sdi->channels, ch); - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HPM"); - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "HN"); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "HPM"); } else if (devc->optarif == OPTARIF_BBR) { - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HPJB"); - sdi->channels = g_slist_append(sdi->channels, ch); - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HPJW"); - sdi->channels = g_slist_append(sdi->channels, ch); - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HPJR"); - sdi->channels = g_slist_append(sdi->channels, ch); - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HCJB"); - sdi->channels = g_slist_append(sdi->channels, ch); - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HCJW"); - sdi->channels = g_slist_append(sdi->channels, ch); - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "HCJR"); - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "HPJB"); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "HPJW"); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "HPJR"); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "HCJB"); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "HCJW"); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "HCJR"); } - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "IINST"); - sdi->channels = g_slist_append(sdi->channels, ch); - - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "PAPP"); - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "IINST"); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "PAPP"); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); diff --git a/src/hardware/testo/protocol.c b/src/hardware/testo/protocol.c index bdfaf1fd..1505e5bc 100644 --- a/src/hardware/testo/protocol.c +++ b/src/hardware/testo/protocol.c @@ -59,7 +59,6 @@ SR_PRIV int testo_probe_channels(struct sr_dev_inst *sdi) { struct dev_context *devc; struct sr_usb_dev_inst *usb; - struct sr_channel *ch; int unit, packet_len, len, i; unsigned char packet[MAX_REPLY_SIZE], buf[MAX_REPLY_SIZE]; char *probe_name; @@ -136,8 +135,7 @@ SR_PRIV int testo_probe_channels(struct sr_dev_inst *sdi) sr_dbg("Unsupported measurement unit %d", unit); return SR_ERR; } - ch = sr_channel_new(i, SR_CHANNEL_ANALOG, TRUE, probe_name); - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, probe_name); } devc->num_channels = packet[6]; sr_dbg("Found %d channel%s.", devc->num_channels, diff --git a/src/hardware/tondaj-sl-814/api.c b/src/hardware/tondaj-sl-814/api.c index 2ea66ebf..cccaeb1d 100644 --- a/src/hardware/tondaj-sl-814/api.c +++ b/src/hardware/tondaj-sl-814/api.c @@ -51,7 +51,6 @@ static GSList *scan(GSList *options) struct dev_context *devc; struct sr_dev_inst *sdi; struct sr_config *src; - struct sr_channel *ch; GSList *devices, *l; const char *conn, *serialcomm; struct sr_serial_dev_inst *serial; @@ -100,8 +99,7 @@ static GSList *scan(GSList *options) sdi->priv = devc; sdi->driver = di; - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"); - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1"); drvc->instances = g_slist_append(drvc->instances, sdi); devices = g_slist_append(devices, sdi); diff --git a/src/hardware/uni-t-dmm/api.c b/src/hardware/uni-t-dmm/api.c index a34873b4..f7b8a941 100644 --- a/src/hardware/uni-t-dmm/api.c +++ b/src/hardware/uni-t-dmm/api.c @@ -235,7 +235,6 @@ static GSList *scan(GSList *options, int dmm) struct drv_context *drvc; struct sr_usb_dev_inst *usb; struct sr_config *src; - struct sr_channel *ch; const char *conn; drvc = udmms[dmm].di->priv; @@ -268,8 +267,7 @@ static GSList *scan(GSList *options, int dmm) sdi->model = g_strdup(udmms[dmm].device); sdi->priv = devc; sdi->driver = udmms[dmm].di; - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"); - sdi->channels = g_slist_append(sdi->channels, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1"); sdi->inst_type = SR_INST_USB; sdi->conn = usb; drvc->instances = g_slist_append(drvc->instances, sdi); diff --git a/src/hardware/uni-t-ut32x/api.c b/src/hardware/uni-t-ut32x/api.c index aa38cf5f..e67a99e3 100644 --- a/src/hardware/uni-t-ut32x/api.c +++ b/src/hardware/uni-t-ut32x/api.c @@ -53,7 +53,6 @@ static GSList *scan(GSList *options) struct drv_context *drvc; struct dev_context *devc; struct sr_dev_inst *sdi; - struct sr_channel *ch; struct sr_config *src; GSList *usb_devices, *devices, *l; int i; @@ -86,11 +85,8 @@ static GSList *scan(GSList *options) sdi->driver = di; sdi->inst_type = SR_INST_USB; sdi->conn = l->data; - for (i = 0; i < 3; i++) { - ch = sr_channel_new(i, SR_CHANNEL_ANALOG, TRUE, - channels[i]); - sdi->channels = g_slist_append(sdi->channels, ch); - } + for (i = 0; i < 3; i++) + sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channels[i]); devc = g_malloc0(sizeof(struct dev_context)); sdi->priv = devc; devc->limit_samples = 0; diff --git a/src/hardware/victor-dmm/api.c b/src/hardware/victor-dmm/api.c index f2e3d783..2552027c 100644 --- a/src/hardware/victor-dmm/api.c +++ b/src/hardware/victor-dmm/api.c @@ -59,7 +59,6 @@ static GSList *scan(GSList *options) struct drv_context *drvc; struct dev_context *devc; struct sr_dev_inst *sdi; - struct sr_channel *ch; struct libusb_device_descriptor des; libusb_device **devlist; GSList *devices; @@ -92,8 +91,7 @@ static GSList *scan(GSList *options) devc = g_malloc0(sizeof(struct dev_context)); sdi->priv = devc; - ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"); - sdi->channels = g_slist_append(NULL, ch); + sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "P1"); sdi->conn = sr_usb_dev_inst_new(libusb_get_bus_number(devlist[i]), libusb_get_device_address(devlist[i]), NULL); diff --git a/src/hardware/yokogawa-dlm/protocol.c b/src/hardware/yokogawa-dlm/protocol.c index 9f5daf1c..8acaf023 100644 --- a/src/hardware/yokogawa-dlm/protocol.c +++ b/src/hardware/yokogawa-dlm/protocol.c @@ -669,9 +669,8 @@ SR_PRIV int dlm_device_init(struct sr_dev_inst *sdi, int model_index) /* Add analog channels. */ for (i = 0; i < scope_models[model_index].analog_channels; i++) { - ch = sr_channel_new(i, SR_CHANNEL_ANALOG, TRUE, + ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, (*scope_models[model_index].analog_names)[i]); - sdi->channels = g_slist_append(sdi->channels, ch); devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group)); @@ -698,9 +697,8 @@ SR_PRIV int dlm_device_init(struct sr_dev_inst *sdi, int model_index) /* Add digital channels. */ for (i = 0; i < scope_models[model_index].digital_channels; i++) { - ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, + ch = sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, (*scope_models[model_index].digital_names)[i]); - sdi->channels = g_slist_append(sdi->channels, ch); devc->digital_groups[i / 8]->channels = g_slist_append( devc->digital_groups[i / 8]->channels, ch); diff --git a/src/hardware/zeroplus-logic-cube/api.c b/src/hardware/zeroplus-logic-cube/api.c index fa6ef1dc..fd3ef08b 100644 --- a/src/hardware/zeroplus-logic-cube/api.c +++ b/src/hardware/zeroplus-logic-cube/api.c @@ -164,7 +164,6 @@ static int init(struct sr_context *sr_ctx) static GSList *scan(GSList *options) { struct sr_dev_inst *sdi; - struct sr_channel *ch; struct drv_context *drvc; struct dev_context *devc; const struct zp_model *prof; @@ -247,11 +246,9 @@ static GSList *scan(GSList *options) // memset(devc->trigger_buffer, 0, NUM_TRIGGER_STAGES); /* Fill in channellist according to this device's profile. */ - for (j = 0; j < devc->num_channels; j++) { - ch = sr_channel_new(j, SR_CHANNEL_LOGIC, TRUE, + for (j = 0; j < devc->num_channels; j++) + sr_channel_new(sdi, j, SR_CHANNEL_LOGIC, TRUE, channel_names[j]); - sdi->channels = g_slist_append(sdi->channels, ch); - } devices = g_slist_append(devices, sdi); drvc->instances = g_slist_append(drvc->instances, sdi); diff --git a/src/input/binary.c b/src/input/binary.c index f9e49de1..d7080b0b 100644 --- a/src/input/binary.c +++ b/src/input/binary.c @@ -39,7 +39,6 @@ struct context { static int init(struct sr_input *in, GHashTable *options) { - struct sr_channel *ch; struct context *inc; int num_channels, i; char name[16]; @@ -57,8 +56,7 @@ static int init(struct sr_input *in, GHashTable *options) for (i = 0; i < num_channels; i++) { snprintf(name, 16, "%d", i); - ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, name); - in->sdi->channels = g_slist_append(in->sdi->channels, ch); + sr_channel_new(in->sdi, i, SR_CHANNEL_LOGIC, TRUE, name); } return SR_OK; diff --git a/src/input/chronovu_la8.c b/src/input/chronovu_la8.c index c28f0e0a..244abf19 100644 --- a/src/input/chronovu_la8.c +++ b/src/input/chronovu_la8.c @@ -51,7 +51,6 @@ static int format_match(GHashTable *metadata) static int init(struct sr_input *in, GHashTable *options) { - struct sr_channel *ch; struct context *inc; int num_channels, i; char name[16]; @@ -69,8 +68,7 @@ static int init(struct sr_input *in, GHashTable *options) for (i = 0; i < num_channels; i++) { snprintf(name, 16, "%d", i); - ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, name); - in->sdi->channels = g_slist_append(in->sdi->channels, ch); + sr_channel_new(in->sdi, i, SR_CHANNEL_LOGIC, TRUE, name); } return SR_OK; diff --git a/src/input/csv.c b/src/input/csv.c index e89f99aa..47fee73e 100644 --- a/src/input/csv.c +++ b/src/input/csv.c @@ -472,7 +472,6 @@ static char *get_line_termination(GString *buf) static int initial_parse(const struct sr_input *in, GString *buf) { struct context *inc; - struct sr_channel *ch; GString *channel_name; gsize num_columns, l, i; unsigned int line_number; @@ -558,8 +557,7 @@ static int initial_parse(const struct sr_input *in, GString *buf) g_string_assign(channel_name, columns[i]); else g_string_printf(channel_name, "%zu", i); - ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, channel_name->str); - in->sdi->channels = g_slist_append(in->sdi->channels, ch); + sr_channel_new(in->sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_name->str); } g_string_free(channel_name, TRUE); diff --git a/src/input/vcd.c b/src/input/vcd.c index f1d0b06c..e69a8071 100644 --- a/src/input/vcd.c +++ b/src/input/vcd.c @@ -404,7 +404,6 @@ static void parse_contents(const struct sr_input *in, char *data) static int init(struct sr_input *in, GHashTable *options) { - struct sr_channel *ch; int num_channels, i; char name[16]; struct context *inc; @@ -434,8 +433,7 @@ static int init(struct sr_input *in, GHashTable *options) for (i = 0; i < num_channels; i++) { snprintf(name, 16, "%d", i); - ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, name); - in->sdi->channels = g_slist_append(in->sdi->channels, ch); + sr_channel_new(in->sdi, i, SR_CHANNEL_LOGIC, TRUE, name); } return SR_OK; diff --git a/src/input/wav.c b/src/input/wav.c index da5a3d5f..0c23010e 100644 --- a/src/input/wav.c +++ b/src/input/wav.c @@ -240,7 +240,6 @@ static int process_buffer(struct sr_input *in) struct context *inc; struct sr_datafeed_packet packet; struct sr_datafeed_meta meta; - struct sr_channel *ch; struct sr_config *src; int offset, chunk_samples, total_samples, processed, max_chunk_samples; int num_samples, i; @@ -250,8 +249,7 @@ static int process_buffer(struct sr_input *in) if (!inc->started) { for (i = 0; i < inc->num_channels; i++) { snprintf(channelname, 8, "CH%d", i + 1); - ch = sr_channel_new(i, SR_CHANNEL_ANALOG, TRUE, channelname); - in->sdi->channels = g_slist_append(in->sdi->channels, ch); + sr_channel_new(in->sdi, i, SR_CHANNEL_ANALOG, TRUE, channelname); } std_session_send_df_header(in->sdi, LOG_PREFIX); diff --git a/src/lcr/es51919.c b/src/lcr/es51919.c index 86237412..c6fddc11 100644 --- a/src/lcr/es51919.c +++ b/src/lcr/es51919.c @@ -792,16 +792,6 @@ static int receive_data(int fd, int revents, void *cb_data) return TRUE; } -static int add_channel(struct sr_dev_inst *sdi, int idx, const char *name) -{ - struct sr_channel *ch; - - ch = sr_channel_new(idx, SR_CHANNEL_ANALOG, TRUE, name); - sdi->channels = g_slist_append(sdi->channels, ch); - - return SR_OK; -} - static const char *const channel_names[] = { "P1", "P2" }; static int setup_channels(struct sr_dev_inst *sdi) @@ -811,11 +801,8 @@ static int setup_channels(struct sr_dev_inst *sdi) ret = SR_ERR_BUG; - for (i = 0; i < ARRAY_SIZE(channel_names); i++) { - ret = add_channel(sdi, i, channel_names[i]); - if (ret != SR_OK) - break; - } + for (i = 0; i < ARRAY_SIZE(channel_names); i++) + sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel_names[i]); return ret; } diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index 574497c1..e6f2dbe2 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -589,8 +589,8 @@ enum { SR_CHANNEL_SET_ENABLED = 1 << 0, }; -SR_PRIV struct sr_channel *sr_channel_new(int index, int type, - gboolean enabled, const char *name); +SR_PRIV struct sr_channel *sr_channel_new(struct sr_dev_inst *sdi, + int index, int type, gboolean enabled, const char *name); /** Device instance data */ struct sr_dev_inst { diff --git a/src/session_file.c b/src/session_file.c index 26c0df7a..e27ed85c 100644 --- a/src/session_file.c +++ b/src/session_file.c @@ -122,7 +122,6 @@ SR_API int sr_session_load(const char *filename, struct sr_session **session) struct zip_file *zf; struct zip_stat zs; struct sr_dev_inst *sdi; - struct sr_channel *ch; int ret, i, j; uint64_t tmp_u64, total_channels, p; char **sections, **keys, *metafile, *val; @@ -212,9 +211,8 @@ SR_API int sr_session_load(const char *filename, struct sr_session **session) g_variant_new_uint64(total_channels), sdi, NULL); for (p = 0; p < total_channels; p++) { snprintf(channelname, SR_MAX_CHANNELNAME_LEN, "%" PRIu64, p); - ch = sr_channel_new(p, SR_CHANNEL_LOGIC, FALSE, + sr_channel_new(sdi, p, SR_CHANNEL_LOGIC, FALSE, channelname); - sdi->channels = g_slist_append(sdi->channels, ch); } } else if (!strncmp(keys[j], "probe", 5)) { if (!sdi) {