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

demo: Use async API

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