summaryrefslogtreecommitdiff
path: root/sap/capabilityagent.cc
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2016-01-01 22:05:42 +0100
committerJavier <dev.git@javispedro.com>2016-01-01 22:05:42 +0100
commita45977185a485624095bff1a15024e9199eee676 (patch)
tree6cc57d085bdd01e493477c870dbe0548137998e1 /sap/capabilityagent.cc
parenta24034bdfea259cdc09c74217be75d4f9de0dce5 (diff)
downloadsapd-a45977185a485624095bff1a15024e9199eee676.tar.gz
sapd-a45977185a485624095bff1a15024e9199eee676.zip
reorganize source files into SAP and agents
Diffstat (limited to 'sap/capabilityagent.cc')
-rw-r--r--sap/capabilityagent.cc69
1 files changed, 69 insertions, 0 deletions
diff --git a/sap/capabilityagent.cc b/sap/capabilityagent.cc
new file mode 100644
index 0000000..cdc80b6
--- /dev/null
+++ b/sap/capabilityagent.cc
@@ -0,0 +1,69 @@
+#include "sapchannelinfo.h"
+#include "sapmanager.h"
+#include "sappeer.h"
+#include "sapsocket.h"
+#include "sapserviceinfo.h"
+#include "sapconnectionrequest.h"
+#include "capabilitypeer.h"
+#include "capabilityagent.h"
+
+static CapabilityAgent *agent = 0;
+
+CapabilityAgent::CapabilityAgent(QObject *parent)
+ : QObject(parent)
+{
+}
+
+CapabilityAgent *CapabilityAgent::instance()
+{
+ if (!agent) {
+ agent = new CapabilityAgent;
+ }
+
+ return agent;
+}
+
+void CapabilityAgent::registerServices(SAPManager *manager)
+{
+ CapabilityAgent *agent = instance();
+ SAPServiceInfo service;
+ SAPChannelInfo channel;
+
+ service.setProfile(SAProtocol::capabilityDiscoveryProfile);
+ service.setFriendlyName("CapabilityAgentProvider");
+ service.setRole(SAPServiceInfo::RoleProvider);
+ service.setVersion(1);
+ service.setConnectionTimeout(0);
+
+ channel.setChannelId(SAProtocol::capabilityDiscoveryChannel);
+ channel.setPayloadType(SAPChannelInfo::PayloadBinary);
+ channel.setQoSType(SAPChannelInfo::QoSRestricted);
+ channel.setQoSDataRate(SAPChannelInfo::QoSDataRateHigh);
+ channel.setQoSPriority(SAPChannelInfo::QoSPriorityHigh);
+ service.addChannel(channel);
+
+ manager->registerServiceAgent(service, agent);
+
+ service.setFriendlyName("CapabilityAgentConsumer");
+ service.setRole(SAPServiceInfo::RoleConsumer);
+
+ manager->registerServiceAgent(service, agent);
+}
+
+void CapabilityAgent::peerFound(SAPPeer *peer)
+{
+ // We make the capability peer a child of the peer object itself,
+ // so that the peer can find it.
+ CapabilityPeer *capPeer = new CapabilityPeer(peer, peer);
+ connect(peer, SIGNAL(disconnected()), capPeer, SLOT(deleteLater()));
+}
+
+void CapabilityAgent::requestConnection(SAPConnectionRequest *request)
+{
+ SAPPeer *peer = request->peer();
+ CapabilityPeer *capPeer = peer->findChild<CapabilityPeer*>();
+
+ Q_ASSERT(capPeer);
+
+ capPeer->requestConnection(request);
+}