Browse Source

mconnect/battery-proxy: send org.freedesktop.DBus.Properties.PropertiesChanged

bboozzoo/dbus-support-wip
Maciek Borzecki 8 years ago
parent
commit
a0f1ba8efa
1 changed files with 37 additions and 0 deletions
  1. +37
    -0
      src/mconnect/battery-proxy.vala

+ 37
- 0
src/mconnect/battery-proxy.vala View File

@ -24,6 +24,7 @@ class BatteryHandlerProxy : Object, PacketHandlerInterfaceProxy {
private Device device = null;
private BatteryHandler battery_handler = null;
private uint register_id = 0;
private ulong notify_id = 0;
public uint level { get; private set; default = 0; }
public bool charging { get; private set; default = false; }
@ -51,6 +52,10 @@ class BatteryHandlerProxy : Object, PacketHandlerInterfaceProxy {
public void bus_register(DBusConnection conn, string path) throws IOError {
if (this.register_id == 0)
this.register_id = conn.register_object(path, this);
this.notify_id = this.notify.connect((spec) => {
this.send_property_change(conn, path, spec);
});
}
[DBus (visible = false)]
@ -58,7 +63,39 @@ class BatteryHandlerProxy : Object, PacketHandlerInterfaceProxy {
if (this.register_id != 0)
conn.unregister_object(this.register_id);
this.register_id = 0;
this.disconnect(this.notify_id);
this.notify_id = 0;
}
public signal void battery(uint level, bool charging);
private void send_property_change(DBusConnection conn, string path, ParamSpec p) {
var builder = new VariantBuilder (VariantType.ARRAY);
var invalid_builder = new VariantBuilder (new VariantType ("as"));
if (p.name == "level") {
Variant i = this.level;
builder.add ("{sv}", "level", i);
}
if (p.name == "charging") {
Variant i = this.charging;
builder.add ("{sv}", "charging", i);
}
try {
conn.emit_signal(null,
path,
"org.freedesktop.DBus.Properties",
"PropertiesChanged",
new Variant ("(sa{sv}as)",
"org.mconnect.Device.Battery",
builder,
invalid_builder)
);
} catch (Error e) {
warning("%s\n", e.message);
}
}
}

Loading…
Cancel
Save