convert spaces to tabs, and make sure functions have sensible names

This commit is contained in:
Richard Hughes 2008-08-01 12:07:56 +01:00
parent cbaa6851d4
commit 4f934ad2df
10 changed files with 1519 additions and 1397 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,4 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 David Zeuthen <david@fubar.dk>
*
@ -27,10 +27,10 @@
G_BEGIN_DECLS
#define DKP_SOURCE_TYPE_DAEMON (dkp_daemon_get_type ())
#define DKP_DAEMON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), DKP_SOURCE_TYPE_DAEMON, DkpDaemon))
#define DKP_DAEMON_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), DKP_SOURCE_TYPE_DAEMON, DkpDaemonClass))
#define DKP_IS_DAEMON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), DKP_SOURCE_TYPE_DAEMON))
#define DKP_SOURCE_TYPE_DAEMON (dkp_daemon_get_type ())
#define DKP_DAEMON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), DKP_SOURCE_TYPE_DAEMON, DkpDaemon))
#define DKP_DAEMON_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), DKP_SOURCE_TYPE_DAEMON, DkpDaemonClass))
#define DKP_IS_DAEMON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), DKP_SOURCE_TYPE_DAEMON))
#define DKP_IS_DAEMON_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), DKP_SOURCE_TYPE_DAEMON))
#define DKP_DAEMON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), DKP_SOURCE_TYPE_DAEMON, DkpDaemonClass))
@ -38,21 +38,21 @@ typedef struct DkpDaemonPrivate DkpDaemonPrivate;
typedef struct
{
GObject parent;
DkpDaemonPrivate *priv;
GObject parent;
DkpDaemonPrivate *priv;
} DkpDaemon;
typedef struct
{
GObjectClass parent_class;
GObjectClass parent_class;
} DkpDaemonClass;
typedef enum
{
DKP_DAEMON_ERROR_GENERAL,
DKP_DAEMON_ERROR_NOT_SUPPORTED,
DKP_DAEMON_ERROR_NO_SUCH_DEVICE,
DKP_DAEMON_NUM_ERRORS
DKP_DAEMON_ERROR_GENERAL,
DKP_DAEMON_ERROR_NOT_SUPPORTED,
DKP_DAEMON_ERROR_NO_SUCH_DEVICE,
DKP_DAEMON_NUM_ERRORS
} DkpDaemonError;
#define DKP_DAEMON_ERROR dkp_daemon_error_quark ()
@ -60,32 +60,31 @@ typedef enum
GType dkp_daemon_error_get_type (void);
#define DKP_DAEMON_TYPE_ERROR (dkp_daemon_error_get_type ())
GQuark dkp_daemon_error_quark (void);
GType dkp_daemon_get_type (void);
DkpDaemon *dkp_daemon_new (void);
GQuark dkp_daemon_error_quark (void);
GType dkp_daemon_get_type (void);
DkpDaemon *dkp_daemon_new (void);
/* local methods */
PolKitCaller *dkp_daemon_local_get_caller_for_context (DkpDaemon *daemon,
DBusGMethodInvocation *context);
PolKitCaller *dkp_daemon_local_get_caller_for_context (DkpDaemon *daemon,
DBusGMethodInvocation *context);
gboolean dkp_daemon_local_check_auth (DkpDaemon *daemon,
PolKitCaller *pk_caller,
const char *action_id,
DBusGMethodInvocation *context);
gboolean dkp_daemon_local_check_auth (DkpDaemon *daemon,
PolKitCaller *pk_caller,
const char *action_id,
DBusGMethodInvocation *context);
/* exported methods */
gboolean dkp_daemon_enumerate_devices (DkpDaemon *daemon,
DBusGMethodInvocation *context);
gboolean dkp_daemon_get_on_battery (DkpDaemon *daemon,
DBusGMethodInvocation *context);
gboolean dkp_daemon_get_low_battery (DkpDaemon *daemon,
DBusGMethodInvocation *context);
gboolean dkp_daemon_suspend (DkpDaemon *daemon,
DBusGMethodInvocation *context);
gboolean dkp_daemon_hibernate (DkpDaemon *daemon,
DBusGMethodInvocation *context);
gboolean dkp_daemon_enumerate_devices (DkpDaemon *daemon,
DBusGMethodInvocation *context);
gboolean dkp_daemon_get_on_battery (DkpDaemon *daemon,
DBusGMethodInvocation *context);
gboolean dkp_daemon_get_low_battery (DkpDaemon *daemon,
DBusGMethodInvocation *context);
gboolean dkp_daemon_suspend (DkpDaemon *daemon,
DBusGMethodInvocation *context);
gboolean dkp_daemon_hibernate (DkpDaemon *daemon,
DBusGMethodInvocation *context);
G_END_DECLS

