ch->index = index;
ch->type = type;
ch->enabled = enabled;
- if (name)
+ if (name && *name)
ch->name = g_strdup(name);
sdi->channels = g_slist_append(sdi->channels, ch);
}
/**
- * Wrapper around @ref sr_channel_free(), suitable for glib iterators.
+ * Wrapper around sr_channel_free(), suitable for glib iterators.
+ *
+ * @private
*/
SR_PRIV void sr_channel_free_cb(void *p)
{
{
if (!channel)
return SR_ERR_ARG;
+ if (!name || !*name)
+ return SR_ERR_ARG;
g_free(channel->name);
channel->name = g_strdup(name);
* @param[in] ch1 First channel.
* @param[in] ch2 Second channel.
*
- * @return #TRUE upon differences or unexpected input, #FALSE otherwise.
+ * @return TRUE upon differences or unexpected input, FALSE otherwise.
*
- * @internal
+ * @private
*/
SR_PRIV gboolean sr_channels_differ(struct sr_channel *ch1, struct sr_channel *ch2)
{
* @param[in] l1 First channel list.
* @param[in] l2 Second channel list.
*
- * @return #TRUE upon differences or unexpected input, #FALSE otherwise.
+ * @return TRUE upon differences or unexpected input, FALSE otherwise.
*
- * @internal
+ * @private
*/
SR_PRIV gboolean sr_channel_lists_differ(GSList *l1, GSList *l2)
{
return FALSE;
}
+/**
+ * Allocate and initialize a new channel group, and add it to sdi.
+ *
+ * @param[in] sdi The device instance the channel group is connected to.
+ * Optional, can be NULL.
+ * @param[in] name @copydoc sr_channel_group::name
+ * @param[in] priv @copydoc sr_channel_group::priv
+ *
+ * @return A pointer to a new struct sr_channel_group, NULL upon error.
+ *
+ * @private
+ */
+SR_PRIV struct sr_channel_group *sr_channel_group_new(struct sr_dev_inst *sdi,
+ const char *name, void *priv)
+{
+ struct sr_channel_group *cg;
+
+ cg = g_malloc0(sizeof(*cg));
+ if (name && *name)
+ cg->name = g_strdup(name);
+ cg->priv = priv;
+
+ if (sdi)
+ sdi->channel_groups = g_slist_append(sdi->channel_groups, cg);
+
+ return cg;
+}
+
+/**
+ * Release a previously allocated struct sr_channel_group.
+ *
+ * @param[in] cg Pointer to struct sr_channel_group.
+ *
+ * @private
+ */
+SR_PRIV void sr_channel_group_free(struct sr_channel_group *cg)
+{
+ if (!cg)
+ return;
+
+ g_free(cg->name);
+ g_slist_free(cg->channels);
+ g_free(cg->priv);
+ g_free(cg);
+}
+
+/**
+ * Wrapper around sr_channel_group_free(), suitable for glib iterators.
+ *
+ * @private
+ */
+SR_PRIV void sr_channel_group_free_cb(void *cg)
+{
+ return sr_channel_group_free(cg);
+}
+
/**
* Determine whether the specified device instance has the specified
* capability.
/**
* Add a new channel to the specified device instance.
*
+ * @param[in] sdi Device instance to use. Must not be NULL.
* @param[in] index @copydoc sr_channel::index
* @param[in] type @copydoc sr_channel::type
* @param[in] name @copydoc sr_channel::name
if (!sdi || sdi->inst_type != SR_INST_USER || index < 0)
return SR_ERR_ARG;
- sr_channel_new(sdi, index, type, TRUE, name);
+ if (!sr_channel_new(sdi, index, type, TRUE, name))
+ return SR_ERR_DATA;
return SR_OK;
}
SR_PRIV void sr_dev_inst_free(struct sr_dev_inst *sdi)
{
struct sr_channel *ch;
- struct sr_channel_group *cg;
GSList *l;
if (!sdi)
sr_channel_free(ch);
}
g_slist_free(sdi->channels);
-
- for (l = sdi->channel_groups; l; l = l->next) {
- cg = l->data;
- g_free(cg->name);
- g_slist_free(cg->channels);
- g_free(cg->priv);
- g_free(cg);
- }
- g_slist_free(sdi->channel_groups);
+ g_slist_free_full(sdi->channel_groups, sr_channel_group_free_cb);
if (sdi->session)
sr_session_dev_remove(sdi->session, sdi);
g_free(usb);
}
+/**
+ * Wrapper for g_slist_free_full() convenience.
+ *
+ * @private
+ */
+SR_PRIV void sr_usb_dev_inst_free_cb(gpointer p)
+{
+ sr_usb_dev_inst_free(p);
+}
#endif
-#ifdef HAVE_LIBSERIALPORT
+#ifdef HAVE_SERIAL_COMM
/**
* Allocate and init a struct for a serial device instance.
struct libusb_device **devlist;
#endif
-#ifdef HAVE_LIBSERIALPORT
+#ifdef HAVE_SERIAL_COMM
struct sr_serial_dev_inst *serial;
#endif
if (!sdi)
return NULL;
-#ifdef HAVE_LIBSERIALPORT
+#ifdef HAVE_SERIAL_COMM
if ((!sdi->connection_id) && (sdi->inst_type == SR_INST_SERIAL)) {
/* connection_id isn't populated, let's do that for serial devices. */