diff --git a/src/Makefile.am b/src/Makefile.am index 8c16d1b..0d31644 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -21,16 +21,16 @@ BUILT_SOURCES = \ dkp-marshal.h dkp-marshal.c dkp-marshal.h: dkp-marshal.list - glib-genmarshal $< --prefix=devkit_power_marshal --header > $@ + glib-genmarshal $< --prefix=dkp_marshal --header > $@ dkp-marshal.c: dkp-marshal.list - echo "#include \"dkp-marshal.h\"" > $@ && glib-genmarshal $< --prefix=devkit_power_marshal --body >> $@ + echo "#include \"dkp-marshal.h\"" > $@ && glib-genmarshal $< --prefix=dkp_marshal --body >> $@ dkp-daemon-glue.h: org.freedesktop.DeviceKit.Power.xml Makefile.am - dbus-binding-tool --prefix=devkit_power_daemon --mode=glib-server --output=dkp-daemon-glue.h org.freedesktop.DeviceKit.Power.xml + dbus-binding-tool --prefix=dkp_daemon --mode=glib-server --output=dkp-daemon-glue.h org.freedesktop.DeviceKit.Power.xml dkp-source-glue.h: org.freedesktop.DeviceKit.Power.Source.xml Makefile.am - dbus-binding-tool --prefix=devkit_power_source --mode=glib-server --output=dkp-source-glue.h org.freedesktop.DeviceKit.Power.Source.xml + dbus-binding-tool --prefix=dkp_source --mode=glib-server --output=dkp-source-glue.h org.freedesktop.DeviceKit.Power.Source.xml libexec_PROGRAMS = devkit-power-daemon diff --git a/src/dkp-daemon.c b/src/dkp-daemon.c index 76d2ba5..b4da9e6 100644 --- a/src/dkp-daemon.c +++ b/src/dkp-daemon.c @@ -51,7 +51,7 @@ enum static guint signals[LAST_SIGNAL] = { 0 }; -struct DevkitPowerDaemonPrivate +struct DkpDaemonPrivate { DBusGConnection *system_bus_connection; DBusGProxy *system_bus_proxy; @@ -65,23 +65,23 @@ struct DevkitPowerDaemonPrivate DevkitClient *devkit_client; }; -static void devkit_power_daemon_class_init (DevkitPowerDaemonClass *klass); -static void devkit_power_daemon_init (DevkitPowerDaemon *seat); -static void devkit_power_daemon_finalize (GObject *object); +static void dkp_daemon_class_init (DkpDaemonClass *klass); +static void dkp_daemon_init (DkpDaemon *seat); +static void dkp_daemon_finalize (GObject *object); -G_DEFINE_TYPE (DevkitPowerDaemon, devkit_power_daemon, G_TYPE_OBJECT) +G_DEFINE_TYPE (DkpDaemon, dkp_daemon, G_TYPE_OBJECT) -#define DEVKIT_POWER_DAEMON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DEVKIT_TYPE_POWER_DAEMON, DevkitPowerDaemonPrivate)) +#define DKP_DAEMON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DKP_SOURCE_TYPE_DAEMON, DkpDaemonPrivate)) /*--------------------------------------------------------------------------------------------------------------*/ GQuark -devkit_power_daemon_error_quark (void) +dkp_daemon_error_quark (void) { static GQuark ret = 0; if (ret == 0) { - ret = g_quark_from_static_string ("devkit_power_daemon_error"); + ret = g_quark_from_static_string ("dkp_daemon_error"); } return ret; @@ -91,7 +91,7 @@ devkit_power_daemon_error_quark (void) #define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC } GType -devkit_power_daemon_error_get_type (void) +dkp_daemon_error_get_type (void) { static GType etype = 0; @@ -99,44 +99,44 @@ devkit_power_daemon_error_get_type (void) { static const GEnumValue values[] = { - ENUM_ENTRY (DEVKIT_POWER_DAEMON_ERROR_GENERAL, "GeneralError"), - ENUM_ENTRY (DEVKIT_POWER_DAEMON_ERROR_NOT_SUPPORTED, "NotSupported"), - ENUM_ENTRY (DEVKIT_POWER_DAEMON_ERROR_NO_SUCH_DEVICE, "NoSuchDevice"), + ENUM_ENTRY (DKP_DAEMON_ERROR_GENERAL, "GeneralError"), + ENUM_ENTRY (DKP_DAEMON_ERROR_NOT_SUPPORTED, "NotSupported"), + ENUM_ENTRY (DKP_DAEMON_ERROR_NO_SUCH_DEVICE, "NoSuchDevice"), { 0, 0, 0 } }; - g_assert (DEVKIT_POWER_DAEMON_NUM_ERRORS == G_N_ELEMENTS (values) - 1); - etype = g_enum_register_static ("DevkitPowerDaemonError", values); + g_assert (DKP_DAEMON_NUM_ERRORS == G_N_ELEMENTS (values) - 1); + etype = g_enum_register_static ("DkpDaemonError", values); } return etype; } static GObject * -devkit_power_daemon_constructor (GType type, +dkp_daemon_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { - DevkitPowerDaemon *daemon; - DevkitPowerDaemonClass *klass; + DkpDaemon *daemon; + DkpDaemonClass *klass; - klass = DEVKIT_POWER_DAEMON_CLASS (g_type_class_peek (DEVKIT_TYPE_POWER_DAEMON)); + klass = DKP_DAEMON_CLASS (g_type_class_peek (DKP_SOURCE_TYPE_DAEMON)); - daemon = DEVKIT_POWER_DAEMON ( - G_OBJECT_CLASS (devkit_power_daemon_parent_class)->constructor (type, + daemon = DKP_DAEMON ( + G_OBJECT_CLASS (dkp_daemon_parent_class)->constructor (type, n_construct_properties, construct_properties)); return G_OBJECT (daemon); } static void -devkit_power_daemon_class_init (DevkitPowerDaemonClass *klass) +dkp_daemon_class_init (DkpDaemonClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->constructor = devkit_power_daemon_constructor; - object_class->finalize = devkit_power_daemon_finalize; + object_class->constructor = dkp_daemon_constructor; + object_class->finalize = dkp_daemon_finalize; - g_type_class_add_private (klass, sizeof (DevkitPowerDaemonPrivate)); + g_type_class_add_private (klass, sizeof (DkpDaemonPrivate)); signals[DEVICE_ADDED_SIGNAL] = g_signal_new ("device-added", @@ -183,17 +183,17 @@ devkit_power_daemon_class_init (DevkitPowerDaemonClass *klass) g_cclosure_marshal_VOID__BOOLEAN, G_TYPE_NONE, 1, G_TYPE_BOOLEAN); - dbus_g_object_type_install_info (DEVKIT_TYPE_POWER_DAEMON, &dbus_glib_devkit_power_daemon_object_info); + dbus_g_object_type_install_info (DKP_SOURCE_TYPE_DAEMON, &dbus_glib_dkp_daemon_object_info); - dbus_g_error_domain_register (DEVKIT_POWER_DAEMON_ERROR, + dbus_g_error_domain_register (DKP_DAEMON_ERROR, NULL, - DEVKIT_POWER_DAEMON_TYPE_ERROR); + DKP_DAEMON_TYPE_ERROR); } static void -devkit_power_daemon_init (DevkitPowerDaemon *daemon) +dkp_daemon_init (DkpDaemon *daemon) { - daemon->priv = DEVKIT_POWER_DAEMON_GET_PRIVATE (daemon); + daemon->priv = DKP_DAEMON_GET_PRIVATE (daemon); daemon->priv->on_battery = FALSE; daemon->priv->low_battery = FALSE; daemon->priv->map_native_path_to_device = g_hash_table_new_full (g_str_hash, @@ -203,14 +203,14 @@ devkit_power_daemon_init (DevkitPowerDaemon *daemon) } static void -devkit_power_daemon_finalize (GObject *object) +dkp_daemon_finalize (GObject *object) { - DevkitPowerDaemon *daemon; + DkpDaemon *daemon; g_return_if_fail (object != NULL); - g_return_if_fail (DEVKIT_IS_POWER_DAEMON (object)); + g_return_if_fail (DKP_IS_DAEMON (object)); - daemon = DEVKIT_POWER_DAEMON (object); + daemon = DKP_DAEMON (object); g_return_if_fail (daemon->priv != NULL); @@ -234,7 +234,7 @@ devkit_power_daemon_finalize (GObject *object) g_hash_table_unref (daemon->priv->map_native_path_to_device); } - G_OBJECT_CLASS (devkit_power_daemon_parent_class)->finalize (object); + G_OBJECT_CLASS (dkp_daemon_parent_class)->finalize (object); } static gboolean @@ -274,7 +274,7 @@ pk_io_remove_watch (PolKitContext *pk_context, int watch_id) static DBusHandlerResult _filter (DBusConnection *connection, DBusMessage *message, void *user_data) { - DevkitPowerDaemon *daemon = DEVKIT_POWER_DAEMON (user_data); + DkpDaemon *daemon = DKP_DAEMON (user_data); const char *interface; interface = dbus_message_get_interface (message); @@ -293,19 +293,19 @@ _filter (DBusConnection *connection, DBusMessage *message, void *user_data) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } -static void device_add (DevkitPowerDaemon *daemon, DevkitDevice *d, gboolean emit_event); -static void device_remove (DevkitPowerDaemon *daemon, DevkitDevice *d); +static void device_add (DkpDaemon *daemon, DevkitDevice *d, gboolean emit_event); +static void device_remove (DkpDaemon *daemon, DevkitDevice *d); static void -device_changed (DevkitPowerDaemon *daemon, DevkitDevice *d, gboolean synthesized) +device_changed (DkpDaemon *daemon, DevkitDevice *d, gboolean synthesized) { - DevkitPowerDevice *device; + DkpDevice *device; const char *native_path; native_path = devkit_device_get_native_path (d); device = g_hash_table_lookup (daemon->priv->map_native_path_to_device, native_path); if (device != NULL) { - if (!devkit_power_device_changed (device, d, synthesized)) { + if (!dkp_device_changed (device, d, synthesized)) { g_print ("changed triggered remove on %s\n", native_path); device_remove (daemon, d); } else { @@ -330,7 +330,7 @@ device_went_away_remove_cb (gpointer key, gpointer value, gpointer user_data) static void device_went_away (gpointer user_data, GObject *where_the_object_was) { - DevkitPowerDaemon *daemon = DEVKIT_POWER_DAEMON (user_data); + DkpDaemon *daemon = DKP_DAEMON (user_data); g_hash_table_foreach_remove (daemon->priv->map_native_path_to_device, device_went_away_remove_cb, @@ -338,9 +338,9 @@ device_went_away (gpointer user_data, GObject *where_the_object_was) } static void -device_add (DevkitPowerDaemon *daemon, DevkitDevice *d, gboolean emit_event) +device_add (DkpDaemon *daemon, DevkitDevice *d, gboolean emit_event) { - DevkitPowerDevice *device; + DkpDevice *device; const char *native_path; native_path = devkit_device_get_native_path (d); @@ -350,7 +350,7 @@ device_add (DevkitPowerDaemon *daemon, DevkitDevice *d, gboolean emit_event) g_print ("treating add event as change event on %s\n", native_path); device_changed (daemon, d, FALSE); } else { - device = devkit_power_device_new (daemon, d); + device = dkp_device_new (daemon, d); if (device != NULL) { /* only take a weak ref; the device will stay on the bus until @@ -364,7 +364,7 @@ device_add (DevkitPowerDaemon *daemon, DevkitDevice *d, gboolean emit_event) g_print ("added %s\n", native_path); if (emit_event) { g_signal_emit (daemon, signals[DEVICE_ADDED_SIGNAL], 0, - devkit_power_device_get_object_path (device)); + dkp_device_get_object_path (device)); } } else { g_print ("ignoring add event on %s\n", native_path); @@ -373,9 +373,9 @@ device_add (DevkitPowerDaemon *daemon, DevkitDevice *d, gboolean emit_event) } static void -device_remove (DevkitPowerDaemon *daemon, DevkitDevice *d) +device_remove (DkpDaemon *daemon, DevkitDevice *d) { - DevkitPowerDevice *device; + DkpDevice *device; const char *native_path; native_path = devkit_device_get_native_path (d); @@ -383,9 +383,9 @@ device_remove (DevkitPowerDaemon *daemon, DevkitDevice *d) if (device == NULL) { g_print ("ignoring remove event on %s\n", native_path); } else { - devkit_power_device_removed (device); + dkp_device_removed (device); g_signal_emit (daemon, signals[DEVICE_REMOVED_SIGNAL], 0, - devkit_power_device_get_object_path (device)); + dkp_device_get_object_path (device)); g_object_unref (device); } } @@ -400,7 +400,7 @@ device_event_signal_handler (DevkitClient *client, DevkitDevice *device, gpointer user_data) { - DevkitPowerDaemon *daemon = DEVKIT_POWER_DAEMON (user_data); + DkpDaemon *daemon = DKP_DAEMON (user_data); if (strcmp (action, "add") == 0) { device_add (daemon, device, TRUE); @@ -414,7 +414,7 @@ device_event_signal_handler (DevkitClient *client, } static gboolean -register_power_daemon (DevkitPowerDaemon *daemon) +register_power_daemon (DkpDaemon *daemon) { DBusConnection *connection; DBusError dbus_error; @@ -508,18 +508,18 @@ error: } -DevkitPowerDaemon * -devkit_power_daemon_new (void) +DkpDaemon * +dkp_daemon_new (void) { - DevkitPowerDaemon *daemon; + DkpDaemon *daemon; GError *error = NULL; GList *devices; GList *l; const char *subsystems[] = {"power_supply", NULL}; - daemon = DEVKIT_POWER_DAEMON (g_object_new (DEVKIT_TYPE_POWER_DAEMON, NULL)); + daemon = DKP_DAEMON (g_object_new (DKP_SOURCE_TYPE_DAEMON, NULL)); - if (!register_power_daemon (DEVKIT_POWER_DAEMON (daemon))) { + if (!register_power_daemon (DKP_DAEMON (daemon))) { g_object_unref (daemon); return NULL; } @@ -545,7 +545,7 @@ devkit_power_daemon_new (void) } PolKitCaller * -devkit_power_damon_local_get_caller_for_context (DevkitPowerDaemon *daemon, +dkp_daemon_local_get_caller_for_context (DkpDaemon *daemon, DBusGMethodInvocation *context) { const char *sender; @@ -559,8 +559,8 @@ devkit_power_damon_local_get_caller_for_context (DevkitPowerDaemon *daemon, sender, &dbus_error); if (pk_caller == NULL) { - error = g_error_new (DEVKIT_POWER_DAEMON_ERROR, - DEVKIT_POWER_DAEMON_ERROR_GENERAL, + error = g_error_new (DKP_DAEMON_ERROR, + DKP_DAEMON_ERROR_GENERAL, "Error getting information about caller: %s: %s", dbus_error.name, dbus_error.message); dbus_error_free (&dbus_error); @@ -573,7 +573,7 @@ devkit_power_damon_local_get_caller_for_context (DevkitPowerDaemon *daemon, } gboolean -devkit_power_damon_local_check_auth (DevkitPowerDaemon *daemon, +dkp_daemon_local_check_auth (DkpDaemon *daemon, PolKitCaller *pk_caller, const char *action_id, DBusGMethodInvocation *context) @@ -624,7 +624,7 @@ throw_error (DBusGMethodInvocation *context, int error_code, const char *format, message = g_strdup_vprintf (format, args); va_end (args); - error = g_error_new (DEVKIT_POWER_DAEMON_ERROR, + error = g_error_new (DKP_DAEMON_ERROR, error_code, message); dbus_g_method_return_error (context, error); @@ -640,13 +640,13 @@ throw_error (DBusGMethodInvocation *context, int error_code, const char *format, static void enumerate_cb (gpointer key, gpointer value, gpointer user_data) { - DevkitPowerDevice *device = DEVKIT_POWER_DEVICE (value); + DkpDevice *device = DKP_DEVICE (value); GPtrArray *object_paths = user_data; - g_ptr_array_add (object_paths, g_strdup (devkit_power_device_get_object_path (device))); + g_ptr_array_add (object_paths, g_strdup (dkp_device_get_object_path (device))); } gboolean -devkit_power_daemon_enumerate_devices (DevkitPowerDaemon *daemon, +dkp_daemon_enumerate_devices (DkpDaemon *daemon, DBusGMethodInvocation *context) { GPtrArray *object_paths; @@ -659,7 +659,7 @@ devkit_power_daemon_enumerate_devices (DevkitPowerDaemon *daemon, } gboolean -devkit_power_daemon_get_on_battery (DevkitPowerDaemon *daemon, +dkp_daemon_get_on_battery (DkpDaemon *daemon, DBusGMethodInvocation *context) { /* this is cached as it's expensive to check all sources */ @@ -668,7 +668,7 @@ devkit_power_daemon_get_on_battery (DevkitPowerDaemon *daemon, } gboolean -devkit_power_daemon_get_low_battery (DevkitPowerDaemon *daemon, +dkp_daemon_get_low_battery (DkpDaemon *daemon, DBusGMethodInvocation *context) { /* this is cached as it's expensive to check all sources */ @@ -677,7 +677,7 @@ devkit_power_daemon_get_low_battery (DevkitPowerDaemon *daemon, } gboolean -devkit_power_daemon_suspend (DevkitPowerDaemon *daemon, DBusGMethodInvocation *context) +dkp_daemon_suspend (DkpDaemon *daemon, DBusGMethodInvocation *context) { gboolean ret; GError *error; @@ -686,11 +686,11 @@ devkit_power_daemon_suspend (DevkitPowerDaemon *daemon, DBusGMethodInvocation *c const gchar *quirks; PolKitCaller *pk_caller; - pk_caller = devkit_power_damon_local_get_caller_for_context (daemon, context); + pk_caller = dkp_daemon_local_get_caller_for_context (daemon, context); if (pk_caller == NULL) goto out; - if (!devkit_power_damon_local_check_auth (daemon, pk_caller, + if (!dkp_daemon_local_check_auth (daemon, pk_caller, "org.freedesktop.devicekit.power.suspend", context)) goto out; @@ -701,8 +701,8 @@ devkit_power_daemon_suspend (DevkitPowerDaemon *daemon, DBusGMethodInvocation *c argv = g_strdup_printf ("/usr/sbin/pm-suspend %s", quirks); ret = g_spawn_command_line_async (argv, &error_local); if (!ret) { - error = g_error_new (DEVKIT_POWER_DAEMON_ERROR, - DEVKIT_POWER_DAEMON_ERROR_GENERAL, + error = g_error_new (DKP_DAEMON_ERROR, + DKP_DAEMON_ERROR_GENERAL, "Cannot spawn: %s", error_local->message); g_error_free (error_local); dbus_g_method_return_error (context, error); @@ -716,7 +716,7 @@ out: } gboolean -devkit_power_daemon_hibernate (DevkitPowerDaemon *daemon, DBusGMethodInvocation *context) +dkp_daemon_hibernate (DkpDaemon *daemon, DBusGMethodInvocation *context) { gboolean ret; GError *error; @@ -725,11 +725,11 @@ devkit_power_daemon_hibernate (DevkitPowerDaemon *daemon, DBusGMethodInvocation const gchar *quirks; PolKitCaller *pk_caller; - pk_caller = devkit_power_damon_local_get_caller_for_context (daemon, context); + pk_caller = dkp_daemon_local_get_caller_for_context (daemon, context); if (pk_caller == NULL) goto out; - if (!devkit_power_damon_local_check_auth (daemon, pk_caller, + if (!dkp_daemon_local_check_auth (daemon, pk_caller, "org.freedesktop.devicekit.power.hibernate", context)) goto out; @@ -740,8 +740,8 @@ devkit_power_daemon_hibernate (DevkitPowerDaemon *daemon, DBusGMethodInvocation argv = g_strdup_printf ("/usr/sbin/pm-hibernate %s", quirks); ret = g_spawn_command_line_async (argv, &error_local); if (!ret) { - error = g_error_new (DEVKIT_POWER_DAEMON_ERROR, - DEVKIT_POWER_DAEMON_ERROR_GENERAL, + error = g_error_new (DKP_DAEMON_ERROR, + DKP_DAEMON_ERROR_GENERAL, "Cannot spawn: %s", error_local->message); g_error_free (error_local); dbus_g_method_return_error (context, error); diff --git a/src/dkp-daemon.h b/src/dkp-daemon.h index 63987f5..ad019e1 100644 --- a/src/dkp-daemon.h +++ b/src/dkp-daemon.h @@ -18,8 +18,8 @@ * */ -#ifndef __DEVKIT_POWER_DAEMON_H__ -#define __DEVKIT_POWER_DAEMON_H__ +#ifndef __DKP_DAEMON_H__ +#define __DKP_DAEMON_H__ #include #include @@ -27,66 +27,66 @@ G_BEGIN_DECLS -#define DEVKIT_TYPE_POWER_DAEMON (devkit_power_daemon_get_type ()) -#define DEVKIT_POWER_DAEMON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), DEVKIT_TYPE_POWER_DAEMON, DevkitPowerDaemon)) -#define DEVKIT_POWER_DAEMON_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), DEVKIT_TYPE_POWER_DAEMON, DevkitPowerDaemonClass)) -#define DEVKIT_IS_POWER_DAEMON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), DEVKIT_TYPE_POWER_DAEMON)) -#define DEVKIT_IS_POWER_DAEMON_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), DEVKIT_TYPE_POWER_DAEMON)) -#define DEVKIT_POWER_DAEMON_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), DEVKIT_TYPE_POWER_DAEMON, DevkitPowerDaemonClass)) +#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)) -typedef struct DevkitPowerDaemonPrivate DevkitPowerDaemonPrivate; +typedef struct DkpDaemonPrivate DkpDaemonPrivate; typedef struct { GObject parent; - DevkitPowerDaemonPrivate *priv; -} DevkitPowerDaemon; + DkpDaemonPrivate *priv; +} DkpDaemon; typedef struct { GObjectClass parent_class; -} DevkitPowerDaemonClass; +} DkpDaemonClass; typedef enum { - DEVKIT_POWER_DAEMON_ERROR_GENERAL, - DEVKIT_POWER_DAEMON_ERROR_NOT_SUPPORTED, - DEVKIT_POWER_DAEMON_ERROR_NO_SUCH_DEVICE, - DEVKIT_POWER_DAEMON_NUM_ERRORS -} DevkitPowerDaemonError; + DKP_DAEMON_ERROR_GENERAL, + DKP_DAEMON_ERROR_NOT_SUPPORTED, + DKP_DAEMON_ERROR_NO_SUCH_DEVICE, + DKP_DAEMON_NUM_ERRORS +} DkpDaemonError; -#define DEVKIT_POWER_DAEMON_ERROR devkit_power_daemon_error_quark () +#define DKP_DAEMON_ERROR dkp_daemon_error_quark () -GType devkit_power_daemon_error_get_type (void); -#define DEVKIT_POWER_DAEMON_TYPE_ERROR (devkit_power_daemon_error_get_type ()) +GType dkp_daemon_error_get_type (void); +#define DKP_DAEMON_TYPE_ERROR (dkp_daemon_error_get_type ()) -GQuark devkit_power_daemon_error_quark (void); -GType devkit_power_daemon_get_type (void); -DevkitPowerDaemon *devkit_power_daemon_new (void); +GQuark dkp_daemon_error_quark (void); +GType dkp_daemon_get_type (void); +DkpDaemon *dkp_daemon_new (void); /* local methods */ -PolKitCaller *devkit_power_damon_local_get_caller_for_context (DevkitPowerDaemon *daemon, +PolKitCaller *dkp_daemon_local_get_caller_for_context (DkpDaemon *daemon, DBusGMethodInvocation *context); -gboolean devkit_power_damon_local_check_auth (DevkitPowerDaemon *daemon, +gboolean dkp_daemon_local_check_auth (DkpDaemon *daemon, PolKitCaller *pk_caller, const char *action_id, DBusGMethodInvocation *context); /* exported methods */ -gboolean devkit_power_daemon_enumerate_devices (DevkitPowerDaemon *daemon, +gboolean dkp_daemon_enumerate_devices (DkpDaemon *daemon, DBusGMethodInvocation *context); -gboolean devkit_power_daemon_get_on_battery (DevkitPowerDaemon *daemon, +gboolean dkp_daemon_get_on_battery (DkpDaemon *daemon, DBusGMethodInvocation *context); -gboolean devkit_power_daemon_get_low_battery (DevkitPowerDaemon *daemon, +gboolean dkp_daemon_get_low_battery (DkpDaemon *daemon, DBusGMethodInvocation *context); -gboolean devkit_power_daemon_suspend (DevkitPowerDaemon *daemon, +gboolean dkp_daemon_suspend (DkpDaemon *daemon, DBusGMethodInvocation *context); -gboolean devkit_power_daemon_hibernate (DevkitPowerDaemon *daemon, +gboolean dkp_daemon_hibernate (DkpDaemon *daemon, DBusGMethodInvocation *context); G_END_DECLS -#endif /* __DEVKIT_POWER_DAEMON_H__ */ +#endif /* __DKP_DAEMON_H__ */ diff --git a/src/dkp-device.c b/src/dkp-device.c index 710dc2c..660a48e 100644 --- a/src/dkp-device.c +++ b/src/dkp-device.c @@ -37,56 +37,56 @@ #include "dkp-device.h" #include "dkp-source.h" -static void devkit_power_device_class_init (DevkitPowerDeviceClass *klass); -static void devkit_power_device_init (DevkitPowerDevice *seat); +static void dkp_device_class_init (DkpDeviceClass *klass); +static void dkp_device_init (DkpDevice *seat); -G_DEFINE_TYPE (DevkitPowerDevice, devkit_power_device, G_TYPE_OBJECT) +G_DEFINE_TYPE (DkpDevice, dkp_device, G_TYPE_OBJECT) -#define DEVKIT_POWER_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DEVKIT_TYPE_POWER_DEVICE, DevkitPowerDevicePrivate)) +#define DKP_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DKP_SOURCE_TYPE_DEVICE, DkpDevicePrivate)) static void -devkit_power_device_class_init (DevkitPowerDeviceClass *klass) +dkp_device_class_init (DkpDeviceClass *klass) { } static void -devkit_power_device_init (DevkitPowerDevice *device) +dkp_device_init (DkpDevice *device) { } void -devkit_power_device_removed (DevkitPowerDevice *device) +dkp_device_removed (DkpDevice *device) { - DevkitPowerDeviceClass *klass = DEVKIT_POWER_DEVICE_GET_CLASS (device); + DkpDeviceClass *klass = DKP_DEVICE_GET_CLASS (device); klass->removed (device); } -DevkitPowerDevice * -devkit_power_device_new (DevkitPowerDaemon *daemon, DevkitDevice *d) +DkpDevice * +dkp_device_new (DkpDaemon *daemon, DevkitDevice *d) { const char *subsys; - DevkitPowerDevice *device; + DkpDevice *device; device = NULL; subsys = devkit_device_get_subsystem (d); if (strcmp (subsys, "power_supply") == 0) { - device = DEVKIT_POWER_DEVICE (devkit_power_source_new (daemon, d)); + device = DKP_DEVICE (dkp_source_new (daemon, d)); } return device; } gboolean -devkit_power_device_changed (DevkitPowerDevice *device, DevkitDevice *d, gboolean synthesized) +dkp_device_changed (DkpDevice *device, DevkitDevice *d, gboolean synthesized) { - DevkitPowerDeviceClass *klass = DEVKIT_POWER_DEVICE_GET_CLASS (device); + DkpDeviceClass *klass = DKP_DEVICE_GET_CLASS (device); return (klass->changed (device, d, synthesized)); } const char * -devkit_power_device_get_object_path (DevkitPowerDevice *device) +dkp_device_get_object_path (DkpDevice *device) { - DevkitPowerDeviceClass *klass = DEVKIT_POWER_DEVICE_GET_CLASS (device); + DkpDeviceClass *klass = DKP_DEVICE_GET_CLASS (device); return (klass->get_object_path (device)); } diff --git a/src/dkp-device.h b/src/dkp-device.h index 9540ec2..2d72a81 100644 --- a/src/dkp-device.h +++ b/src/dkp-device.h @@ -18,8 +18,8 @@ * */ -#ifndef __DEVKIT_POWER_DEVICE_H__ -#define __DEVKIT_POWER_DEVICE_H__ +#ifndef __DKP_DEVICE_H__ +#define __DKP_DEVICE_H__ #include #include @@ -29,40 +29,40 @@ G_BEGIN_DECLS -#define DEVKIT_TYPE_POWER_DEVICE (devkit_power_device_get_type ()) -#define DEVKIT_POWER_DEVICE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), DEVKIT_TYPE_POWER_DEVICE, DevkitPowerDevice)) -#define DEVKIT_POWER_DEVICE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), DEVKIT_TYPE_POWER_DEVICE, DevkitPowerDeviceClass)) -#define DEVKIT_IS_POWER_DEVICE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), DEVKIT_TYPE_POWER_DEVICE)) -#define DEVKIT_IS_POWER_DEVICE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), DEVKIT_TYPE_POWER_DEVICE)) -#define DEVKIT_POWER_DEVICE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), DEVKIT_TYPE_POWER_DEVICE, DevkitPowerDeviceClass)) +#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; -} DevkitPowerDevice; +} DkpDevice; typedef struct { GObjectClass parent_class; /* vtable */ - gboolean (*changed) (DevkitPowerDevice *device, + gboolean (*changed) (DkpDevice *device, DevkitDevice *d, gboolean synthesized); - void (*removed) (DevkitPowerDevice *device); - const char *(*get_object_path) (DevkitPowerDevice *device); -} DevkitPowerDeviceClass; + void (*removed) (DkpDevice *device); + const char *(*get_object_path) (DkpDevice *device); +} DkpDeviceClass; -GType devkit_power_device_get_type (void); -DevkitPowerDevice *devkit_power_device_new (DevkitPowerDaemon *daemon, +GType dkp_device_get_type (void); +DkpDevice *dkp_device_new (DkpDaemon *daemon, DevkitDevice *d); -gboolean devkit_power_device_changed (DevkitPowerDevice *device, +gboolean dkp_device_changed (DkpDevice *device, DevkitDevice *d, gboolean synthesized); -void devkit_power_device_removed (DevkitPowerDevice *device); +void dkp_device_removed (DkpDevice *device); -const char *devkit_power_device_get_object_path (DevkitPowerDevice *device); +const char *dkp_device_get_object_path (DkpDevice *device); G_END_DECLS -#endif /* __DEVKIT_POWER_DEVICE_H__ */ +#endif /* __DKP_DEVICE_H__ */ diff --git a/src/dkp-enum.c b/src/dkp-enum.c index 6aafdd8..bac43eb 100644 --- a/src/dkp-enum.c +++ b/src/dkp-enum.c @@ -24,29 +24,29 @@ #include "dkp-enum.h" const char * -devkit_power_convert_type_to_text (DevkitPowerType type_enum) +dkp_source_type_to_text (DkpSourceType type_enum) { const char *type = NULL; switch (type_enum) { - case DEVKIT_POWER_TYPE_LINE_POWER: + case DKP_SOURCE_TYPE_LINE_POWER: type = "line-power"; break; - case DEVKIT_POWER_TYPE_BATTERY: + case DKP_SOURCE_TYPE_BATTERY: type = "battery"; break; - case DEVKIT_POWER_TYPE_UPS: + case DKP_SOURCE_TYPE_UPS: type = "ups"; break; - case DEVKIT_POWER_TYPE_MOUSE: + case DKP_SOURCE_TYPE_MOUSE: type = "mouse"; break; - case DEVKIT_POWER_TYPE_KEYBOARD: + case DKP_SOURCE_TYPE_KEYBOARD: type = "keyboard"; break; - case DEVKIT_POWER_TYPE_PDA: + case DKP_SOURCE_TYPE_PDA: type = "pda"; break; - case DEVKIT_POWER_TYPE_PHONE: + case DKP_SOURCE_TYPE_PHONE: type = "phone"; break; default: @@ -57,20 +57,20 @@ devkit_power_convert_type_to_text (DevkitPowerType type_enum) } const char * -devkit_power_convert_state_to_text (DevkitPowerState state_enum) +dkp_source_state_to_text (DkpSourceState state_enum) { const char *state = NULL; switch (state_enum) { - case DEVKIT_POWER_STATE_CHARGING: + case DKP_SOURCE_STATE_CHARGING: state = "charging"; break; - case DEVKIT_POWER_STATE_DISCHARGING: + case DKP_SOURCE_STATE_DISCHARGING: state = "discharging"; break; - case DEVKIT_POWER_STATE_EMPTY: + case DKP_SOURCE_STATE_EMPTY: state = "empty"; break; - case DEVKIT_POWER_STATE_FULLY_CHARGED: + case DKP_SOURCE_STATE_FULLY_CHARGED: state = "fully-charged"; break; default: @@ -81,29 +81,29 @@ devkit_power_convert_state_to_text (DevkitPowerState state_enum) } const char * -devkit_power_convert_technology_to_text (DevkitPowerTechnology technology_enum) +dkp_source_technology_to_text (DkpSourceTechnology technology_enum) { const char *technology = NULL; switch (technology_enum) { - case DEVKIT_POWER_TECHNOLGY_LITHIUM_ION: + case DKP_SOURCE_TECHNOLGY_LITHIUM_ION: technology = "lithium-ion"; break; - case DEVKIT_POWER_TECHNOLGY_LITHIUM_POLYMER: + case DKP_SOURCE_TECHNOLGY_LITHIUM_POLYMER: technology = "lithium-polymer"; break; - case DEVKIT_POWER_TECHNOLGY_LITHIUM_IRON_PHOSPHATE: + case DKP_SOURCE_TECHNOLGY_LITHIUM_IRON_PHOSPHATE: technology = "lithium-iron-phosphate"; break; - case DEVKIT_POWER_TECHNOLGY_LEAD_ACID: + case DKP_SOURCE_TECHNOLGY_LEAD_ACID: technology = "lead-acid"; break; - case DEVKIT_POWER_TECHNOLGY_NICKEL_CADMIUM: + case DKP_SOURCE_TECHNOLGY_NICKEL_CADMIUM: technology = "nickel-cadmium"; break; - case DEVKIT_POWER_TECHNOLGY_NICKEL_METAL_HYDRIDE: + case DKP_SOURCE_TECHNOLGY_NICKEL_METAL_HYDRIDE: technology = "nickel-metal-hydride"; break; - case DEVKIT_POWER_TECHNOLGY_UNKNOWN: + case DKP_SOURCE_TECHNOLGY_UNKNOWN: technology = "unknown"; break; default: @@ -113,31 +113,31 @@ devkit_power_convert_technology_to_text (DevkitPowerTechnology technology_enum) return technology; } -DevkitPowerTechnology -devkit_power_convert_acpi_technology_to_enum (const char *type) +DkpSourceTechnology +dkp_acpi_to_source_technology (const char *type) { if (type == NULL) { - return DEVKIT_POWER_TECHNOLGY_UNKNOWN; + return DKP_SOURCE_TECHNOLGY_UNKNOWN; } /* every case combination of Li-Ion is commonly used.. */ if (strcasecmp (type, "li-ion") == 0 || strcasecmp (type, "lion") == 0) { - return DEVKIT_POWER_TECHNOLGY_LITHIUM_ION; + return DKP_SOURCE_TECHNOLGY_LITHIUM_ION; } if (strcasecmp (type, "pb") == 0 || strcasecmp (type, "pbac") == 0) { - return DEVKIT_POWER_TECHNOLGY_LEAD_ACID; + return DKP_SOURCE_TECHNOLGY_LEAD_ACID; } if (strcasecmp (type, "lip") == 0 || strcasecmp (type, "lipo") == 0) { - return DEVKIT_POWER_TECHNOLGY_LITHIUM_POLYMER; + return DKP_SOURCE_TECHNOLGY_LITHIUM_POLYMER; } if (strcasecmp (type, "nimh") == 0) { - return DEVKIT_POWER_TECHNOLGY_NICKEL_METAL_HYDRIDE; + return DKP_SOURCE_TECHNOLGY_NICKEL_METAL_HYDRIDE; } if (strcasecmp (type, "lifo") == 0) { - return DEVKIT_POWER_TECHNOLGY_LITHIUM_IRON_PHOSPHATE; + return DKP_SOURCE_TECHNOLGY_LITHIUM_IRON_PHOSPHATE; } - return DEVKIT_POWER_TECHNOLGY_UNKNOWN; + return DKP_SOURCE_TECHNOLGY_UNKNOWN; } diff --git a/src/dkp-enum.h b/src/dkp-enum.h index a7c1d6d..31c8755 100644 --- a/src/dkp-enum.h +++ b/src/dkp-enum.h @@ -19,48 +19,48 @@ * */ -#ifndef __DEVKIT_POWER_ENUM_H__ -#define __DEVKIT_POWER_ENUM_H__ +#ifndef __DKP_ENUM_H__ +#define __DKP_ENUM_H__ #include G_BEGIN_DECLS typedef enum { - DEVKIT_POWER_TYPE_LINE_POWER, - DEVKIT_POWER_TYPE_BATTERY, - DEVKIT_POWER_TYPE_UPS, - DEVKIT_POWER_TYPE_MOUSE, - DEVKIT_POWER_TYPE_KEYBOARD, - DEVKIT_POWER_TYPE_PDA, - DEVKIT_POWER_TYPE_PHONE, - DEVKIT_POWER_TYPE_UNKNOWN -} DevkitPowerType; + 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 { - DEVKIT_POWER_STATE_CHARGING, - DEVKIT_POWER_STATE_DISCHARGING, - DEVKIT_POWER_STATE_EMPTY, - DEVKIT_POWER_STATE_FULLY_CHARGED, - DEVKIT_POWER_STATE_UNKNOWN -} DevkitPowerState; + DKP_SOURCE_STATE_CHARGING, + DKP_SOURCE_STATE_DISCHARGING, + DKP_SOURCE_STATE_EMPTY, + DKP_SOURCE_STATE_FULLY_CHARGED, + DKP_SOURCE_STATE_UNKNOWN +} DkpSourceState; typedef enum { - DEVKIT_POWER_TECHNOLGY_LITHIUM_ION, - DEVKIT_POWER_TECHNOLGY_LITHIUM_POLYMER, - DEVKIT_POWER_TECHNOLGY_LITHIUM_IRON_PHOSPHATE, - DEVKIT_POWER_TECHNOLGY_LEAD_ACID, - DEVKIT_POWER_TECHNOLGY_NICKEL_CADMIUM, - DEVKIT_POWER_TECHNOLGY_NICKEL_METAL_HYDRIDE, - DEVKIT_POWER_TECHNOLGY_UNKNOWN -} DevkitPowerTechnology; + 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 *devkit_power_convert_type_to_text (DevkitPowerType type_enum); -const char *devkit_power_convert_state_to_text (DevkitPowerState state_enum); -const char *devkit_power_convert_technology_to_text (DevkitPowerTechnology technology_enum); -DevkitPowerTechnology devkit_power_convert_acpi_technology_to_enum (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 -#endif /* __DEVKIT_POWER_ENUM_H__ */ +#endif /* __DKP_ENUM_H__ */ diff --git a/src/dkp-source.c b/src/dkp-source.c index 24873f9..ebee66f 100644 --- a/src/dkp-source.c +++ b/src/dkp-source.c @@ -45,11 +45,11 @@ #define DK_POWER_MIN_CHARGED_PERCENTAGE 60 -struct DevkitPowerSourcePrivate +struct DkpSourcePrivate { DBusGConnection *system_bus_connection; DBusGProxy *system_bus_proxy; - DevkitPowerDaemon *daemon; + DkpDaemon *daemon; DevkitDevice *d; char *object_path; @@ -61,15 +61,15 @@ struct DevkitPowerSourcePrivate char *model; char *serial; GTimeVal update_time; - DevkitPowerType type; + DkpSourceType type; gboolean has_coldplug_values; gboolean power_supply; gboolean line_power_online; gboolean battery_is_present; gboolean battery_is_rechargeable; - DevkitPowerState battery_state; - DevkitPowerTechnology battery_technology; + DkpSourceState battery_state; + DkpSourceTechnology battery_technology; double battery_capacity; double battery_energy; @@ -85,12 +85,12 @@ struct DevkitPowerSourcePrivate GTimeVal battery_energy_old_timespec; }; -static void devkit_power_source_class_init (DevkitPowerSourceClass *klass); -static void devkit_power_source_init (DevkitPowerSource *source); -static void devkit_power_source_finalize (GObject *object); -static void devkit_power_source_reset_values(DevkitPowerSource *source); +static void dkp_source_class_init (DkpSourceClass *klass); +static void dkp_source_init (DkpSource *source); +static void dkp_source_finalize (GObject *object); +static void dkp_source_reset_values(DkpSource *source); -static gboolean update (DevkitPowerSource *source); +static gboolean update (DkpSource *source); enum { @@ -126,12 +126,12 @@ enum static guint signals[LAST_SIGNAL] = { 0 }; -G_DEFINE_TYPE (DevkitPowerSource, devkit_power_source, DEVKIT_TYPE_POWER_DEVICE) -#define DEVKIT_POWER_SOURCE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DEVKIT_TYPE_POWER_SOURCE, DevkitPowerSourcePrivate)) +G_DEFINE_TYPE (DkpSource, dkp_source, DKP_SOURCE_TYPE_DEVICE) +#define DKP_SOURCE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DKP_SOURCE_TYPE_SOURCE, DkpSourcePrivate)) -static const char *devkit_power_source_get_object_path (DevkitPowerDevice *device); -static void devkit_power_source_removed (DevkitPowerDevice *device); -static gboolean devkit_power_source_changed (DevkitPowerDevice *device, +static const char *dkp_source_get_object_path (DkpDevice *device); +static void dkp_source_removed (DkpDevice *device); +static gboolean dkp_source_changed (DkpDevice *device, DevkitDevice *d, gboolean synthesized); @@ -141,7 +141,7 @@ get_property (GObject *object, GValue *value, GParamSpec *pspec) { - DevkitPowerSource *source = DEVKIT_POWER_SOURCE (object); + DkpSource *source = DKP_SOURCE (object); switch (prop_id) { case PROP_NATIVE_PATH: @@ -160,7 +160,7 @@ get_property (GObject *object, g_value_set_uint64 (value, source->priv->update_time.tv_sec); break; case PROP_TYPE: - g_value_set_string (value, devkit_power_convert_type_to_text (source->priv->type)); + g_value_set_string (value, dkp_source_type_to_text (source->priv->type)); break; case PROP_POWER_SUPPLY: @@ -178,7 +178,7 @@ get_property (GObject *object, g_value_set_boolean (value, source->priv->battery_is_rechargeable); break; case PROP_BATTERY_STATE: - g_value_set_string (value, devkit_power_convert_state_to_text (source->priv->battery_state)); + g_value_set_string (value, dkp_source_state_to_text (source->priv->battery_state)); break; case PROP_BATTERY_CAPACITY: g_value_set_double (value, source->priv->battery_capacity); @@ -209,7 +209,7 @@ get_property (GObject *object, break; case PROP_BATTERY_TECHNOLOGY: - g_value_set_string (value, devkit_power_convert_technology_to_text (source->priv->battery_technology)); + g_value_set_string (value, dkp_source_technology_to_text (source->priv->battery_technology)); break; default: @@ -221,18 +221,18 @@ get_property (GObject *object, static void -devkit_power_source_class_init (DevkitPowerSourceClass *klass) +dkp_source_class_init (DkpSourceClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - DevkitPowerDeviceClass *device_class = DEVKIT_POWER_DEVICE_CLASS (klass); + DkpDeviceClass *device_class = DKP_DEVICE_CLASS (klass); - object_class->finalize = devkit_power_source_finalize; + object_class->finalize = dkp_source_finalize; object_class->get_property = get_property; - device_class->changed = devkit_power_source_changed; - device_class->removed = devkit_power_source_removed; - device_class->get_object_path = devkit_power_source_get_object_path; + device_class->changed = dkp_source_changed; + device_class->removed = dkp_source_removed; + device_class->get_object_path = dkp_source_get_object_path; - g_type_class_add_private (klass, sizeof (DevkitPowerSourcePrivate)); + g_type_class_add_private (klass, sizeof (DkpSourcePrivate)); signals[CHANGED_SIGNAL] = g_signal_new ("changed", @@ -243,7 +243,7 @@ devkit_power_source_class_init (DevkitPowerSourceClass *klass) g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); - dbus_g_object_type_install_info (DEVKIT_TYPE_POWER_SOURCE, &dbus_glib_devkit_power_source_object_info); + dbus_g_object_type_install_info (DKP_SOURCE_TYPE_SOURCE, &dbus_glib_dkp_source_object_info); g_object_class_install_property ( object_class, @@ -333,21 +333,21 @@ devkit_power_source_class_init (DevkitPowerSourceClass *klass) } static void -devkit_power_source_init (DevkitPowerSource *source) +dkp_source_init (DkpSource *source) { - source->priv = DEVKIT_POWER_SOURCE_GET_PRIVATE (source); - devkit_power_source_reset_values (source); + source->priv = DKP_SOURCE_GET_PRIVATE (source); + dkp_source_reset_values (source); } static void -devkit_power_source_finalize (GObject *object) +dkp_source_finalize (GObject *object) { - DevkitPowerSource *source; + DkpSource *source; g_return_if_fail (object != NULL); - g_return_if_fail (DEVKIT_IS_POWER_SOURCE (object)); + g_return_if_fail (DKP_IS_SOURCE (object)); - source = DEVKIT_POWER_SOURCE (object); + source = DKP_SOURCE (object); g_return_if_fail (source->priv != NULL); g_object_unref (source->priv->d); @@ -362,7 +362,7 @@ devkit_power_source_finalize (GObject *object) if (source->priv->poll_timer_id > 0) g_source_remove (source->priv->poll_timer_id); - G_OBJECT_CLASS (devkit_power_source_parent_class)->finalize (object); + G_OBJECT_CLASS (dkp_source_parent_class)->finalize (object); } static char * @@ -399,7 +399,7 @@ compute_object_path (const char *native_path) } static gboolean -register_power_source (DevkitPowerSource *source) +register_power_source (DkpSource *source) { DBusConnection *connection; GError *error = NULL; @@ -431,25 +431,25 @@ error: return FALSE; } -DevkitPowerSource * -devkit_power_source_new (DevkitPowerDaemon *daemon, DevkitDevice *d) +DkpSource * +dkp_source_new (DkpDaemon *daemon, DevkitDevice *d) { - DevkitPowerSource *source; + DkpSource *source; const char *native_path; source = NULL; native_path = devkit_device_get_native_path (d); - source = DEVKIT_POWER_SOURCE (g_object_new (DEVKIT_TYPE_POWER_SOURCE, NULL)); + source = DKP_SOURCE (g_object_new (DKP_SOURCE_TYPE_SOURCE, NULL)); source->priv->d = g_object_ref (d); source->priv->daemon = g_object_ref (daemon); source->priv->native_path = g_strdup (native_path); if (sysfs_file_exists (native_path, "online")) { - source->priv->type = DEVKIT_POWER_TYPE_LINE_POWER; + source->priv->type = DKP_SOURCE_TYPE_LINE_POWER; } else { /* this is correct, UPS and CSR are not in the kernel */ - source->priv->type = DEVKIT_POWER_TYPE_BATTERY; + source->priv->type = DKP_SOURCE_TYPE_BATTERY; } if (!update (source)) { @@ -458,7 +458,7 @@ devkit_power_source_new (DevkitPowerDaemon *daemon, DevkitDevice *d) goto out; } - if (! register_power_source (DEVKIT_POWER_SOURCE (source))) { + if (! register_power_source (DKP_SOURCE (source))) { g_object_unref (source); source = NULL; goto out; @@ -469,7 +469,7 @@ out: } static void -emit_changed (DevkitPowerSource *source) +emit_changed (DkpSource *source) { g_print ("emitting changed on %s\n", source->priv->native_path); g_signal_emit_by_name (source->priv->daemon, @@ -480,9 +480,9 @@ emit_changed (DevkitPowerSource *source) } static gboolean -devkit_power_source_changed (DevkitPowerDevice *device, DevkitDevice *d, gboolean synthesized) +dkp_source_changed (DkpDevice *device, DevkitDevice *d, gboolean synthesized) { - DevkitPowerSource *source = DEVKIT_POWER_SOURCE (device); + DkpSource *source = DKP_SOURCE (device); gboolean keep_source; g_object_unref (source->priv->d); @@ -502,28 +502,28 @@ out: } void -devkit_power_source_removed (DevkitPowerDevice *device) +dkp_source_removed (DkpDevice *device) { } static const char * -devkit_power_source_get_object_path (DevkitPowerDevice *device) +dkp_source_get_object_path (DkpDevice *device) { - DevkitPowerSource *source = DEVKIT_POWER_SOURCE (device); + DkpSource *source = DKP_SOURCE (device); return source->priv->object_path; } /*--------------------------------------------------------------------------------------------------------------*/ static gboolean -update_line_power (DevkitPowerSource *source) +update_line_power (DkpSource *source) { source->priv->line_power_online = sysfs_get_int (source->priv->native_path, "online"); return TRUE; } static void -devkit_power_source_reset_values (DevkitPowerSource *source) +dkp_source_reset_values (DkpSource *source) { source->priv->battery_energy = -1; source->priv->battery_energy_old = -1; @@ -534,8 +534,8 @@ devkit_power_source_reset_values (DevkitPowerSource *source) source->priv->battery_capacity = -1; source->priv->battery_time_to_empty = -1; source->priv->battery_time_to_full = -1; - source->priv->battery_state = DEVKIT_POWER_STATE_UNKNOWN; - source->priv->battery_technology = DEVKIT_POWER_TECHNOLGY_UNKNOWN; + source->priv->battery_state = DKP_SOURCE_STATE_UNKNOWN; + source->priv->battery_technology = DKP_SOURCE_TECHNOLGY_UNKNOWN; source->priv->vendor = NULL; source->priv->model = NULL; source->priv->serial = NULL; @@ -548,7 +548,7 @@ devkit_power_source_reset_values (DevkitPowerSource *source) } gchar * -devkit_power_source_get_id (DevkitPowerSource *source) +dkp_source_get_id (DkpSource *source) { GString *string; gchar *id = NULL; @@ -558,7 +558,7 @@ devkit_power_source_get_id (DevkitPowerSource *source) return id; /* only valid for batteries */ - if (source->priv->type != DEVKIT_POWER_TYPE_BATTERY) + if (source->priv->type != DKP_SOURCE_TYPE_BATTERY) return id; /* we don't have an ID if we are not present */ @@ -598,7 +598,7 @@ devkit_power_source_get_id (DevkitPowerSource *source) } static void -calculate_battery_rate (DevkitPowerSource *source) +calculate_battery_rate (DkpSource *source) { guint time; gdouble energy; @@ -630,12 +630,12 @@ calculate_battery_rate (DevkitPowerSource *source) } static gboolean -update_battery (DevkitPowerSource *source) +update_battery (DkpSource *source) { char *status; gboolean is_charging; gboolean is_discharging; - DevkitPowerState battery_state; + DkpSourceState battery_state; /* are we present? */ source->priv->battery_is_present = sysfs_get_bool (source->priv->native_path, "present"); @@ -643,7 +643,7 @@ update_battery (DevkitPowerSource *source) g_free (source->priv->vendor); g_free (source->priv->model); g_free (source->priv->serial); - devkit_power_source_reset_values (source); + dkp_source_reset_values (source); return TRUE; } @@ -656,7 +656,7 @@ update_battery (DevkitPowerSource *source) /* the ACPI spec is bad at defining battery type constants */ technology_native = g_strstrip (sysfs_get_string (source->priv->native_path, "technology")); - source->priv->battery_technology = devkit_power_convert_acpi_technology_to_enum (technology_native); + source->priv->battery_technology = dkp_acpi_to_source_technology (technology_native); g_free (technology_native); source->priv->vendor = g_strstrip (sysfs_get_string (source->priv->native_path, "manufacturer")); @@ -758,13 +758,13 @@ update_battery (DevkitPowerSource *source) /* get the state */ if (is_charging) - battery_state = DEVKIT_POWER_STATE_CHARGING; + battery_state = DKP_SOURCE_STATE_CHARGING; else if (is_discharging) - battery_state = DEVKIT_POWER_STATE_DISCHARGING; + battery_state = DKP_SOURCE_STATE_DISCHARGING; else if (source->priv->battery_percentage > DK_POWER_MIN_CHARGED_PERCENTAGE) - battery_state = DEVKIT_POWER_STATE_FULLY_CHARGED; + battery_state = DKP_SOURCE_STATE_FULLY_CHARGED; else - battery_state = DEVKIT_POWER_STATE_EMPTY; + battery_state = DKP_SOURCE_STATE_EMPTY; /* set the old status */ source->priv->battery_energy_old = source->priv->battery_energy; @@ -781,7 +781,7 @@ update_battery (DevkitPowerSource *source) } static gboolean -_poll_battery (DevkitPowerSource *source) +_poll_battery (DkpSource *source) { g_warning ("No updates on source %s for 30 seconds; forcing update", source->priv->native_path); source->priv->poll_timer_id = 0; @@ -791,7 +791,7 @@ _poll_battery (DevkitPowerSource *source) } static gboolean -update (DevkitPowerSource *source) +update (DkpSource *source) { gboolean ret; @@ -803,10 +803,10 @@ update (DevkitPowerSource *source) g_get_current_time (&(source->priv->update_time)); switch (source->priv->type) { - case DEVKIT_POWER_TYPE_LINE_POWER: + case DKP_SOURCE_TYPE_LINE_POWER: ret = update_line_power (source); break; - case DEVKIT_POWER_TYPE_BATTERY: + case DKP_SOURCE_TYPE_BATTERY: ret = update_battery (source); @@ -829,7 +829,7 @@ update (DevkitPowerSource *source) /*--------------------------------------------------------------------------------------------------------------*/ gboolean -devkit_power_source_refresh (DevkitPowerSource *power_source, +dkp_source_refresh (DkpSource *power_source, DBusGMethodInvocation *context) { update (power_source); diff --git a/src/dkp-source.h b/src/dkp-source.h index c5225d2..19ab3fb 100644 --- a/src/dkp-source.h +++ b/src/dkp-source.h @@ -18,8 +18,8 @@ * */ -#ifndef __DEVKIT_POWER_SOURCE_H__ -#define __DEVKIT_POWER_SOURCE_H__ +#ifndef __DKP_SOURCE_H__ +#define __DKP_SOURCE_H__ #include #include @@ -30,36 +30,36 @@ G_BEGIN_DECLS -#define DEVKIT_TYPE_POWER_SOURCE (devkit_power_source_get_type ()) -#define DEVKIT_POWER_SOURCE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), DEVKIT_TYPE_POWER_SOURCE, DevkitPowerSource)) -#define DEVKIT_POWER_SOURCE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), DEVKIT_TYPE_POWER_SOURCE, DevkitPowerSourceClass)) -#define DEVKIT_IS_POWER_SOURCE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), DEVKIT_TYPE_POWER_SOURCE)) -#define DEVKIT_IS_POWER_SOURCE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), DEVKIT_TYPE_POWER_SOURCE)) -#define DEVKIT_POWER_SOURCE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), DEVKIT_TYPE_POWER_SOURCE, DevkitPowerSourceClass)) +#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)) -typedef struct DevkitPowerSourcePrivate DevkitPowerSourcePrivate; +typedef struct DkpSourcePrivate DkpSourcePrivate; typedef struct { - DevkitPowerDevice parent; - DevkitPowerSourcePrivate *priv; -} DevkitPowerSource; + DkpDevice parent; + DkpSourcePrivate *priv; +} DkpSource; typedef struct { - DevkitPowerDeviceClass parent_class; -} DevkitPowerSourceClass; + DkpDeviceClass parent_class; +} DkpSourceClass; -GType devkit_power_source_get_type (void); -DevkitPowerSource *devkit_power_source_new (DevkitPowerDaemon *daemon, +GType dkp_source_get_type (void); +DkpSource *dkp_source_new (DkpDaemon *daemon, DevkitDevice *d); /* exported methods */ -gboolean devkit_power_source_refresh (DevkitPowerSource *power_source, +gboolean dkp_source_refresh (DkpSource *power_source, DBusGMethodInvocation *context); -gchar *devkit_power_source_get_id (DevkitPowerSource *power_source); +gchar *dkp_source_get_id (DkpSource *power_source); G_END_DECLS -#endif /* __DEVKIT_POWER_SOURCE_H__ */ +#endif /* __DKP_SOURCE_H__ */ diff --git a/src/main.c b/src/main.c index bca0d83..c140c37 100644 --- a/src/main.c +++ b/src/main.c @@ -96,7 +96,7 @@ main (int argc, char **argv) { GError *error; GMainLoop *loop; - DevkitPowerDaemon *power_daemon; + DkpDaemon *power_daemon; GOptionContext *context; DBusGProxy *bus_proxy; DBusGConnection *bus; @@ -138,7 +138,7 @@ main (int argc, char **argv) g_debug ("Starting devkit-power-daemon version %s", VERSION); - power_daemon = devkit_power_daemon_new (); + power_daemon = dkp_daemon_new (); if (power_daemon == NULL) { goto out;