-From eeac836f256fe07004d67e13c3c89532982af9bd Mon Sep 17 00:00:00 2001
-From: Richard Hughes <richard@hughsie.com>
-Date: Mon, 20 Jul 2015 10:57:28 +0100
-Subject: [PATCH] Allow creating devices with the same device ID from different
- users
-
----
- src/cd-device-array.c | 13 ++++++++-----
- src/cd-device-array.h | 9 ++++++++-
- src/cd-main.c | 15 ++++++++++-----
- src/cd-self-test.c | 7 +++++--
- 4 files changed, 31 insertions(+), 13 deletions(-)
-
-diff --git a/src/cd-device-array.c b/src/cd-device-array.c
-index 88d4b2c..41a9597 100644
---- a/src/cd-device-array.c
-+++ b/src/cd-device-array.c
-@@ -76,7 +76,8 @@ cd_device_array_remove (CdDeviceArray *device_array, CdDevice *device)
- CdDevice *
- cd_device_array_get_by_id_owner (CdDeviceArray *device_array,
- const gchar *id,
-- guint owner)
-+ guint owner,
-+ CdDeviceArrayFlags flags)
- {
- CdDeviceArrayPrivate *priv = device_array->priv;
- CdDevice *device_tmp;
-@@ -90,10 +91,12 @@ cd_device_array_get_by_id_owner (CdDeviceArray *device_array,
- if (g_strcmp0 (cd_device_get_id (device_tmp), id) == 0)
- return g_object_ref (device_tmp);
- }
-- for (i = 0; i < priv->array->len; i++) {
-- device_tmp = g_ptr_array_index (priv->array, i);
-- if (g_strcmp0 (cd_device_get_id (device_tmp), id) == 0)
-- return g_object_ref (device_tmp);
-+ if (flags & CD_DEVICE_ARRAY_FLAG_OWNER_OPTIONAL) {
-+ for (i = 0; i < priv->array->len; i++) {
-+ device_tmp = g_ptr_array_index (priv->array, i);
-+ if (g_strcmp0 (cd_device_get_id (device_tmp), id) == 0)
-+ return g_object_ref (device_tmp);
-+ }
- }
- return NULL;
- }
-diff --git a/src/cd-device-array.h b/src/cd-device-array.h
-index b625dbf..31dc067 100644
---- a/src/cd-device-array.h
-+++ b/src/cd-device-array.h
-@@ -50,6 +50,12 @@ struct _CdDeviceArrayClass
- GObjectClass parent_class;
- };
-
-+typedef enum {
-+ CD_DEVICE_ARRAY_FLAG_NONE = 0,
-+ CD_DEVICE_ARRAY_FLAG_OWNER_OPTIONAL = 1,
-+ CD_DEVICE_ARRAY_FLAG_LAST,
-+} CdDeviceArrayFlags;
-+
- GType cd_device_array_get_type (void);
- CdDeviceArray *cd_device_array_new (void);
-
-@@ -59,7 +65,8 @@ void cd_device_array_remove (CdDeviceArray *device_array,
- CdDevice *device);
- CdDevice *cd_device_array_get_by_id_owner (CdDeviceArray *device_array,
- const gchar *id,
-- guint owner);
-+ guint owner,
-+ CdDeviceArrayFlags flags);
- CdDevice *cd_device_array_get_by_object_path (CdDeviceArray *device_array,
- const gchar *object_path);
- CdDevice *cd_device_array_get_by_property (CdDeviceArray *device_array,
-diff --git a/src/cd-main.c b/src/cd-main.c
-index b5b3a4f..37817e3 100644
---- a/src/cd-main.c
-+++ b/src/cd-main.c
-@@ -720,7 +720,8 @@ cd_main_profile_auto_add_from_db (CdMainPrivate *priv,
- device_id_tmp = g_ptr_array_index (array, i);
- device_tmp = cd_device_array_get_by_id_owner (priv->devices_array,
- device_id_tmp,
-- cd_profile_get_owner (profile));
-+ cd_profile_get_owner (profile),
-+ CD_DEVICE_ARRAY_FLAG_OWNER_OPTIONAL);
- if (device_tmp == NULL)
- continue;
-
-@@ -747,7 +748,8 @@ cd_main_profile_auto_add_from_md (CdMainPrivate *priv,
- return;
- device = cd_device_array_get_by_id_owner (priv->devices_array,
- device_id,
-- cd_profile_get_owner (profile));
-+ cd_profile_get_owner (profile),
-+ CD_DEVICE_ARRAY_FLAG_OWNER_OPTIONAL);
- if (device == NULL)
- return;
- cd_main_auto_add_from_md (priv, device, profile);
-@@ -1022,7 +1024,8 @@ cd_main_daemon_method_call (GDBusConnection *connection, const gchar *sender,
- sender, device_id);
- device = cd_device_array_get_by_id_owner (priv->devices_array,
- device_id,
-- uid);
-+ uid,
-+ CD_DEVICE_ARRAY_FLAG_OWNER_OPTIONAL);
- if (device == NULL) {
- g_dbus_method_invocation_return_error (invocation,
- CD_CLIENT_ERROR,
-@@ -1279,7 +1282,8 @@ cd_main_daemon_method_call (GDBusConnection *connection, const gchar *sender,
- }
- device = cd_device_array_get_by_id_owner (priv->devices_array,
- device_id,
-- uid);
-+ uid,
-+ CD_DEVICE_ARRAY_FLAG_NONE);
- if (device != NULL) {
- /* where we try to manually add an existing
- * virtual device, which means promoting it to
-@@ -1399,7 +1403,8 @@ cd_main_daemon_method_call (GDBusConnection *connection, const gchar *sender,
- sender, device_id);
- device = cd_device_array_get_by_id_owner (priv->devices_array,
- device_id,
-- uid);
-+ uid,
-+ CD_DEVICE_ARRAY_FLAG_OWNER_OPTIONAL);
- if (device == NULL) {
- /* fall back to checking the object path */
- device = cd_device_array_get_by_object_path (priv->devices_array,
-diff --git a/src/cd-self-test.c b/src/cd-self-test.c
-index 4a76d07..6536d3c 100644
---- a/src/cd-self-test.c
-+++ b/src/cd-self-test.c
-@@ -178,10 +178,13 @@ colord_device_array_func (void)
- cd_device_array_add (device_array, device);
- g_object_unref (device);
-
-- device = cd_device_array_get_by_id_owner (device_array, "does not exist", 0);
-+ device = cd_device_array_get_by_id_owner (device_array, "does not exist", 0, CD_DEVICE_ARRAY_FLAG_OWNER_OPTIONAL);
- g_assert (device == NULL);
-
-- device = cd_device_array_get_by_id_owner (device_array, "dave", 0);
-+ device = cd_device_array_get_by_id_owner (device_array, "dave", 999, CD_DEVICE_ARRAY_FLAG_NONE);
-+ g_assert (device == NULL);
-+
-+ device = cd_device_array_get_by_id_owner (device_array, "dave", 0, CD_DEVICE_ARRAY_FLAG_OWNER_OPTIONAL);
- g_assert (device != NULL);
- g_assert_cmpstr (cd_device_get_id (device), ==, "dave");
- g_object_unref (device);
---
-2.4.3
-