[rygel-grilo] Get rid of asynchronous functions
- From: Juan A. Suarez Romero <jasuarez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel-grilo] Get rid of asynchronous functions
- Date: Wed, 12 May 2010 09:59:40 +0000 (UTC)
commit 0b10b3f99846e8f1cd1163065b93f366efbec8db
Author: Juan A. Suarez Romero <jasuarez igalia com>
Date: Wed May 5 20:36:59 2010 +0200
Get rid of asynchronous functions
While they are very useful, refactoring them is consuming my little time.
So forget about them and maybe in future I or any other volunteer will add them
again.
lib/media-server2-client.c | 233 --------------------------------------------
lib/media-server2-client.h | 22 ----
src/test-client.c | 142 +--------------------------
3 files changed, 4 insertions(+), 393 deletions(-)
---
diff --git a/lib/media-server2-client.c b/lib/media-server2-client.c
index facf8d3..f75d0e6 100644
--- a/lib/media-server2-client.c
+++ b/lib/media-server2-client.c
@@ -49,24 +49,6 @@ enum {
};
/*
- * AsyncData: used to pack needed data when dealing with async functions
- * properties_result: when using get_properties_async() functions, it will
- * store the properties table result
- * children_result: when using get_children_async() functions, it will store
- * the list of children result
- * client: a reference to MS2Client
- * properties: list of properties requested
- * id: id of MediaObject to get properties/children from
- */
-typedef struct {
- GHashTable *properties_result;
- GList *children_result;
- MS2Client *client;
- gchar **properties;
- gchar *id;
-} AsyncData;
-
-/*
* Private MS2Client structure
* bus: connection to DBus session
* name: name of provider
@@ -108,16 +90,6 @@ free_gvalue (GValue *v)
g_free (v);
}
-/* Free AsyncData struct */
-static void
-free_async_data (AsyncData *adata)
-{
- g_object_unref (adata->client);
- g_free (adata->id);
- g_strfreev (adata->properties);
- g_slice_free (AsyncData, adata);
-}
-
static gboolean
collect_value (gpointer key,
gpointer value,
@@ -202,53 +174,6 @@ get_children_list (GPtrArray *result,
return children;
}
-#if 0
-/* Callback invoked by dbus as answer to get_properties_async() */
-static void
-get_properties_async_reply (DBusGProxy *proxy,
- GPtrArray *result,
- GError *error,
- gpointer data)
-{
- GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (data);
- AsyncData *adata;
-
- adata = g_simple_async_result_get_op_res_gpointer (res);
-
- adata->properties_result =
- get_properties_table (result,
- (const gchar **) adata->properties);
- g_boxed_free (DBUS_TYPE_PROPERTIES, result);
-
- g_simple_async_result_complete (res);
- g_object_unref (res);
-}
-#endif
-
-#if 0
-/* Callback invoked by dbus as answer to get_children_async() */
-static void
-get_children_async_reply (DBusGProxy *proxy,
- GPtrArray *result,
- GError *error,
- gpointer data)
-{
- GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (data);
- AsyncData *adata;
-
- adata = g_simple_async_result_get_op_res_gpointer (res);
-
- adata->children_result =
- get_children_list (result,
- (const gchar **) adata->properties);
-
- g_boxed_free (DBUS_TYPE_CHILDREN, result);
-
- g_simple_async_result_complete (res);
- g_object_unref (res);
-}
-#endif
-
/* Dispose function */
static void
ms2_client_dispose (GObject *object)
@@ -562,82 +487,6 @@ ms2_client_get_properties (MS2Client *client,
}
/**
- * ms2_client_get_properties_async:
- * @client: a #MS2Client
- * @id: media identifier to obtain properties from
- * @properties: @NULL-terminated array of properties to request
- * @callback: a #GAsyncReadyCallback to call when request is satisfied
- * @user_data: the data to pass to callback function
- *
- * Starts an asynchronous get properties.
- *
- * For more details, see ms2_client_get_properties(), which is the synchronous
- * version of this call.
- *
- * When the properties have been obtained, @callback will be called with
- * @user_data. To finish the operation, call ms2_client_get_properties_finish()
- * with the #GAsyncResult returned by the @callback.
- **/
-void ms2_client_get_properties_async (MS2Client *client,
- const gchar *id,
- const gchar **properties,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- AsyncData *adata;
- GSimpleAsyncResult *res;
-
- g_return_if_fail (MS2_IS_CLIENT (client));
-
- adata = g_slice_new0 (AsyncData);
-
- res = g_simple_async_result_new (G_OBJECT (client),
- callback,
- user_data,
- ms2_client_get_properties_async);
-
- adata->client = g_object_ref (client);
- adata->id = g_strdup (id);
- adata->properties = g_strdupv ((gchar **) properties);
-
- g_simple_async_result_set_op_res_gpointer (res,
- adata,
- (GDestroyNotify) free_async_data);
-
- /* org_gnome_UPnP_MediaServer2_get_properties_async (client->priv->proxy_provider, */
- /* id, */
- /* properties, */
- /* get_properties_async_reply, */
- /* res); */
-}
-
-/**
- * ms2_client_get_properties_finish:
- * @client: a #MS2Client
- * @res: a #GAsyncResult
- * @error: a #GError location to store the error ocurring, or @NULL to ignore
- *
- * Finishes an asynchronous getting properties operation. Properties are
- * returned in a #GHashTable.
- *
- * Returns: a new #GHashTable
- **/
-GHashTable *
-ms2_client_get_properties_finish (MS2Client *client,
- GAsyncResult *res,
- GError **error)
-{
- AsyncData *adata;
-
- g_return_val_if_fail (g_simple_async_result_get_source_tag (G_SIMPLE_ASYNC_RESULT (res)) ==
- ms2_client_get_properties_async, NULL);
-
- adata =
- g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
- return adata->properties_result;
-}
-
-/**
* ms2_client_get_children:
* @client: a #MS2Client
* @id: container identifier to get children from
@@ -683,88 +532,6 @@ ms2_client_get_children (MS2Client *client,
return children;
}
-/**
- * ms2_client_get_children_async:
- * @client: a #MS2Client
- * @id: container identifier to get children from
- * @offset: number of children to skip
- * @max_count: maximum number of children to return, or -1 for no limit
- * @properties: @NULL-terminated array of properties to request for each child
- * @callback: a #GAsyncReadyCallback to call when request is satisfied
- * @user_data: the data to pass to callback function
- *
- * Starts an asynchronous get children.
- *
- * For more details, see ms2_client_get_children(), which is the synchronous
- * version of this call.
- *
- * When the children have been obtained, @callback will be called with
- * @user_data. To finish the operation, call ms2_client_get_children_finish()
- * with the #GAsyncResult returned by the @callback.
- **/
-void ms2_client_get_children_async (MS2Client *client,
- const gchar *id,
- guint offset,
- gint max_count,
- const gchar **properties,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- AsyncData *adata;
- GSimpleAsyncResult *res;
-
- g_return_if_fail (MS2_IS_CLIENT (client));
-
- adata = g_slice_new0 (AsyncData);
-
- res = g_simple_async_result_new (G_OBJECT (client),
- callback,
- user_data,
- ms2_client_get_children_async);
-
- adata->client = g_object_ref (client);
- adata->id = g_strdup (id);
- adata->properties = g_strdupv ((gchar **) properties);
-
- g_simple_async_result_set_op_res_gpointer (res,
- adata,
- (GDestroyNotify) free_async_data);
-
- /* org_gnome_UPnP_MediaServer2_get_children_async (client->priv->proxy_provider, */
- /* id, */
- /* offset, */
- /* max_count, */
- /* properties, */
- /* get_children_async_reply, */
- /* res); */
-}
-
-/**
- * ms2_client_get_children_finish:
- * @client: a #MS2Client
- * @res: a #GAsyncResult
- * @error: a #GError location to store the error ocurring, or @NULL to ignore
- *
- * Finishes an asynchronous getting children operation.
- *
- * Returns: a new #GList of #GHashTAble. To free it, free first each element
- * (g_hash_table_unref()) and finally the list itself (g_list_free())
- **/
-GList *
-ms2_client_get_children_finish (MS2Client *client,
- GAsyncResult *res,
- GError **error)
-{
- AsyncData *adata;
-
- g_return_val_if_fail (g_simple_async_result_get_source_tag (G_SIMPLE_ASYNC_RESULT (res)) ==
- ms2_client_get_children_async, NULL);
-
- adata =
- g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (res));
- return adata->children_result;
-}
-
const gchar *
ms2_client_get_root_path (MS2Client *client)
{
diff --git a/lib/media-server2-client.h b/lib/media-server2-client.h
index b7f9baa..cfbff54 100644
--- a/lib/media-server2-client.h
+++ b/lib/media-server2-client.h
@@ -91,16 +91,6 @@ GHashTable *ms2_client_get_properties (MS2Client *client,
gchar **properties,
GError **error);
-void ms2_client_get_properties_async (MS2Client *client,
- const gchar *id,
- const gchar **properties,
- GAsyncReadyCallback callback,
- gpointer user_data);
-
-GHashTable *ms2_client_get_properties_finish (MS2Client *client,
- GAsyncResult *res,
- GError **error);
-
GList *ms2_client_get_children (MS2Client *client,
const gchar *id,
guint offset,
@@ -108,18 +98,6 @@ GList *ms2_client_get_children (MS2Client *client,
const gchar **properties,
GError **error);
-void ms2_client_get_children_async (MS2Client *client,
- const gchar *id,
- guint offset,
- gint max_count,
- const gchar **properties,
- GAsyncReadyCallback callback,
- gpointer user_data);
-
-GList *ms2_client_get_children_finish (MS2Client *client,
- GAsyncResult *res,
- GError **error);
-
const gchar *ms2_client_get_root_path (MS2Client *client);
const gchar *ms2_client_get_path (GHashTable *properties);
diff --git a/src/test-client.c b/src/test-client.c
index 24d9db9..c3d043b 100644
--- a/src/test-client.c
+++ b/src/test-client.c
@@ -9,139 +9,7 @@ static const gchar *properties[] = { MS2_PROP_PATH,
NULL };
static void
-children_reply (GObject *source,
- GAsyncResult *res,
- gpointer user_data)
-{
- GError *error = NULL;
- GList *children;
- GList *child;
- gchar *provider = (gchar *) user_data;
-
- children = ms2_client_get_children_finish (MS2_CLIENT (source), res, &error);
-
- g_print ("\n* Provider '%s'\n", provider);
- g_free (provider);
-
- if (!children) {
- g_print ("\tDid not get any child, %s\n", error? error->message: "no error");
- return;
- }
-
- for (child = children; child; child = g_list_next (child)) {
- g_print ("\t* '%s', '%s'\n",
- ms2_client_get_path (child->data),
- ms2_client_get_display_name(child->data));
- }
-
- g_list_foreach (children, (GFunc) g_hash_table_unref, NULL);
- g_list_free (children);
- g_object_unref (source);
-}
-
-static void
-test_children_async ()
-{
- MS2Client *client;
- gchar **provider;
- gchar **providers;
-
- providers = ms2_client_get_providers ();
-
- if (!providers) {
- g_print ("There is no MediaServer2 provider\n");
- return;
- }
-
- for (provider = providers; *provider; provider ++) {
- client = ms2_client_new (*provider);
-
- if (!client) {
- g_printerr ("Unable to create a client\n");
- return;
- }
-
- ms2_client_get_children_async (client,
- ms2_client_get_root_path (client),
- 0,
- -1,
- properties,
- children_reply,
- g_strdup (*provider));
- }
-
- g_strfreev (providers);
-}
-
-static void
-properties_reply (GObject *source,
- GAsyncResult *res,
- gpointer user_data)
-{
- GError *error = NULL;
- GHashTable *result;
- GValue *v;
- const gchar **p;
- gchar *provider = (gchar *) user_data;
-
- result = ms2_client_get_properties_finish (MS2_CLIENT (source), res, &error);
-
- g_print ("\n* Provider '%s'\n", provider);
- g_free (provider);
-
- if (!result) {
- g_print ("\tDid not get any property, %s\n", error? error->message: "no error");
- return;
- }
-
- for (p = properties; *p; p++) {
- v = g_hash_table_lookup (result, *p);
- if (v && G_VALUE_HOLDS_INT (v)) {
- g_print ("\t* '%s' value: '%d'\n", *p, g_value_get_int (v));
- } else if (v && G_VALUE_HOLDS_STRING (v)) {
- g_print ("\t* '%s' value: '%s'\n", *p, g_value_get_string (v));
- } else {
- g_print ("\t* '%s' value: ---\n", *p);
- }
- }
- g_hash_table_unref (result);
- g_object_unref (source);
-}
-
-static void
-test_properties_async ()
-{
- MS2Client *client;
- gchar **provider;
- gchar **providers;
-
- providers = ms2_client_get_providers ();
-
- if (!providers) {
- g_print ("There is no MediaServer2 provider\n");
- return;
- }
-
- for (provider = providers; *provider; provider++) {
- client = ms2_client_new (*provider);
-
- if (!client) {
- g_printerr ("Unable to create a client\n");
- return;
- }
-
- ms2_client_get_properties_async (client,
- ms2_client_get_root_path (client),
- properties,
- properties_reply,
- g_strdup (*provider));
- }
-
- g_strfreev (providers);
-}
-
-static void
-test_properties_sync ()
+test_properties ()
{
GError *error = NULL;
GHashTable *result;
@@ -195,7 +63,7 @@ test_properties_sync ()
}
static void
-test_children_sync ()
+test_children ()
{
GError *error = NULL;
GList *children;
@@ -336,10 +204,8 @@ int main (int argc, char **argv)
g_type_init ();
- if (1) test_properties_sync ();
- if (0) test_children_sync ();
- if (0) test_properties_async ();
- if (0) test_children_async ();
+ if (1) test_properties ();
+ if (0) test_children ();
if (0) test_provider_free ();
if (0) test_dynamic_providers ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]