/* * 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 #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* WhiteboardSessionManager::getSession(const JID& to) { if (sessions_.find(to.toBare()) == sessions_.end()) { return NULL; } return sessions_[to.toBare()]; } WhiteboardSession* WhiteboardSessionManager::createSession(const JID& to) { JID fullJID = to; if (fullJID.isBare()) { fullJID = getFullJID(fullJID); } WhiteboardSession* session = new WhiteboardSession(fullJID, router_); sessions_[to.toBare()] = session; return session; } WhiteboardSession* WhiteboardSessionManager::acceptSession(const JID& to) { responder->sendRequestResponse(to, true); WhiteboardSession* session = getSession(to); if (session == NULL) { return createSession(to); } 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::cancelSession(const JID& to) { responder->sendRequestResponse(to, false); } void WhiteboardSessionManager::handleRequestAccepted(const JID& contact, WhiteboardSession* session) { onRequestAccepted(contact, session); } JID WhiteboardSessionManager::getFullJID(const JID& bareJID) { std::vector presences = presenceOracle_->getAllPresence(bareJID); return presences[0]->getFrom(); } }