From ea3b58c2cd3570afb0e9e6766c7360618364be6c Mon Sep 17 00:00:00 2001
From: Julian Bouzas <julian.bouzas@collabora.com>
Date: Tue, 19 Nov 2019 14:21:42 -0500
Subject: [PATCH] properties: add wp_properties_matches API

---
 lib/wp/properties.c | 21 +++++++++++++++++++++
 lib/wp/properties.h |  1 +
 2 files changed, 22 insertions(+)

diff --git a/lib/wp/properties.c b/lib/wp/properties.c
index e06b69fc..448c9caa 100644
--- a/lib/wp/properties.c
+++ b/lib/wp/properties.c
@@ -262,3 +262,24 @@ wp_properties_to_pw_properties (WpProperties * self)
 
   return pw_properties_new_dict (wp_properties_peek_dict (self));
 }
+
+gboolean
+wp_properties_matches (WpProperties * self, WpProperties *other)
+{
+  const struct spa_dict * dict;
+  const struct spa_dict_item *item;
+  const gchar *value;
+
+  g_return_val_if_fail (self != NULL, FALSE);
+
+  /* Check if the property vakues matches the ones from 'other' */
+  dict = wp_properties_peek_dict (self);
+  spa_dict_for_each(item, dict) {
+    value = wp_properties_get (other, item->key);
+    if (value && g_strcmp0 (item->value, value) != 0)
+      return FALSE;
+  }
+
+  return TRUE;
+}
+
diff --git a/lib/wp/properties.h b/lib/wp/properties.h
index 553f937a..b41b4e98 100644
--- a/lib/wp/properties.h
+++ b/lib/wp/properties.h
@@ -57,6 +57,7 @@ gint wp_properties_setf_valist (WpProperties * self, const gchar * key,
 
 const struct spa_dict * wp_properties_peek_dict (WpProperties * self);
 struct pw_properties * wp_properties_to_pw_properties (WpProperties * self);
+gboolean wp_properties_matches (WpProperties * self, WpProperties *other);
 
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (WpProperties, wp_properties_unref)
 
-- 
GitLab