summaryrefslogtreecommitdiff
path: root/demo/agent.c
blob: b55fc059afe95b502abe1bab15d2f85c02a6c671 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* vim: set et ts=8 sw=8: */
/* agent.c
 *
 * Copyright 2013 Red Hat, Inc.
 *
 * Geoclue is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * Geoclue is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along
 * with Geoclue; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
 */
#include <config.h>

#include <gio/gio.h>
#include <locale.h>
#include <glib/gi18n.h>
#include <stdlib.h>
#include <libnotify/notify.h>

#include "gclue-service-agent.h"

/* Commandline options */
static gboolean version;

static GOptionEntry entries[] =
{
        { "version",
          0,
          0,
          G_OPTION_ARG_NONE,
          &version,
          N_("Display version number"),
          NULL },
        { NULL }
};

GClueServiceAgent *agent = NULL;

static void
on_get_bus_ready (GObject      *source_object,
                  GAsyncResult *res,
                  gpointer      user_data)
{
        g_autoptr(GError) error = NULL;
        GDBusConnection *connection;

        connection = g_bus_get_finish (res, &error);
        if (connection == NULL) {
                g_critical ("Failed to get connection to system bus: %s",
                            error->message);

                exit (-2);
        }

        agent = gclue_service_agent_new (connection);
}

#define ABS_PATH ABS_SRCDIR "/agent"

int
main (int argc, char **argv)
{
        GMainLoop *main_loop;
        GError *error = NULL;
        GOptionContext *context;

        setlocale (LC_ALL, "");

        textdomain (GETTEXT_PACKAGE);
        bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
        g_set_application_name ("GeoClue Agent");

        notify_init (_("GeoClue"));

        context = g_option_context_new ("- Geoclue Agent service");
        g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
        if (!g_option_context_parse (context, &argc, &argv, &error)) {
                g_critical ("option parsing failed: %s\n", error->message);
                exit (-1);
        }

        if (version) {
                g_print ("%s\n", PACKAGE_VERSION);
                exit (0);
        }

        g_bus_get (G_BUS_TYPE_SYSTEM,
                   NULL,
                   on_get_bus_ready,
                   NULL);

        main_loop = g_main_loop_new (NULL, FALSE);
        g_main_loop_run (main_loop);

        if (agent != NULL)
                g_object_unref (agent);
        g_main_loop_unref (main_loop);

        return 0;
}