summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMateusz Piekos <mateuszpiekos@gmail.com>2012-08-08 11:43:56 (GMT)
committerMateusz Piekos <mateuszpiekos@gmail.com>2012-08-08 11:43:56 (GMT)
commit3fa0d466150981d33f535108190f1e9744fb3e09 (patch)
tree1f41ed407741e3e9719dedce8b8405ea18c4c78d /Swiften/Whiteboard
parent84cc4e93c5e3f68d055cbddf8072025d91c44a23 (diff)
downloadswift-contrib-3fa0d466150981d33f535108190f1e9744fb3e09.zip
swift-contrib-3fa0d466150981d33f535108190f1e9744fb3e09.tar.bz2
Handling of sessions with contacts which become unavailable
Diffstat (limited to 'Swiften/Whiteboard')
-rw-r--r--Swiften/Whiteboard/WhiteboardSession.cpp4
-rw-r--r--Swiften/Whiteboard/WhiteboardSession.h3
-rw-r--r--Swiften/Whiteboard/WhiteboardSessionManager.cpp29
-rw-r--r--Swiften/Whiteboard/WhiteboardSessionManager.h10
4 files changed, 32 insertions, 14 deletions
diff --git a/Swiften/Whiteboard/WhiteboardSession.cpp b/Swiften/Whiteboard/WhiteboardSession.cpp
index 92865e3..10b5e51 100644
--- a/Swiften/Whiteboard/WhiteboardSession.cpp
+++ b/Swiften/Whiteboard/WhiteboardSession.cpp
@@ -28,7 +28,7 @@ namespace Swift {
onRequestAccepted(toJID_);
return;
case WhiteboardPayload::SessionTerminate:
- onSessionTerminateReceived(toJID_);
+ onSessionTerminated(toJID_);
return;
//handled elsewhere
@@ -55,7 +55,7 @@ namespace Swift {
boost::shared_ptr<WhiteboardPayload> payload = boost::make_shared<WhiteboardPayload>(WhiteboardPayload::SessionTerminate);
boost::shared_ptr<GenericRequest<WhiteboardPayload> > request = boost::make_shared<GenericRequest<WhiteboardPayload> >(IQ::Set, toJID_, payload, router_);
request->send();
- onSessionCancelled(toJID_);
+ onSessionTerminated(toJID_);
}
const JID& WhiteboardSession::getTo() const {
diff --git a/Swiften/Whiteboard/WhiteboardSession.h b/Swiften/Whiteboard/WhiteboardSession.h
index 1b5d93f..7f0ccd3 100644
--- a/Swiften/Whiteboard/WhiteboardSession.h
+++ b/Swiften/Whiteboard/WhiteboardSession.h
@@ -37,9 +37,8 @@ namespace Swift {
public:
boost::signal< void(const WhiteboardElement::ref element)> onElementReceived;
boost::signal< void(const WhiteboardOperation::ref operation)> onOperationReceived;
- boost::signal< void(const JID& contact)> onSessionTerminateReceived;
+ boost::signal< void(const JID& contact)> onSessionTerminated;
boost::signal< void(const JID& contact)> onRequestAccepted;
- boost::signal< void(const JID& contact)> onSessionCancelled;
boost::signal< void(const JID& contact)> onRequestRejected;
private:
diff --git a/Swiften/Whiteboard/WhiteboardSessionManager.cpp b/Swiften/Whiteboard/WhiteboardSessionManager.cpp
index 88771e7..c8e9a6a 100644
--- a/Swiften/Whiteboard/WhiteboardSessionManager.cpp
+++ b/Swiften/Whiteboard/WhiteboardSessionManager.cpp
@@ -16,9 +16,11 @@
#include "Swiften/Disco/EntityCapsProvider.h"
namespace Swift {
- WhiteboardSessionManager::WhiteboardSessionManager(IQRouter* router, PresenceOracle* presenceOracle, EntityCapsProvider* capsProvider) : router_(router), presenceOracle_(presenceOracle), capsProvider_(capsProvider) {
+ WhiteboardSessionManager::WhiteboardSessionManager(IQRouter* router, StanzaChannel* stanzaChannel, PresenceOracle* presenceOracle, EntityCapsProvider* capsProvider) : router_(router), stanzaChannel_(stanzaChannel), presenceOracle_(presenceOracle), capsProvider_(capsProvider) {
responder = new WhiteboardResponder(this, router);
responder->start();
+ stanzaChannel_->onPresenceReceived.connect(boost::bind(&WhiteboardSessionManager::handlePresenceReceived, this, _1));
+ stanzaChannel_->onAvailableChanged.connect(boost::bind(&WhiteboardSessionManager::handleAvailableChanged, this, _1));
}
WhiteboardSessionManager::~WhiteboardSessionManager() {
@@ -40,8 +42,7 @@ namespace Swift {
}
OutgoingWhiteboardSession::ref session = boost::make_shared<OutgoingWhiteboardSession>(fullJID, router_);
sessions_[fullJID] = session;
- session->onSessionTerminateReceived.connect(boost::bind(&WhiteboardSessionManager::deleteSessionEntry, this, _1));
- session->onSessionCancelled.connect(boost::bind(&WhiteboardSessionManager::deleteSessionEntry, this, _1));
+ session->onSessionTerminated.connect(boost::bind(&WhiteboardSessionManager::deleteSessionEntry, this, _1));
session->onRequestRejected.connect(boost::bind(&WhiteboardSessionManager::deleteSessionEntry, this, _1));
return session;
}
@@ -59,8 +60,7 @@ namespace Swift {
void WhiteboardSessionManager::handleIncomingSession(IncomingWhiteboardSession::ref session) {
sessions_[session->getTo()] = session;
- session->onSessionTerminateReceived.connect(boost::bind(&WhiteboardSessionManager::deleteSessionEntry, this, _1));
- session->onSessionCancelled.connect(boost::bind(&WhiteboardSessionManager::deleteSessionEntry, this, _1));
+ session->onSessionTerminated.connect(boost::bind(&WhiteboardSessionManager::deleteSessionEntry, this, _1));
onSessionRequest(session);
}
@@ -89,4 +89,23 @@ namespace Swift {
void WhiteboardSessionManager::deleteSessionEntry(const JID& contact) {
sessions_.erase(contact);
}
+
+ void WhiteboardSessionManager::handlePresenceReceived(Presence::ref presence) {
+ if (!presence->isAvailable()) {
+ WhiteboardSession::ref session = getSession(presence->getFrom());
+ if (session) {
+ session->cancel();
+ }
+ }
+ }
+
+ void WhiteboardSessionManager::handleAvailableChanged(bool available) {
+ if (!available) {
+ std::map<JID, WhiteboardSession::ref> sessionsCopy = sessions_;
+ std::map<JID, WhiteboardSession::ref>::iterator it;
+ for (it = sessionsCopy.begin(); it != sessionsCopy.end(); ++it) {
+ it->second->cancel();
+ }
+ }
+ }
}
diff --git a/Swiften/Whiteboard/WhiteboardSessionManager.h b/Swiften/Whiteboard/WhiteboardSessionManager.h
index faccb97..f696eb8 100644
--- a/Swiften/Whiteboard/WhiteboardSessionManager.h
+++ b/Swiften/Whiteboard/WhiteboardSessionManager.h
@@ -10,6 +10,7 @@
#include <Swiften/Queries/IQRouter.h>
#include <Swiften/JID/JID.h>
+#include <Swiften/Client/StanzaChannel.h>
#include <Swiften/Base/boost_bsignals.h>
#include <Swiften/Whiteboard/WhiteboardSession.h>
#include <Swiften/Whiteboard/IncomingWhiteboardSession.h>
@@ -24,28 +25,27 @@ namespace Swift {
class WhiteboardSessionManager {
friend class WhiteboardResponder;
public:
- WhiteboardSessionManager(IQRouter* router, PresenceOracle* presenceOracle, EntityCapsProvider* capsProvider);
+ WhiteboardSessionManager(IQRouter* router, StanzaChannel* stanzaChannel, PresenceOracle* presenceOracle, EntityCapsProvider* capsProvider);
~WhiteboardSessionManager();
WhiteboardSession::ref getSession(const JID& to);
WhiteboardSession::ref requestSession(const JID& to);
public:
- /*boost::signal< void (const JID&, bool senderIsSelf)> onSessionRequest;
- boost::signal< void (const JID&)> onSessionTerminate;
- boost::signal< void (const JID&)> onRequestAccepted;
- boost::signal< void (const JID&)> onRequestRejected;*/
boost::signal< void (IncomingWhiteboardSession::ref)> onSessionRequest;
private:
JID getFullJID(const JID& bareJID);
OutgoingWhiteboardSession::ref createOutgoingSession(const JID& to);
void handleIncomingSession(IncomingWhiteboardSession::ref session);
+ void handlePresenceReceived(Presence::ref presence);
+ void handleAvailableChanged(bool available);
void deleteSessionEntry(const JID& contact);
private:
std::map<JID, boost::shared_ptr<WhiteboardSession> > sessions_;
IQRouter* router_;
+ StanzaChannel* stanzaChannel_;
PresenceOracle* presenceOracle_;
EntityCapsProvider* capsProvider_;
WhiteboardResponder* responder;