Commit 9eebd2e1 authored by Zeeshan Ali's avatar Zeeshan Ali

demo: Use async API

parent f8613abd
......@@ -27,36 +27,57 @@
#include <glib/gi18n.h>
#include <geoclue.h>
gint
main (gint argc, gchar *argv[])
GMainLoop *main_loop;
static void
on_start_ready (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
GClueManagerProxy *manager;
GClueClientProxy *client;
const char *client_path;
GClueManagerProxy *manager = GCLUE_MANAGER_PROXY (user_data);
GClueClientProxy *client = GCLUE_CLIENT_PROXY (source_object);
GError *error = NULL;
textdomain (GETTEXT_PACKAGE);
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
g_set_application_name (_("Where Am I"));
if (!gclue_client_call_start_finish (client, res, &error)) {
g_critical ("Failed to start GeoClue2 client: %s", error->message);
error = NULL;
manager = gclue_manager_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE,
"org.freedesktop.GeoClue2",
"/org/freedesktop/GeoClue2/Manager",
NULL,
&error);
exit (-4);
}
g_object_unref (client);
g_object_unref (manager);
g_main_loop_quit (main_loop);
}
static void
on_client_proxy_ready (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
GClueClientProxy *client;
GError *error = NULL;
client = gclue_client_proxy_new_for_bus_finish (res, &error);
if (error != NULL) {
g_critical ("Failed to connect to GeoClue2 service: %s", error->message);
exit (-1);
exit (-3);
}
if (!gclue_manager_call_get_client_sync (manager,
&client_path,
NULL,
&error)) {
gclue_client_call_start (client, NULL, on_start_ready, user_data);
}
static void
on_get_client_ready (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
GClueManagerProxy *manager = GCLUE_MANAGER_PROXY (source_object);
const char *client_path;
GError *error = NULL;
if (!gclue_manager_call_get_client_finish (manager, &client_path, res, &error)) {
g_critical ("Failed to connect to GeoClue2 service: %s", error->message);
exit (-2);
......@@ -64,26 +85,54 @@ main (gint argc, gchar *argv[])
g_print ("Client object: %s\n", client_path);
client = gclue_client_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
gclue_client_proxy_new_for_bus (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE,
"org.freedesktop.GeoClue2",
client_path,
NULL,
&error);
on_client_proxy_ready,
manager);
}
static void
on_manager_proxy_ready (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
GClueManagerProxy *manager;
GError *error = NULL;
manager = gclue_manager_proxy_new_for_bus_finish (res, &error);
if (error != NULL) {
g_critical ("Failed to connect to GeoClue2 service: %s", error->message);
exit (-3);
exit (-1);
}
if (!gclue_client_call_start_sync (client, NULL, &error)) {
g_critical ("Failed to start GeoClue2 client: %s", error->message);
gclue_manager_call_get_client (manager,
NULL,
on_get_client_ready,
NULL);
}
exit (-4);
}
gint
main (gint argc, gchar *argv[])
{
textdomain (GETTEXT_PACKAGE);
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
g_set_application_name (_("Where Am I"));
g_object_unref (client);
g_object_unref (manager);
gclue_manager_proxy_new_for_bus (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_NONE,
"org.freedesktop.GeoClue2",
"/org/freedesktop/GeoClue2/Manager",
NULL,
on_manager_proxy_ready,
NULL);
main_loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (main_loop);
return EXIT_SUCCESS;
}
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