summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2011-03-31 11:14:51 +0100
committerRichard Hughes <richard@hughsie.com>2011-03-31 11:14:51 +0100
commit2c18669e95b2e2004599346cc9f5f23eeaebbf1c (patch)
tree8159f9e1825a9bd602a6dca9dc8de58cdc4513d0
parent0b65b15e1eb3335d4163b3ecced2c21c0ee25286 (diff)
downloadcolord-2c18669e95b2e2004599346cc9f5f23eeaebbf1c.tar.gz
Add a 'Metadata' property to the device object
Any properties not interstood by colord will be added as dictionary values to this property.
-rw-r--r--client/cd-util.c16
-rw-r--r--libcolord/cd-device.c76
-rw-r--r--libcolord/cd-device.h3
-rw-r--r--libcolord/cd-self-test.c6
-rw-r--r--src/cd-device.c53
-rw-r--r--src/org.freedesktop.ColorManager.Device.xml12
-rw-r--r--src/org.freedesktop.ColorManager.xml5
7 files changed, 165 insertions, 6 deletions
diff --git a/client/cd-util.c b/client/cd-util.c
index f128107..2e36b9e 100644
--- a/client/cd-util.c
+++ b/client/cd-util.c
@@ -119,6 +119,8 @@ static void
cd_util_show_device (CdDevice *device)
{
CdProfile *profile_tmp;
+ GHashTable *metadata;
+ GList *list, *l;
GPtrArray *profiles;
guint i;
@@ -177,6 +179,20 @@ cd_util_show_device (CdDevice *device)
i+1,
cd_profile_get_object_path (profile_tmp));
}
+
+ /* list all the items of metadata */
+ metadata = cd_device_get_metadata (device);
+ list = g_hash_table_get_keys (metadata);
+ for (l = list; l != NULL; l = l->next) {
+ /* TRANSLATORS: the metadata for the device */
+ g_print ("%s:\t%s=%s\n",
+ _("Metadata"),
+ (const gchar *) l->data,
+ (const gchar *) g_hash_table_lookup (metadata,
+ l->data));
+ }
+ g_list_free (list);
+ g_hash_table_unref (metadata);
}
/**
diff --git a/libcolord/cd-device.c b/libcolord/cd-device.c
index 30905f4..f25faeb 100644
--- a/libcolord/cd-device.c
+++ b/libcolord/cd-device.c
@@ -64,6 +64,7 @@ struct _CdDevicePrivate
CdDeviceKind kind;
CdColorspace colorspace;
CdDeviceMode mode;
+ GHashTable *metadata;
};
enum {
@@ -345,6 +346,66 @@ out:
}
/**
+ * cd_device_get_metadata:
+ * @device: a #CdDevice instance.
+ *
+ * Returns the device metadata.
+ *
+ * Return value: a #GHashTable, free with g_hash_table_unref().
+ *
+ * Since: 0.1.5
+ **/
+GHashTable *
+cd_device_get_metadata (CdDevice *device)
+{
+ g_return_val_if_fail (CD_IS_DEVICE (device), NULL);
+ return g_hash_table_ref (device->priv->metadata);
+}
+
+/**
+ * cd_device_get_metadata_item:
+ * @device: a #CdDevice instance.
+ * @key: a key for the metadata dictionary
+ *
+ * Returns the device metadata for a specific key.
+ *
+ * Return value: the metadata value, or %NULL if not set.
+ *
+ * Since: 0.1.5
+ **/
+const gchar *
+cd_device_get_metadata_item (CdDevice *device, const gchar *key)
+{
+ g_return_val_if_fail (CD_IS_DEVICE (device), NULL);
+ return g_hash_table_lookup (device->priv->metadata, key);
+}
+
+/**
+ * cd_device_set_metadata_from_variant:
+ **/
+static void
+cd_device_set_metadata_from_variant (CdDevice *device, GVariant *variant)
+{
+ GVariantIter *iter = NULL;
+ const gchar *prop_key;
+ const gchar *prop_value;
+
+ /* remove old entries */
+ g_hash_table_remove_all (device->priv->metadata);
+
+ /* insert the new metadata */
+ g_variant_get (variant, "a{ss}",
+ &iter);
+ while (g_variant_iter_loop (iter, "{ss}",
+ &prop_key, &prop_value)) {
+ g_hash_table_insert (device->priv->metadata,
+ g_strdup (prop_key),
+ g_strdup (prop_value));
+
+ }
+}
+
+/**
* cd_device_dbus_properties_changed:
**/
static void
@@ -392,6 +453,8 @@ cd_device_dbus_properties_changed (GDBusProxy *proxy,
device->priv->created = g_variant_get_uint64 (property_value);
} else if (g_strcmp0 (property_name, "Modified") == 0) {
device->priv->modified = g_variant_get_uint64 (property_value);
+ } else if (g_strcmp0 (property_name, "Metadata") == 0) {
+ cd_device_set_metadata_from_variant (device, property_value);
} else if (g_strcmp0 (property_name, "DeviceId") == 0) {
/* ignore this, we don't support it changing */;
} else {
@@ -453,6 +516,7 @@ cd_device_set_object_path_sync (CdDevice *device,
GVariant *colorspace = NULL;
GVariant *mode = NULL;
GVariant *profiles = NULL;
+ GVariant *metadata = NULL;
g_return_val_if_fail (CD_IS_DEVICE (device), FALSE);
g_return_val_if_fail (device->priv->proxy == NULL, FALSE);
@@ -549,6 +613,12 @@ cd_device_set_object_path_sync (CdDevice *device,
if (!ret)
goto out;
+ /* get metadata */
+ metadata = g_dbus_proxy_get_cached_property (device->priv->proxy,
+ "Metadata");
+ if (metadata != NULL)
+ cd_device_set_metadata_from_variant (device, metadata);
+
/* get signals from DBus */
g_signal_connect (device->priv->proxy,
"g-signal",
@@ -585,6 +655,8 @@ out:
g_variant_unref (kind);
if (profiles != NULL)
g_variant_unref (profiles);
+ if (metadata != NULL)
+ g_variant_unref (metadata);
return ret;
}
@@ -1458,6 +1530,10 @@ cd_device_init (CdDevice *device)
{
device->priv = CD_DEVICE_GET_PRIVATE (device);
device->priv->profiles = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
+ device->priv->metadata = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ g_free,
+ g_free);
}
/*
diff --git a/libcolord/cd-device.h b/libcolord/cd-device.h
index a9dbc87..d39cfcc 100644
--- a/libcolord/cd-device.h
+++ b/libcolord/cd-device.h
@@ -150,6 +150,9 @@ CdDeviceMode cd_device_get_mode (CdDevice *device);
GPtrArray *cd_device_get_profiles (CdDevice *device);
CdProfile *cd_device_get_default_profile (CdDevice *device);
const gchar *cd_device_get_object_path (CdDevice *device);
+GHashTable *cd_device_get_metadata (CdDevice *device);
+const gchar *cd_device_get_metadata_item (CdDevice *device,
+ const gchar *key);
G_END_DECLS
diff --git a/libcolord/cd-self-test.c b/libcolord/cd-self-test.c
index f8b5048..1cce145 100644
--- a/libcolord/cd-self-test.c
+++ b/libcolord/cd-self-test.c
@@ -175,6 +175,9 @@ colord_client_func (void)
g_hash_table_insert (device_props,
g_strdup ("Model"),
g_strdup ("3000"));
+ g_hash_table_insert (device_props,
+ g_strdup ("XRANDR_name"),
+ g_strdup ("lvds1"));
device = cd_client_create_device_sync (client,
device_id,
CD_OBJECT_SCOPE_TEMP,
@@ -238,6 +241,9 @@ colord_client_func (void)
/* check device serial */
g_assert_cmpstr (cd_device_get_serial (device), ==, "0001");
+ /* check device metadata item */
+ g_assert_cmpstr (cd_device_get_metadata_item (device, "XRANDR_name"), ==, "lvds1");
+
/* check device kind */
g_assert_cmpint (cd_device_get_kind (device), ==, CD_DEVICE_KIND_DISPLAY);
diff --git a/src/cd-device.c b/src/cd-device.c
index fa5254e..ad2c714 100644
--- a/src/cd-device.c
+++ b/src/cd-device.c
@@ -70,6 +70,7 @@ struct _CdDevicePrivate
guint64 created;
guint64 modified;
gboolean is_virtual;
+ GHashTable *metadata;
};
enum {
@@ -628,6 +629,36 @@ cd_device_set_property_to_db (CdDevice *device,
}
/**
+ * cd_device_get_metadata_as_variant:
+ **/
+static GVariant *
+cd_device_get_metadata_as_variant (CdDevice *device)
+{
+ GList *list, *l;
+ GVariantBuilder builder;
+
+ /* we always must have at least one bit of metadata */
+ if (g_hash_table_size (device->priv->metadata) == 0) {
+ g_debug ("no metadata, so faking something");
+ g_hash_table_insert (device->priv->metadata,
+ g_strdup ("CMS"),
+ g_strdup ("colord"));
+ }
+ /* add all the keys in the dictionary to the variant builder */
+ list = g_hash_table_get_keys (device->priv->metadata);
+ g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
+ for (l = list; l != NULL; l = l->next) {
+ g_variant_builder_add (&builder,
+ "{ss}",
+ l->data,
+ g_hash_table_lookup (device->priv->metadata,
+ l->data));
+ }
+ g_list_free (list);
+ return g_variant_builder_end (&builder);
+}
+
+/**
* cd_device_set_property_internal:
**/
gboolean
@@ -661,12 +692,13 @@ cd_device_set_property_internal (CdDevice *device,
g_free (priv->mode);
priv->mode = g_strdup (value);
} else {
- ret = FALSE;
- g_set_error (error,
- CD_MAIN_ERROR,
- CD_MAIN_ERROR_FAILED,
- "property %s not understood on CdDevice",
- property);
+ /* add to metadata */
+ g_hash_table_insert (device->priv->metadata,
+ g_strdup (property),
+ g_strdup (value));
+ cd_device_dbus_emit_property_changed (device,
+ "Metadata",
+ cd_device_get_metadata_as_variant (device));
goto out;
}
@@ -1152,6 +1184,10 @@ cd_device_dbus_get_property (GDBusConnection *connection_, const gchar *sender,
}
goto out;
}
+ if (g_strcmp0 (property_name, "Metadata") == 0) {
+ retval = cd_device_get_metadata_as_variant (device);
+ goto out;
+ }
g_critical ("failed to get property %s", property_name);
out:
@@ -1349,6 +1385,10 @@ cd_device_init (CdDevice *device)
"changed",
G_CALLBACK (cd_device_inhibit_changed_cb),
device);
+ device->priv->metadata = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ g_free,
+ g_free);
}
/**
@@ -1384,6 +1424,7 @@ cd_device_finalize (GObject *object)
g_object_unref (priv->mapping_db);
g_object_unref (priv->device_db);
g_object_unref (priv->inhibit);
+ g_hash_table_unref (priv->metadata);
G_OBJECT_CLASS (cd_device_parent_class)->finalize (object);
}
diff --git a/src/org.freedesktop.ColorManager.Device.xml b/src/org.freedesktop.ColorManager.Device.xml
index b702e61..a565121 100644
--- a/src/org.freedesktop.ColorManager.Device.xml
+++ b/src/org.freedesktop.ColorManager.Device.xml
@@ -135,6 +135,18 @@
</property>
<!--***********************************************************-->
+ <property name='Metadata' type='a{ss}' access='read'>
+ <doc:doc>
+ <doc:description>
+ <doc:para>
+ The metadata for the device, which may include optional
+ keys like <doc:tt>XRANDR_name</doc:tt>.
+ </doc:para>
+ </doc:description>
+ </doc:doc>
+ </property>
+
+ <!--***********************************************************-->
<method name='SetProperty'>
<annotation name='org.freedesktop.DBus.GLib.Async' value=''/>
<doc:doc>
diff --git a/src/org.freedesktop.ColorManager.xml b/src/org.freedesktop.ColorManager.xml
index e24bbe5..549f328 100644
--- a/src/org.freedesktop.ColorManager.xml
+++ b/src/org.freedesktop.ColorManager.xml
@@ -409,6 +409,11 @@
the latency of one bus round-trip, rather than doing
a few <doc:tt>SetProperty</doc:tt> methods indervidually.
</doc:para>
+ <doc:para>
+ Any properties not interstood by colord will be added as
+ dictionary values to the <doc:tt>Metadata</doc:tt>
+ property.
+ </doc:para>
</doc:summary>
</doc:doc>
</arg>