]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
ctl: elem_id: add an API to check whether two instances indicates the same element
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Sun, 22 Dec 2019 02:05:29 +0000 (11:05 +0900)
committer坂本 貴史 <o-takashi@sakamocchi.jp>
Sat, 28 Dec 2019 04:16:48 +0000 (13:16 +0900)
It's convenient for users to check whether two instances of elem_id
indicates the same element. This commit adds an API to satisfy the
convenience.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
src/ctl/alsactl.map
src/ctl/elem-id.c
src/ctl/elem-id.h
tests/alsactl-elem-id

index b88de5504785cfcf749cb469ef12a9f252d66fbf..37268cfc926bcdaa8ee0b4b6a89592bee28cc0eb 100644 (file)
@@ -40,6 +40,7 @@ ALSA_GOBJECT_0_0_0 {
     "alsactl_elem_id_get_subdevice_id";
     "alsactl_elem_id_get_name";
     "alsactl_elem_id_get_index";
+    "alsactl_elem_id_equal";
 
     "alsactl_elem_info_get_type";
 
index b598e917fa9cbf1158add95ed04f653c6a08d2f2..79c70175c24418e55f2dc42fcf44d0e92dbca6ba 100644 (file)
@@ -129,3 +129,25 @@ void alsactl_elem_id_get_index(const ALSACtlElemId *self, guint *index)
 {
     *index = self->index;
 }
+
+/**
+ * alsactl_elem_id_equal:
+ * @self: A #ALSACtlElemId.
+ * @target: A #ALSACtlElemId to compare.
+ *
+ * Returns: whether the given object indicates the same element.
+ */
+gboolean alsactl_elem_id_equal(const ALSACtlElemId *self,
+                               const ALSACtlElemId *target) {
+    const struct snd_ctl_elem_id *lhs, *rhs;
+
+    lhs = (const struct snd_ctl_elem_id *)self;
+    rhs = (const struct snd_ctl_elem_id *)target;
+
+    return lhs->numid == rhs->numid ||
+           (lhs->iface == rhs->iface &&
+            lhs->device == rhs->device &&
+            lhs->subdevice == rhs->subdevice &&
+            !strcmp((const char *)lhs->name, (const char *)rhs->name) &&
+            lhs->index == rhs->index);
+}
index 748234868fb792b402ee1714f4740c2cc29c08ae..b20f5819421880b497e7c0d0ebea2a274acea54b 100644 (file)
@@ -31,6 +31,9 @@ void alsactl_elem_id_get_subdevice_id(const ALSACtlElemId *self,
 void alsactl_elem_id_get_name(const ALSACtlElemId *self, const gchar **name);
 void alsactl_elem_id_get_index(const ALSACtlElemId *self, guint *index);
 
+gboolean alsactl_elem_id_equal(const ALSACtlElemId *self,
+                               const ALSACtlElemId *target);
+
 G_END_DECLS
 
 #endif
index 454ff9dfe6958a1167d2771ed29fa34aac6fa216..08f6b1eeeda784c6dfa26692c04c90d99c42c10b 100644 (file)
@@ -18,6 +18,7 @@ methods = (
     'get_subdevice',
     'get_name',
     'get_index',
+    'equals',
 )
 signals = ()