summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--capabilityagent.cc5
-rw-r--r--hostmanagerconn.cc1
-rw-r--r--notificationconn.cc1
-rw-r--r--sapmanager.cc9
-rw-r--r--sapmanager.h5
-rw-r--r--sappeer.cc23
-rw-r--r--sappeer.h1
-rw-r--r--webproxyconn.cc1
8 files changed, 37 insertions, 9 deletions
diff --git a/capabilityagent.cc b/capabilityagent.cc
index 3831e5d..cdc80b6 100644
--- a/capabilityagent.cc
+++ b/capabilityagent.cc
@@ -52,9 +52,10 @@ void CapabilityAgent::registerServices(SAPManager *manager)
void CapabilityAgent::peerFound(SAPPeer *peer)
{
- new CapabilityPeer(peer, 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)
@@ -62,5 +63,7 @@ void CapabilityAgent::requestConnection(SAPConnectionRequest *request)
SAPPeer *peer = request->peer();
CapabilityPeer *capPeer = peer->findChild<CapabilityPeer*>();
+ Q_ASSERT(capPeer);
+
capPeer->requestConnection(request);
}
diff --git a/hostmanagerconn.cc b/hostmanagerconn.cc
index b8d1d31..87bed09 100644
--- a/hostmanagerconn.cc
+++ b/hostmanagerconn.cc
@@ -16,6 +16,7 @@ HostManagerConn::HostManagerConn(SAPConnection *conn, QObject *parent)
: QObject(parent), _conn(conn), _socket(conn->getSocket(103))
{
connect(_conn, SIGNAL(disconnected()), SLOT(deleteLater()));
+ connect(_conn, SIGNAL(destroyed()), SLOT(deleteLater()));
Q_ASSERT(_socket);
connect(_socket, SIGNAL(connected()), SLOT(handleConnected()));
connect(_socket, SIGNAL(messageReceived()), SLOT(handleMessageReceived()));
diff --git a/notificationconn.cc b/notificationconn.cc
index 592f3e5..7ac17f8 100644
--- a/notificationconn.cc
+++ b/notificationconn.cc
@@ -25,6 +25,7 @@ NotificationConn::NotificationConn(SAPConnection *conn, QObject *parent)
: QObject(parent), _conn(conn), _socket(conn->getSocket(104))
{
connect(_conn, SIGNAL(disconnected()), SLOT(deleteLater()));
+ connect(_conn, SIGNAL(destroyed()), SLOT(deleteLater()));
Q_ASSERT(_socket);
connect(_socket, SIGNAL(connected()), SLOT(handleConnected()));
connect(_socket, SIGNAL(messageReceived()), SLOT(handleMessageReceived()));
diff --git a/sapmanager.cc b/sapmanager.cc
index c9d7df6..ab3fcd0 100644
--- a/sapmanager.cc
+++ b/sapmanager.cc
@@ -97,6 +97,15 @@ QSet<QString> SAPManager::allProfiles()
+ QSet<QString>::fromList(_providerProfiles.keys());
}
+QSet<SAPAgent*> SAPManager::allAgents()
+{
+ QSet<SAPAgent*> agents;
+ foreach (const RegisteredAgent &ragent, _agents) {
+ agents.insert(ragent.agent);
+ }
+ return agents;
+}
+
int SAPManager::findUnusedAgentId() const
{
if (_agents.size() > 20000) {
diff --git a/sapmanager.h b/sapmanager.h
index e9f60cc..31b84a0 100644
--- a/sapmanager.h
+++ b/sapmanager.h
@@ -29,10 +29,7 @@ public:
SAPServiceInfo serviceInfo(int agentId) const;
QSet<QString> allProfiles();
-
-signals:
-
-public slots:
+ QSet<SAPAgent*> allAgents();
private:
int findUnusedAgentId() const;
diff --git a/sappeer.cc b/sappeer.cc
index 7f570eb..551ca45 100644
--- a/sappeer.cc
+++ b/sappeer.cc
@@ -18,6 +18,14 @@ SAPPeer::SAPPeer(SAProtocol::Role role, const QString &localName, const QString
{
}
+SAPPeer::~SAPPeer()
+{
+ qDeleteAll(_conns);
+ qDeleteAll(_sessions);
+ _conns.clear();
+ _sessions.clear();
+}
+
SAPConnection * SAPPeer::createServiceConnection(const QString &profile, const QString &requesterProfile, SAPServiceInfo::Role requesterRole)
{
SAPManager *manager = SAPManager::instance();
@@ -212,15 +220,22 @@ void SAPPeer::handleConnected()
{
emit connected();
- // Manually call the capability agent in order to trigger initial capability discovery.
- CapabilityAgent *caps = CapabilityAgent::instance();
- caps->peerFound(this);
+ // Call in all the agents
+ SAPManager *manager = SAPManager::instance();
+ foreach (SAPAgent *agent, manager->allAgents()) {
+ agent->peerFound(this);
+ }
}
void SAPPeer::handleDisconnected()
{
- // TODO Figure out who should actually reconnect
+ // Clear out all active sessions
emit disconnected();
+ qDeleteAll(_conns);
+ qDeleteAll(_sessions);
+ _conns.clear();
+ _sessions.clear();
+ // TODO Figure out who should actually reconnect
}
int SAPPeer::findUnusedSessionId() const
diff --git a/sappeer.h b/sappeer.h
index ffddea4..1c477c4 100644
--- a/sappeer.h
+++ b/sappeer.h
@@ -19,6 +19,7 @@ class SAPPeer : public QObject
Q_OBJECT
public:
explicit SAPPeer(SAProtocol::Role role, const QString &localName, const QString &peerName, QObject *parent = 0);
+ ~SAPPeer();
SAPConnection* createServiceConnection(const QString &profile, const QString &requesterProfile, SAPServiceInfo::Role requesterRole);
bool terminateServiceConnection(const QString &profile, const QString &requesterProfile, SAPServiceInfo::Role requesterRole);
diff --git a/webproxyconn.cc b/webproxyconn.cc
index fa4bc9d..91a9510 100644
--- a/webproxyconn.cc
+++ b/webproxyconn.cc
@@ -11,6 +11,7 @@ WebProxyConn::WebProxyConn(SAPConnection *conn, QObject *parent)
_in(conn->getSocket(501)), _out(conn->getSocket(502))
{
connect(_conn, SIGNAL(disconnected()), SLOT(deleteLater()));
+ connect(_conn, SIGNAL(destroyed()), SLOT(deleteLater()));
Q_ASSERT(_in && _out);
connect(_in, SIGNAL(messageReceived()), SLOT(handleMessageReceived()));
}