summaryrefslogtreecommitdiff
path: root/libdevkit-power
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2008-08-28 15:49:19 +0100
committerRichard Hughes <richard@hughsie.com>2008-08-28 15:49:19 +0100
commit7fdcc278dc80aa0bb07c834e0d8de5787852ecb2 (patch)
tree91c2afadfa42f96082bb9423a875f89c4b795b16 /libdevkit-power
parent0e2c7ef0ecb7ef924230a4e45c0b75a3937678d7 (diff)
convert to using egg_ functionality like other projects
Diffstat (limited to 'libdevkit-power')
-rw-r--r--libdevkit-power/Makefile.am7
-rw-r--r--libdevkit-power/dkp-client-device.c22
-rw-r--r--libdevkit-power/dkp-client.c8
-rw-r--r--libdevkit-power/dkp-debug.c240
-rw-r--r--libdevkit-power/dkp-debug.h80
-rw-r--r--libdevkit-power/dkp-enum.c40
-rw-r--r--libdevkit-power/dkp-history-obj.c4
-rw-r--r--libdevkit-power/dkp-object.c111
-rw-r--r--libdevkit-power/dkp-stats-obj.c2
l---------libdevkit-power/egg-debug.c1
l---------libdevkit-power/egg-debug.h1
l---------libdevkit-power/egg-string.c1
l---------libdevkit-power/egg-string.h1
13 files changed, 83 insertions, 435 deletions
diff --git a/libdevkit-power/Makefile.am b/libdevkit-power/Makefile.am
index 1e065ea..6d776d2 100644
--- a/libdevkit-power/Makefile.am
+++ b/libdevkit-power/Makefile.am
@@ -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 \
diff --git a/libdevkit-power/dkp-client-device.c b/libdevkit-power/dkp-client-device.c
index 81ee5d9..2374e37 100644
--- a/libdevkit-power/dkp-client-device.c
+++ b/libdevkit-power/dkp-client-device.c
@@ -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;
diff --git a/libdevkit-power/dkp-client.c b/libdevkit-power/dkp-client.c
index d82bdc0..51122fb 100644
--- a/libdevkit-power/dkp-client.c
+++ b/libdevkit-power/dkp-client.c
@@ -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;
}
diff --git a/libdevkit-power/dkp-debug.c b/libdevkit-power/dkp-debug.c
deleted file mode 100644
index bf3f12e..0000000
--- a/libdevkit-power/dkp-debug.c
+++ /dev/null
@@ -1,240 +0,0 @@
-/* -*- 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:dkp-debug
- * @short_description: Debugging functions
- *
- * This file contains functions that can be used for debugging.
- */
-
-#include <glib.h>
-#include <glib/gi18n.h>
-#include <glib/gprintf.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <time.h>
-#include <execinfo.h>
-
-#include "dkp-debug.h"
-
-#define CONSOLE_RESET 0
-#define CONSOLE_BLACK 30
-#define CONSOLE_RED 31
-#define CONSOLE_GREEN 32
-#define CONSOLE_YELLOW 33
-#define CONSOLE_BLUE 34
-#define CONSOLE_MAGENTA 35
-#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 is_console = FALSE;
-
-/**
- * dkp_set_console_mode:
- **/
-static void
-dkp_set_console_mode (guint console_code)
-{
- gchar command[13];
-
- /* don't put extra commands into logs */
- if (!is_console) {
- return;
- }
- /* Command is the control command to the terminal */
- g_snprintf (command, 13, "%c[%dm", 0x1B, console_code);
- printf ("%s", command);
-}
-
-/**
- * dkp_debug_backtrace:
- **/
-void
-dkp_debug_backtrace (void)
-{
- void *call_stack[512];
- int call_stack_size;
- char **symbols;
- int i = 1;
-
- 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);
- g_print ("Traceback:\n");
- while (i < call_stack_size) {
- g_print ("\t%s\n", symbols[i]);
- i++;
- }
- dkp_set_console_mode (CONSOLE_RESET);
- free (symbols);
- }
-}
-
-/**
- * dkp_print_line:
- **/
-static void
-dkp_print_line (const gchar *func, const gchar *file, const int line, const gchar *buffer, guint color)
-{
- gchar *str_time;
- gchar *header;
- time_t the_time;
- GThread *thread;
-
- time (&the_time);
- str_time = g_new0 (gchar, 255);
- strftime (str_time, 254, "%H:%M:%S", localtime (&the_time));
- thread = g_thread_self ();
-
- /* generate header text */
- header = g_strdup_printf ("TI:%s\tTH:%p\tFI:%s\tFN:%s,%d", str_time, thread, file, func, line);
- g_free (str_time);
-
- /* always in light green */
- dkp_set_console_mode (CONSOLE_GREEN);
- printf ("%s\n", header);
-
- /* different colours according to the severity */
- dkp_set_console_mode (color);
- printf (" - %s\n", buffer);
- dkp_set_console_mode (CONSOLE_RESET);
-
- /* flush this output, as we need to debug */
- fflush (stdout);
-
- g_free (header);
-}
-
-/**
- * dkp_debug_real:
- **/
-void
-dkp_debug_real (const gchar *func, const gchar *file, const int line, const gchar *format, ...)
-{
- va_list args;
- gchar *buffer = NULL;
-
- if (do_verbose == FALSE) {
- return;
- }
-
- va_start (args, format);
- g_vasprintf (&buffer, format, args);
- va_end (args);
-
- dkp_print_line (func, file, line, buffer, CONSOLE_BLUE);
-
- g_free(buffer);
-}
-
-/**
- * dkp_warning_real:
- **/
-void
-dkp_warning_real (const gchar *func, const gchar *file, const int line, const gchar *format, ...)
-{
- va_list args;
- gchar *buffer = NULL;
-
- if (do_verbose == FALSE) {
- return;
- }
-
- va_start (args, format);
- g_vasprintf (&buffer, format, args);
- va_end (args);
-
- /* do extra stuff for a warning */
- if (!is_console) {
- printf ("*** WARNING ***\n");
- }
- dkp_print_line (func, file, line, buffer, CONSOLE_RED);
-
- g_free(buffer);
-
- /* we want to fix this! */
- dkp_debug_backtrace ();
-}
-
-/**
- * dkp_error_real:
- **/
-void
-dkp_error_real (const gchar *func, const gchar *file, const int line, const gchar *format, ...)
-{
- va_list args;
- gchar *buffer = NULL;
-
- va_start (args, format);
- g_vasprintf (&buffer, format, args);
- va_end (args);
-
- /* do extra stuff for a warning */
- if (!is_console) {
- printf ("*** ERROR ***\n");
- }
- dkp_print_line (func, file, line, buffer, CONSOLE_RED);
- g_free(buffer);
-
- /* we want to fix this! */
- dkp_debug_backtrace ();
-
- exit (1);
-}
-
-/**
- * dkp_debug_enabled:
- *
- * Returns: TRUE if we have debugging enabled
- **/
-gboolean
-dkp_debug_enabled (void)
-{
- return do_verbose;
-}
-
-/**
- * dkp_debug_init:
- * @debug: If we should print out verbose debugging
- **/
-void
-dkp_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);
-}
-
diff --git a/libdevkit-power/dkp-debug.h b/libdevkit-power/dkp-debug.h
deleted file mode 100644
index 8f05c01..0000000
--- a/libdevkit-power/dkp-debug.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/* -*- 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 __PK_DEBUG_H
-#define __PK_DEBUG_H
-
-#include <stdarg.h>
-#include <glib.h>
-
-G_BEGIN_DECLS
-
-#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
-/**
- * dkp_debug:
- *
- * Non critical debugging
- */
-#define dkp_debug(...) dkp_debug_real (__func__, __FILE__, __LINE__, __VA_ARGS__)
-
-/**
- * dkp_warning:
- *
- * Important debugging
- */
-#define dkp_warning(...) dkp_warning_real (__func__, __FILE__, __LINE__, __VA_ARGS__)
-
-/**
- * dkp_error:
- *
- * Critical debugging, with exit
- */
-#define dkp_error(...) dkp_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__)
-#else
-#define dkp_debug(...)
-#define dkp_warning(...)
-#define dkp_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,
- const gchar *file,
- int line,
- const gchar *format, ...) __attribute__((format (printf,4,5)));
-void dkp_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,
- const gchar *file,
- int line,
- const gchar *format, ...) __attribute__((format (printf,4,5)));
-
-G_END_DECLS
-
-#endif /* __PK_DEBUG_H */
diff --git a/libdevkit-power/dkp-enum.c b/libdevkit-power/dkp-enum.c
index bfb00fa..2423d80 100644
--- a/libdevkit-power/dkp-enum.c
+++ b/libdevkit-power/dkp-enum.c
@@ -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;
}
diff --git a/libdevkit-power/dkp-history-obj.c b/libdevkit-power/dkp-history-obj.c
index 491ddaf..5727cb9 100644
--- a/libdevkit-power/dkp-history-obj.c
+++ b/libdevkit-power/dkp-history-obj.c
@@ -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;
}
diff --git a/libdevkit-power/dkp-object.c b/libdevkit-power/dkp-object.c
index ff2df68..8a85598 100644
--- a/libdevkit-power/dkp-object.c
+++ b/libdevkit-power/dkp-object.c
@@ -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);
}
/**
@@ -155,26 +157,6 @@ dkp_object_copy (const DkpObject *cobj)
}
/**
- * 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:
**/
gboolean
@@ -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 &&
@@ -205,29 +187,6 @@ dkp_object_equal (const DkpObject *obj1, const DkpObject *obj2)
}
/**
- * 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:
**/
static gchar *
@@ -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));
diff --git a/libdevkit-power/dkp-stats-obj.c b/libdevkit-power/dkp-stats-obj.c
index 163336b..fcc70ca 100644
--- a/libdevkit-power/dkp-stats-obj.c
+++ b/libdevkit-power/dkp-stats-obj.c
@@ -23,7 +23,7 @@
#include <string.h>
#include <stdlib.h>
-#include "dkp-debug.h"
+#include "egg-debug.h"
#include "dkp-stats-obj.h"
/**
diff --git a/libdevkit-power/egg-debug.c b/libdevkit-power/egg-debug.c
new file mode 120000
index 0000000..0a3eb62
--- /dev/null
+++ b/libdevkit-power/egg-debug.c
@@ -0,0 +1 @@
+../src/egg-debug.c \ No newline at end of file
diff --git a/libdevkit-power/egg-debug.h b/libdevkit-power/egg-debug.h
new file mode 120000
index 0000000..db811d2
--- /dev/null
+++ b/libdevkit-power/egg-debug.h
@@ -0,0 +1 @@
+../src/egg-debug.h \ No newline at end of file
diff --git a/libdevkit-power/egg-string.c b/libdevkit-power/egg-string.c
new file mode 120000
index 0000000..6ad7909
--- /dev/null
+++ b/libdevkit-power/egg-string.c
@@ -0,0 +1 @@
+../src/egg-string.c \ No newline at end of file
diff --git a/libdevkit-power/egg-string.h b/libdevkit-power/egg-string.h
new file mode 120000
index 0000000..d7e801b
--- /dev/null
+++ b/libdevkit-power/egg-string.h
@@ -0,0 +1 @@
+../src/egg-string.h \ No newline at end of file