View file

@ -1,4 +1,4 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 David Zeuthen <david@fubar.dk>
*
@ -38,55 +38,72 @@
#include "dkp-source.h"
static void dkp_device_class_init (DkpDeviceClass *klass);
static void dkp_device_init (DkpDevice *seat);
static void dkp_device_init (DkpDevice *seat);
G_DEFINE_TYPE (DkpDevice, dkp_device, G_TYPE_OBJECT)
#define DKP_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DKP_SOURCE_TYPE_DEVICE, DkpDevicePrivate))
/**
* dkp_device_class_init:
**/
static void
dkp_device_class_init (DkpDeviceClass *klass)
{
}
/**
* dkp_device_init:
**/
static void
dkp_device_init (DkpDevice *device)
{
}
/**
* dkp_device_removed:
**/
void
dkp_device_removed (DkpDevice *device)
{
DkpDeviceClass *klass = DKP_DEVICE_GET_CLASS (device);
klass->removed (device);
DkpDeviceClass *klass = DKP_DEVICE_GET_CLASS (device);
klass->removed (device);
}
/**
* dkp_device_new:
**/
DkpDevice *
dkp_device_new (DkpDaemon *daemon, DevkitDevice *d)
{
const char *subsys;
DkpDevice *device;
const char *subsys;
DkpDevice *device;
device = NULL;
device = NULL;
subsys = devkit_device_get_subsystem (d);
if (strcmp (subsys, "power_supply") == 0) {
device = DKP_DEVICE (dkp_source_new (daemon, d));
}
subsys = devkit_device_get_subsystem (d);
if (strcmp (subsys, "power_supply") == 0)
device = DKP_DEVICE (dkp_source_new (daemon, d));
return device;
return device;
}
/**
* dkp_device_changed:
**/
gboolean
dkp_device_changed (DkpDevice *device, DevkitDevice *d, gboolean synthesized)
{
DkpDeviceClass *klass = DKP_DEVICE_GET_CLASS (device);
return (klass->changed (device, d, synthesized));
DkpDeviceClass *klass = DKP_DEVICE_GET_CLASS (device);
return (klass->changed (device, d, synthesized));
}
/**
* dkp_device_get_object_path:
**/
const char *
dkp_device_get_object_path (DkpDevice *device)
{
DkpDeviceClass *klass = DKP_DEVICE_GET_CLASS (device);
return (klass->get_object_path (device));
DkpDeviceClass *klass = DKP_DEVICE_GET_CLASS (device);
return (klass->get_object_path (device));
}

View file

