aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-09-09 04:22:19 +0000
committerCI bot <ps-jenkins@lists.canonical.com>2014-09-09 04:22:19 +0000
commit2720a578326d51a49f00e3e4e69d86f8ba23ab0d (patch)
tree383d4b9a64d0ad6601b00fe30d39d8f72ef9a7a2 /src
parent4b15eb106da8764c3bd12e746b8f19bf458b7470 (diff)
parent0c312c160b796c6c724c26e8a1063843c23b9ba3 (diff)
downloadayatana-indicator-power-2720a578326d51a49f00e3e4e69d86f8ba23ab0d.tar.gz
ayatana-indicator-power-2720a578326d51a49f00e3e4e69d86f8ba23ab0d.tar.bz2
ayatana-indicator-power-2720a578326d51a49f00e3e4e69d86f8ba23ab0d.zip
Add support for UPower 0.99. Fixes: 1330037
Approved by: Ted Gould, PS Jenkins bot
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt5
-rw-r--r--src/device-provider-upower.c499
-rw-r--r--src/device-provider-upower.h4
-rw-r--r--src/org.freedesktop.UPower.xml43
4 files changed, 306 insertions, 245 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 7a4a297..9b3d815 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -16,10 +16,6 @@ set(SERVICE_MANUAL_SOURCES
# generated sources
include(GdbusCodegen)
set(SERVICE_GENERATED_SOURCES)
-add_gdbus_codegen_with_namespace(SERVICE_GENERATED_SOURCES dbus-upower
- org.freedesktop
- Dbus
- ${CMAKE_CURRENT_SOURCE_DIR}/org.freedesktop.UPower.xml)
add_gdbus_codegen_with_namespace(SERVICE_GENERATED_SOURCES dbus-battery
com.canonical.indicator.power
Dbus
@@ -31,6 +27,7 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
# add warnings/coverage info on handwritten files
# but not the autogenerated ones...
set(C_WARNING_ARGS "${C_WARNING_ARGS} -Wno-bad-function-cast") # g_clear_object()
+set(C_WARNING_ARGS "${C_WARNING_ARGS} -Wno-used-but-marked-unused") # G_ADD_PRIVATE
set(C_WARNING_ARGS "${C_WARNING_ARGS} -Wno-disabled-macro-expansion") # G_DEFINE_TYPE
set(C_WARNING_ARGS "${C_WARNING_ARGS} -Wno-assign-enum") # GParamFlags
set(C_WARNING_ARGS "${C_WARNING_ARGS} -Wno-switch-enum")
diff --git a/src/device-provider-upower.c b/src/device-provider-upower.c
index 400a060..63f78ad 100644
--- a/src/device-provider-upower.c
+++ b/src/device-provider-upower.c
@@ -17,34 +17,45 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "dbus-upower.h"
#include "device.h"
#include "device-provider.h"
#include "device-provider-upower.h"
#define BUS_NAME "org.freedesktop.UPower"
-#define BUS_PATH "/org/freedesktop/UPower"
+
+#define MGR_IFACE "org.freedesktop.UPower"
+#define MGR_PATH "/org/freedesktop/UPower"
+
+#define DISPLAY_DEVICE_PATH "/org/freedesktop/UPower/devices/DisplayDevice"
/***
**** private struct
***/
-struct _IndicatorPowerDeviceProviderUPowerPriv
+typedef struct
{
GDBusConnection * bus;
-
- DbusUPower * upower_proxy;
- GHashTable * devices; /* dbus object path --> IndicatorPowerDevice */
GCancellable * cancellable;
+ /* dbus object path --> IndicatorPowerDevice */
+ GHashTable * devices;
+
/* a hashset of paths whose devices need to be refreshed */
GHashTable * queued_paths;
/* when this timer fires, the queued_paths will be refreshed */
guint queued_paths_timer;
-};
-typedef IndicatorPowerDeviceProviderUPowerPriv priv_t;
+ GSList* subscriptions;
+
+ guint name_tag;
+}
+IndicatorPowerDeviceProviderUPowerPrivate;
+
+typedef IndicatorPowerDeviceProviderUPowerPrivate priv_t;
+
+#define get_priv(o) ((priv_t*)indicator_power_device_provider_upower_get_instance_private(o))
+
/***
**** GObject boilerplate
@@ -57,6 +68,7 @@ G_DEFINE_TYPE_WITH_CODE (
IndicatorPowerDeviceProviderUPower,
indicator_power_device_provider_upower,
G_TYPE_OBJECT,
+ G_ADD_PRIVATE(IndicatorPowerDeviceProviderUPower)
G_IMPLEMENT_INTERFACE (INDICATOR_TYPE_POWER_DEVICE_PROVIDER,
indicator_power_device_provider_interface_init))
@@ -77,11 +89,11 @@ emit_devices_changed (IndicatorPowerDeviceProviderUPower * self)
}
static void
-on_device_properties_ready (GObject * o, GAsyncResult * res, gpointer gdata)
+on_get_all_response (GObject * o, GAsyncResult * res, gpointer gdata)
{
+ struct device_get_all_data * data = gdata;
GError * error;
GVariant * response;
- struct device_get_all_data * data = gdata;
error = NULL;
response = g_dbus_connection_call_finish (G_DBUS_CONNECTION(o), res, &error);
@@ -102,7 +114,7 @@ on_device_properties_ready (GObject * o, GAsyncResult * res, gpointer gdata)
gint64 time_to_full = 0;
gint64 time;
IndicatorPowerDevice * device;
- IndicatorPowerDeviceProviderUPowerPriv * p = data->self->priv;
+ priv_t * p = get_priv(data->self);
GVariant * dict = g_variant_get_child_value (response, 0);
g_variant_lookup (dict, "Type", "u", &kind);
@@ -149,55 +161,55 @@ static void
update_device_from_object_path (IndicatorPowerDeviceProviderUPower * self,
const char * path)
{
- priv_t * p = self->priv;
+ priv_t * p = get_priv(self);
struct device_get_all_data * data;
+ /* Symbolic composite item. Nice idea! But its composite rules
+ differ from Design's so (for now) don't use it.
+ https://wiki.ubuntu.com/Power#Handling_multiple_batteries */
+ if (!g_strcmp0(path, DISPLAY_DEVICE_PATH))
+ return;
+
data = g_slice_new (struct device_get_all_data);
data->path = g_strdup (path);
data->self = self;
- g_dbus_connection_call (p->bus,
- BUS_NAME,
- path,
- "org.freedesktop.DBus.Properties",
- "GetAll",
- g_variant_new ("(s)", "org.freedesktop.UPower.Device"),
- G_VARIANT_TYPE("(a{sv})"),
- G_DBUS_CALL_FLAGS_NO_AUTO_START,
- -1, /* default timeout */
- p->cancellable,
- on_device_properties_ready,
- data);
+ g_dbus_connection_call(p->bus,
+ BUS_NAME,
+ path,
+ "org.freedesktop.DBus.Properties",
+ "GetAll",
+ g_variant_new ("(s)", "org.freedesktop.UPower.Device"),
+ G_VARIANT_TYPE("(a{sv})"),
+ G_DBUS_CALL_FLAGS_NO_AUTO_START,
+ -1, /* default timeout */
+ p->cancellable,
+ on_get_all_response,
+ data);
}
/*
- * UPower doesn't seem to be sending PropertyChanged signals.
- *
- * Instead, it's got a DIY mechanism for notification: a DeviceChanged signal
- * that doesn't tell us which property changed, so to refresh we need to
- * rebuild all the properties with a GetAll() call.
- *
- * To make things worse, these DeviceChanged signals come fast and furious
- * in common situations like disconnecting a power cable.
+ * UPower 0.99 added proper PropertyChanged signals, but before that
+ * it MGR_IFACE emitted a DeviceChanged signal which didn't tell which
+ * property changed, so all properties had to get refreshed w/GetAll().
*
- * This code tries to reduce bus traffic by adding a timer to wait a small bit
- * before rebuilding our proxy's properties. This helps to fold multiple
- * DeviceChanged events into a single rebuild.
+ * Changes often come in bursts, so this timer tries to fold them together
+ * by waiting a small bit before making calling GetAll().
*/
-/* rebuild all the proxies listed in our queued_paths hashset */
+/* rebuild all the devices listed in our queued_paths hashset */
static gboolean
-on_queued_paths_timer (gpointer gself)
+on_queued_paths_timer(gpointer gself)
{
- gpointer path;
- GHashTableIter iter;
IndicatorPowerDeviceProviderUPower * self;
priv_t * p;
+ GHashTableIter iter;
+ gpointer path;
self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER (gself);
- p = self->priv;
+ p = get_priv(self);
- /* create new proxies for all the queued paths */
+ /* create new devices for all the queued paths */
g_hash_table_iter_init (&iter, p->queued_paths);
while (g_hash_table_iter_next (&iter, &path, NULL))
update_device_from_object_path (self, path);
@@ -213,7 +225,7 @@ static void
refresh_device_soon (IndicatorPowerDeviceProviderUPower * self,
const char * object_path)
{
- priv_t * p = self->priv;
+ priv_t * p = get_priv(self);
g_hash_table_add (p->queued_paths, g_strdup (object_path));
@@ -226,155 +238,261 @@ refresh_device_soon (IndicatorPowerDeviceProviderUPower * self,
***/
static void
-on_upower_device_enumerations_ready (GObject * proxy,
- GAsyncResult * res,
- gpointer gself)
+on_enumerate_devices_response(GObject * bus,
+ GAsyncResult * res,
+ gpointer gself)
{
- GError * err;
- char ** object_paths;
-
- err = NULL;
- dbus_upower_call_enumerate_devices_finish (DBUS_UPOWER(proxy),
- &object_paths,
- res,
- &err);
+ GError* error;
+ GVariant* v;
- if (err != NULL)
+ error = NULL;
+ v = g_dbus_connection_call_finish(G_DBUS_CONNECTION(bus), res, &error);
+ if (v == NULL)
{
- g_warning ("Unable to get UPower devices: %s", err->message);
- g_error_free (err);
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_warning ("Unable to enumerate UPower devices: %s", error->message);
+ g_error_free (error);
}
- else
+ else if (g_variant_is_of_type(v, G_VARIANT_TYPE("(ao)")))
{
- guint i;
+ GVariant * ao;
+ GVariantIter iter;
+ const gchar * path;
- for (i=0; object_paths && object_paths[i]; i++)
- refresh_device_soon (gself, object_paths[i]);
+ ao = g_variant_get_child_value(v, 0);
+ g_variant_iter_init(&iter, ao);
+ path = NULL;
+ while(g_variant_iter_loop(&iter, "o", &path))
+ refresh_device_soon (gself, path);
- g_strfreev (object_paths);
+ g_variant_unref(ao);
}
-}
-static void
-on_upower_device_changed (DbusUPower * unused G_GNUC_UNUSED,
- const char * object_path,
- gpointer gself)
-{
- refresh_device_soon (gself, object_path);
+ g_clear_pointer(&v, g_variant_unref);
}
static void
-on_upower_device_added (DbusUPower * unused G_GNUC_UNUSED,
- const char * object_path,
- gpointer gself)
+on_device_properties_changed(GDBusConnection * connection G_GNUC_UNUSED,
+ const gchar * sender_name G_GNUC_UNUSED,
+ const gchar * object_path,
+ const gchar * interface_name G_GNUC_UNUSED,
+ const gchar * signal_name G_GNUC_UNUSED,
+ GVariant * parameters,
+ gpointer gself)
{
- refresh_device_soon (gself, object_path);
-}
+ IndicatorPowerDeviceProviderUPower* self;
+ priv_t* p;
+ IndicatorPowerDevice* device;
-static void
-on_upower_device_removed (DbusUPower * unused G_GNUC_UNUSED,
- const char * object_path,
- gpointer gself)
-{
- IndicatorPowerDeviceProviderUPower * self;
+ self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER(gself);
+ p = get_priv(self);
- self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER (gself);
- g_hash_table_remove (self->priv->devices, object_path);
- g_hash_table_remove (self->priv->queued_paths, object_path);
+ device = g_hash_table_lookup(p->devices, object_path);
+ if (device == NULL) /* unlikely, but let's handle it */
+ {
+ refresh_device_soon (self, object_path);
+ }
+ else if ((parameters != NULL) && g_variant_n_children(parameters)>=2)
+ {
+ gboolean changed = FALSE;
+ GVariant* dict;
+ GVariantIter iter;
+ gchar* key;
+ GVariant* value;
+
+ dict = g_variant_get_child_value(parameters, 1);
+ g_variant_iter_init(&iter, dict);
+ while (g_variant_iter_next(&iter, "{sv}", &key, &value))
+ {
+ if (!g_strcmp0(key, "TimeToFull") || !g_strcmp0(key, "TimeToEmpty"))
+ {
+ const gint64 i = g_variant_get_int64(value);
+ if (i != 0)
+ {
+ g_object_set(device,
+ INDICATOR_POWER_DEVICE_TIME, (guint64)i,
+ NULL);
+ changed = TRUE;
+ }
+ }
+ else if (!g_strcmp0(key, "Percentage"))
+ {
+ const gdouble d = g_variant_get_double(value);
+ g_object_set(device,
+ INDICATOR_POWER_DEVICE_PERCENTAGE, d,
+ NULL);
+ changed = TRUE;
+ }
+ else if (!g_strcmp0(key, "Type"))
+ {
+ const guint32 u = g_variant_get_uint32(value);
+ g_object_set(device,
+ INDICATOR_POWER_DEVICE_KIND, (gint)u,
+ NULL);
+ changed = TRUE;
+ }
+ else if (!g_strcmp0(key, "State"))
+ {
+ const guint32 u = g_variant_get_uint32(value);
+ g_object_set(device,
+ INDICATOR_POWER_DEVICE_STATE, (gint)u,
+ NULL);
+ changed = TRUE;
+ }
+ }
+ g_variant_unref(dict);
- emit_devices_changed (self);
+ if (changed)
+ emit_devices_changed(self);
+ }
}
-static void
-on_upower_resuming (DbusUPower * unused G_GNUC_UNUSED,
- gpointer gself)
+static const gchar*
+get_path_from_nth_child(GVariant* parameters, gsize i)
{
- IndicatorPowerDeviceProviderUPower * self;
- GHashTableIter iter;
- gpointer object_path;
+ const gchar* path = NULL;
- self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER (gself);
+ if ((parameters != NULL) && g_variant_n_children(parameters)>i)
+ {
+ GVariant* v = g_variant_get_child_value(parameters, i);
+ if (g_variant_is_of_type(v, G_VARIANT_TYPE_STRING) || /* UPower < 0.99 */
+ g_variant_is_of_type(v, G_VARIANT_TYPE_OBJECT_PATH)) /* and >= 0.99 */
+ {
+ path = g_variant_get_string(v, NULL);
+ }
+ g_variant_unref(v);
+ }
- g_debug ("Resumed from hibernate/sleep; queueing all devices for a refresh");
- g_hash_table_iter_init (&iter, self->priv->devices);
- while (g_hash_table_iter_next (&iter, &object_path, NULL))
- refresh_device_soon (self, object_path);
+ return path;
}
static void
-on_upower_proxy_ready (GObject * source G_GNUC_UNUSED,
- GAsyncResult * res,
- gpointer gself)
+on_upower_signal(GDBusConnection * connection G_GNUC_UNUSED,
+ const gchar * sender_name G_GNUC_UNUSED,
+ const gchar * object_path G_GNUC_UNUSED,
+ const gchar * interface_name G_GNUC_UNUSED,
+ const gchar * signal_name,
+ GVariant * parameters,
+ gpointer gself)
{
- GError * err;
- DbusUPower * proxy;
+ IndicatorPowerDeviceProviderUPower * self;
+ priv_t * p;
- err = NULL;
- proxy = dbus_upower_proxy_new_finish (res, &err);
- if (err != NULL)
+ self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER(gself);
+ p = get_priv(self);
+
+ if (!g_strcmp0(signal_name, "DeviceAdded"))
{
- g_warning ("Unable to get UPower proxy: %s", err->message);
- g_error_free (err);
+ refresh_device_soon (self, get_path_from_nth_child(parameters, 0));
}
- else
+ else if (!g_strcmp0(signal_name, "DeviceRemoved"))
+ {
+ const char* device_path = get_path_from_nth_child(parameters, 0);
+ g_hash_table_remove(p->devices, device_path);
+ g_hash_table_remove(p->queued_paths, device_path);
+ emit_devices_changed(self);
+ }
+ else if (!g_strcmp0(signal_name, "DeviceChanged")) /* UPower < 0.99 */
+ {
+ refresh_device_soon (self, get_path_from_nth_child(parameters, 0));
+ }
+ else if (!g_strcmp0(signal_name, "Resuming")) /* UPower < 0.99 */
{
- IndicatorPowerDeviceProviderUPower * self;
- priv_t * p;
-
- self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER (gself);
- p = self->priv;
-
- p->upower_proxy = proxy;
- g_signal_connect (proxy, "resuming",
- G_CALLBACK (on_upower_resuming), self);
- g_signal_connect (proxy, "device-changed",
- G_CALLBACK (on_upower_device_changed), self);
- g_signal_connect (proxy, "device-added",
- G_CALLBACK (on_upower_device_added), self);
- g_signal_connect (proxy, "device-removed",
- G_CALLBACK (on_upower_device_removed), self);
-
- dbus_upower_call_enumerate_devices (p->upower_proxy,
- p->cancellable,
- on_upower_device_enumerations_ready,
- self);
+ GHashTableIter iter;
+ gpointer device_path = NULL;
+ g_debug("Resumed from hibernate/sleep; queueing all devices for a refresh");
+ g_hash_table_iter_init (&iter, p->devices);
+ while (g_hash_table_iter_next (&iter, &device_path, NULL))
+ refresh_device_soon (self, device_path);
}
}
+/* start listening for UPower events on the bus */
static void
-on_bus_ready (GObject * source_object G_GNUC_UNUSED,
- GAsyncResult * res,
- gpointer gself)
+on_bus_name_appeared(GDBusConnection * bus,
+ const gchar * name G_GNUC_UNUSED,
+ const gchar * name_owner,
+ gpointer gself)
{
- GError * error;
- GDBusConnection * tmp;
+ IndicatorPowerDeviceProviderUPower * self;
+ priv_t * p;
+ guint tag;
+
+ self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER(gself);
+ p = get_priv(self);
+ p->bus = G_DBUS_CONNECTION(g_object_ref(bus));
+
+ /* listen for signals from the boss */
+ tag = g_dbus_connection_signal_subscribe(p->bus,
+ name_owner,
+ MGR_IFACE,
+ NULL /*signal_name*/,
+ MGR_PATH,
+ NULL /*arg0*/,
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ on_upower_signal,
+ self,
+ NULL);
+ p->subscriptions = g_slist_prepend(p->subscriptions, GUINT_TO_POINTER(tag));
+
+ /* listen for change events from the devices */
+ tag = g_dbus_connection_signal_subscribe(p->bus,
+ name_owner,
+ "org.freedesktop.DBus.Properties",
+ "PropertiesChanged",
+ NULL /*object_path*/,
+ "org.freedesktop.UPower.Device", /*arg0*/
+ G_DBUS_SIGNAL_FLAGS_MATCH_ARG0_NAMESPACE,
+ on_device_properties_changed,
+ self,
+ NULL);
+ p->subscriptions = g_slist_prepend(p->subscriptions, GUINT_TO_POINTER(tag));
+
+ /* rebuild our devices list */
+ g_dbus_connection_call(p->bus,
+ BUS_NAME,
+ MGR_PATH,
+ MGR_IFACE,
+ "EnumerateDevices",
+ NULL,
+ G_VARIANT_TYPE("(ao)"),
+ G_DBUS_CALL_FLAGS_NO_AUTO_START,
+ -1, /* default timeout */
+ p->cancellable,
+ on_enumerate_devices_response,
+ self);
+}
- error = NULL;
- tmp = g_bus_get_finish (res, &error);
- if (error != NULL)
+static void
+on_bus_name_vanished(GDBusConnection * connection G_GNUC_UNUSED,
+ const gchar * name G_GNUC_UNUSED,
+ gpointer gself)
+{
+ IndicatorPowerDeviceProviderUPower * self;
+ priv_t * p;
+ GSList * l;
+
+ self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER(gself);
+ p = get_priv(self);
+
+ /* clear the devices */
+ g_hash_table_remove_all(p->devices);
+ g_hash_table_remove_all(p->queued_paths);
+ if (p->queued_paths_timer != 0)
{
- if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
- g_warning ("Error acquiring bus: %s", error->message);
- g_error_free (error);
+ g_source_remove(p->queued_paths_timer);
+ p->queued_paths_timer = 0;
}
- else
- {
- IndicatorPowerDeviceProviderUPower * self;
- priv_t * p;
-
- self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER (gself);
- p = self->priv;
+ emit_devices_changed (self);
- p->bus = tmp;
+ /* clear the bus subscriptions */
+ for (l=p->subscriptions; l!=NULL; l=l->next)
+ g_dbus_connection_signal_unsubscribe(p->bus, GPOINTER_TO_UINT(l->data));
+ g_slist_free(p->subscriptions);
+ p->subscriptions = NULL;
- dbus_upower_proxy_new (p->bus,
- G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
- BUS_NAME,
- BUS_PATH,
- p->cancellable,
- on_upower_proxy_ready,
- self);
- }
+ /* clear the bus */
+ g_clear_object(&p->bus);
}
/***
@@ -382,14 +500,16 @@ on_bus_ready (GObject * source_object G_GNUC_UNUSED,
***/
static GList *
-my_get_devices (IndicatorPowerDeviceProvider * provider)
+my_get_devices(IndicatorPowerDeviceProvider * provider)
{
- GList * devices;
IndicatorPowerDeviceProviderUPower * self;
+ priv_t * p;
+ GList * devices;
self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER(provider);
+ p = get_priv(self);
- devices = g_hash_table_get_values (self->priv->devices);
+ devices = g_hash_table_get_values (p->devices);
g_list_foreach (devices, (GFunc)g_object_ref, NULL);
return devices;
}
@@ -405,7 +525,7 @@ my_dispose (GObject * o)
priv_t * p;
self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER(o);
- p = self->priv;
+ p = get_priv(self);
if (p->cancellable != NULL)
{
@@ -421,18 +541,15 @@ my_dispose (GObject * o)
p->queued_paths_timer = 0;
}
- if (p->upower_proxy != NULL)
+ if (p->name_tag != 0)
{
- g_signal_handlers_disconnect_by_data (p->upower_proxy, self);
+ g_bus_unwatch_name(p->name_tag);
+ on_bus_name_vanished(NULL, NULL, self);
- g_clear_object (&p->upower_proxy);
+ p->name_tag = 0;
}
- g_hash_table_remove_all (p->devices);
-
- g_clear_object (&p->bus);
-
- G_OBJECT_CLASS (indicator_power_device_provider_upower_parent_class)->dispose (o);
+ G_OBJECT_CLASS (indicator_power_device_provider_upower_parent_class)->dispose(o);
}
static void
@@ -442,12 +559,12 @@ my_finalize (GObject * o)
priv_t * p;
self = INDICATOR_POWER_DEVICE_PROVIDER_UPOWER(o);
- p = self->priv;
+ p = get_priv(self);
g_hash_table_destroy (p->devices);
g_hash_table_destroy (p->queued_paths);
- G_OBJECT_CLASS (indicator_power_device_provider_upower_parent_class)->dispose (o);
+ G_OBJECT_CLASS (indicator_power_device_provider_upower_parent_class)->finalize (o);
}
/***
@@ -461,9 +578,6 @@ indicator_power_device_provider_upower_class_init (IndicatorPowerDeviceProviderU
object_class->dispose = my_dispose;
object_class->finalize = my_finalize;
-
- g_type_class_add_private (klass,
- sizeof (IndicatorPowerDeviceProviderUPowerPriv));
}
static void
@@ -475,30 +589,27 @@ indicator_power_device_provider_interface_init (IndicatorPowerDeviceProviderInte
static void
indicator_power_device_provider_upower_init (IndicatorPowerDeviceProviderUPower * self)
{
- IndicatorPowerDeviceProviderUPowerPriv * p;
-
- p = G_TYPE_INSTANCE_GET_PRIVATE (self,
- INDICATOR_TYPE_POWER_DEVICE_PROVIDER_UPOWER,
- IndicatorPowerDeviceProviderUPowerPriv);
-
- self->priv = p;
-
- p->cancellable = g_cancellable_new ();
-
- p->devices = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- g_free,
- g_object_unref);
-
- p->queued_paths = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- g_free,
- NULL);
-
- g_bus_get (G_BUS_TYPE_SYSTEM,
- p->cancellable,
- on_bus_ready,
- self);
+ priv_t * p = get_priv(self);
+
+ p->cancellable = g_cancellable_new();
+
+ p->devices = g_hash_table_new_full(g_str_hash,
+ g_str_equal,
+ g_free,
+ g_object_unref);
+
+ p->queued_paths = g_hash_table_new_full(g_str_hash,
+ g_str_equal,
+ g_free,
+ NULL);
+
+ p->name_tag = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
+ BUS_NAME,
+ G_BUS_NAME_WATCHER_FLAGS_NONE,
+ on_bus_name_appeared,
+ on_bus_name_vanished,
+ self,
+ NULL);
}
/***
@@ -506,7 +617,7 @@ indicator_power_device_provider_upower_init (IndicatorPowerDeviceProviderUPower
***/
IndicatorPowerDeviceProvider *
-indicator_power_device_provider_upower_new (void)
+indicator_power_device_provider_upower_new(void)
{
gpointer o = g_object_new (INDICATOR_TYPE_POWER_DEVICE_PROVIDER_UPOWER, NULL);
diff --git a/src/device-provider-upower.h b/src/device-provider-upower.h
index 7bfecd9..f385479 100644
--- a/src/device-provider-upower.h
+++ b/src/device-provider-upower.h
@@ -45,8 +45,6 @@ G_BEGIN_DECLS
typedef struct _IndicatorPowerDeviceProviderUPower
IndicatorPowerDeviceProviderUPower;
-typedef struct _IndicatorPowerDeviceProviderUPowerPriv
- IndicatorPowerDeviceProviderUPowerPriv;
typedef struct _IndicatorPowerDeviceProviderUPowerClass
IndicatorPowerDeviceProviderUPowerClass;
@@ -56,8 +54,6 @@ typedef struct _IndicatorPowerDeviceProviderUPowerClass
struct _IndicatorPowerDeviceProviderUPower
{
GObject parent_instance;
-
- IndicatorPowerDeviceProviderUPowerPriv * priv;
};
struct _IndicatorPowerDeviceProviderUPowerClass
diff --git a/src/org.freedesktop.UPower.xml b/src/org.freedesktop.UPower.xml
deleted file mode 100644
index 7b73583..0000000
--- a/src/org.freedesktop.UPower.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
- "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
-<node>
- <interface name="org.freedesktop.UPower">
- <method name="HibernateAllowed">
- <arg name="allowed" type="b" direction="out"/>
- </method>
- <method name="Hibernate">
- </method>
- <method name="SuspendAllowed">
- <arg name="allowed" type="b" direction="out"/>
- </method>
- <method name="Suspend">
- </method>
- <method name="AboutToSleep">
- </method>
- <method name="EnumerateDevices">
- <arg name="devices" type="ao" direction="out"/>
- </method>
- <signal name="Resuming">
- </signal>
- <signal name="Sleeping">
- </signal>
- <signal name="Changed">
- </signal>
- <signal name="DeviceChanged">
- <arg type="s"/>
- </signal>
- <signal name="DeviceRemoved">
- <arg type="s"/>
- </signal>
- <signal name="DeviceAdded">
- <arg type="s"/>
- </signal>
- <property name="LidIsPresent" type="b" access="read"/>
- <property name="LidIsClosed" type="b" access="read"/>
- <property name="OnLowBattery" type="b" access="read"/>
- <property name="OnBattery" type="b" access="read"/>
- <property name="CanHibernate" type="b" access="read"/>
- <property name="CanSuspend" type="b" access="read"/>
- <property name="DaemonVersion" type="s" access="read"/>
- </interface>
-</node> \ No newline at end of file