summaryrefslogtreecommitdiff
path: root/src/dkp-main.c
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2009-07-27 16:40:11 +0100
committerRichard Hughes <richard@hughsie.com>2009-07-27 16:40:11 +0100
commit0c8d29a90f5b5b7d84ec834213ac7e4390e89db9 (patch)
tree913239be76d6075d7926c8cd1252060ca9dc170f /src/dkp-main.c
parent8cf5c058c337a114d6fc5cf18593c5ecf1099efd (diff)
Initial split to make DeviceKit-power compile without GUdev for non-linux platforms
Diffstat (limited to 'src/dkp-main.c')
-rw-r--r--src/dkp-main.c88
1 files changed, 43 insertions, 45 deletions
diff --git a/src/dkp-main.c b/src/dkp-main.c
index 9f33d60..ed9f81c 100644
--- a/src/dkp-main.c
+++ b/src/dkp-main.c
@@ -1,27 +1,23 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2007 David Zeuthen <davidz@redhat.com>
+ * Copyright (C) 2008-2009 Richard Hughes <richard@hughsie.com>
*
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use, copy,
- * modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
+ * Licensed under the GNU General Public License Version 2
*
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
+ * This program 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.
*
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
@@ -39,7 +35,6 @@
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
-#include <gudev/gudev.h>
#include "egg-debug.h"
@@ -47,53 +42,49 @@
#include "dkp-qos.h"
#include "dkp-wakeups.h"
-#define NAME_TO_CLAIM "org.freedesktop.DeviceKit.Power"
+#define DEVKIT_POWER_SERVICE_NAME "org.freedesktop.DeviceKit.Power"
static GMainLoop *loop = NULL;
/**
- * main_acquire_name_on_proxy:
+ * dkp_main_acquire_name_on_proxy:
**/
static gboolean
-main_acquire_name_on_proxy (DBusGProxy *bus_proxy)
+dkp_main_acquire_name_on_proxy (DBusGProxy *bus_proxy, const gchar *name)
{
- GError *error;
+ GError *error = NULL;
guint result;
- gboolean res;
gboolean ret = FALSE;
if (bus_proxy == NULL)
goto out;
- error = NULL;
- res = dbus_g_proxy_call (bus_proxy,
- "RequestName",
- &error,
- G_TYPE_STRING, NAME_TO_CLAIM,
+ ret = dbus_g_proxy_call (bus_proxy, "RequestName", &error,
+ G_TYPE_STRING, name,
G_TYPE_UINT, 0,
G_TYPE_INVALID,
G_TYPE_UINT, &result,
G_TYPE_INVALID);
- if (!res) {
+ if (!ret) {
if (error != NULL) {
- egg_warning ("Failed to acquire %s: %s", NAME_TO_CLAIM, error->message);
+ egg_warning ("Failed to acquire %s: %s", name, error->message);
g_error_free (error);
} else {
- egg_warning ("Failed to acquire %s", NAME_TO_CLAIM);
+ egg_warning ("Failed to acquire %s", name);
}
goto out;
}
+ /* already taken */
if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
if (error != NULL) {
- egg_warning ("Failed to acquire %s: %s", NAME_TO_CLAIM, error->message);
+ egg_warning ("Failed to acquire %s: %s", name, error->message);
g_error_free (error);
} else {
- egg_warning ("Failed to acquire %s", NAME_TO_CLAIM);
+ egg_warning ("Failed to acquire %s", name);
}
+ ret = FALSE;
goto out;
}
-
- ret = TRUE;
out:
return ret;
}
@@ -102,7 +93,7 @@ out:
* dkp_main_sigint_handler:
**/
static void
-dkp_main_sigint_handler (int sig)
+dkp_main_sigint_handler (gint sig)
{
egg_debug ("Handling SIGINT");
@@ -116,10 +107,10 @@ dkp_main_sigint_handler (int sig)
/**
* main:
**/
-int
-main (int argc, char **argv)
+gint
+main (gint argc, gchar **argv)
{
- GError *error;
+ GError *error = NULL;
DkpDaemon *daemon;
DkpQos *qos;
DkpWakeups *wakeups;
@@ -127,7 +118,8 @@ main (int argc, char **argv)
DBusGProxy *bus_proxy;
DBusGConnection *bus;
gboolean verbose = FALSE;
- int ret = 1;
+ gboolean ret;
+ gint retval = 1;
const GOptionEntry entries[] = {
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
@@ -143,7 +135,7 @@ main (int argc, char **argv)
g_option_context_free (context);
egg_debug_init (verbose);
- error = NULL;
+ /* get bus connection */
bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
if (bus == NULL) {
egg_warning ("Couldn't connect to system bus: %s", error->message);
@@ -151,6 +143,7 @@ main (int argc, char **argv)
goto out;
}
+ /* get proxy */
bus_proxy = dbus_g_proxy_new_for_name (bus, DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
if (bus_proxy == NULL) {
@@ -158,7 +151,9 @@ main (int argc, char **argv)
goto out;
}
- if (!main_acquire_name_on_proxy (bus_proxy) ) {
+ /* aquire name */
+ ret = dkp_main_acquire_name_on_proxy (bus_proxy, DEVKIT_POWER_SERVICE_NAME);
+ if (!ret) {
egg_warning ("Could not acquire name; bailing out");
goto out;
}
@@ -171,8 +166,11 @@ main (int argc, char **argv)
qos = dkp_qos_new ();
wakeups = dkp_wakeups_new ();
daemon = dkp_daemon_new ();
- if (daemon == NULL)
+ ret = dkp_daemon_startup (daemon);
+ if (!ret) {
+ egg_warning ("Could not startup; bailing out");
goto out;
+ }
loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (loop);
@@ -181,8 +179,8 @@ main (int argc, char **argv)
g_object_unref (wakeups);
g_object_unref (daemon);
g_main_loop_unref (loop);
- ret = 0;
+ retval = 0;
out:
- return ret;
+ return retval;
}