]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
ctl: elem_value: add an API to check whether two instances have the same values
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Sun, 22 Dec 2019 02:02:34 +0000 (11:02 +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_value
have the same values. 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-value.c
src/ctl/elem-value.h
tests/alsactl-elem-value

index 37268cfc926bcdaa8ee0b4b6a89592bee28cc0eb..626071dcb46b782b3116c4a4aa090c22a5061e5b 100644 (file)
@@ -76,6 +76,7 @@ ALSA_GOBJECT_0_0_0 {
     "alsactl_elem_value_get_iec60958";
     "alsactl_elem_value_set_int64";
     "alsactl_elem_value_get_int64";
+    "alsactl_elem_value_equal";
   local:
     *;
 };
index 5c3b6389e685b480d65f7ec14f962fadff777996..2a36d4a79893b0056ddcea3c4ff68e330ddf3932 100644 (file)
@@ -398,3 +398,23 @@ void alsactl_elem_value_get_int64(ALSACtlElemValue *self,
     for (i = 0; i < *value_count; ++i)
         (*values)[i] = (gint64)value->value.integer64.value[i];
 }
+
+/**
+ * alsactl_elem_value_equal:
+ * @self: A #ALSACtlElemValue.
+ * @target: A #ALSACtlElemValue to compare.
+ *
+ * Returns: whether the given object includes the same values as the instance.
+ *          The other fields are ignored to be compared.
+ */
+gboolean alsactl_elem_value_equal(const ALSACtlElemValue *self,
+                                  const ALSACtlElemValue *target) {
+    const ALSACtlElemValuePrivate *lhs, *rhs;
+
+    g_return_val_if_fail(ALSACTL_IS_ELEM_VALUE(self), FALSE);
+    g_return_val_if_fail(ALSACTL_IS_ELEM_VALUE(target), FALSE);
+    lhs = alsactl_elem_value_get_instance_private((ALSACtlElemValue *)self);
+    rhs = alsactl_elem_value_get_instance_private((ALSACtlElemValue *)target);
+
+    return !memcmp(&lhs->value, &rhs->value, sizeof(lhs->value));
+}
index fcbd30ad91078eb5f87c128ecb05ff305ebf65c4..cf7e14bf7bf6a2edb61c5ff7dd43970fb082f4a1 100644 (file)
@@ -81,6 +81,9 @@ void alsactl_elem_value_set_int64(ALSACtlElemValue *self, const gint64 *values,
 void alsactl_elem_value_get_int64(ALSACtlElemValue *self,
                                   gint64 *const *values, gsize *value_count);
 
+gboolean alsactl_elem_value_equal(const ALSACtlElemValue *self,
+                                  const ALSACtlElemValue *target);
+
 G_END_DECLS
 
 #endif
index 62d071ebe6b3f66d5be13a1d35a637a12db71394..119fb1422aa9da3697a6e21d8b35047698f0eada 100644 (file)
@@ -27,6 +27,7 @@ methods = (
     'get_iec60958',
     'set_int64',
     'get_int64',
+    'equal',
 )
 signals = ()