Commit 93358fa8 authored by Jussi Kukkonen's avatar Jussi Kukkonen

add async functions to GeoclueProvider

parent 70b8f87c
......@@ -27,9 +27,7 @@
*
* pos = geoclue_position_new ("org.freedesktop.Geoclue.Providers.Example",
* "/org/freedesktop/Geoclue/Providers/Example");
* if (pos == NULL) {
* / * error * /
* }
*
* if (geoclue_provider_get_provider_info (GEOCLUE_PROVIDER (pos),
* &name, NULL, &error)) {
* g_print ("name = %s", name);
......@@ -45,6 +43,12 @@
#include <geoclue/geoclue-provider.h>
#include "gc-iface-geoclue-bindings.h"
typedef struct _GeoclueProviderAsyncData {
GeoclueProvider *provider;
GCallback callback;
gpointer userdata;
} GeoclueProviderAsyncData;
typedef struct _GeoclueProviderPrivate {
DBusGProxy *geoclue_proxy;
......@@ -303,6 +307,60 @@ geoclue_provider_get_status (GeoclueProvider *provider,
return TRUE;
}
static void
get_status_async_callback (DBusGProxy *proxy,
GeoclueStatus status,
GError *error,
GeoclueProviderAsyncData *data)
{
(*(GeoclueProviderStatusCallback)data->callback) (data->provider,
status,
error,
data->userdata);
g_free (data);
}
/**
* GeoclueProviderStatusCallback:
* @provider: A #GeoclueProvider object
* @status: A #GeoclueStatus
* @error: Error as #GError or %NULL
* @userdata: User data pointer set in geoclue_provider_get_status_async()
*
* Callback function for geoclue_provider_get_status_async().
*/
/**
* geoclue_provider_get_status_async:
* @provider: A #GeoclueProvider object
* @callback: A #GeoclueProviderStatusCallback function that will be called when return values are available
* @userdata: pointer for user specified data
*
* Asynchronous version of geoclue_provider_get_status(). Function returns
* (essentially) immediately and calls @callback when status is available or
* when there is an error.
*/
void
geoclue_provider_get_status_async (GeoclueProvider *provider,
GeoclueProviderStatusCallback callback,
gpointer userdata)
{
GeoclueProviderPrivate *priv = GET_PRIVATE (provider);
GeoclueProviderAsyncData *data;
data = g_new (GeoclueProviderAsyncData, 1);
data->provider = provider;
data->callback = G_CALLBACK (callback);
data->userdata = userdata;
org_freedesktop_Geoclue_get_status_async
(priv->geoclue_proxy,
(org_freedesktop_Geoclue_get_status_reply)get_status_async_callback,
data);
}
/**
* geoclue_provider_set_options:
* @provider: A #GeoclueProvider object
......@@ -328,6 +386,58 @@ geoclue_provider_set_options (GeoclueProvider *provider,
options, error);
}
static void
set_options_async_callback (DBusGProxy *proxy,
GError *error,
GeoclueProviderAsyncData *data)
{
(*(GeoclueProviderOptionsCallback)data->callback) (data->provider,
error,
data->userdata);
g_free (data);
}
/**
* GeoclueProviderOptionsCallback:
* @provider: A #GeoclueProvider object
* @error: Error as #GError or %NULL
* @userdata: User data pointer set in geoclue_provider_set_options_async()
*
* Callback function for geoclue_provider_set_options_async().
*/
/**
* geoclue_provider_set_options_async:
* @provider: A #GeoclueProvider object
* @options: A #GHashTable of options
* @callback: A #GeoclueProviderOptionsCallback function that will be called when options are set
* @userdata: pointer for user specified data
*
* Asynchronous version of geoclue_provider_set_options(). Function returns
* (essentially) immediately and calls @callback when options have been set or
* when there is an error.
*/
void
geoclue_provider_set_options_async (GeoclueProvider *provider,
GHashTable *options,
GeoclueProviderOptionsCallback callback,
gpointer userdata)
{
GeoclueProviderPrivate *priv = GET_PRIVATE (provider);
GeoclueProviderAsyncData *data;
data = g_new (GeoclueProviderAsyncData, 1);
data->provider = provider;
data->callback = G_CALLBACK (callback);
data->userdata = userdata;
org_freedesktop_Geoclue_set_options_async
(priv->geoclue_proxy,
options,
(org_freedesktop_Geoclue_set_options_reply)set_options_async_callback,
data);
}
/**
* geoclue_provider_get_provider_info:
* @provider: A #GeoclueProvider object
......@@ -351,3 +461,58 @@ geoclue_provider_get_provider_info (GeoclueProvider *provider,
name, description,
error);
}
static void
get_provider_info_async_callback (DBusGProxy *proxy,
char *name,
char *description,
GError *error,
GeoclueProviderAsyncData *data)
{
(*(GeoclueProviderInfoCallback)data->callback) (data->provider,
name,
description,
error,
data->userdata);
g_free (data);
}
/**
* GeoclueProviderInfoCallback:
* @provider: A #GeoclueProvider object
* @name: Name of the provider
* @description: one-line description of the provider
* @error: Error as #GError or %NULL
* @userdata: User data pointer set in geoclue_provider_get_provider_info_async()
*
* Callback function for geoclue_provider_get_provider_info_async().
*/
/**
* geoclue_provider_get_provider_info_async:
* @provider: A #GeoclueProvider object
* @callback: A #GeoclueProviderInfoCallback function that will be called when info is available
* @userdata: pointer for user specified data
*
* Asynchronous version of geoclue_provider_get_provider_info(). Function returns
* (essentially) immediately and calls @callback when info is available or
* when there is an error.
*/
void
geoclue_provider_get_provider_info_async (GeoclueProvider *provider,
GeoclueProviderInfoCallback callback,
gpointer userdata)
{
GeoclueProviderPrivate *priv = GET_PRIVATE (provider);
GeoclueProviderAsyncData *data;
data = g_new (GeoclueProviderAsyncData, 1);
data->provider = provider;
data->callback = G_CALLBACK (callback);
data->userdata = userdata;
org_freedesktop_Geoclue_get_provider_info_async
(priv->geoclue_proxy,
(org_freedesktop_Geoclue_get_provider_info_reply)get_provider_info_async_callback,
data);
}
......@@ -40,13 +40,37 @@ GType geoclue_provider_get_type (void);
gboolean geoclue_provider_get_status (GeoclueProvider *provider,
GeoclueStatus *status,
GError **error);
typedef void (*GeoclueProviderStatusCallback) (GeoclueProvider *provider,
GeoclueStatus status,
GError *error,
gpointer userdata);
void geoclue_provider_get_status_async (GeoclueProvider *provider,
GeoclueProviderStatusCallback callback,
gpointer userdata);
gboolean geoclue_provider_get_provider_info (GeoclueProvider *provider,
char **name,
char **description,
GError **error);
typedef void (*GeoclueProviderInfoCallback) (GeoclueProvider *provider,
char *name,
char *description,
GError *error,
gpointer userdata);
void geoclue_provider_get_provider_info_async (GeoclueProvider *provider,
GeoclueProviderInfoCallback callback,
gpointer userdata);
gboolean geoclue_provider_set_options (GeoclueProvider *provider,
GHashTable *options,
GError **error);
typedef void (*GeoclueProviderOptionsCallback) (GeoclueProvider *provider,
GError *error,
gpointer userdata);
void geoclue_provider_set_options_async (GeoclueProvider *provider,
GHashTable *options,
GeoclueProviderOptionsCallback callback,
gpointer userdata);
G_END_DECLS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment