From 86341d140e6d36b61f9630c96a28e7948547beba Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Sun, 22 Dec 2019 11:02:34 +0900 Subject: [PATCH] ctl: elem_value: add an API to check whether two instances have the same values 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 --- src/ctl/alsactl.map | 1 + src/ctl/elem-value.c | 20 ++++++++++++++++++++ src/ctl/elem-value.h | 3 +++ tests/alsactl-elem-value | 1 + 4 files changed, 25 insertions(+) diff --git a/src/ctl/alsactl.map b/src/ctl/alsactl.map index 37268cf..626071d 100644 --- a/src/ctl/alsactl.map +++ b/src/ctl/alsactl.map @@ -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: *; }; diff --git a/src/ctl/elem-value.c b/src/ctl/elem-value.c index 5c3b638..2a36d4a 100644 --- a/src/ctl/elem-value.c +++ b/src/ctl/elem-value.c @@ -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)); +} diff --git a/src/ctl/elem-value.h b/src/ctl/elem-value.h index fcbd30a..cf7e14b 100644 --- a/src/ctl/elem-value.h +++ b/src/ctl/elem-value.h @@ -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 diff --git a/tests/alsactl-elem-value b/tests/alsactl-elem-value index 62d071e..119fb14 100644 --- a/tests/alsactl-elem-value +++ b/tests/alsactl-elem-value @@ -27,6 +27,7 @@ methods = ( 'get_iec60958', 'set_int64', 'get_int64', + 'equal', ) signals = () -- 2.47.3