From b5c740174f1262bd3ce680d62a9586009df9bf60 Mon Sep 17 00:00:00 2001 From: Maciek Borzecki Date: Mon, 5 Jun 2017 21:40:52 +0200 Subject: [PATCH] packethandlers: enable only supported capabilities --- src/mconnect/packethandlers.vala | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/mconnect/packethandlers.vala b/src/mconnect/packethandlers.vala index c40b28c..d601079 100644 --- a/src/mconnect/packethandlers.vala +++ b/src/mconnect/packethandlers.vala @@ -64,9 +64,35 @@ class PacketHandlers : Object { // return interfaces; } - public void use_device(Device dev) { + /** + * SupportedCapabilityFunc: + * @capability: capability name + * @handler: packet handler + * + * User provided callback called when enabling @capability handled + * by @handler for a particular device. + */ + public delegate void SupportedCapabilityFunc(string capability, + PacketHandlerInterface handler); + + /** + * use_device: + * @dev: device + * @cb: callback see @SupportedCapabilityFunc to details + * + * Enable protocol handlers supported by device + */ + public void use_device(Device dev, SupportedCapabilityFunc? cb) { _handlers.foreach((h) => { - h.use_device(dev); + var cap = h.get_pkt_type(); + if (dev.supports_capability(cap)) { + h.use_device(dev); + if (cb != null) { + cb(cap, h); + } + } else { + warning("capability %s not supported by device", cap); + } }); }