gclue-main.c 2.54 KB
Newer Older
Zeeshan Ali's avatar
Zeeshan Ali committed
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
/* vim: set et ts=8 sw=8: */
/* main.c
 *
 * Copyright (C) 2013 Red Hat, Inc.
 *
 * This file is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This file 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Author: Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
 */
#include <config.h>

#include <glib.h>
#include <locale.h>
#include <glib/gi18n.h>

#include "gclue-service-manager.h"

#define BUS_NAME "org.freedesktop.GeoClue2"

31
GClueServiceManager *manager = NULL;
Zeeshan Ali's avatar
Zeeshan Ali committed
32 33 34 35 36 37 38 39

static void
on_bus_acquired (GDBusConnection *connection,
                 const gchar     *name,
                 gpointer         user_data)
{
        GError *error = NULL;

40 41
        manager = gclue_service_manager_new (connection, &error);
        if (error != NULL) {
Zeeshan Ali's avatar
Zeeshan Ali committed
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
                g_critical ("Failed to register server: %s", error->message);
                g_error_free (&error);

                exit (-2);
        }
}

on_name_lost (GDBusConnection *connection,
              const gchar     *name,
              gpointer         user_data)
{
        g_critical ("Failed to acquire name '%s' on session bus or lost it.", name);

        exit (-3);
}

int
main (int argc, char **argv)
{
        GMainLoop *main_loop;
        guint owner_id;

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

        owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
                                   BUS_NAME,
                                   G_BUS_NAME_OWNER_FLAGS_NONE,
                                   on_bus_acquired,
                                   NULL,
                                   on_name_lost,
                                   NULL,
                                   NULL);

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

81 82
        if (manager != NULL);
                g_object_unref (manager);
Zeeshan Ali's avatar
Zeeshan Ali committed
83 84 85 86 87
        g_bus_unown_name (owner_id);
        g_main_loop_unref (main_loop);

        return 0;
}