convert to using egg_ functionality like other projects

This commit is contained in:
Richard Hughes 2008-08-28 15:49:19 +01:00
parent 0e2c7ef0ec
commit 7fdcc278dc
31 changed files with 611 additions and 302 deletions

View file

@ -2,6 +2,7 @@ INCLUDES = \
$(GLIB_CFLAGS) \
$(DBUS_GLIB_CFLAGS) \
-I$(top_srcdir)/libdevkit-power \
-DEGG_LOG_FILE=\""$(PK_LOG_DIR)/DeviceKit-power"\" \
-DPACKAGE_DATA_DIR=\""$(datadir)"\" \
-DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\"
@ -9,8 +10,10 @@ noinst_LTLIBRARIES = \
libdevkit-power.la
libdevkit_power_la_SOURCES = \
dkp-debug.c \
dkp-debug.h \
egg-debug.c \
egg-debug.h \
egg-string.c \
egg-string.h \
dkp-client.c \
dkp-client.h \
dkp-client-device.c \

View file

@ -26,7 +26,7 @@
#include <glib.h>
#include <dbus/dbus-glib.h>
#include "dkp-debug.h"
#include "egg-debug.h"
#include "dkp-client-device.h"
#include "dkp-object.h"
#include "dkp-stats-obj.h"
@ -73,7 +73,7 @@ dkp_client_device_get_device_properties (DkpClientDevice *device)
&hash_table,
G_TYPE_INVALID);
if (!ret) {
dkp_debug ("Couldn't call GetAll() to get properties for %s: %s", device->priv->object_path, error->message);
egg_debug ("Couldn't call GetAll() to get properties for %s: %s", device->priv->object_path, error->message);
g_error_free (error);
goto out;
}
@ -92,7 +92,7 @@ dkp_client_device_refresh_internal (DkpClientDevice *device)
/* get all the properties */
hash = dkp_client_device_get_device_properties (device);
if (hash == NULL) {
dkp_warning ("Cannot get device properties for %s", device->priv->object_path);
egg_warning ("Cannot get device properties for %s", device->priv->object_path);
return FALSE;
}
dkp_object_set_from_map (device->priv->obj, hash);
@ -132,7 +132,7 @@ dkp_client_device_set_object_path (DkpClientDevice *device, const gchar *object_
/* connect to the bus */
device->priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
if (device->priv->bus == NULL) {
dkp_warning ("Couldn't connect to system bus: %s", error->message);
egg_warning ("Couldn't connect to system bus: %s", error->message);
g_error_free (error);
goto out;
}
@ -141,7 +141,7 @@ dkp_client_device_set_object_path (DkpClientDevice *device, const gchar *object_
proxy_props = dbus_g_proxy_new_for_name (device->priv->bus, "org.freedesktop.DeviceKit.Power",
object_path, "org.freedesktop.DBus.Properties");
if (proxy_props == NULL) {
dkp_warning ("Couldn't connect to proxy");
egg_warning ("Couldn't connect to proxy");
goto out;
}
@ -149,7 +149,7 @@ dkp_client_device_set_object_path (DkpClientDevice *device, const gchar *object_
proxy_device = dbus_g_proxy_new_for_name (device->priv->bus, "org.freedesktop.DeviceKit.Power",
object_path, "org.freedesktop.DeviceKit.Power.Device");
if (proxy_device == NULL) {
dkp_warning ("Couldn't connect to proxy");
egg_warning ("Couldn't connect to proxy");
goto out;
}
@ -159,7 +159,7 @@ dkp_client_device_set_object_path (DkpClientDevice *device, const gchar *object_
G_CALLBACK (dkp_client_device_changed_cb), device, NULL);
/* yay */
dkp_debug ("using object_path: %s", object_path);
egg_debug ("using object_path: %s", object_path);
device->priv->proxy_device = proxy_device;
device->priv->proxy_props = proxy_props;
device->priv->object_path = g_strdup (object_path);
@ -167,7 +167,7 @@ dkp_client_device_set_object_path (DkpClientDevice *device, const gchar *object_
/* coldplug */
ret = dkp_client_device_refresh_internal (device);
if (!ret)
dkp_warning ("cannot refresh");
egg_warning ("cannot refresh");
out:
return ret;
}
@ -255,7 +255,7 @@ dkp_client_device_refresh (DkpClientDevice *device)
ret = dbus_g_proxy_call (device->priv->proxy_device, "Refresh", &error,
G_TYPE_INVALID, G_TYPE_INVALID);
if (!ret) {
dkp_debug ("Refresh() on %s failed: %s", device->priv->object_path, error->message);
egg_debug ("Refresh() on %s failed: %s", device->priv->object_path, error->message);
g_error_free (error);
goto out;
}
@ -298,7 +298,7 @@ dkp_client_device_get_history (const DkpClientDevice *device, const gchar *type,
g_type_gvalue_array, &gvalue_ptr_array,
G_TYPE_INVALID);
if (!ret) {
dkp_debug ("GetStatistics(%s,%i) on %s failed: %s", type, timespec,
egg_debug ("GetStatistics(%s,%i) on %s failed: %s", type, timespec,
device->priv->object_path, error->message);
g_error_free (error);
goto out;
@ -368,7 +368,7 @@ dkp_client_device_get_statistics (const DkpClientDevice *device, const gchar *ty
g_type_gvalue_array, &gvalue_ptr_array,
G_TYPE_INVALID);
if (!ret) {
dkp_debug ("GetStatistics(%s) on %s failed: %s", type,
egg_debug ("GetStatistics(%s) on %s failed: %s", type,
device->priv->object_path, error->message);
g_error_free (error);
goto out;

View file

@ -26,7 +26,7 @@
#include <glib.h>
#include <dbus/dbus-glib.h>
#include "dkp-debug.h"
#include "egg-debug.h"
#include "dkp-client.h"
#include "dkp-client-device.h"
@ -83,7 +83,7 @@ dkp_client_enumerate_devices (const DkpClient *client)
g_type_array, &devices,
G_TYPE_INVALID);
if (!ret) {
dkp_warning ("Couldn't enumerate devices: %s", error->message);
egg_warning ("Couldn't enumerate devices: %s", error->message);
g_error_free (error);
}
return devices;
@ -209,7 +209,7 @@ dkp_client_init (DkpClient *client)
/* get on the bus */
client->priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
if (client->priv->bus == NULL) {
dkp_warning ("Couldn't connect to system bus: %s", error->message);
egg_warning ("Couldn't connect to system bus: %s", error->message);
g_error_free (error);
goto out;
}
@ -218,7 +218,7 @@ dkp_client_init (DkpClient *client)
client->priv->proxy = dbus_g_proxy_new_for_name (client->priv->bus, "org.freedesktop.DeviceKit.Power",
"/", "org.freedesktop.DeviceKit.Power");
if (client->priv->proxy == NULL) {
dkp_warning ("Couldn't connect to proxy");
egg_warning ("Couldn't connect to proxy");
goto out;
}

View file

@ -21,7 +21,9 @@
#include <glib.h>
#include <string.h>
#include "dkp-debug.h"
#include "egg-debug.h"
#include "egg-string.h"
#include "dkp-enum.h"
/**
@ -74,21 +76,21 @@ dkp_device_type_from_text (const gchar *type)
{
if (type == NULL)
return DKP_DEVICE_TYPE_UNKNOWN;
if (strcmp (type, "line-power") == 0)
if (egg_strequal (type, "line-power"))
return DKP_DEVICE_TYPE_LINE_POWER;
if (strcmp (type, "battery") == 0)
if (egg_strequal (type, "battery"))
return DKP_DEVICE_TYPE_BATTERY;
if (strcmp (type, "ups") == 0)
if (egg_strequal (type, "ups"))
return DKP_DEVICE_TYPE_UPS;
if (strcmp (type, "monitor") == 0)
if (egg_strequal (type, "monitor"))
return DKP_DEVICE_TYPE_MONITOR;
if (strcmp (type, "mouse") == 0)
if (egg_strequal (type, "mouse"))
return DKP_DEVICE_TYPE_MOUSE;
if (strcmp (type, "keyboard") == 0)
if (egg_strequal (type, "keyboard"))
return DKP_DEVICE_TYPE_KEYBOARD;
if (strcmp (type, "pda") == 0)
if (egg_strequal (type, "pda"))
return DKP_DEVICE_TYPE_PDA;
if (strcmp (type, "phone") == 0)
if (egg_strequal (type, "phone"))
return DKP_DEVICE_TYPE_PHONE;
return DKP_DEVICE_TYPE_UNKNOWN;
}
@ -131,13 +133,13 @@ dkp_device_state_from_text (const gchar *state)
{
if (state == NULL)
return DKP_DEVICE_STATE_UNKNOWN;
if (strcmp (state, "charging") == 0)
if (egg_strequal (state, "charging"))
return DKP_DEVICE_STATE_CHARGING;
if (strcmp (state, "discharging") == 0)
if (egg_strequal (state, "discharging"))
return DKP_DEVICE_STATE_DISCHARGING;
if (strcmp (state, "empty") == 0)
if (egg_strequal (state, "empty"))
return DKP_DEVICE_STATE_EMPTY;
if (strcmp (state, "fully-charged") == 0)
if (egg_strequal (state, "fully-charged"))
return DKP_DEVICE_STATE_FULLY_CHARGED;
return DKP_DEVICE_STATE_UNKNOWN;
}
@ -186,17 +188,17 @@ dkp_device_technology_from_text (const gchar *technology)
{
if (technology == NULL)
return DKP_DEVICE_TECHNOLGY_UNKNOWN;
if (strcmp (technology, "lithium-ion") == 0)
if (egg_strequal (technology, "lithium-ion"))
return DKP_DEVICE_TECHNOLGY_LITHIUM_ION;
if (strcmp (technology, "lithium-polymer") == 0)
if (egg_strequal (technology, "lithium-polymer"))
return DKP_DEVICE_TECHNOLGY_LITHIUM_POLYMER;
if (strcmp (technology, "lithium-iron-phosphate") == 0)
if (egg_strequal (technology, "lithium-iron-phosphate"))
return DKP_DEVICE_TECHNOLGY_LITHIUM_IRON_PHOSPHATE;
if (strcmp (technology, "lead-acid") == 0)
if (egg_strequal (technology, "lead-acid"))
return DKP_DEVICE_TECHNOLGY_LEAD_ACID;
if (strcmp (technology, "nickel-cadmium") == 0)
if (egg_strequal (technology, "nickel-cadmium"))
return DKP_DEVICE_TECHNOLGY_NICKEL_CADMIUM;
if (strcmp (technology, "nickel-metal-hydride") == 0)
if (egg_strequal (technology, "nickel-metal-hydride"))
return DKP_DEVICE_TECHNOLGY_NICKEL_METAL_HYDRIDE;
return DKP_DEVICE_TECHNOLGY_UNKNOWN;
}

View file

@ -23,7 +23,7 @@
#include <string.h>
#include <stdlib.h>
#include "dkp-debug.h"
#include "egg-debug.h"
#include "dkp-enum.h"
#include "dkp-history-obj.h"
@ -146,7 +146,7 @@ dkp_history_obj_from_string (const gchar *text)
parts = g_strsplit (text, "\t", 0);
length = g_strv_length (parts);
if (length != 3) {
dkp_warning ("invalid string: '%s'", text);
egg_warning ("invalid string: '%s'", text);
goto out;
}

View file

@ -22,7 +22,9 @@
#include <glib-object.h>
#include <string.h>
#include "dkp-debug.h"
#include "egg-debug.h"
#include "egg-string.h"
#include "dkp-enum.h"
#include "dkp-object.h"
@ -62,53 +64,53 @@ dkp_object_collect_props (const char *key, const GValue *value, DkpObject *obj)
{
gboolean handled = TRUE;
if (strcmp (key, "native-path") == 0)
if (egg_strequal (key, "native-path"))
obj->native_path = g_strdup (g_value_get_string (value));
else if (strcmp (key, "vendor") == 0)
else if (egg_strequal (key, "vendor"))
obj->vendor = g_strdup (g_value_get_string (value));
else if (strcmp (key, "model") == 0)
else if (egg_strequal (key, "model"))
obj->model = g_strdup (g_value_get_string (value));
else if (strcmp (key, "serial") == 0)
else if (egg_strequal (key, "serial"))
obj->serial = g_strdup (g_value_get_string (value));
else if (strcmp (key, "update-time") == 0)
else if (egg_strequal (key, "update-time"))
obj->update_time = g_value_get_uint64 (value);
else if (strcmp (key, "type") == 0)
else if (egg_strequal (key, "type"))
obj->type = dkp_device_type_from_text (g_value_get_string (value));
else if (strcmp (key, "online") == 0)
else if (egg_strequal (key, "online"))
obj->online = g_value_get_boolean (value);
else if (strcmp (key, "energy") == 0)
else if (egg_strequal (key, "energy"))
obj->energy = g_value_get_double (value);
else if (strcmp (key, "energy-empty") == 0)
else if (egg_strequal (key, "energy-empty"))
obj->energy_empty = g_value_get_double (value);
else if (strcmp (key, "energy-full") == 0)
else if (egg_strequal (key, "energy-full"))
obj->energy_full = g_value_get_double (value);
else if (strcmp (key, "energy-full-design") == 0)
else if (egg_strequal (key, "energy-full-design"))
obj->energy_full_design = g_value_get_double (value);
else if (strcmp (key, "energy-rate") == 0)
else if (egg_strequal (key, "energy-rate"))
obj->energy_rate = g_value_get_double (value);
else if (strcmp (key, "time-to-full") == 0)
else if (egg_strequal (key, "time-to-full"))
obj->time_to_full = g_value_get_int64 (value);
else if (strcmp (key, "time-to-empty") == 0)
else if (egg_strequal (key, "time-to-empty"))
obj->time_to_empty = g_value_get_int64 (value);
else if (strcmp (key, "percentage") == 0)
else if (egg_strequal (key, "percentage"))
obj->percentage = g_value_get_double (value);
else if (strcmp (key, "technology") == 0)
else if (egg_strequal (key, "technology"))
obj->technology = dkp_device_technology_from_text (g_value_get_string (value));
else if (strcmp (key, "is-present") == 0)
else if (egg_strequal (key, "is-present"))
obj->is_present = g_value_get_boolean (value);
else if (strcmp (key, "is-rechargeable") == 0)
else if (egg_strequal (key, "is-rechargeable"))
obj->is_rechargeable = g_value_get_boolean (value);
else if (strcmp (key, "power-supply") == 0)
else if (egg_strequal (key, "power-supply"))
obj->power_supply = g_value_get_boolean (value);
else if (strcmp (key, "capacity") == 0)
else if (egg_strequal (key, "capacity"))
obj->capacity = g_value_get_double (value);
else if (strcmp (key, "state") == 0)
else if (egg_strequal (key, "state"))
obj->state = dkp_device_state_from_text (g_value_get_string (value));
else
handled = FALSE;
if (!handled)
dkp_warning ("unhandled property '%s'", key);
egg_warning ("unhandled property '%s'", key);
}
/**
@ -154,26 +156,6 @@ dkp_object_copy (const DkpObject *cobj)
return obj;
}
/**
* dkp_strequal:
* @id1: the first item of text to test
* @id2: the second item of text to test
*
* This function is a much safer way of doing strcmp as it checks for
* NULL first, and returns boolean TRUE, not zero for success.
*
* Return value: %TRUE if the string are the same.
**/
static gboolean
dkp_strequal (const gchar *id1, const gchar *id2)
{
if (id1 == NULL && id2 == NULL)
return TRUE;
if (id1 == NULL || id2 == NULL)
return FALSE;
return (strcmp (id1, id2) == 0);
}
/**
* dkp_object_equal:
**/
@ -192,10 +174,10 @@ dkp_object_equal (const DkpObject *obj1, const DkpObject *obj2)
obj1->time_to_full == obj2->time_to_full &&
obj1->state == obj2->state &&
obj1->technology == obj2->technology &&
dkp_strequal (obj1->vendor, obj2->vendor) &&
dkp_strequal (obj1->model, obj2->model) &&
dkp_strequal (obj1->serial, obj2->serial) &&
dkp_strequal (obj1->native_path, obj2->native_path) &&
egg_strequal (obj1->vendor, obj2->vendor) &&
egg_strequal (obj1->model, obj2->model) &&
egg_strequal (obj1->serial, obj2->serial) &&
egg_strequal (obj1->native_path, obj2->native_path) &&
obj1->online == obj2->online &&
obj1->is_present == obj2->is_present &&
obj1->power_supply == obj2->power_supply &&
@ -204,29 +186,6 @@ dkp_object_equal (const DkpObject *obj1, const DkpObject *obj2)
return FALSE;
}
/**
* dkp_strzero:
* @text: The text to check
*
* This function is a much safer way of doing "if (strlen (text) == 0))"
* as it does not rely on text being NULL terminated. It's also much
* quicker as it only checks the first byte rather than scanning the whole
* string just to verify it's not zero length.
*
* Return value: %TRUE if the string was converted correctly
**/
static gboolean
dkp_strzero (const gchar *text)
{
if (text == NULL) {
return TRUE;
}
if (text[0] == '\0') {
return TRUE;
}
return FALSE;
}
/**
* dkp_object_time_to_text:
**/
@ -276,11 +235,11 @@ dkp_object_print (const DkpObject *obj)
strftime (time_buf, sizeof time_buf, "%c", time_tm);
g_print (" native-path: %s\n", obj->native_path);
if (!dkp_strzero (obj->vendor))
if (!egg_strzero (obj->vendor))
g_print (" vendor: %s\n", obj->vendor);
if (!dkp_strzero (obj->model))
if (!egg_strzero (obj->model))
g_print (" model: %s\n", obj->model);
if (!dkp_strzero (obj->serial))
if (!egg_strzero (obj->serial))
g_print (" serial: %s\n", obj->serial);
g_print (" power supply: %s\n", dkp_object_bool_to_text (obj->power_supply));
g_print (" updated: %s (%d seconds ago)\n", time_buf, (int) (time (NULL) - obj->update_time));
@ -346,11 +305,11 @@ dkp_object_diff (const DkpObject *old, const DkpObject *obj)
gchar *time_str_old;
g_print (" native-path: %s\n", obj->native_path);
if (!dkp_strequal (obj->vendor, old->vendor))
if (!egg_strequal (obj->vendor, old->vendor))
g_print (" vendor: %s -> %s\n", old->vendor, obj->vendor);
if (!dkp_strequal (obj->model, old->model))
if (!egg_strequal (obj->model, old->model))
g_print (" model: %s -> %s\n", old->model, obj->model);
if (!dkp_strequal (obj->serial, old->serial))
if (!egg_strequal (obj->serial, old->serial))
g_print (" serial: %s -> %s\n", old->serial, obj->serial);
g_print (" %s\n", dkp_device_type_to_text (obj->type));

View file

@ -23,7 +23,7 @@
#include <string.h>
#include <stdlib.h>
#include "dkp-debug.h"
#include "egg-debug.h"
#include "dkp-stats-obj.h"
/**

1
libdevkit-power/egg-debug.c Symbolic link
View file

@ -0,0 +1 @@
../src/egg-debug.c

1
libdevkit-power/egg-debug.h Symbolic link
View file

@ -0,0 +1 @@
../src/egg-debug.h

View file

@ -0,0 +1 @@
../src/egg-string.c

View file

@ -0,0 +1 @@
../src/egg-string.h

View file

@ -10,6 +10,7 @@ INCLUDES = \
-DPACKAGE_LOCALE_DIR=\""$(localedir)"\" \
-DPACKAGE_LIB_DIR=\""$(libdir)"\" \
-D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT \
-DEGG_LOG_FILE=\""$(PK_LOG_DIR)/DeviceKit-power"\" \
-I$(top_srcdir)/libdevkit-power \
$(GIO_CFLAGS) \
$(DBUS_GLIB_CFLAGS) \
@ -42,6 +43,8 @@ dbusifdir = $(datadir)/dbus-1/interfaces
dbusif_DATA = org.freedesktop.DeviceKit.Power.xml org.freedesktop.DeviceKit.Power.Device.xml
devkit_power_daemon_SOURCES = \
egg-debug.c \
egg-debug.h \
dkp-daemon.h dkp-daemon.c \
dkp-device.h dkp-device.c \
dkp-device-list.h dkp-device-list.c \

View file

@ -34,7 +34,9 @@
#include <usb.h>
#include "sysfs-utils.h"
#include "dkp-debug.h"
#include "egg-debug.h"
#include "egg-string.h"
#include "dkp-enum.h"
#include "dkp-object.h"
#include "dkp-csr.h"
@ -78,7 +80,7 @@ dkp_csr_poll (DkpCsr *csr)
DkpDevice *device = DKP_DEVICE (csr);
DkpObject *obj = dkp_device_get_obj (device);
dkp_debug ("Polling: %s", obj->native_path);
egg_debug ("Polling: %s", obj->native_path);
ret = dkp_csr_refresh (device);
if (ret)
dkp_device_emit_changed (device);
@ -98,19 +100,19 @@ dkp_csr_find_device (DkpCsr *csr)
dir_name = g_strdup_printf ("%03d", csr->priv->bus_num);
filename = g_strdup_printf ("%03d",csr->priv->dev_num);
dkp_debug ("Looking for: [%s][%s]", dir_name, filename);
egg_debug ("Looking for: [%s][%s]", dir_name, filename);
for (curr_bus = usb_busses; curr_bus != NULL; curr_bus = curr_bus->next) {
/* dkp_debug ("Checking bus: [%s]", curr_bus->dirname); */
/* egg_debug ("Checking bus: [%s]", curr_bus->dirname); */
if (g_strcasecmp (dir_name, curr_bus->dirname))
continue;
for (curr_device = curr_bus->devices; curr_device != NULL;
curr_device = curr_device->next) {
/* dkp_debug ("Checking port: [%s]", curr_device->filename); */
/* egg_debug ("Checking port: [%s]", curr_device->filename); */
if (g_strcasecmp (filename, curr_device->filename))
continue;
dkp_debug ("Matched device: [%s][%s][%04X:%04X]", curr_bus->dirname,
egg_debug ("Matched device: [%s][%s][%04X:%04X]", curr_bus->dirname,
curr_device->filename,
curr_device->descriptor.idVendor,
curr_device->descriptor.idProduct);
@ -140,24 +142,24 @@ dkp_csr_coldplug (DkpDevice *device)
/* detect what kind of device we are */
d = dkp_device_get_d (device);
if (d == NULL)
dkp_error ("could not get device");
egg_error ("could not get device");
/* get the type */
type = devkit_device_get_property (d, "DKP_BATTERY_TYPE");
if (type == NULL) {
dkp_debug ("not a CSR device");
egg_debug ("not a CSR device");
goto out;
}
/* which one? */
if (strcmp (type, "mouse") == 0)
if (egg_strequal (type, "mouse"))
obj->type = DKP_DEVICE_TYPE_MOUSE;
if (strcmp (type, "keyboard") == 0)
if (egg_strequal (type, "keyboard"))
obj->type = DKP_DEVICE_TYPE_KEYBOARD;
/* nothing known */
if (obj->type == DKP_DEVICE_TYPE_UNKNOWN) {
dkp_debug ("not a recognised csr device");
egg_debug ("not a recognised csr device");
goto out;
}
@ -167,14 +169,14 @@ dkp_csr_coldplug (DkpDevice *device)
/* get correct bus numbers? */
if (csr->priv->bus_num == 0 || csr->priv->dev_num == 0) {
dkp_warning ("unable to get bus or device numbers");
egg_warning ("unable to get bus or device numbers");
goto out;
}
/* try to get the usb device */
csr->priv->device = dkp_csr_find_device (csr);
if (csr->priv->device == NULL) {
dkp_debug ("failed to get device %p", csr);
egg_debug ("failed to get device %p", csr);
goto out;
}
@ -182,7 +184,7 @@ dkp_csr_coldplug (DkpDevice *device)
ret = devkit_device_has_property (d, "DKP_CSR_DUAL");
if (ret)
csr->priv->is_dual = devkit_device_get_property_as_boolean (d, "DKP_CSR_DUAL");
dkp_debug ("is_dual=%i", csr->priv->is_dual);
egg_debug ("is_dual=%i", csr->priv->is_dual);
obj->vendor = g_strdup (devkit_device_get_property (d, "ID_VENDOR"));
obj->model = g_strdup (devkit_device_get_property (d, "ID_PRODUCT"));
@ -228,14 +230,14 @@ dkp_csr_refresh (DkpDevice *device)
addr = csr->priv->is_dual ? 1<<8 : 0;
if (csr->priv->device == NULL) {
dkp_warning ("no device!");
egg_warning ("no device!");
return FALSE;
}
/* open USB device */
handle = usb_open (csr->priv->device);
if (handle == NULL) {
dkp_warning ("could not open device");
egg_warning ("could not open device");
return FALSE;
}
@ -243,22 +245,22 @@ dkp_csr_refresh (DkpDevice *device)
written = usb_control_msg (handle, 0xc0, 0x09, 0x03|addr, 0x00|addr, buf, 8, DKP_CSR_REFRESH_TIMEOUT);
ret = (written == 8);
if (!ret) {
dkp_warning ("failed to write to device, wrote %i bytes", written);
egg_warning ("failed to write to device, wrote %i bytes", written);
goto out;
}
/* is a C504 receiver busy? */
if (CSR_P0 == 0x3b && CSR_P4 == 0) {
dkp_debug ("receiver busy");
egg_debug ("receiver busy");
goto out;
}
/* get battery status */
csr->priv->raw_value = CSR_P5 & 0x07;
dkp_debug ("charge level: %d", csr->priv->raw_value);
egg_debug ("charge level: %d", csr->priv->raw_value);
if (csr->priv->raw_value != 0) {
obj->percentage = (100.0 / 7.0) * csr->priv->raw_value;
dkp_debug ("percentage=%f", obj->percentage);
egg_debug ("percentage=%f", obj->percentage);
}
out:

View file

@ -31,7 +31,9 @@
#include <dbus/dbus-glib-lowlevel.h>
#include <devkit-gobject.h>
#include "dkp-debug.h"
#include "egg-debug.h"
#include "egg-string.h"
#include "dkp-daemon.h"
#include "dkp-device.h"
#include "dkp-supply.h"
@ -379,23 +381,23 @@ gpk_daemon_device_changed (DkpDaemon *daemon, DevkitDevice *d, gboolean synthesi
ret = dkp_daemon_get_on_battery_local (daemon);
if (ret != daemon->priv->on_battery) {
daemon->priv->on_battery = ret;
dkp_debug ("now on_battery = %s", ret ? "yes" : "no");
egg_debug ("now on_battery = %s", ret ? "yes" : "no");
g_signal_emit (daemon, signals[ON_BATTERY_CHANGED_SIGNAL], 0, ret);
}
ret = dkp_daemon_get_low_battery_local (daemon);
if (ret != daemon->priv->low_battery) {
daemon->priv->low_battery = ret;
dkp_debug ("now low_battery = %s", ret ? "yes" : "no");
egg_debug ("now low_battery = %s", ret ? "yes" : "no");
g_signal_emit (daemon, signals[LOW_BATTERY_CHANGED_SIGNAL], 0, ret);
}
/* does the device exist in the db? */
device = dkp_device_list_lookup (daemon->priv->list, d);
if (device != NULL) {
dkp_debug ("changed %s", dkp_device_get_object_path (device));
egg_debug ("changed %s", dkp_device_get_object_path (device));
dkp_device_changed (device, d, synthesized);
} else {
dkp_debug ("treating change event as add on %s", dkp_device_get_object_path (device));
egg_debug ("treating change event as add on %s", dkp_device_get_object_path (device));
gpk_daemon_device_add (daemon, d, TRUE);
}
}
@ -423,7 +425,7 @@ gpk_daemon_device_get (DkpDaemon *daemon, DevkitDevice *d)
gboolean ret;
subsys = devkit_device_get_subsystem (d);
if (strcmp (subsys, "power_supply") == 0) {
if (egg_strequal (subsys, "power_supply")) {
/* are we a valid power supply */
device = DKP_DEVICE (dkp_supply_new ());
@ -435,7 +437,7 @@ gpk_daemon_device_get (DkpDaemon *daemon, DevkitDevice *d)
/* no valid power supply object */
device = NULL;
} else if (strcmp (subsys, "usb") == 0) {
} else if (egg_strequal (subsys, "usb")) {
/* see if this is a CSR mouse or keyboard */
device = DKP_DEVICE (dkp_csr_new ());
@ -463,7 +465,7 @@ gpk_daemon_device_get (DkpDaemon *daemon, DevkitDevice *d)
} else {
native_path = devkit_device_get_native_path (d);
dkp_warning ("native path %s (%s) ignoring", native_path, subsys);
egg_warning ("native path %s (%s) ignoring", native_path, subsys);
}
out:
return device;
@ -482,14 +484,14 @@ gpk_daemon_device_add (DkpDaemon *daemon, DevkitDevice *d, gboolean emit_event)
device = dkp_device_list_lookup (daemon->priv->list, d);
if (device != NULL) {
/* we already have the device; treat as change event */
dkp_debug ("treating add event as change event on %s", dkp_device_get_object_path (device));
egg_debug ("treating add event as change event on %s", dkp_device_get_object_path (device));
gpk_daemon_device_changed (daemon, d, FALSE);
} else {
/* get the right sort of device */
device = gpk_daemon_device_get (daemon, d);
if (device == NULL) {
dkp_debug ("ignoring add event on %s", devkit_device_get_native_path (d));
egg_debug ("ignoring add event on %s", devkit_device_get_native_path (d));
ret = FALSE;
goto out;
}
@ -518,7 +520,7 @@ gpk_daemon_device_remove (DkpDaemon *daemon, DevkitDevice *d)
/* does device exist in db? */
device = dkp_device_list_lookup (daemon->priv->list, d);
if (device == NULL) {
dkp_debug ("ignoring remove event on %s", devkit_device_get_native_path (d));
egg_debug ("ignoring remove event on %s", devkit_device_get_native_path (d));
} else {
dkp_device_removed (device);
g_signal_emit (daemon, signals[DEVICE_REMOVED_SIGNAL], 0,
@ -536,17 +538,17 @@ gpk_daemon_device_event_signal_handler (DevkitClient *client, const char *action
{
DkpDaemon *daemon = DKP_DAEMON (user_data);
if (strcmp (action, "add") == 0) {
dkp_debug ("add %s", devkit_device_get_native_path (device));
if (egg_strequal (action, "add")) {
egg_debug ("add %s", devkit_device_get_native_path (device));
gpk_daemon_device_add (daemon, device, TRUE);
} else if (strcmp (action, "remove") == 0) {
dkp_debug ("remove %s", devkit_device_get_native_path (device));
} else if (egg_strequal (action, "remove")) {
egg_debug ("remove %s", devkit_device_get_native_path (device));
gpk_daemon_device_remove (daemon, device);
} else if (strcmp (action, "change") == 0) {
dkp_debug ("change %s", devkit_device_get_native_path (device));
} else if (egg_strequal (action, "change")) {
egg_debug ("change %s", devkit_device_get_native_path (device));
gpk_daemon_device_changed (daemon, device, FALSE);
} else {
dkp_warning ("unhandled action '%s' on %s", action, devkit_device_get_native_path (device));
egg_warning ("unhandled action '%s' on %s", action, devkit_device_get_native_path (device));
}
}
@ -607,7 +609,7 @@ gpk_daemon_register_power_daemon (DkpDaemon *daemon)
&dbus_error);
if (dbus_error_is_set (&dbus_error)) {
dkp_warning ("Cannot add match rule: %s: %s", dbus_error.name, dbus_error.message);
egg_warning ("Cannot add match rule: %s: %s", dbus_error.name, dbus_error.message);
dbus_error_free (&dbus_error);
goto error;
}
@ -618,7 +620,7 @@ gpk_daemon_register_power_daemon (DkpDaemon *daemon)
&dbus_error);
if (dbus_error_is_set (&dbus_error)) {
dkp_warning ("Cannot add match rule: %s: %s", dbus_error.name, dbus_error.message);
egg_warning ("Cannot add match rule: %s: %s", dbus_error.name, dbus_error.message);
dbus_error_free (&dbus_error);
goto error;
}
@ -627,14 +629,14 @@ gpk_daemon_register_power_daemon (DkpDaemon *daemon)
gpk_daemon_dbus_filter,
daemon,
NULL)) {
dkp_warning ("Cannot add D-Bus filter: %s: %s", dbus_error.name, dbus_error.message);
egg_warning ("Cannot add D-Bus filter: %s: %s", dbus_error.name, dbus_error.message);
goto error;
}
/* connect to the DeviceKit daemon */
daemon->priv->devkit_client = devkit_client_new (subsystems);
if (!devkit_client_connect (daemon->priv->devkit_client, &error)) {
dkp_warning ("Couldn't open connection to DeviceKit daemon: %s", error->message);
egg_warning ("Couldn't open connection to DeviceKit daemon: %s", error->message);
g_error_free (error);
goto error;
}
@ -667,7 +669,7 @@ dkp_daemon_new (void)
devices = devkit_client_enumerate_by_subsystem (daemon->priv->devkit_client, subsystems, &error);
if (error != NULL) {
dkp_warning ("Cannot enumerate devices: %s", error->message);
egg_warning ("Cannot enumerate devices: %s", error->message);
g_error_free (error);
g_object_unref (daemon);
return NULL;

View file

@ -25,7 +25,7 @@
#include <stdio.h>
#include <glib.h>
#include "dkp-debug.h"
#include "egg-debug.h"
#include "dkp-device.h"
#include "dkp-device-list.h"
@ -82,7 +82,7 @@ dkp_device_list_insert (DkpDeviceList *list, DevkitDevice *d, DkpDevice *device)
g_hash_table_insert (list->priv->map_native_path_to_device,
g_strdup (native_path), device);
g_ptr_array_add (list->priv->array, device);
dkp_debug ("added %s", native_path);
egg_debug ("added %s", native_path);
return TRUE;
}
@ -93,7 +93,7 @@ static gboolean
dkp_device_list_remove_cb (gpointer key, gpointer value, gpointer user_data)
{
if (value == user_data) {
dkp_debug ("removed %s", (char *) key);
egg_debug ("removed %s", (char *) key);
return TRUE;
}
return FALSE;

View file

@ -35,7 +35,7 @@
#include <polkit-dbus/polkit-dbus.h>
#include "sysfs-utils.h"
#include "dkp-debug.h"
#include "egg-debug.h"
#include "dkp-supply.h"
#include "dkp-device.h"
#include "dkp-device.h"
@ -228,7 +228,7 @@ dkp_device_removed (DkpDevice *device)
//DkpDeviceClass *klass = DKP_DEVICE_GET_CLASS (device);
//klass->removed (device);
g_return_if_fail (DKP_IS_DEVICE (device));
dkp_warning ("do something here?");
egg_warning ("do something here?");
}
/**
@ -522,7 +522,7 @@ dkp_device_emit_changed (DkpDevice *device)
{
g_return_if_fail (DKP_IS_DEVICE (device));
dkp_debug ("emitting changed on %s", device->priv->obj->native_path);
egg_debug ("emitting changed on %s", device->priv->obj->native_path);
g_signal_emit_by_name (device->priv->daemon, "device-changed",
device->priv->object_path, NULL);
g_signal_emit (device, signals[CHANGED_SIGNAL], 0);
@ -572,13 +572,13 @@ dkp_device_register_device (DkpDevice *device)
gboolean ret = TRUE;
device->priv->object_path = dkp_device_compute_object_path (device);
dkp_debug ("object path = %s", device->priv->object_path);
egg_debug ("object path = %s", device->priv->object_path);
dbus_g_connection_register_g_object (device->priv->system_bus_connection,
device->priv->object_path, G_OBJECT (device));
device->priv->system_bus_proxy = dbus_g_proxy_new_for_name (device->priv->system_bus_connection,
DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
if (device->priv->system_bus_proxy == NULL) {
dkp_warning ("proxy invalid");
egg_warning ("proxy invalid");
ret = FALSE;
}
return ret;
@ -603,7 +603,7 @@ dkp_device_init (DkpDevice *device)
device->priv->system_bus_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
if (device->priv->system_bus_connection == NULL) {
dkp_error ("error getting system bus: %s", error->message);
egg_error ("error getting system bus: %s", error->message);
g_error_free (error);
}
}

View file

@ -47,7 +47,9 @@
#include <unistd.h>
#include "sysfs-utils.h"
#include "dkp-debug.h"
#include "egg-debug.h"
#include "egg-string.h"
#include "dkp-enum.h"
#include "dkp-object.h"
#include "dkp-hid.h"
@ -111,7 +113,7 @@ dkp_hid_is_ups (DkpHid *hid)
/* get device info */
retval = ioctl (hid->priv->fd, HIDIOCGDEVINFO, &device_info);
if (retval < 0) {
dkp_debug ("HIDIOCGDEVINFO failed: %s", strerror (errno));
egg_debug ("HIDIOCGDEVINFO failed: %s", strerror (errno));
goto out;
}
@ -137,7 +139,7 @@ dkp_hid_poll (DkpHid *hid)
DkpDevice *device = DKP_DEVICE (hid);
DkpObject *obj = dkp_device_get_obj (device);
dkp_debug ("Polling: %s", obj->native_path);
egg_debug ("Polling: %s", obj->native_path);
ret = dkp_hid_refresh (device);
if (ret)
dkp_device_emit_changed (device);
@ -162,7 +164,7 @@ dkp_hid_get_string (DkpHid *hid, int sindex)
if (ioctl (hid->priv->fd, HIDIOCGSTRING, &sdesc) < 0)
return "";
dkp_debug ("value: '%s'", sdesc.value);
egg_debug ("value: '%s'", sdesc.value);
return sdesc.value;
}
@ -283,33 +285,33 @@ dkp_hid_coldplug (DkpDevice *device)
/* detect what kind of device we are */
d = dkp_device_get_d (device);
if (d == NULL)
dkp_error ("could not get device");
egg_error ("could not get device");
/* get the type */
type = devkit_device_get_property (d, "DKP_BATTERY_TYPE");
if (type == NULL || strcmp (type, "ups") != 0) {
dkp_debug ("not a UPS device");
if (type == NULL || !egg_strequal (type, "ups")) {
egg_debug ("not a UPS device");
goto out;
}
/* get the device file */
device_file = devkit_device_get_device_file (d);
if (device_file == NULL) {
dkp_debug ("could not get device file for HID device");
egg_debug ("could not get device file for HID device");
goto out;
}
/* connect to the device */
hid->priv->fd = open (device_file, O_RDONLY | O_NONBLOCK);
if (hid->priv->fd < 0) {
dkp_debug ("cannot open device file %s", device_file);
egg_debug ("cannot open device file %s", device_file);
goto out;
}
/* first check that we are an UPS */
ret = dkp_hid_is_ups (hid);
if (!ret) {
dkp_debug ("not a HID device: %s", device_file);
egg_debug ("not a HID device: %s", device_file);
goto out;
}

View file

@ -26,7 +26,7 @@
#include <glib/gi18n.h>
#include <gio/gio.h>
#include "dkp-debug.h"
#include "egg-debug.h"
#include "dkp-history.h"
#include "dkp-history-obj.h"
@ -202,7 +202,7 @@ dkp_history_save_data_array (const gchar *filename, GPtrArray *array)
/* we failed to convert to string */
if (!ret) {
dkp_warning ("failed to convert");
egg_warning ("failed to convert");
goto out;
}
@ -211,11 +211,11 @@ dkp_history_save_data_array (const gchar *filename, GPtrArray *array)
ret = g_file_set_contents (filename, part, -1, &error);
// ret = g_file_replace_contents (file, part, -1, NULL, TRUE, G_FILE_CREATE_NONE, NULL, NULL, &error);
if (!ret) {
dkp_warning ("failed to set data: %s", error->message);
egg_warning ("failed to set data: %s", error->message);
g_error_free (error);
goto out;
}
dkp_debug ("saved %s", filename);
egg_debug ("saved %s", filename);
out:
if (file != NULL)
@ -234,7 +234,7 @@ dkp_history_save_data (DkpHistory *history)
/* we have an ID? */
if (history->priv->id == NULL) {
dkp_warning ("no ID, cannot save");
egg_warning ("no ID, cannot save");
return FALSE;
}
@ -319,7 +319,7 @@ dkp_history_schedule_save (DkpHistory *history)
/* we already have one saved, cancel and reschedule */
if (history->priv->save_id != 0) {
dkp_debug ("deferring as others queued");
egg_debug ("deferring as others queued");
g_source_remove (history->priv->save_id);
history->priv->save_id = g_timeout_add_seconds (DKP_HISTORY_SAVE_INTERVAL,
(GSourceFunc) dkp_history_schedule_save_cb, history);
@ -327,7 +327,7 @@ dkp_history_schedule_save (DkpHistory *history)
}
/* nothing scheduled, do new */
dkp_debug ("saving in %i seconds", DKP_HISTORY_SAVE_INTERVAL);
egg_debug ("saving in %i seconds", DKP_HISTORY_SAVE_INTERVAL);
history->priv->save_id = g_timeout_add_seconds (DKP_HISTORY_SAVE_INTERVAL,
(GSourceFunc) dkp_history_schedule_save_cb, history);
@ -352,7 +352,7 @@ dkp_history_load_data_array (const gchar *filename, GPtrArray *array)
/* do we exist */
ret = g_file_test (filename, G_FILE_TEST_EXISTS);
if (!ret) {
dkp_debug ("failed to get data from %s as file does not exist", filename);
egg_debug ("failed to get data from %s as file does not exist", filename);
goto out;
}
@ -360,7 +360,7 @@ dkp_history_load_data_array (const gchar *filename, GPtrArray *array)
file = g_file_new_for_path (filename);
ret = g_file_load_contents (file, NULL, &data, NULL, NULL, &error);
if (!ret) {
dkp_warning ("failed to get data: %s", error->message);
egg_warning ("failed to get data: %s", error->message);
g_error_free (error);
goto out;
}
@ -369,12 +369,12 @@ dkp_history_load_data_array (const gchar *filename, GPtrArray *array)
parts = g_strsplit (data, "\n", 0);
length = g_strv_length (parts);
if (length == 0) {
dkp_debug ("no data in %s", filename);
egg_debug ("no data in %s", filename);
goto out;
}
/* add valid entries */
dkp_debug ("loading %i items of data from %s", length, filename);
egg_debug ("loading %i items of data from %s", length, filename);
for (i=0; i<length-1; i++) {
obj = dkp_history_obj_from_string (parts[i]);
if (obj != NULL)
@ -436,7 +436,7 @@ dkp_history_set_id (DkpHistory *history, const gchar *id)
if (id == NULL)
return FALSE;
dkp_debug ("using id: %s", id);
egg_debug ("using id: %s", id);
history->priv->id = g_strdup (id);
/* load all previous data */
ret = dkp_history_load_data (history);

View file

@ -33,7 +33,9 @@
#include <devkit-gobject.h>
#include "sysfs-utils.h"
#include "dkp-debug.h"
#include "egg-debug.h"
#include "egg-string.h"
#include "dkp-enum.h"
#include "dkp-object.h"
#include "dkp-supply.h"
@ -259,7 +261,7 @@ dkp_supply_refresh_battery (DkpSupply *supply)
else if (strcasecmp (status, "empty") == 0)
state = DKP_DEVICE_STATE_EMPTY;
else {
dkp_warning ("unknown status string: %s", status);
egg_warning ("unknown status string: %s", status);
state = DKP_DEVICE_STATE_UNKNOWN;
}
@ -348,7 +350,7 @@ dkp_supply_poll_battery (DkpSupply *supply)
DkpDevice *device = DKP_DEVICE (supply);
DkpObject *obj = dkp_device_get_obj (device);
dkp_debug ("No updates on supply %s for 30 seconds; forcing update", obj->native_path);
egg_debug ("No updates on supply %s for 30 seconds; forcing update", obj->native_path);
supply->priv->poll_timer_id = 0;
ret = dkp_supply_refresh (device);
if (ret)
@ -369,13 +371,13 @@ dkp_supply_get_history (DkpDevice *device, const gchar *type, guint timespan)
g_return_val_if_fail (type != NULL, FALSE);
/* get the correct data */
if (strcmp (type, "rate") == 0)
if (egg_strequal (type, "rate"))
array = dkp_history_get_rate_data (supply->priv->history, timespan);
else if (strcmp (type, "charge") == 0)
else if (egg_strequal (type, "charge"))
array = dkp_history_get_charge_data (supply->priv->history, timespan);
else if (strcmp (type, "time-full") == 0)
else if (egg_strequal (type, "time-full"))
array = dkp_history_get_time_full_data (supply->priv->history, timespan);
else if (strcmp (type, "time-empty") == 0)
else if (egg_strequal (type, "time-empty"))
array = dkp_history_get_time_empty_data (supply->priv->history, timespan);
return array;
@ -398,11 +400,11 @@ dkp_supply_coldplug (DkpDevice *device)
/* detect what kind of device we are */
d = dkp_device_get_d (device);
if (d == NULL)
dkp_error ("could not get device");
egg_error ("could not get device");
native_path = devkit_device_get_native_path (d);
if (native_path == NULL)
dkp_error ("could not get native path");
egg_error ("could not get native path");
if (sysfs_file_exists (native_path, "online")) {
obj->type = DKP_DEVICE_TYPE_LINE_POWER;

View file

@ -41,7 +41,9 @@
#include <getopt.h>
#include "sysfs-utils.h"
#include "dkp-debug.h"
#include "egg-debug.h"
#include "egg-string.h"
#include "dkp-enum.h"
#include "dkp-object.h"
#include "dkp-wup.h"
@ -77,7 +79,7 @@ dkp_wup_poll (DkpWup *wup)
DkpDevice *device = DKP_DEVICE (wup);
DkpObject *obj = dkp_device_get_obj (device);
dkp_debug ("Polling: %s", obj->native_path);
egg_debug ("Polling: %s", obj->native_path);
ret = dkp_wup_refresh (device);
if (ret)
dkp_device_emit_changed (device);
@ -95,7 +97,7 @@ dkp_wup_set_speed (DkpWup *wup)
retval = tcgetattr (wup->priv->fd, &t);
if (retval != 0) {
dkp_debug ("failed to get speed");
egg_debug ("failed to get speed");
return FALSE;
}
@ -108,7 +110,7 @@ dkp_wup_set_speed (DkpWup *wup)
t.c_cflag &= ~CSTOPB;
retval = tcsetattr (wup->priv->fd, TCSANOW, &t);
if (retval != 0) {
dkp_debug ("failed to set speed");
egg_debug ("failed to set speed");
return FALSE;
}
@ -128,10 +130,10 @@ dkp_wup_write_command (DkpWup *wup, const gchar *data)
gint length;
length = strlen (data);
dkp_debug ("writing [%s]", data);
egg_debug ("writing [%s]", data);
retval = write (wup->priv->fd, data, length);
if (retval != length) {
dkp_debug ("Writing [%s] to device failed", data);
egg_debug ("Writing [%s] to device failed", data);
ret = FALSE;
}
return ret;
@ -149,10 +151,10 @@ dkp_wup_read_command (DkpWup *wup)
gchar buffer[DKP_WUP_COMMAND_LEN];
retval = read (wup->priv->fd, &buffer, DKP_WUP_COMMAND_LEN);
if (retval < 0) {
dkp_debug ("failed to read from fd");
egg_debug ("failed to read from fd");
return NULL;
}
dkp_debug ("reading [%s]", buffer);
egg_debug ("reading [%s]", buffer);
return g_strdup (buffer);
}
@ -190,7 +192,7 @@ dkp_wup_parse_command (DkpWup *wup, const gchar *data)
/* does packet exist? */
if (packet == NULL) {
dkp_debug ("no start char in %s", data);
egg_debug ("no start char in %s", data);
goto out;
}
@ -207,7 +209,7 @@ dkp_wup_parse_command (DkpWup *wup, const gchar *data)
tokens = g_strsplit (data, ",", -1);
length = g_strv_length (tokens);
if (length < 3) {
dkp_debug ("not enough tokens '%s'", data);
egg_debug ("not enough tokens '%s'", data);
goto out;
}
@ -219,11 +221,11 @@ dkp_wup_parse_command (DkpWup *wup, const gchar *data)
/* check the first token */
length_tok = strlen (tokens[0]);
if (length_tok != 2) {
dkp_debug ("expected command '#?' but got '%s'", tokens[0]);
egg_debug ("expected command '#?' but got '%s'", tokens[0]);
goto out;
}
if (tokens[0][0] != '#') {
dkp_debug ("expected command '#?' but got '%s'", tokens[0]);
egg_debug ("expected command '#?' but got '%s'", tokens[0]);
goto out;
}
command = tokens[0][1];
@ -231,7 +233,7 @@ dkp_wup_parse_command (DkpWup *wup, const gchar *data)
/* check the second token */
length_tok = strlen (tokens[1]);
if (length_tok != 1) {
dkp_debug ("expected command '?' but got '%s'", tokens[1]);
egg_debug ("expected command '?' but got '%s'", tokens[1]);
goto out;
}
subcommand = tokens[1][0]; /* expect to be '-' */
@ -239,14 +241,14 @@ dkp_wup_parse_command (DkpWup *wup, const gchar *data)
/* check the length */
size = atoi (tokens[1]);
if (size != length - offset) {
dkp_debug ("size expected to be '%i' but got '%i'", length - offset, size);
egg_debug ("size expected to be '%i' but got '%i'", length - offset, size);
goto out;
}
/* print the data */
dkp_debug ("command=%c:%c", command, subcommand);
egg_debug ("command=%c:%c", command, subcommand);
for (i=0; i<size; i++) {
dkp_debug ("%i\t'%s'", i, tokens[i+offset]);
egg_debug ("%i\t'%s'", i, tokens[i+offset]);
}
/* update the command fields */
@ -254,7 +256,7 @@ dkp_wup_parse_command (DkpWup *wup, const gchar *data)
obj->energy_rate = strtod (tokens[offset+DKP_WUP_RESPONSE_HEADER_WATTS], NULL);
// obj->volts = strtod (tokens[offset+DKP_WUP_RESPONSE_HEADER_VOLTS], NULL);
} else {
dkp_debug ("ignoring command '%c'", command);
egg_debug ("ignoring command '%c'", command);
}
out:
@ -280,33 +282,33 @@ dkp_wup_coldplug (DkpDevice *device)
/* detect what kind of device we are */
d = dkp_device_get_d (device);
if (d == NULL)
dkp_error ("could not get device");
egg_error ("could not get device");
/* get the type */
type = devkit_device_get_property (d, "DKP_MONITOR_TYPE");
if (type == NULL || strcmp (type, "wup") != 0) {
dkp_debug ("not a Watts Up? Pro device");
if (type == NULL || !egg_strequal (type, "wup")) {
egg_debug ("not a Watts Up? Pro device");
goto out;
}
/* get the device file */
device_file = devkit_device_get_device_file (d);
if (device_file == NULL) {
dkp_debug ("could not get device file for WUP device");
egg_debug ("could not get device file for WUP device");
goto out;
}
/* connect to the device */
wup->priv->fd = open (device_file, O_RDONLY | O_NONBLOCK);
if (wup->priv->fd < 0) {
dkp_debug ("cannot open device file %s", device_file);
egg_debug ("cannot open device file %s", device_file);
goto out;
}
/* set speed */
ret = dkp_wup_set_speed (wup);
if (!ret) {
dkp_debug ("not a WUP device (cannot set speed): %s", device_file);
egg_debug ("not a WUP device (cannot set speed): %s", device_file);
goto out;
}
@ -314,7 +316,7 @@ dkp_wup_coldplug (DkpDevice *device)
ret = dkp_wup_write_command (wup, DKP_WUP_COMMAND_CLEAR);
/* dummy read */
data = dkp_wup_read_command (wup);
dkp_debug ("data after clear %s", data);
egg_debug ("data after clear %s", data);
/* shouldn't do anything */
dkp_wup_parse_command (wup, data);
@ -356,14 +358,14 @@ dkp_wup_refresh (DkpDevice *device)
/* get data */
data = dkp_wup_read_command (wup);
if (data == NULL) {
dkp_debug ("no data");
egg_debug ("no data");
goto out;
}
/* parse */
ret = dkp_wup_parse_command (wup, data);
if (!ret) {
dkp_debug ("failed to parse %s", data);
egg_debug ("failed to parse %s", data);
goto out;
}
ret = TRUE;

View file

@ -20,7 +20,7 @@
*/
/**
* SECTION:dkp-debug
* SECTION:egg-debug
* @short_description: Debugging functions
*
* This file contains functions that can be used for debugging.
@ -41,7 +41,7 @@
#include <time.h>
#include <execinfo.h>
#include "dkp-debug.h"
#include "egg-debug.h"
#define CONSOLE_RESET 0
#define CONSOLE_BLACK 30
@ -53,16 +53,28 @@
#define CONSOLE_CYAN 36
#define CONSOLE_WHITE 37
#define PK_LOG_FILE PK_LOG_DIR "/PackageKit"
static gboolean do_verbose = FALSE; /* if we should print out debugging */
static gboolean do_logging = FALSE; /* if we should write to a file */
static gboolean is_console = FALSE;
static gint fd = -1;
/**
* dkp_set_console_mode:
* egg_debug_set_logging:
**/
void
egg_debug_set_logging (gboolean enabled)
{
do_logging = enabled;
if (enabled) {
egg_debug ("now logging to %s", EGG_LOG_FILE);
}
}
/**
* pk_set_console_mode:
**/
static void
dkp_set_console_mode (guint console_code)
pk_set_console_mode (guint console_code)
{
gchar command[13];
@ -76,10 +88,10 @@ dkp_set_console_mode (guint console_code)
}
/**
* dkp_debug_backtrace:
* egg_debug_backtrace:
**/
void
dkp_debug_backtrace (void)
egg_debug_backtrace (void)
{
void *call_stack[512];
int call_stack_size;
@ -89,22 +101,50 @@ dkp_debug_backtrace (void)
call_stack_size = backtrace (call_stack, G_N_ELEMENTS (call_stack));
symbols = backtrace_symbols (call_stack, call_stack_size);
if (symbols != NULL) {
dkp_set_console_mode (CONSOLE_RED);
pk_set_console_mode (CONSOLE_RED);
g_print ("Traceback:\n");
while (i < call_stack_size) {
g_print ("\t%s\n", symbols[i]);
i++;
}
dkp_set_console_mode (CONSOLE_RESET);
pk_set_console_mode (CONSOLE_RESET);
free (symbols);
}
}
/**
* dkp_print_line:
* pk_log_line:
**/
static void
dkp_print_line (const gchar *func, const gchar *file, const int line, const gchar *buffer, guint color)
pk_log_line (const gchar *buffer)
{
ssize_t count;
/* open a file */
if (fd == -1) {
/* ITS4: ignore, /var/log/foo is owned by root, and this is just debug text */
fd = open (EGG_LOG_FILE, O_WRONLY|O_APPEND|O_CREAT, 0777);
if (fd == -1) {
g_error ("could not open log: '%s'", EGG_LOG_FILE);
}
}
/* ITS4: ignore, debug text always NULL terminated */
count = write (fd, buffer, strlen (buffer));
if (count == -1) {
g_warning ("could not write %s", buffer);
}
/* newline */
count = write (fd, "\n", 1);
if (count == -1) {
g_warning ("could not write newline");
}
}
/**
* pk_print_line:
**/
static void
pk_print_line (const gchar *func, const gchar *file, const int line, const gchar *buffer, guint color)
{
gchar *str_time;
gchar *header;
@ -121,13 +161,19 @@ dkp_print_line (const gchar *func, const gchar *file, const int line, const gcha
g_free (str_time);
/* always in light green */
dkp_set_console_mode (CONSOLE_GREEN);
pk_set_console_mode (CONSOLE_GREEN);
printf ("%s\n", header);
/* different colours according to the severity */
dkp_set_console_mode (color);
pk_set_console_mode (color);
printf (" - %s\n", buffer);
dkp_set_console_mode (CONSOLE_RESET);
pk_set_console_mode (CONSOLE_RESET);
/* log to a file */
if (do_logging) {
pk_log_line (header);
pk_log_line (buffer);
}
/* flush this output, as we need to debug */
fflush (stdout);
@ -136,10 +182,10 @@ dkp_print_line (const gchar *func, const gchar *file, const int line, const gcha
}
/**
* dkp_debug_real:
* egg_debug_real:
**/
void
dkp_debug_real (const gchar *func, const gchar *file, const int line, const gchar *format, ...)
egg_debug_real (const gchar *func, const gchar *file, const int line, const gchar *format, ...)
{
va_list args;
gchar *buffer = NULL;
@ -152,16 +198,16 @@ dkp_debug_real (const gchar *func, const gchar *file, const int line, const gcha
g_vasprintf (&buffer, format, args);
va_end (args);
dkp_print_line (func, file, line, buffer, CONSOLE_BLUE);
pk_print_line (func, file, line, buffer, CONSOLE_BLUE);
g_free(buffer);
}
/**
* dkp_warning_real:
* egg_warning_real:
**/
void
dkp_warning_real (const gchar *func, const gchar *file, const int line, const gchar *format, ...)
egg_warning_real (const gchar *func, const gchar *file, const int line, const gchar *format, ...)
{
va_list args;
gchar *buffer = NULL;
@ -178,19 +224,16 @@ dkp_warning_real (const gchar *func, const gchar *file, const int line, const gc
if (!is_console) {
printf ("*** WARNING ***\n");
}
dkp_print_line (func, file, line, buffer, CONSOLE_RED);
pk_print_line (func, file, line, buffer, CONSOLE_RED);
g_free(buffer);
/* we want to fix this! */
dkp_debug_backtrace ();
}
/**
* dkp_error_real:
* egg_error_real:
**/
void
dkp_error_real (const gchar *func, const gchar *file, const int line, const gchar *format, ...)
egg_error_real (const gchar *func, const gchar *file, const int line, const gchar *format, ...)
{
va_list args;
gchar *buffer = NULL;
@ -203,38 +246,38 @@ dkp_error_real (const gchar *func, const gchar *file, const int line, const gcha
if (!is_console) {
printf ("*** ERROR ***\n");
}
dkp_print_line (func, file, line, buffer, CONSOLE_RED);
pk_print_line (func, file, line, buffer, CONSOLE_RED);
g_free(buffer);
/* we want to fix this! */
dkp_debug_backtrace ();
egg_debug_backtrace ();
exit (1);
}
/**
* dkp_debug_enabled:
* egg_debug_enabled:
*
* Returns: TRUE if we have debugging enabled
**/
gboolean
dkp_debug_enabled (void)
egg_debug_enabled (void)
{
return do_verbose;
}
/**
* dkp_debug_init:
* @debug: If we should print out verbose debugging
* egg_debug_init:
* @debug: If we should print out verbose logging
**/
void
dkp_debug_init (gboolean debug)
egg_debug_init (gboolean debug)
{
do_verbose = debug;
/* check if we are on console */
if (isatty (fileno (stdout)) == 1) {
is_console = TRUE;
}
dkp_debug ("Verbose debugging %i (on console %i)", do_verbose, is_console);
egg_debug ("Verbose debugging %i (on console %i)", do_verbose, is_console);
}

View file

@ -19,8 +19,8 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __PK_DEBUG_H
#define __PK_DEBUG_H
#ifndef __EGG_DEBUG_H
#define __EGG_DEBUG_H
#include <stdarg.h>
#include <glib.h>
@ -29,52 +29,53 @@ G_BEGIN_DECLS
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
/**
* dkp_debug:
* egg_debug:
*
* Non critical debugging
*/
#define dkp_debug(...) dkp_debug_real (__func__, __FILE__, __LINE__, __VA_ARGS__)
#define egg_debug(...) egg_debug_real (__func__, __FILE__, __LINE__, __VA_ARGS__)
/**
* dkp_warning:
* egg_warning:
*
* Important debugging
*/
#define dkp_warning(...) dkp_warning_real (__func__, __FILE__, __LINE__, __VA_ARGS__)
#define egg_warning(...) egg_warning_real (__func__, __FILE__, __LINE__, __VA_ARGS__)
/**
* dkp_error:
* egg_error:
*
* Critical debugging, with exit
*/
#define dkp_error(...) dkp_error_real (__func__, __FILE__, __LINE__, __VA_ARGS__)
#define egg_error(...) egg_error_real (__func__, __FILE__, __LINE__, __VA_ARGS__)
#elif defined(__GNUC__) && __GNUC__ >= 3
#define dkp_debug(...) dkp_debug_real (__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
#define dkp_warning(...) dkp_warning_real (__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
#define dkp_error(...) dkp_error_real (__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
#define egg_debug(...) egg_debug_real (__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
#define egg_warning(...) egg_warning_real (__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
#define egg_error(...) egg_error_real (__FUNCTION__, __FILE__, __LINE__, __VA_ARGS__)
#else
#define dkp_debug(...)
#define dkp_warning(...)
#define dkp_error(...)
#define egg_debug(...)
#define egg_warning(...)
#define egg_error(...)
#endif
void dkp_debug_init (gboolean debug);
gboolean dkp_debug_enabled (void);
void dkp_debug_backtrace (void);
void dkp_debug_real (const gchar *func,
void egg_debug_init (gboolean debug);
void egg_debug_set_logging (gboolean enabled);
gboolean egg_debug_enabled (void);
void egg_debug_backtrace (void);
void egg_debug_real (const gchar *func,
const gchar *file,
int line,
const gchar *format, ...) __attribute__((format (printf,4,5)));
void dkp_warning_real (const gchar *func,
void egg_warning_real (const gchar *func,
const gchar *file,
int line,
const gchar *format, ...) __attribute__((format (printf,4,5)));
void dkp_error_real (const gchar *func,
void egg_error_real (const gchar *func,
const gchar *file,
int line,
const gchar *format, ...) __attribute__((format (printf,4,5)));
G_END_DECLS
#endif /* __PK_DEBUG_H */
#endif /* __EGG_DEBUG_H */

228
src/egg-string.c Normal file
View file

@ -0,0 +1,228 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2007-2008 Richard Hughes <richard@hughsie.com>
*
* Licensed under the GNU General Public License Version 2
*
* 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.
*
* 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.
*/
/**
* SECTION:pk-common
* @short_description: Common utility functions for PackageKit
*
* This file contains functions that may be useful.
*/
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <sys/stat.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
#include <glib.h>
#include "egg-debug.h"
#include "egg-string.h"
/**
* egg_strnumber:
* @text: The text the validate
*
* Tests a string to see if it is a number. Both positive and negative numbers
* are allowed.
*
* Return value: %TRUE if the string represents a numeric value
**/
gboolean
egg_strnumber (const gchar *text)
{
guint i;
guint length;
/* check explicitly */
if (egg_strzero (text))
return FALSE;
/* max length is 10 */
length = egg_strlen (text, 10);
if (length == 10) {
egg_warning ("input too long: %s", text);
return FALSE;
}
for (i=0; i<length; i++) {
if (i == 0 && text[i] == '-') {
/* negative sign */
} else if (g_ascii_isdigit (text[i]) == FALSE) {
egg_warning ("not a number '%c' in text!", text[i]);
return FALSE;
}
}
return TRUE;
}
/**
* egg_strtoint:
* @text: The text the convert
* @value: The return numeric return value, or 0 if invalid.
*
* Converts a string into a signed integer value in a safe way.
*
* Return value: %TRUE if the string was converted correctly
**/
gboolean
egg_strtoint (const gchar *text, gint *value)
{
gboolean ret;
ret = egg_strnumber (text);
if (!ret) {
*value = 0;
return FALSE;
}
/* ITS4: ignore, we've already checked for validity */
*value = atoi (text);
return TRUE;
}
/**
* egg_strtouint:
* @text: The text the convert
* @value: The return numeric return value, or 0 if invalid.
*
* Converts a string into a unsigned integer value in a safe way.
*
* Return value: %TRUE if the string was converted correctly
**/
gboolean
egg_strtouint (const gchar *text, guint *value)
{
gboolean ret;
gint temp;
ret = egg_strtoint (text, &temp);
if (ret == FALSE || temp < 0) {
*value = 0;
return FALSE;
}
*value = (guint) temp;
return TRUE;
}
/**
* egg_strzero:
* @text: The text to check
*
* This function is a much safer way of doing "if (strlen (text) == 0))"
* as it does not rely on text being NULL terminated. It's also much
* quicker as it only checks the first byte rather than scanning the whole
* string just to verify it's not zero length.
*
* Return value: %TRUE if the string was converted correctly
**/
gboolean
egg_strzero (const gchar *text)
{
if (text == NULL)
return TRUE;
if (text[0] == '\0')
return TRUE;
return FALSE;
}
/**
* egg_strlen:
* @text: The text to check
* @len: The maximum length of the string
*
* This function is a much safer way of doing strlen as it checks for NULL and
* a stupidly long string.
*
* Return value: the length of the string, or len if the string is too long.
**/
guint
egg_strlen (const gchar *text, guint len)
{
guint i;
/* common case */
if (text == NULL || text[0] == '\0') {
return 0;
}
/* only count up to len */
for (i=1; i<len; i++) {
if (text[i] == '\0')
break;
}
return i;
}
/**
* egg_strequal:
* @id1: the first item of text to test
* @id2: the second item of text to test
*
* This function is a much safer way of doing strcmp as it checks for
* NULL first, and returns boolean TRUE, not zero for success.
*
* Return value: %TRUE if the string are both non-%NULL and the same.
**/
gboolean
egg_strequal (const gchar *id1, const gchar *id2)
{
if (id1 == NULL || id2 == NULL) {
egg_debug ("string compare invalid '%s' and '%s'", id1, id2);
return FALSE;
}
return (strcmp (id1, id2) == 0);
}
/**
* egg_strreplace:
* @text: The input text to make safe
* @find: What to search for
* @replace: What to replace with
*
* Replaces chars in the text with a replacement.
* The %find and %replace variables to not have to be of the same length
*
* Return value: the new string (copied)
**/
gchar *
egg_strreplace (const gchar *text, const gchar *find, const gchar *replace)
{
gchar **array;
gchar *retval;
/* common case, not found */
if (strstr (text, find) == NULL) {
return g_strdup (text);
}
/* split apart and rejoin with new delimiter */
array = g_strsplit (text, find, 0);
retval = g_strjoinv (replace, array);
g_strfreev (array);
return retval;
}

49
src/egg-string.h Normal file
View file

@ -0,0 +1,49 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2007-2008 Richard Hughes <richard@hughsie.com>
*
* Licensed under the GNU General Public License Version 2
*
* 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.
*
* 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.
*/
#ifndef __EGG_STRING_H
#define __EGG_STRING_H
#include <glib.h>
G_BEGIN_DECLS
guint egg_strlen (const gchar *text,
guint len)
G_GNUC_WARN_UNUSED_RESULT;
gboolean egg_strzero (const gchar *text)
G_GNUC_WARN_UNUSED_RESULT;
gboolean egg_strequal (const gchar *id1,
const gchar *id2)
G_GNUC_WARN_UNUSED_RESULT;
gboolean egg_strnumber (const gchar *text)
G_GNUC_WARN_UNUSED_RESULT;
gboolean egg_strtoint (const gchar *text,
gint *value);
gboolean egg_strtouint (const gchar *text,
guint *value);
gchar *egg_strreplace (const gchar *text,
const gchar *find,
const gchar *replace);
G_END_DECLS
#endif /* __EGG_STRING_H */

View file

@ -41,7 +41,7 @@
#include <dbus/dbus-glib-lowlevel.h>
#include <devkit-gobject.h>
#include "dkp-debug.h"
#include "egg-debug.h"
#include "dkp-daemon.h"
#define NAME_TO_CLAIM "org.freedesktop.DeviceKit.Power"
@ -75,20 +75,20 @@ main_acquire_name_on_proxy (DBusGProxy *bus_proxy)
G_TYPE_INVALID);
if (!res) {
if (error != NULL) {
dkp_warning ("Failed to acquire %s: %s", NAME_TO_CLAIM, error->message);
egg_warning ("Failed to acquire %s: %s", NAME_TO_CLAIM, error->message);
g_error_free (error);
} else {
dkp_warning ("Failed to acquire %s", NAME_TO_CLAIM);
egg_warning ("Failed to acquire %s", NAME_TO_CLAIM);
}
goto out;
}
if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
if (error != NULL) {
dkp_warning ("Failed to acquire %s: %s", NAME_TO_CLAIM, error->message);
egg_warning ("Failed to acquire %s: %s", NAME_TO_CLAIM, error->message);
g_error_free (error);
} else {
dkp_warning ("Failed to acquire %s", NAME_TO_CLAIM);
egg_warning ("Failed to acquire %s", NAME_TO_CLAIM);
}
goto out;
}
@ -105,7 +105,7 @@ main_acquire_name_on_proxy (DBusGProxy *bus_proxy)
static void
dkp_main_sigint_handler (int sig)
{
dkp_debug ("Handling SIGINT");
egg_debug ("Handling SIGINT");
/* restore default */
signal (SIGINT, SIG_DFL);
@ -140,12 +140,12 @@ main (int argc, char **argv)
g_option_context_add_main_entries (context, entries, NULL);
g_option_context_parse (context, &argc, &argv, NULL);
g_option_context_free (context);
dkp_debug_init (verbose);
egg_debug_init (verbose);
error = NULL;
bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
if (bus == NULL) {
dkp_warning ("Couldn't connect to system bus: %s", error->message);
egg_warning ("Couldn't connect to system bus: %s", error->message);
g_error_free (error);
goto out;
}
@ -153,19 +153,19 @@ main (int argc, char **argv)
bus_proxy = dbus_g_proxy_new_for_name (bus, DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);
if (bus_proxy == NULL) {
dkp_warning ("Could not construct bus_proxy object; bailing out");
egg_warning ("Could not construct bus_proxy object; bailing out");
goto out;
}
if (!main_acquire_name_on_proxy (bus_proxy) ) {
dkp_warning ("Could not acquire name; bailing out");
egg_warning ("Could not acquire name; bailing out");
goto out;
}
/* do stuff on ctrl-c */
signal (SIGINT, dkp_main_sigint_handler);
dkp_debug ("Starting devkit-power-daemon version %s", VERSION);
egg_debug ("Starting devkit-power-daemon version %s", VERSION);
power_daemon = dkp_daemon_new ();

View file

@ -213,19 +213,19 @@ sysfs_resolve_link (const char *dir, const char *attribute)
full_path = g_build_filename (dir, attribute, NULL);
//dkp_warning ("attribute='%s'", attribute);
//dkp_warning ("full_path='%s'", full_path);
//egg_warning ("attribute='%s'", attribute);
//egg_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';
//dkp_warning ("link_path='%s'", link_path);
//egg_warning ("link_path='%s'", link_path);
absolute_path = g_build_filename (dir, link_path, NULL);
//dkp_warning ("absolute_path='%s'", absolute_path);
//egg_warning ("absolute_path='%s'", absolute_path);
if (realpath (absolute_path, resolved_path) != NULL) {
//dkp_warning ("resolved_path='%s'", resolved_path);
//egg_warning ("resolved_path='%s'", resolved_path);
found_it = TRUE;
}
g_free (absolute_path);

View file

@ -10,6 +10,7 @@ INCLUDES = \
-DPACKAGE_LOCALE_DIR=\""$(localedir)"\" \
-DPACKAGE_LIB_DIR=\""$(libdir)"\" \
-D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT \
-DEGG_LOG_FILE=\""$(PK_LOG_DIR)/DeviceKit-power"\" \
-I$(top_srcdir)/libdevkit-power \
$(DBUS_GLIB_CFLAGS) \
$(POLKIT_DBUS_CFLAGS) \
@ -33,6 +34,8 @@ dkp-daemon-glue.h: $(top_srcdir)/src/org.freedesktop.DeviceKit.Power.xml Makefil
bin_PROGRAMS = devkit-power devkit-power-on-battery
devkit_power_SOURCES = \
egg-debug.c \
egg-debug.h \
dkp-tool.c \
$(BUILT_SOURCES)
@ -47,6 +50,8 @@ devkit_power_LDADD = \
$(POLKIT_DBUS_LIBS)
devkit_power_on_battery_SOURCES = \
egg-debug.c \
egg-debug.h \
dkp-battery-power.c \
$(BUILT_SOURCES)

View file

@ -1,6 +1,6 @@
#include <glib.h>
#include <dbus/dbus-glib.h>
#include "dkp-debug.h"
#include "egg-debug.h"
/**
* main:
@ -28,11 +28,11 @@ main (int argc, char **argv)
g_option_context_add_main_entries (context, entries, NULL);
g_option_context_parse (context, &argc, &argv, NULL);
g_option_context_free (context);
dkp_debug_init (verbose);
egg_debug_init (verbose);
bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
if (bus == NULL) {
dkp_warning ("Couldn't connect to system bus: %s", error->message);
egg_warning ("Couldn't connect to system bus: %s", error->message);
g_error_free (error);
goto out;
}
@ -40,7 +40,7 @@ main (int argc, char **argv)
proxy = dbus_g_proxy_new_for_name (bus, "org.freedesktop.DeviceKit.Power",
"/", "org.freedesktop.DeviceKit.Power");
if (proxy == NULL) {
dkp_warning ("Couldn't connect to DeviceKit-power");
egg_warning ("Couldn't connect to DeviceKit-power");
goto out;
}
@ -49,7 +49,7 @@ main (int argc, char **argv)
G_TYPE_BOOLEAN, &on_battery,
G_TYPE_INVALID);
if (!ret) {
dkp_debug ("GetOnBattery failed: %s", error->message);
egg_debug ("GetOnBattery failed: %s", error->message);
g_error_free (error);
goto out;
}

View file

@ -31,7 +31,7 @@
#include <glib/gi18n-lib.h>
#include "dkp-marshal.h"
#include "dkp-debug.h"
#include "egg-debug.h"
#include "dkp-client.h"
#include "dkp-client-device.h"
@ -123,7 +123,7 @@ main (int argc, char **argv)
g_option_context_add_main_entries (context, entries, NULL);
g_option_context_parse (context, &argc, &argv, NULL);
g_option_context_free (context);
dkp_debug_init (verbose);
egg_debug_init (verbose);
loop = g_main_loop_new (NULL, FALSE);
client = dkp_client_new ();

1
tools/egg-debug.c Symbolic link
View file

@ -0,0 +1 @@
../src/egg-debug.c

1
tools/egg-debug.h Symbolic link
View file

@ -0,0 +1 @@
../src/egg-debug.h