@ -1,4 +1,4 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 David Zeuthen <david@fubar.dk>
*
@ -29,39 +29,38 @@
G_BEGIN_DECLS
#define DKP_SOURCE_TYPE_DEVICE (dkp_device_get_type ())
#define DKP_DEVICE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), DKP_SOURCE_TYPE_DEVICE, DkpDevice))
#define DKP_DEVICE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), DKP_SOURCE_TYPE_DEVICE, DkpDeviceClass))
#define DKP_IS_DEVICE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), DKP_SOURCE_TYPE_DEVICE))
#define DKP_SOURCE_TYPE_DEVICE (dkp_device_get_type ())
#define DKP_DEVICE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), DKP_SOURCE_TYPE_DEVICE, DkpDevice))
#define DKP_DEVICE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), DKP_SOURCE_TYPE_DEVICE, DkpDeviceClass))
#define DKP_IS_DEVICE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), DKP_SOURCE_TYPE_DEVICE))
#define DKP_IS_DEVICE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), DKP_SOURCE_TYPE_DEVICE))
#define DKP_DEVICE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), DKP_SOURCE_TYPE_DEVICE, DkpDeviceClass))
typedef struct
{
GObject parent;
GObject parent;
} DkpDevice;
typedef struct
{
GObjectClass parent_class;
GObjectClass parent_class;
/* vtable */
gboolean (*changed) (DkpDevice *device,
DevkitDevice *d,
gboolean synthesized);
void (*removed) (DkpDevice *device);
const char *(*get_object_path) (DkpDevice *device);
/* vtable */
gboolean (*changed) (DkpDevice *device,
DevkitDevice *d,
gboolean synthesized);
void (*removed) (DkpDevice *device);
const char *(*get_object_path) (DkpDevice *device);
} DkpDeviceClass;
GType dkp_device_get_type (void);
DkpDevice *dkp_device_new (DkpDaemon *daemon,
DevkitDevice *d);
gboolean dkp_device_changed (DkpDevice *device,
DevkitDevice *d,
gboolean synthesized);
void dkp_device_removed (DkpDevice *device);
const char *dkp_device_get_object_path (DkpDevice *device);
GType dkp_device_get_type (void);
DkpDevice *dkp_device_new (DkpDaemon *daemon,
DevkitDevice *d);
gboolean dkp_device_changed (DkpDevice *device,
DevkitDevice *d,
gboolean synthesized);
void dkp_device_removed (DkpDevice *device);
const char *dkp_device_get_object_path (DkpDevice *device);
G_END_DECLS

View file

