[rygel-grilo] Add API to get values from property tables
- From: Juan A. Suarez Romero <jasuarez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel-grilo] Add API to get values from property tables
- Date: Fri, 16 Apr 2010 10:07:18 +0000 (UTC)
commit 3f41155caa83d100c01f774247a8b0cc31134976
Author: Juan A. Suarez Romero <jasuarez igalia com>
Date: Fri Apr 16 12:06:34 2010 +0200
Add API to get values from property tables
These are just helper functions to make life easier for developers.
lib/media-server2-client.c | 394 +++++++++++++++++++++++++++++++++++++++++++-
lib/media-server2-client.h | 48 ++++++
lib/media-server2-common.h | 14 ++-
lib/media-server2-server.c | 117 ++++++-------
lib/media-server2-server.h | 18 +--
src/test-client.c | 8 +-
6 files changed, 511 insertions(+), 88 deletions(-)
---
diff --git a/lib/media-server2-client.c b/lib/media-server2-client.c
index 83ee92c..57f8b6c 100644
--- a/lib/media-server2-client.c
+++ b/lib/media-server2-client.c
@@ -34,13 +34,14 @@
#define ENTRY_POINT_IFACE "/org/gnome/UPnP/MediaServer2/"
#define ENTRY_POINT_NAME "org.gnome.UPnP.MediaServer2."
-#define DBUS_TYPE_PROPERTIES \
- dbus_g_type_get_collection ("GPtrArray", \
- G_TYPE_VALUE)
+#define DBUS_TYPE_G_ARRAY_OF_STRING \
+ (dbus_g_type_get_collection ("GPtrArray", G_TYPE_STRING))
-#define DBUS_TYPE_CHILDREN \
- dbus_g_type_get_collection ("GPtrArray", \
- DBUS_TYPE_PROPERTIES)
+#define DBUS_TYPE_PROPERTIES \
+ dbus_g_type_get_collection ("GPtrArray", G_TYPE_VALUE)
+
+#define DBUS_TYPE_CHILDREN \
+ dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_PROPERTIES)
#define MS2_CLIENT_GET_PRIVATE(o) \
G_TYPE_INSTANCE_GET_PRIVATE((o), MS2_TYPE_CLIENT, MS2ClientPrivate)
@@ -452,3 +453,384 @@ ms2_client_get_children_finish (MS2Client *client,
adata = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
return adata->children_result;
}
+
+/******************** PROPERTIES TABLE API ********************/
+
+const gchar *
+ms2_client_get_id (GHashTable *properties)
+{
+ GValue *val;
+
+ g_return_val_if_fail (properties, NULL);
+
+ val = g_hash_table_lookup (properties, MS2_PROP_ID);
+ if (!val || !G_VALUE_HOLDS_STRING (val)) {
+ return NULL;
+ }
+
+ return g_value_get_string (val);
+}
+
+const gchar *
+ms2_client_get_parent (GHashTable *properties)
+{
+ GValue *val;
+
+ g_return_val_if_fail (properties, NULL);
+
+ val = g_hash_table_lookup (properties, MS2_PROP_PARENT);
+ if (!val || !G_VALUE_HOLDS_STRING (val)) {
+ return NULL;
+ }
+
+ return g_value_get_string (val);
+}
+
+const gchar *
+ms2_client_get_display_name (GHashTable *properties)
+{
+ GValue *val;
+
+ g_return_val_if_fail (properties, NULL);
+
+ val = g_hash_table_lookup (properties, MS2_PROP_DISPLAY_NAME);
+ if (!val || !G_VALUE_HOLDS_STRING (val)) {
+ return NULL;
+ }
+
+ return g_value_get_string (val);
+}
+
+MS2ItemType
+ms2_client_get_item_type (GHashTable *properties)
+{
+ GValue *val;
+ const gchar *type;
+
+ g_return_val_if_fail (properties, MS2_ITEM_TYPE_UNKNOWN);
+
+ val = g_hash_table_lookup (properties, MS2_PROP_DISPLAY_NAME);
+ if (!val || !G_VALUE_HOLDS_STRING (val)) {
+ return MS2_ITEM_TYPE_UNKNOWN;
+ }
+
+ type = g_value_get_string (val);
+
+ if (g_strcmp0 (type, MS2_TYPE_CONTAINER) == 0) {
+ return MS2_ITEM_TYPE_CONTAINER;
+ } else if (g_strcmp0 (type, MS2_TYPE_VIDEO) == 0) {
+ return MS2_ITEM_TYPE_VIDEO;
+ } else if (g_strcmp0 (type, MS2_TYPE_MOVIE) == 0) {
+ return MS2_ITEM_TYPE_MOVIE;
+ } else if (g_strcmp0 (type, MS2_TYPE_AUDIO) == 0) {
+ return MS2_ITEM_TYPE_AUDIO;
+ } else if (g_strcmp0 (type, MS2_TYPE_MUSIC) == 0) {
+ return MS2_ITEM_TYPE_MUSIC;
+ } else if (g_strcmp0 (type, MS2_TYPE_IMAGE) == 0) {
+ return MS2_ITEM_TYPE_IMAGE;
+ } else if (g_strcmp0 (type, MS2_TYPE_PHOTO) == 0) {
+ return MS2_ITEM_TYPE_PHOTO;
+ } else {
+ return MS2_ITEM_TYPE_UNKNOWN;
+ }
+}
+
+const gchar *
+ms2_client_get_icon (GHashTable *properties)
+{
+ GValue *val;
+
+ g_return_val_if_fail (properties, NULL);
+
+ val = g_hash_table_lookup (properties, MS2_PROP_ICON);
+ if (!val || !G_VALUE_HOLDS_STRING (val)) {
+ return NULL;
+ }
+
+ return g_value_get_string (val);
+}
+
+const gchar *
+ms2_client_get_mime_type (GHashTable *properties)
+{
+ GValue *val;
+
+ g_return_val_if_fail (properties, NULL);
+
+ val = g_hash_table_lookup (properties, MS2_PROP_MIME_TYPE);
+ if (!val || !G_VALUE_HOLDS_STRING (val)) {
+ return NULL;
+ }
+
+ return g_value_get_string (val);
+}
+
+const gchar *
+ms2_client_get_artist (GHashTable *properties)
+{
+ GValue *val;
+
+ g_return_val_if_fail (properties, NULL);
+
+ val = g_hash_table_lookup (properties, MS2_PROP_ARTIST);
+ if (!val || !G_VALUE_HOLDS_STRING (val)) {
+ return NULL;
+ }
+
+ return g_value_get_string (val);
+}
+
+const gchar *
+ms2_client_get_album (GHashTable *properties)
+{
+ GValue *val;
+
+ g_return_val_if_fail (properties, NULL);
+
+ val = g_hash_table_lookup (properties, MS2_PROP_ALBUM);
+ if (!val || !G_VALUE_HOLDS_STRING (val)) {
+ return NULL;
+ }
+
+ return g_value_get_string (val);
+}
+
+const gchar *
+ms2_client_get_date (GHashTable *properties)
+{
+ GValue *val;
+
+ g_return_val_if_fail (properties, NULL);
+
+ val = g_hash_table_lookup (properties, MS2_PROP_DATE);
+ if (!val || !G_VALUE_HOLDS_STRING (val)) {
+ return NULL;
+ }
+
+ return g_value_get_string (val);
+}
+
+const gchar *
+ms2_client_get_dlna_profile (GHashTable *properties)
+{
+ GValue *val;
+
+ g_return_val_if_fail (properties, NULL);
+
+ val = g_hash_table_lookup (properties, MS2_PROP_DLNA_PROFILE);
+ if (!val || !G_VALUE_HOLDS_STRING (val)) {
+ return NULL;
+ }
+
+ return g_value_get_string (val);
+}
+
+const gchar *
+ms2_client_get_thumbnail (GHashTable *properties)
+{
+ GValue *val;
+
+ g_return_val_if_fail (properties, NULL);
+
+ val = g_hash_table_lookup (properties, MS2_PROP_THUMBNAIL);
+ if (!val || !G_VALUE_HOLDS_STRING (val)) {
+ return NULL;
+ }
+
+ return g_value_get_string (val);
+}
+
+const gchar *
+ms2_client_get_genre (GHashTable *properties)
+{
+ GValue *val;
+
+ g_return_val_if_fail (properties, NULL);
+
+ val = g_hash_table_lookup (properties, MS2_PROP_GENRE);
+ if (!val || !G_VALUE_HOLDS_STRING (val)) {
+ return NULL;
+ }
+
+ return g_value_get_string (val);
+}
+
+gint
+ms2_client_get_child_count (GHashTable *properties)
+{
+ GValue *val;
+
+ g_return_val_if_fail (properties, -1);
+
+ val = g_hash_table_lookup (properties, MS2_PROP_CHILD_COUNT);
+ if (!val || !G_VALUE_HOLDS_INT (val)) {
+ return -1;
+ }
+
+ return g_value_get_int (val);
+}
+
+gint
+ms2_client_get_size (GHashTable *properties)
+{
+ GValue *val;
+
+ g_return_val_if_fail (properties, -1);
+
+ val = g_hash_table_lookup (properties, MS2_PROP_SIZE);
+ if (!val || !G_VALUE_HOLDS_INT (val)) {
+ return -1;
+ }
+
+ return g_value_get_int (val);
+}
+
+gint
+ms2_client_get_duration (GHashTable *properties)
+{
+ GValue *val;
+
+ g_return_val_if_fail (properties, -1);
+
+ val = g_hash_table_lookup (properties, MS2_PROP_DURATION);
+ if (!val || !G_VALUE_HOLDS_INT (val)) {
+ return -1;
+ }
+
+ return g_value_get_int (val);
+}
+
+gint
+ms2_client_get_bitrate (GHashTable *properties)
+{
+ GValue *val;
+
+ g_return_val_if_fail (properties, -1);
+
+ val = g_hash_table_lookup (properties, MS2_PROP_BITRATE);
+ if (!val || !G_VALUE_HOLDS_INT (val)) {
+ return -1;
+ }
+
+ return g_value_get_int (val);
+}
+
+gint
+ms2_client_get_sample_rate (GHashTable *properties)
+{
+ GValue *val;
+
+ g_return_val_if_fail (properties, -1);
+
+ val = g_hash_table_lookup (properties, MS2_PROP_SAMPLE_RATE);
+ if (!val || !G_VALUE_HOLDS_INT (val)) {
+ return -1;
+ }
+
+ return g_value_get_int (val);
+}
+
+gint
+ms2_client_get_bits_per_sample (GHashTable *properties)
+{
+ GValue *val;
+
+ g_return_val_if_fail (properties, -1);
+
+ val = g_hash_table_lookup (properties, MS2_PROP_BITS_PER_SAMPLE);
+ if (!val || !G_VALUE_HOLDS_INT (val)) {
+ return -1;
+ }
+
+ return g_value_get_int (val);
+}
+
+gint
+ms2_client_get_width (GHashTable *properties)
+{
+ GValue *val;
+
+ g_return_val_if_fail (properties, -1);
+
+ val = g_hash_table_lookup (properties, MS2_PROP_WIDTH);
+ if (!val || !G_VALUE_HOLDS_INT (val)) {
+ return -1;
+ }
+
+ return g_value_get_int (val);
+}
+
+gint
+ms2_client_get_height (GHashTable *properties)
+{
+ GValue *val;
+
+ g_return_val_if_fail (properties, -1);
+
+ val = g_hash_table_lookup (properties, MS2_PROP_HEIGHT);
+ if (!val || !G_VALUE_HOLDS_INT (val)) {
+ return -1;
+ }
+
+ return g_value_get_int (val);
+}
+
+gint
+ms2_client_get_color_depth (GHashTable *properties)
+{
+ GValue *val;
+
+ g_return_val_if_fail (properties, -1);
+
+ val = g_hash_table_lookup (properties, MS2_PROP_COLOR_DEPTH);
+ if (!val || !G_VALUE_HOLDS_INT (val)) {
+ return -1;
+ }
+
+ return g_value_get_int (val);
+}
+
+gint
+ms2_client_get_pixel_width (GHashTable *properties)
+{
+ GValue *val;
+
+ g_return_val_if_fail (properties, -1);
+
+ val = g_hash_table_lookup (properties, MS2_PROP_PIXEL_WIDTH);
+ if (!val || !G_VALUE_HOLDS_INT (val)) {
+ return -1;
+ }
+
+ return g_value_get_int (val);
+}
+
+gint
+ms2_client_get_pixel_height (GHashTable *properties)
+{
+ GValue *val;
+
+ g_return_val_if_fail (properties, -1);
+
+ val = g_hash_table_lookup (properties, MS2_PROP_PIXEL_HEIGHT);
+ if (!val || !G_VALUE_HOLDS_INT (val)) {
+ return -1;
+ }
+
+ return g_value_get_int (val);
+}
+
+gchar **
+ms2_client_get_urls (GHashTable *properties)
+{
+ GValue *val;
+
+ g_return_val_if_fail (properties, NULL);
+
+ val = g_hash_table_lookup (properties, MS2_PROP_URLS);
+ if (!val || !G_VALUE_HOLDS_BOXED (val)) {
+ return NULL;
+ }
+
+ return g_strdupv (g_value_get_boxed (val));
+}
diff --git a/lib/media-server2-client.h b/lib/media-server2-client.h
index 5213573..792d57b 100644
--- a/lib/media-server2-client.h
+++ b/lib/media-server2-client.h
@@ -113,4 +113,52 @@ GList *ms2_client_get_children_finish (MS2Client *client,
GAsyncResult *res,
GError **error);
+const gchar *ms2_client_get_id (GHashTable *properties);
+
+const gchar *ms2_client_get_parent (GHashTable *properties);
+
+const gchar *ms2_client_get_display_name (GHashTable *properties);
+
+MS2ItemType ms2_client_get_item_type (GHashTable *properties);
+
+const gchar *ms2_client_get_icon (GHashTable *properties);
+
+const gchar *ms2_client_get_mime_type (GHashTable *properties);
+
+const gchar *ms2_client_get_artist (GHashTable *properties);
+
+const gchar *ms2_client_get_album (GHashTable *properties);
+
+const gchar *ms2_client_get_date (GHashTable *properties);
+
+const gchar *ms2_client_get_dlna_profile (GHashTable *properties);
+
+const gchar *ms2_client_get_thumbnail (GHashTable *properties);
+
+const gchar *ms2_client_get_genre (GHashTable *properties);
+
+gint ms2_client_get_child_count (GHashTable *properties);
+
+gint ms2_client_get_size (GHashTable *properties);
+
+gint ms2_client_get_duration (GHashTable *properties);
+
+gint ms2_client_get_bitrate (GHashTable *properties);
+
+gint ms2_client_get_sample_rate (GHashTable *properties);
+
+gint ms2_client_get_bits_per_sample (GHashTable *properties);
+
+gint ms2_client_get_width (GHashTable *properties);
+
+gint ms2_client_get_height (GHashTable *properties);
+
+gint ms2_client_get_color_depth (GHashTable *properties);
+
+gint ms2_client_get_pixel_width (GHashTable *properties);
+
+gint ms2_client_get_pixel_height (GHashTable *properties);
+
+gchar **ms2_client_get_urls (GHashTable *properties);
+
#endif /* _MEDIA_SERVER2_CLIENT_H_ */
diff --git a/lib/media-server2-common.h b/lib/media-server2-common.h
index c5198e0..d791253 100644
--- a/lib/media-server2-common.h
+++ b/lib/media-server2-common.h
@@ -54,7 +54,7 @@
/* Video/Image items properties */
#define MS2_PROP_WIDTH "width"
#define MS2_PROP_HEIGHT "height"
-#define MS2_PROP_COLOR_DEPTH "depth"
+#define MS2_PROP_COLOR_DEPTH "color-depth"
#define MS2_PROP_PIXEL_WIDTH "pixel-width"
#define MS2_PROP_PIXEL_HEIGHT "pixel-height"
#define MS2_PROP_THUMBNAIL "thumbnail"
@@ -82,5 +82,17 @@ typedef enum {
MS2_ERROR_GENERAL = 1
} MS2Error;
+/* Type items definition */
+typedef enum {
+ MS2_ITEM_TYPE_UNKNOWN = 0,
+ MS2_ITEM_TYPE_CONTAINER,
+ MS2_ITEM_TYPE_VIDEO,
+ MS2_ITEM_TYPE_MOVIE,
+ MS2_ITEM_TYPE_AUDIO,
+ MS2_ITEM_TYPE_MUSIC,
+ MS2_ITEM_TYPE_IMAGE,
+ MS2_ITEM_TYPE_PHOTO
+} MS2ItemType;
+
#endif /* _MEDIA_SERVER2_COMMON_H_ */
diff --git a/lib/media-server2-server.c b/lib/media-server2-server.c
index 3007b2d..4aa4acb 100644
--- a/lib/media-server2-server.c
+++ b/lib/media-server2-server.c
@@ -501,73 +501,51 @@ ms2_server_set_display_name (GHashTable *properties,
}
void
-ms2_server_set_type_container (GHashTable *properties)
+ms2_server_set_item_type (GHashTable *properties,
+ MS2ItemType type)
{
g_return_if_fail (properties);
- g_hash_table_insert (properties,
- MS2_PROP_TYPE,
- str_to_value (MS2_TYPE_CONTAINER));
-}
-
-void
-ms2_server_set_type_video (GHashTable *properties)
-{
- g_return_if_fail (properties);
-
- g_hash_table_insert (properties,
- MS2_PROP_TYPE,
- str_to_value (MS2_TYPE_VIDEO));
-}
-
-void
-ms2_server_set_type_movie (GHashTable *properties)
-{
- g_return_if_fail (properties);
-
- g_hash_table_insert (properties,
- MS2_PROP_TYPE,
- str_to_value (MS2_TYPE_MOVIE));
-}
-
-void
-ms2_server_set_type_audio (GHashTable *properties)
-{
- g_return_if_fail (properties);
-
- g_hash_table_insert (properties,
- MS2_PROP_TYPE,
- str_to_value (MS2_TYPE_AUDIO));
-}
-
-void
-ms2_server_set_type_music (GHashTable *properties)
-{
- g_return_if_fail (properties);
-
- g_hash_table_insert (properties,
- MS2_PROP_TYPE,
- str_to_value (MS2_TYPE_MUSIC));
-}
-
-void
-ms2_server_set_type_image (GHashTable *properties)
-{
- g_return_if_fail (properties);
-
- g_hash_table_insert (properties,
- MS2_PROP_TYPE,
- str_to_value (MS2_TYPE_IMAGE));
-}
-
-void
-ms2_server_set_type_photo (GHashTable *properties)
-{
- g_return_if_fail (properties);
-
- g_hash_table_insert (properties,
- MS2_PROP_TYPE,
- str_to_value (MS2_TYPE_PHOTO));
+ switch (type) {
+ case MS2_ITEM_TYPE_UNKNOWN:
+ /* Do not handle unknown values */
+ break;
+ case MS2_ITEM_TYPE_CONTAINER:
+ g_hash_table_insert (properties,
+ MS2_PROP_TYPE,
+ str_to_value (MS2_TYPE_CONTAINER));
+ break;
+ case MS2_ITEM_TYPE_VIDEO:
+ g_hash_table_insert (properties,
+ MS2_PROP_TYPE,
+ str_to_value (MS2_TYPE_VIDEO));
+ break;
+ case MS2_ITEM_TYPE_MOVIE:
+ g_hash_table_insert (properties,
+ MS2_PROP_TYPE,
+ str_to_value (MS2_TYPE_MOVIE));
+ break;
+ case MS2_ITEM_TYPE_AUDIO:
+ g_hash_table_insert (properties,
+ MS2_PROP_TYPE,
+ str_to_value (MS2_TYPE_AUDIO));
+ break;
+ case MS2_ITEM_TYPE_MUSIC:
+ g_hash_table_insert (properties,
+ MS2_PROP_TYPE,
+ str_to_value (MS2_TYPE_MUSIC));
+ break;
+ case MS2_ITEM_TYPE_IMAGE:
+ g_hash_table_insert (properties,
+ MS2_PROP_TYPE,
+ str_to_value (MS2_TYPE_IMAGE));
+ break;
+ case MS2_ITEM_TYPE_PHOTO:
+ g_hash_table_insert (properties,
+ MS2_PROP_TYPE,
+ str_to_value (MS2_TYPE_PHOTO));
+ break;
+ }
}
void
@@ -763,6 +741,17 @@ ms2_server_set_height (GHashTable *properties,
}
void
+ms2_server_set_color_depth (GHashTable *properties,
+ gint depth)
+{
+ g_return_if_fail (properties);
+
+ g_hash_table_insert (properties,
+ MS2_PROP_COLOR_DEPTH,
+ int_to_value (depth));
+}
+
+void
ms2_server_set_pixel_width (GHashTable *properties,
gint pixel_width)
{
diff --git a/lib/media-server2-server.h b/lib/media-server2-server.h
index f97e480..8f04c11 100644
--- a/lib/media-server2-server.h
+++ b/lib/media-server2-server.h
@@ -103,19 +103,8 @@ void ms2_server_set_parent (GHashTable *properties,
void ms2_server_set_display_name (GHashTable *properties,
const gchar *display_name);
-void ms2_server_set_type_container (GHashTable *properties);
-
-void ms2_server_set_type_video (GHashTable *properties);
-
-void ms2_server_set_type_movie (GHashTable *properties);
-
-void ms2_server_set_type_audio (GHashTable *properties);
-
-void ms2_server_set_type_music (GHashTable *properties);
-
-void ms2_server_set_type_image (GHashTable *properties);
-
-void ms2_server_set_type_photo (GHashTable *properties);
+void ms2_server_set_item_type (GHashTable *properties,
+ MS2ItemType type);
void ms2_server_set_icon (GHashTable *properties,
const gchar *icon);
@@ -165,6 +154,9 @@ void ms2_server_set_width (GHashTable *properties,
void ms2_server_set_height (GHashTable *properties,
gint height);
+void ms2_server_set_color_depth (GHashTable *properties,
+ gint depth);
+
void ms2_server_set_pixel_width (GHashTable *properties,
gint pixel_width);
diff --git a/src/test-client.c b/src/test-client.c
index f49ff4c..4a7671d 100644
--- a/src/test-client.c
+++ b/src/test-client.c
@@ -31,8 +31,8 @@ children_reply (GObject *source,
for (child = children; child; child = g_list_next (child)) {
g_print ("\t* '%s', '%s'\n",
- g_value_get_string(g_hash_table_lookup (child->data, MS2_PROP_ID)),
- g_value_get_string(g_hash_table_lookup (child->data, MS2_PROP_DISPLAY_NAME)));
+ ms2_client_get_id (child->data),
+ ms2_client_get_display_name(child->data));
}
g_list_foreach (children, (GFunc) g_hash_table_unref, NULL);
@@ -227,8 +227,8 @@ test_children_sync ()
for (child = children; child; child = g_list_next (child)) {
g_print ("\t* '%s', '%s'\n",
- g_value_get_string(g_hash_table_lookup (child->data, MS2_PROP_ID)),
- g_value_get_string(g_hash_table_lookup (child->data, MS2_PROP_DISPLAY_NAME)));
+ ms2_client_get_id (child->data),
+ ms2_client_get_display_name(child->data));
}
g_list_foreach (children, (GFunc) g_hash_table_unref, NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]