Bug 1282433 - Use dbus PropertiesChanged signal for notification of battery status changes, r=karlt

From UPower 0.99, DeviceChanged has been removed from the UPower interface and
PropertiesChanged support added.
This commit is contained in:
Andrea Marchesini 2016-11-02 10:37:11 +01:00
Родитель 95dd1d792e
Коммит a18bf77d4d
1 изменённых файлов: 34 добавлений и 1 удалений

Просмотреть файл

@ -91,6 +91,15 @@ private:
static void DeviceChanged(DBusGProxy* aProxy, const gchar* aObjectPath,
UPowerClient* aListener);
/**
* Callback used by 'PropertiesChanged' signal.
* This method is called when the the battery level changes.
* (Only with upower >= 0.99)
*/
static void PropertiesChanged(DBusGProxy* aProxy, const gchar*,
GHashTable*, char**,
UPowerClient* aListener);
/**
* Callback called when mDBusConnection gets a signal.
*/
@ -243,6 +252,9 @@ UPowerClient::StopListening()
mTrackedDevice = nullptr;
if (mTrackedDeviceProxy) {
dbus_g_proxy_disconnect_signal(mTrackedDeviceProxy, "PropertiesChanged",
G_CALLBACK (PropertiesChanged), this);
g_object_unref(mTrackedDeviceProxy);
mTrackedDeviceProxy = nullptr;
}
@ -273,6 +285,9 @@ UPowerClient::UpdateTrackedDeviceSync()
// Reset the current tracked device proxy:
if (mTrackedDeviceProxy) {
dbus_g_proxy_disconnect_signal(mTrackedDeviceProxy, "PropertiesChanged",
G_CALLBACK (PropertiesChanged), this);
g_object_unref(mTrackedDeviceProxy);
mTrackedDeviceProxy = nullptr;
}
@ -309,11 +324,22 @@ UPowerClient::UpdateTrackedDeviceSync()
g_free(devicePath);
}
if (mTrackedDeviceProxy) {
dbus_g_proxy_add_signal(mTrackedDeviceProxy, "PropertiesChanged",
G_TYPE_STRING,
dbus_g_type_get_map("GHashTable", G_TYPE_STRING,
G_TYPE_VALUE),
G_TYPE_STRV, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(mTrackedDeviceProxy, "PropertiesChanged",
G_CALLBACK (PropertiesChanged), this, nullptr);
}
g_ptr_array_free(devices, true);
}
/* static */ void
UPowerClient::DeviceChanged(DBusGProxy* aProxy, const gchar* aObjectPath, UPowerClient* aListener)
UPowerClient::DeviceChanged(DBusGProxy* aProxy, const gchar* aObjectPath,
UPowerClient* aListener)
{
if (!aListener->mTrackedDevice) {
return;
@ -330,6 +356,13 @@ UPowerClient::DeviceChanged(DBusGProxy* aProxy, const gchar* aObjectPath, UPower
aListener->GetDevicePropertiesAsync(aListener->mTrackedDeviceProxy);
}
/* static */ void
UPowerClient::PropertiesChanged(DBusGProxy* aProxy, const gchar*, GHashTable*,
char**, UPowerClient* aListener)
{
aListener->GetDevicePropertiesAsync(aListener->mTrackedDeviceProxy);
}
/* static */ DBusHandlerResult
UPowerClient::ConnectionSignalFilter(DBusConnection* aConnection,
DBusMessage* aMessage, void* aData)