@ -1,4 +1,4 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 David Zeuthen <david@fubar.dk>
* Copyright (C) 2008 Richard Hughes <richard@hughsie.com>
@ -23,96 +23,108 @@
#include <strings.h>
#include "dkp-enum.h"
/**
* dkp_source_type_to_text:
**/
const char *
dkp_source_type_to_text (DkpSourceType type_enum)
{
const char *type = NULL;
switch (type_enum) {
case DKP_SOURCE_TYPE_LINE_POWER:
type = "line-power";
break;
case DKP_SOURCE_TYPE_BATTERY:
type = "battery";
break;
case DKP_SOURCE_TYPE_UPS:
type = "ups";
break;
case DKP_SOURCE_TYPE_MOUSE:
type = "mouse";
break;
case DKP_SOURCE_TYPE_KEYBOARD:
type = "keyboard";
break;
case DKP_SOURCE_TYPE_PDA:
type = "pda";
break;
case DKP_SOURCE_TYPE_PHONE:
type = "phone";
break;
default:
g_assert_not_reached ();
break;
}
return type;
const char *type = NULL;
switch (type_enum) {
case DKP_SOURCE_TYPE_LINE_POWER:
type = "line-power";
break;
case DKP_SOURCE_TYPE_BATTERY:
type = "battery";
break;
case DKP_SOURCE_TYPE_UPS:
type = "ups";
break;
case DKP_SOURCE_TYPE_MOUSE:
type = "mouse";
break;
case DKP_SOURCE_TYPE_KEYBOARD:
type = "keyboard";
break;
case DKP_SOURCE_TYPE_PDA:
type = "pda";
break;
case DKP_SOURCE_TYPE_PHONE:
type = "phone";
break;
default:
g_assert_not_reached ();
break;
}
return type;
}
/**
* dkp_source_state_to_text:
**/
const char *
dkp_source_state_to_text (DkpSourceState state_enum)
{
const char *state = NULL;
switch (state_enum) {
case DKP_SOURCE_STATE_CHARGING:
state = "charging";
break;
case DKP_SOURCE_STATE_DISCHARGING:
state = "discharging";
break;
case DKP_SOURCE_STATE_EMPTY:
state = "empty";
break;
case DKP_SOURCE_STATE_FULLY_CHARGED:
state = "fully-charged";
break;
default:
g_assert_not_reached ();
break;
}
return state;
const char *state = NULL;
switch (state_enum) {
case DKP_SOURCE_STATE_CHARGING:
state = "charging";
break;
case DKP_SOURCE_STATE_DISCHARGING:
state = "discharging";
break;
case DKP_SOURCE_STATE_EMPTY:
state = "empty";
break;
case DKP_SOURCE_STATE_FULLY_CHARGED:
state = "fully-charged";
break;
default:
g_assert_not_reached ();
break;
}
return state;
}
/**
* dkp_source_technology_to_text:
**/
const char *
dkp_source_technology_to_text (DkpSourceTechnology technology_enum)
{
const char *technology = NULL;
switch (technology_enum) {
case DKP_SOURCE_TECHNOLGY_LITHIUM_ION:
technology = "lithium-ion";
break;
case DKP_SOURCE_TECHNOLGY_LITHIUM_POLYMER:
technology = "lithium-polymer";
break;
case DKP_SOURCE_TECHNOLGY_LITHIUM_IRON_PHOSPHATE:
technology = "lithium-iron-phosphate";
break;
case DKP_SOURCE_TECHNOLGY_LEAD_ACID:
technology = "lead-acid";
break;
case DKP_SOURCE_TECHNOLGY_NICKEL_CADMIUM:
technology = "nickel-cadmium";
break;
case DKP_SOURCE_TECHNOLGY_NICKEL_METAL_HYDRIDE:
technology = "nickel-metal-hydride";
break;
case DKP_SOURCE_TECHNOLGY_UNKNOWN:
technology = "unknown";
break;
default:
g_assert_not_reached ();
break;
}
return technology;
const char *technology = NULL;
switch (technology_enum) {
case DKP_SOURCE_TECHNOLGY_LITHIUM_ION:
technology = "lithium-ion";
break;
case DKP_SOURCE_TECHNOLGY_LITHIUM_POLYMER:
technology = "lithium-polymer";
break;
case DKP_SOURCE_TECHNOLGY_LITHIUM_IRON_PHOSPHATE:
technology = "lithium-iron-phosphate";
break;
case DKP_SOURCE_TECHNOLGY_LEAD_ACID:
technology = "lead-acid";
break;
case DKP_SOURCE_TECHNOLGY_NICKEL_CADMIUM:
technology = "nickel-cadmium";
break;
case DKP_SOURCE_TECHNOLGY_NICKEL_METAL_HYDRIDE:
technology = "nickel-metal-hydride";
break;
case DKP_SOURCE_TECHNOLGY_UNKNOWN:
technology = "unknown";
break;
default:
g_assert_not_reached ();
break;
}
return technology;
}
/**
* dkp_acpi_to_source_technology:
**/
DkpSourceTechnology
dkp_acpi_to_source_technology (const char *type)
{

View file

@ -1,4 +1,4 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 David Zeuthen <david@fubar.dk>
* Copyright (C) 2008 Richard Hughes <richard@hughsie.com>
@ -27,38 +27,38 @@
G_BEGIN_DECLS
typedef enum {
DKP_SOURCE_TYPE_LINE_POWER,
DKP_SOURCE_TYPE_BATTERY,
DKP_SOURCE_TYPE_UPS,
DKP_SOURCE_TYPE_MOUSE,
DKP_SOURCE_TYPE_KEYBOARD,
DKP_SOURCE_TYPE_PDA,
DKP_SOURCE_TYPE_PHONE,
DKP_SOURCE_TYPE_UNKNOWN
DKP_SOURCE_TYPE_LINE_POWER,
DKP_SOURCE_TYPE_BATTERY,
DKP_SOURCE_TYPE_UPS,
DKP_SOURCE_TYPE_MOUSE,
DKP_SOURCE_TYPE_KEYBOARD,
DKP_SOURCE_TYPE_PDA,
DKP_SOURCE_TYPE_PHONE,
DKP_SOURCE_TYPE_UNKNOWN
} DkpSourceType;
typedef enum {
DKP_SOURCE_STATE_CHARGING,
DKP_SOURCE_STATE_DISCHARGING,
DKP_SOURCE_STATE_EMPTY,
DKP_SOURCE_STATE_FULLY_CHARGED,
DKP_SOURCE_STATE_UNKNOWN
DKP_SOURCE_STATE_CHARGING,
DKP_SOURCE_STATE_DISCHARGING,
DKP_SOURCE_STATE_EMPTY,
DKP_SOURCE_STATE_FULLY_CHARGED,
DKP_SOURCE_STATE_UNKNOWN
} DkpSourceState;
typedef enum {
DKP_SOURCE_TECHNOLGY_LITHIUM_ION,
DKP_SOURCE_TECHNOLGY_LITHIUM_POLYMER,
DKP_SOURCE_TECHNOLGY_LITHIUM_IRON_PHOSPHATE,
DKP_SOURCE_TECHNOLGY_LEAD_ACID,
DKP_SOURCE_TECHNOLGY_NICKEL_CADMIUM,
DKP_SOURCE_TECHNOLGY_NICKEL_METAL_HYDRIDE,
DKP_SOURCE_TECHNOLGY_UNKNOWN
DKP_SOURCE_TECHNOLGY_LITHIUM_ION,
DKP_SOURCE_TECHNOLGY_LITHIUM_POLYMER,
DKP_SOURCE_TECHNOLGY_LITHIUM_IRON_PHOSPHATE,
DKP_SOURCE_TECHNOLGY_LEAD_ACID,
DKP_SOURCE_TECHNOLGY_NICKEL_CADMIUM,
DKP_SOURCE_TECHNOLGY_NICKEL_METAL_HYDRIDE,
DKP_SOURCE_TECHNOLGY_UNKNOWN
} DkpSourceTechnology;
const char *dkp_source_type_to_text (DkpSourceType type_enum);
const char *dkp_source_state_to_text (DkpSourceState state_enum);
const char *dkp_source_technology_to_text (DkpSourceTechnology technology_enum);
DkpSourceTechnology dkp_acpi_to_source_technology (const char *type);
const char *dkp_source_type_to_text (DkpSourceType type_enum);
const char *dkp_source_state_to_text (DkpSourceState state_enum);
const char *dkp_source_technology_to_text (DkpSourceTechnology technology_enum);
DkpSourceTechnology dkp_acpi_to_source_technology (const char *type);
G_END_DECLS

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,4 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 David Zeuthen <david@fubar.dk>
*
@ -30,10 +30,10 @@
G_BEGIN_DECLS
#define DKP_SOURCE_TYPE_SOURCE (dkp_source_get_type ())
#define DKP_SOURCE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), DKP_SOURCE_TYPE_SOURCE, DkpSource))
#define DKP_SOURCE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), DKP_SOURCE_TYPE_SOURCE, DkpSourceClass))
#define DKP_IS_SOURCE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), DKP_SOURCE_TYPE_SOURCE))
#define DKP_SOURCE_TYPE_SOURCE (dkp_source_get_type ())
#define DKP_SOURCE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), DKP_SOURCE_TYPE_SOURCE, DkpSource))
#define DKP_SOURCE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), DKP_SOURCE_TYPE_SOURCE, DkpSourceClass))
#define DKP_IS_SOURCE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), DKP_SOURCE_TYPE_SOURCE))
#define DKP_IS_SOURCE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), DKP_SOURCE_TYPE_SOURCE))
#define DKP_SOURCE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), DKP_SOURCE_TYPE_SOURCE, DkpSourceClass))
@ -41,24 +41,23 @@ typedef struct DkpSourcePrivate DkpSourcePrivate;
typedef struct
{
DkpDevice parent;
DkpSourcePrivate *priv;
DkpDevice parent;
DkpSourcePrivate *priv;
} DkpSource;
typedef struct
{
DkpDeviceClass parent_class;
DkpDeviceClass parent_class;
} DkpSourceClass;
GType dkp_source_get_type (void);
DkpSource *dkp_source_new (DkpDaemon *daemon,
DevkitDevice *d);
GType dkp_source_get_type (void);
DkpSource *dkp_source_new (DkpDaemon *daemon,
DevkitDevice *d);
/* exported methods */
gboolean dkp_source_refresh (DkpSource *power_source,
DBusGMethodInvocation *context);
gchar *dkp_source_get_id (DkpSource *power_source);
gboolean dkp_source_refresh (DkpSource *power_source,
DBusGMethodInvocation *context);
gchar *dkp_source_get_id (DkpSource *power_source);
G_END_DECLS

View file

@ -1,4 +1,4 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2007 David Zeuthen <david@fubar.dk>
*
@ -42,116 +42,122 @@
#define NAME_TO_CLAIM "org.freedesktop.DeviceKit.Power"
/**
* main_acquire_name_on_proxy:
**/
static gboolean
acquire_name_on_proxy (DBusGProxy *bus_proxy)
main_acquire_name_on_proxy (DBusGProxy *bus_proxy)
{
GError *error;
guint result;
gboolean res;
gboolean ret;
GError *error;
guint result;
gboolean res;
gboolean ret;
ret = FALSE;
ret = FALSE;
if (bus_proxy == NULL) {
goto out;
}
if (bus_proxy == NULL) {
goto out;
}
error = NULL;
error = NULL;
res = dbus_g_proxy_call (bus_proxy,
"RequestName",
&error,
G_TYPE_STRING, NAME_TO_CLAIM,
G_TYPE_UINT, 0,
G_TYPE_INVALID,
G_TYPE_UINT, &result,
G_TYPE_INVALID);
if (! res) {
if (error != NULL) {
g_warning ("Failed to acquire %s: %s", NAME_TO_CLAIM, error->message);
g_error_free (error);
} else {
g_warning ("Failed to acquire %s", NAME_TO_CLAIM);
}
goto out;
"RequestName",
&error,
G_TYPE_STRING, NAME_TO_CLAIM,
G_TYPE_UINT, 0,
G_TYPE_INVALID,
G_TYPE_UINT, &result,
G_TYPE_INVALID);
if (!res) {
if (error != NULL) {
g_warning ("Failed to acquire %s: %s", NAME_TO_CLAIM, error->message);
g_error_free (error);
} else {
g_warning ("Failed to acquire %s", NAME_TO_CLAIM);
}
goto out;
}
if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
if (error != NULL) {
g_warning ("Failed to acquire %s: %s", NAME_TO_CLAIM, error->message);
g_error_free (error);
} else {
g_warning ("Failed to acquire %s", NAME_TO_CLAIM);
}
goto out;
}
if (error != NULL) {
g_warning ("Failed to acquire %s: %s", NAME_TO_CLAIM, error->message);
g_error_free (error);
} else {
g_warning ("Failed to acquire %s", NAME_TO_CLAIM);
}
goto out;
}
ret = TRUE;
ret = TRUE;
out:
return ret;
return ret;
}
/**
* main:
**/
int
main (int argc, char **argv)
{
GError *error;
GMainLoop *loop;
DkpDaemon *power_daemon;
GOptionContext *context;
DBusGProxy *bus_proxy;
DBusGConnection *bus;
int ret;
static GOptionEntry entries [] = {
{ NULL }
};
GError *error;
GMainLoop *loop;
DkpDaemon *power_daemon;
GOptionContext *context;
DBusGProxy *bus_proxy;
DBusGConnection *bus;
int ret;
static GOptionEntry entries [] = {
{ NULL }
};
ret = 1;
ret = 1;
g_type_init ();
g_type_init ();
context = g_option_context_new ("DeviceKit Power Daemon");
g_option_context_add_main_entries (context, entries, NULL);
g_option_context_parse (context, &argc, &argv, NULL);
g_option_context_free (context);
context = g_option_context_new ("DeviceKit Power Daemon");
g_option_context_add_main_entries (context, entries, NULL);
g_option_context_parse (context, &argc, &argv, NULL);
g_option_context_free (context);
error = NULL;
bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
if (bus == NULL) {
g_warning ("Couldn't connect to system bus: %s", error->message);
g_error_free (error);
goto out;
}
error = NULL;
bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
if (bus == NULL) {
g_warning ("Couldn't connect to system bus: %s", error->message);
g_error_free (error);
goto out;
}
bus_proxy = dbus_g_proxy_new_for_name (bus,
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS);
if (bus_proxy == NULL) {
g_warning ("Could not construct bus_proxy object; bailing out");
goto out;
}
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS);
if (bus_proxy == NULL) {
g_warning ("Could not construct bus_proxy object; bailing out");
goto out;
}
if (!acquire_name_on_proxy (bus_proxy) ) {
g_warning ("Could not acquire name; bailing out");
goto out;
}
if (!main_acquire_name_on_proxy (bus_proxy) ) {
g_warning ("Could not acquire name; bailing out");
goto out;
}
g_debug ("Starting devkit-power-daemon version %s", VERSION);
g_debug ("Starting devkit-power-daemon version %s", VERSION);
power_daemon = dkp_daemon_new ();
power_daemon = dkp_daemon_new ();
if (power_daemon == NULL) {
goto out;
}
if (power_daemon == NULL) {
goto out;
}
loop = g_main_loop_new (NULL, FALSE);
loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (loop);
g_main_loop_run (loop);
g_object_unref (power_daemon);
g_main_loop_unref (loop);
ret = 0;
g_object_unref (power_daemon);
g_main_loop_unref (loop);
ret = 0;
out:
return ret;
return ret;
}

