From 278d4ca2a4ff07c54ad7abacf9b24d357f06898e Mon Sep 17 00:00:00 2001 From: Maciek Borzecki Date: Wed, 7 Jun 2017 08:58:11 +0200 Subject: [PATCH] device-proxy, devicemanager-proxy: register packet handlers on DBus Signed-off-by: Maciek Borzecki --- src/mconnect/device-proxy.vala | 30 +++++++++++++++++++++++---- src/mconnect/devicemanager-proxy.vala | 5 +++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/mconnect/device-proxy.vala b/src/mconnect/device-proxy.vala index 2e3b47c..10daae6 100644 --- a/src/mconnect/device-proxy.vala +++ b/src/mconnect/device-proxy.vala @@ -74,7 +74,7 @@ class DeviceDBusProxy : Object { private set; } - private ArrayList handlers; + private HashMap handlers; private uint register_id = 0; @@ -87,7 +87,7 @@ class DeviceDBusProxy : Object { public DeviceDBusProxy.for_device_with_path(Device device, ObjectPath path) { this.device = device; this.object_path = path; - this.handlers = new ArrayList(); + this.handlers = new HashMap(); this.update_address(); this.update_capabilities(); this.device.notify.connect(this.param_changed); @@ -143,8 +143,8 @@ class DeviceDBusProxy : Object { } [DBus (visible = false)] - public void add_handler(PacketHandlerInterfaceProxy h) { - this.handlers.add(h); + public bool has_handler(string cap) { + return this.handlers.has_key(cap); } [DBus (visible = false)] @@ -164,4 +164,26 @@ class DeviceDBusProxy : Object { } this.register_id = 0; } + + [DBus (visible = false)] + public void bus_register_handler(DBusConnection conn, + string cap, + PacketHandlerInterfaceProxy handler) { + + handler.bus_register(conn, this.object_path); + this.handlers.@set(cap, handler); + } + + [DBus (visible = false)] + public void bus_unregister_handler(DBusConnection conn, + string cap) { + PacketHandlerInterfaceProxy handler; + + this.handlers.@unset(cap, out handler); + if (handler != null) { + handler.bus_unregister(conn); + } + } + + } \ No newline at end of file diff --git a/src/mconnect/devicemanager-proxy.vala b/src/mconnect/devicemanager-proxy.vala index 8d0d3b8..061f4e5 100644 --- a/src/mconnect/devicemanager-proxy.vala +++ b/src/mconnect/devicemanager-proxy.vala @@ -112,6 +112,11 @@ class DeviceManagerDBusProxy : Object if (dp == null) { warning("no bus proxy for device %s", dev.to_string()); + return; + } + + if (dp.has_handler(capability)) { + return; } info("add capability handler %s for device at path %s",