1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
3
* Copyright (C) 2007 David Zeuthen <david@fubar.dk>
5
* Permission is hereby granted, free of charge, to any person
6
* obtaining a copy of this software and associated documentation
7
* files (the "Software"), to deal in the Software without
8
* restriction, including without limitation the rights to use, copy,
9
* modify, merge, publish, distribute, sublicense, and/or sell copies
10
* of the Software, and to permit persons to whom the Software is
11
* furnished to do so, subject to the following conditions:
13
* The above copyright notice and this permission notice shall be
14
* included in all copies or substantial portions of the Software.
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23
* DEALINGS IN THE SOFTWARE.
33
#include <sys/types.h>
37
#include <glib/gi18n-lib.h>
38
#include <glib-object.h>
40
#include <dbus/dbus-glib.h>
41
#include <dbus/dbus-glib-lowlevel.h>
42
#include <devkit-gobject.h>
44
#include "egg-debug.h"
45
#include "dkp-daemon.h"
47
#define NAME_TO_CLAIM "org.freedesktop.DeviceKit.Power"
48
static GMainLoop *loop = NULL;
51
* main_acquire_name_on_proxy:
54
main_acquire_name_on_proxy (DBusGProxy *bus_proxy)
63
if (bus_proxy == NULL) {
68
res = dbus_g_proxy_call (bus_proxy,
71
G_TYPE_STRING, NAME_TO_CLAIM,
78
egg_warning ("Failed to acquire %s: %s", NAME_TO_CLAIM, error->message);
81
egg_warning ("Failed to acquire %s", NAME_TO_CLAIM);
86
if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
88
egg_warning ("Failed to acquire %s: %s", NAME_TO_CLAIM, error->message);
91
egg_warning ("Failed to acquire %s", NAME_TO_CLAIM);
103
* dkp_main_sigint_handler:
106
dkp_main_sigint_handler (int sig)
108
egg_debug ("Handling SIGINT");
110
/* restore default */
111
signal (SIGINT, SIG_DFL);
114
g_main_loop_quit (loop);
121
main (int argc, char **argv)
124
DkpDaemon *power_daemon;
125
GOptionContext *context;
126
DBusGProxy *bus_proxy;
127
DBusGConnection *bus;
128
gboolean verbose = FALSE;
131
const GOptionEntry entries[] = {
132
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
133
_("Show extra debugging information"), NULL },
139
context = g_option_context_new ("DeviceKit Power Daemon");
140
g_option_context_add_main_entries (context, entries, NULL);
141
g_option_context_parse (context, &argc, &argv, NULL);
142
g_option_context_free (context);
143
egg_debug_init (verbose);
146
bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
148
egg_warning ("Couldn't connect to system bus: %s", error->message);
149
g_error_free (error);
153
bus_proxy = dbus_g_proxy_new_for_name (bus, DBUS_SERVICE_DBUS,
154
DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
155
if (bus_proxy == NULL) {
156
egg_warning ("Could not construct bus_proxy object; bailing out");
160
if (!main_acquire_name_on_proxy (bus_proxy) ) {
161
egg_warning ("Could not acquire name; bailing out");
165
/* do stuff on ctrl-c */
166
signal (SIGINT, dkp_main_sigint_handler);
168
egg_debug ("Starting devkit-power-daemon version %s", VERSION);
170
power_daemon = dkp_daemon_new ();
172
if (power_daemon == NULL)
175
loop = g_main_loop_new (NULL, FALSE);
176
g_main_loop_run (loop);
178
g_object_unref (power_daemon);
179
g_main_loop_unref (loop);