View file

@ -1,4 +1,4 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2008 David Zeuthen <david@fubar.dk>
*
@ -44,178 +44,178 @@
double
sysfs_get_double (const char *dir, const char *attribute)
{
double result;
char *contents;
char *filename;
double result;
char *contents;
char *filename;
result = 0.0;
filename = g_build_filename (dir, attribute, NULL);
if (g_file_get_contents (filename, &contents, NULL, NULL)) {
result = atof (contents);
g_free (contents);
}
g_free (filename);
result = 0.0;
filename = g_build_filename (dir, attribute, NULL);
if (g_file_get_contents (filename, &contents, NULL, NULL)) {
result = atof (contents);
g_free (contents);
}
g_free (filename);
return result;
return result;
}
gboolean
sysfs_file_contains (const char *dir, const char *attribute, const char *string)
{
gboolean result;
char *filename;
char *s;
gboolean result;
char *filename;
char *s;
result = FALSE;
result = FALSE;
filename = g_build_filename (dir, attribute, NULL);
if (g_file_get_contents (filename, &s, NULL, NULL)) {
result = (strstr(s, string) != NULL);
g_free (s);
}
g_free (filename);
filename = g_build_filename (dir, attribute, NULL);
if (g_file_get_contents (filename, &s, NULL, NULL)) {
result = (strstr(s, string) != NULL);
g_free (s);
}
g_free (filename);
return result;
return result;
}
char *
sysfs_get_string (const char *dir, const char *attribute)
{
char *result;
char *filename;
char *result;
char *filename;
result = NULL;
filename = g_build_filename (dir, attribute, NULL);
if (!g_file_get_contents (filename, &result, NULL, NULL)) {
result = g_strdup ("");
}
g_free (filename);
result = NULL;
filename = g_build_filename (dir, attribute, NULL);
if (!g_file_get_contents (filename, &result, NULL, NULL)) {
result = g_strdup ("");
}
g_free (filename);
return result;
return result;
}
int
sysfs_get_int (const char *dir, const char *attribute)
{
int result;
char *contents;
char *filename;
int result;
char *contents;
char *filename;
result = 0;
filename = g_build_filename (dir, attribute, NULL);
if (g_file_get_contents (filename, &contents, NULL, NULL)) {
result = atoi (contents);
g_free (contents);
}
g_free (filename);
result = 0;
filename = g_build_filename (dir, attribute, NULL);
if (g_file_get_contents (filename, &contents, NULL, NULL)) {
result = atoi (contents);
g_free (contents);
}
g_free (filename);
return result;
return result;
}
gboolean
sysfs_get_bool (const char *dir, const char *attribute)
{
gboolean result = FALSE;
char *contents;
char *filename;
gboolean result = FALSE;
char *contents;
char *filename;
result = 0;
filename = g_build_filename (dir, attribute, NULL);
if (g_file_get_contents (filename, &contents, NULL, NULL)) {
if (strcmp (contents, "1"))
result = TRUE;
g_free (contents);
}
g_free (filename);
result = 0;
filename = g_build_filename (dir, attribute, NULL);
if (g_file_get_contents (filename, &contents, NULL, NULL)) {
if (strcmp (contents, "1"))
result = TRUE;
g_free (contents);
}
g_free (filename);
return result;
return result;
}
guint64
sysfs_get_uint64 (const char *dir, const char *attribute)
{
guint64 result;
char *contents;
char *filename;
guint64 result;
char *contents;
char *filename;
result = 0;
filename = g_build_filename (dir, attribute, NULL);
if (g_file_get_contents (filename, &contents, NULL, NULL)) {
result = atoll (contents);
g_free (contents);
}
g_free (filename);
result = 0;
filename = g_build_filename (dir, attribute, NULL);
if (g_file_get_contents (filename, &contents, NULL, NULL)) {
result = atoll (contents);
g_free (contents);
}
g_free (filename);
return result;
return result;
}
gboolean
sysfs_file_exists (const char *dir, const char *attribute)
{
gboolean result;
char *filename;
gboolean result;
char *filename;
result = FALSE;
filename = g_build_filename (dir, attribute, NULL);
if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
result = TRUE;
}
g_free (filename);
result = FALSE;
filename = g_build_filename (dir, attribute, NULL);
if (g_file_test (filename, G_FILE_TEST_EXISTS)) {
result = TRUE;
}
g_free (filename);
return result;
return result;
}
char *
_dupv8 (const char *s)
{
const char *end_valid;
const char *end_valid;
if (!g_utf8_validate (s,
-1,
&end_valid)) {
g_warning ("The string '%s' is not valid UTF-8. Invalid characters begins at '%s'", s, end_valid);
return g_strndup (s, end_valid - s);
} else {
return g_strdup (s);
}
if (!g_utf8_validate (s,
-1,
&end_valid)) {
g_warning ("The string '%s' is not valid UTF-8. Invalid characters begins at '%s'", s, end_valid);
return g_strndup (s, end_valid - s);
} else {
return g_strdup (s);
}
}
char *
sysfs_resolve_link (const char *dir, const char *attribute)
{
char *full_path;
char link_path[PATH_MAX];
char resolved_path[PATH_MAX];
ssize_t num;
gboolean found_it;
char *full_path;
char link_path[PATH_MAX];
char resolved_path[PATH_MAX];
ssize_t num;
gboolean found_it;
found_it = FALSE;
found_it = FALSE;
full_path = g_build_filename (dir, attribute, NULL);
full_path = g_build_filename (dir, attribute, NULL);
//g_warning ("attribute='%s'", attribute);
//g_warning ("full_path='%s'", full_path);
num = readlink (full_path, link_path, sizeof (link_path) - 1);
if (num != -1) {
char *absolute_path;
//g_warning ("attribute='%s'", attribute);
//g_warning ("full_path='%s'", full_path);
num = readlink (full_path, link_path, sizeof (link_path) - 1);
if (num != -1) {
char *absolute_path;
link_path[num] = '\0';
link_path[num] = '\0';
//g_warning ("link_path='%s'", link_path);
absolute_path = g_build_filename (dir, link_path, NULL);
//g_warning ("absolute_path='%s'", absolute_path);
if (realpath (absolute_path, resolved_path) != NULL) {
//g_warning ("resolved_path='%s'", resolved_path);
found_it = TRUE;
}
g_free (absolute_path);
}
g_free (full_path);
//g_warning ("link_path='%s'", link_path);
absolute_path = g_build_filename (dir, link_path, NULL);
//g_warning ("absolute_path='%s'", absolute_path);
if (realpath (absolute_path, resolved_path) != NULL) {
//g_warning ("resolved_path='%s'", resolved_path);
found_it = TRUE;
}
g_free (absolute_path);
}
g_free (full_path);
if (found_it)
return g_strdup (resolved_path);
else
return NULL;
if (found_it)
return g_strdup (resolved_path);
else
return NULL;
}