~deejay1/geoclue/master

« back to all changes in this revision

Viewing changes to src/gclue-main.c

  • Committer: Zeeshan Ali (Khattak)
  • Date: 2013-05-28 09:21:20 UTC
  • Revision ID: git-v1:f8613abd7d3634eaa09db8f17c9d99fc83d3b539
First commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* vim: set et ts=8 sw=8: */
 
2
/* main.c
 
3
 *
 
4
 * Copyright (C) 2013 Red Hat, Inc.
 
5
 *
 
6
 * This file is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU Lesser General Public
 
8
 * License as published by the Free Software Foundation; either
 
9
 * version 2.1 of the License, or (at your option) any later version.
 
10
 *
 
11
 * This file is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * Lesser General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 *
 
19
 * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
 
20
 */
 
21
#include <config.h>
 
22
 
 
23
#include <glib.h>
 
24
#include <locale.h>
 
25
#include <glib/gi18n.h>
 
26
 
 
27
#include "gclue-service-manager.h"
 
28
 
 
29
#define BUS_NAME "org.freedesktop.GeoClue2"
 
30
 
 
31
GClueServiceManager *manager;
 
32
 
 
33
static void
 
34
on_bus_acquired (GDBusConnection *connection,
 
35
                 const gchar     *name,
 
36
                 gpointer         user_data)
 
37
{
 
38
        GError *error = NULL;
 
39
 
 
40
        if (!gclue_service_manager_export (manager, connection, &error)) {
 
41
                g_critical ("Failed to register server: %s", error->message);
 
42
                g_error_free (&error);
 
43
 
 
44
                exit (-2);
 
45
        }
 
46
}
 
47
 
 
48
on_name_lost (GDBusConnection *connection,
 
49
              const gchar     *name,
 
50
              gpointer         user_data)
 
51
{
 
52
        g_critical ("Failed to acquire name '%s' on session bus or lost it.", name);
 
53
 
 
54
        exit (-3);
 
55
}
 
56
 
 
57
int
 
58
main (int argc, char **argv)
 
59
{
 
60
        GMainLoop *main_loop;
 
61
        guint owner_id;
 
62
 
 
63
        textdomain (GETTEXT_PACKAGE);
 
64
        bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
 
65
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 
66
        g_set_application_name (_("GeoClue"));
 
67
 
 
68
        manager = gclue_service_manager_new ();
 
69
 
 
70
        owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
 
71
                                   BUS_NAME,
 
72
                                   G_BUS_NAME_OWNER_FLAGS_NONE,
 
73
                                   on_bus_acquired,
 
74
                                   NULL,
 
75
                                   on_name_lost,
 
76
                                   NULL,
 
77
                                   NULL);
 
78
 
 
79
        main_loop = g_main_loop_new (NULL, FALSE);
 
80
        g_main_loop_run (main_loop);
 
81
 
 
82
        g_object_unref (manager);
 
83
        g_bus_unown_name (owner_id);
 
84
        g_main_loop_unref (main_loop);
 
85
 
 
86
        return 0;
 
87
}