diff options
Diffstat (limited to 'Swiften/Whiteboard/WhiteboardSessionManager.cpp')
-rw-r--r-- | Swiften/Whiteboard/WhiteboardSessionManager.cpp | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/Swiften/Whiteboard/WhiteboardSessionManager.cpp b/Swiften/Whiteboard/WhiteboardSessionManager.cpp index ccbc4d7..eae9e5b 100644 --- a/Swiften/Whiteboard/WhiteboardSessionManager.cpp +++ b/Swiften/Whiteboard/WhiteboardSessionManager.cpp @@ -9,7 +9,6 @@ #include <boost/bind.hpp> #include <Swiften/Queries/IQRouter.h> -#include <Swiften/Whiteboard/WhiteboardSession.h> #include <Swiften/Whiteboard/WhiteboardResponder.h> #include <Swiften/Presence/PresenceOracle.h> @@ -24,48 +23,53 @@ namespace Swift { delete responder; } - WhiteboardSession* WhiteboardSessionManager::getSession(const JID& to) { + WhiteboardSession::ref WhiteboardSessionManager::getSession(const JID& to) { if (sessions_.find(to.toBare()) == sessions_.end()) { - return NULL; + return boost::shared_ptr<WhiteboardSession>(); } return sessions_[to.toBare()]; } - WhiteboardSession* WhiteboardSessionManager::createSession(const JID& to) { + OutgoingWhiteboardSession::ref WhiteboardSessionManager::createOutgoingSession(const JID& to) { JID fullJID = to; if (fullJID.isBare()) { fullJID = getFullJID(fullJID); } - WhiteboardSession* session = new WhiteboardSession(fullJID, router_); + OutgoingWhiteboardSession::ref session = boost::make_shared<OutgoingWhiteboardSession>(fullJID, router_); sessions_[to.toBare()] = session; + session->onSessionTerminateReceived.connect(boost::bind(&WhiteboardSessionManager::handleSessionTerminate, this, _1)); + session->onSessionCancelled.connect(boost::bind(&WhiteboardSessionManager::handleSessionCancelled, this, _1)); return session; } - WhiteboardSession* WhiteboardSessionManager::acceptSession(const JID& to) { - responder->sendRequestResponse(to, true); - WhiteboardSession* session = getSession(to); - if (session == NULL) { - return createSession(to); + WhiteboardSession::ref WhiteboardSessionManager::requestSession(const JID& to) { + WhiteboardSession::ref session = getSession(to); + if (!session) { + OutgoingWhiteboardSession::ref outgoingSession = createOutgoingSession(to); + outgoingSession->startSession(); + return outgoingSession; + } else { + return session; } - return session; } - void WhiteboardSessionManager::requestSession(const JID& to) { - WhiteboardSession* session = createSession(to); - session->onRequestAccepted.connect(boost::bind(&WhiteboardSessionManager::handleRequestAccepted, this, _1, _2)); - session->sendSessionRequest(); + void WhiteboardSessionManager::handleIncomingSession(IncomingWhiteboardSession::ref session) { + sessions_[session->getTo().toBare()] = session; + session->onSessionTerminateReceived.connect(boost::bind(&WhiteboardSessionManager::handleSessionTerminate, this, _1)); + session->onSessionCancelled.connect(boost::bind(&WhiteboardSessionManager::handleSessionCancelled, this, _1)); + onRequestReceived(session->getTo()); } - void WhiteboardSessionManager::cancelSession(const JID& to) { - responder->sendRequestResponse(to, false); + JID WhiteboardSessionManager::getFullJID(const JID& bareJID) { + std::vector<Presence::ref> presences = presenceOracle_->getAllPresence(bareJID); + return presences[0]->getFrom(); } - void WhiteboardSessionManager::handleRequestAccepted(const JID& contact, WhiteboardSession* session) { - onRequestAccepted(contact, session); + void WhiteboardSessionManager::handleSessionTerminate(const JID& contact) { + sessions_.erase(contact.toBare()); } - JID WhiteboardSessionManager::getFullJID(const JID& bareJID) { - std::vector<Presence::ref> presences = presenceOracle_->getAllPresence(bareJID); - return presences[0]->getFrom(); + void WhiteboardSessionManager::handleSessionCancelled(const JID& contact) { + sessions_.erase(contact.toBare()); } } |