/* * Copyright (c) 2012 Mateusz Piękos * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ #include #include #include #include #include namespace Swift { WhiteboardSessionManager::WhiteboardSessionManager(IQRouter* router, PresenceOracle* presenceOracle) : router_(router), presenceOracle_(presenceOracle) { responder = new WhiteboardResponder(this, router); responder->start(); } WhiteboardSessionManager::~WhiteboardSessionManager() { responder->stop(); delete responder; } WhiteboardSession::ref WhiteboardSessionManager::getSession(const JID& to) { if (sessions_.find(to.toBare()) == sessions_.end()) { return boost::shared_ptr(); } return sessions_[to.toBare()]; } OutgoingWhiteboardSession::ref WhiteboardSessionManager::createOutgoingSession(const JID& to) { JID fullJID = to; if (fullJID.isBare()) { fullJID = getFullJID(fullJID); } OutgoingWhiteboardSession::ref session = boost::make_shared(fullJID, router_); sessions_[to.toBare()] = session; session->onSessionTerminateReceived.connect(boost::bind(&WhiteboardSessionManager::handleSessionTerminate, this, _1)); session->onSessionCancelled.connect(boost::bind(&WhiteboardSessionManager::handleSessionCancel, this, _1)); session->onRequestAccepted.connect(boost::bind(&WhiteboardSessionManager::handleSessionAccept, this, _1)); return session; } WhiteboardSession::ref WhiteboardSessionManager::requestSession(const JID& to) { WhiteboardSession::ref session = getSession(to); if (!session) { OutgoingWhiteboardSession::ref outgoingSession = createOutgoingSession(to); outgoingSession->startSession(); onSessionRequest(to, true); return outgoingSession; } else { return session; } } 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::handleSessionCancel, this, _1)); onSessionRequest(session->getTo(), false); } JID WhiteboardSessionManager::getFullJID(const JID& bareJID) { std::vector presences = presenceOracle_->getAllPresence(bareJID); return presences[0]->getFrom(); } void WhiteboardSessionManager::handleSessionTerminate(const JID& contact) { sessions_.erase(contact.toBare()); onSessionTerminate(contact); } void WhiteboardSessionManager::handleSessionCancel(const JID& contact) { sessions_.erase(contact.toBare()); onSessionTerminate(contact); } void WhiteboardSessionManager::handleSessionAccept(const JID& contact) { onRequestAccepted(contact); } }