diff options
Diffstat (limited to 'Swiften/Whiteboard')
-rw-r--r-- | Swiften/Whiteboard/IncomingWhiteboardSession.cpp | 22 | ||||
-rw-r--r-- | Swiften/Whiteboard/IncomingWhiteboardSession.h | 24 | ||||
-rw-r--r-- | Swiften/Whiteboard/OutgoingWhiteboardSession.cpp | 24 | ||||
-rw-r--r-- | Swiften/Whiteboard/OutgoingWhiteboardSession.h | 24 | ||||
-rw-r--r-- | Swiften/Whiteboard/WhiteboardResponder.cpp | 24 | ||||
-rw-r--r-- | Swiften/Whiteboard/WhiteboardResponder.h | 2 | ||||
-rw-r--r-- | Swiften/Whiteboard/WhiteboardSession.cpp | 35 | ||||
-rw-r--r-- | Swiften/Whiteboard/WhiteboardSession.h | 15 | ||||
-rw-r--r-- | Swiften/Whiteboard/WhiteboardSessionManager.cpp | 48 | ||||
-rw-r--r-- | Swiften/Whiteboard/WhiteboardSessionManager.h | 21 |
10 files changed, 173 insertions, 66 deletions
diff --git a/Swiften/Whiteboard/IncomingWhiteboardSession.cpp b/Swiften/Whiteboard/IncomingWhiteboardSession.cpp new file mode 100644 index 0000000..92a86a1 --- /dev/null +++ b/Swiften/Whiteboard/IncomingWhiteboardSession.cpp @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2012 Mateusz Piękos + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Whiteboard/IncomingWhiteboardSession.h> +#include <Swiften/Elements/WhiteboardPayload.h> + +namespace Swift { + IncomingWhiteboardSession::IncomingWhiteboardSession(const JID& jid, IQRouter* router) : WhiteboardSession(jid, router) { + } + + IncomingWhiteboardSession::~IncomingWhiteboardSession() { + } + + void IncomingWhiteboardSession::accept() { + boost::shared_ptr<WhiteboardPayload> payload = boost::make_shared<WhiteboardPayload>(WhiteboardPayload::SessionAccept); + boost::shared_ptr<GenericRequest<WhiteboardPayload> > request = boost::make_shared<GenericRequest<WhiteboardPayload> >(IQ::Set, toJID_, payload, router_); + request->send(); + } +} diff --git a/Swiften/Whiteboard/IncomingWhiteboardSession.h b/Swiften/Whiteboard/IncomingWhiteboardSession.h new file mode 100644 index 0000000..3b15a49 --- /dev/null +++ b/Swiften/Whiteboard/IncomingWhiteboardSession.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2012 Mateusz Piękos + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Whiteboard/WhiteboardSession.h> + +#include <boost/shared_ptr.hpp> + +#pragma once + +namespace Swift { + class IncomingWhiteboardSession : public WhiteboardSession { + public: + typedef boost::shared_ptr<IncomingWhiteboardSession> ref; + + public: + IncomingWhiteboardSession(const JID& jid, IQRouter* router); + ~IncomingWhiteboardSession(); + + void accept(); + }; +} diff --git a/Swiften/Whiteboard/OutgoingWhiteboardSession.cpp b/Swiften/Whiteboard/OutgoingWhiteboardSession.cpp new file mode 100644 index 0000000..2693fcd --- /dev/null +++ b/Swiften/Whiteboard/OutgoingWhiteboardSession.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2012 Mateusz Piękos + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Whiteboard/OutgoingWhiteboardSession.h> + +#include <boost/bind.hpp> +#include <Swiften/Elements/WhiteboardPayload.h> + +namespace Swift { + OutgoingWhiteboardSession::OutgoingWhiteboardSession(const JID& jid, IQRouter* router) : WhiteboardSession(jid, router) { + } + + OutgoingWhiteboardSession::~OutgoingWhiteboardSession() { + } + + void OutgoingWhiteboardSession::startSession() { + boost::shared_ptr<WhiteboardPayload> payload = boost::make_shared<WhiteboardPayload>(WhiteboardPayload::SessionRequest); + boost::shared_ptr<GenericRequest<WhiteboardPayload> > request = boost::make_shared<GenericRequest<WhiteboardPayload> >(IQ::Set, toJID_, payload, router_); + request->send(); + } +} diff --git a/Swiften/Whiteboard/OutgoingWhiteboardSession.h b/Swiften/Whiteboard/OutgoingWhiteboardSession.h new file mode 100644 index 0000000..dfbd200 --- /dev/null +++ b/Swiften/Whiteboard/OutgoingWhiteboardSession.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2012 Mateusz Piękos + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <Swiften/Whiteboard/WhiteboardSession.h> + +#include <boost/shared_ptr.hpp> +#include <Swiften/Queries/GenericRequest.h> + +namespace Swift { + class OutgoingWhiteboardSession : public WhiteboardSession { + public: + typedef boost::shared_ptr<OutgoingWhiteboardSession> ref; + + public: + OutgoingWhiteboardSession(const JID& jid, IQRouter* router); + virtual ~OutgoingWhiteboardSession(); + void startSession(); + }; +} diff --git a/Swiften/Whiteboard/WhiteboardResponder.cpp b/Swiften/Whiteboard/WhiteboardResponder.cpp index 8a1b290..c947aec 100644 --- a/Swiften/Whiteboard/WhiteboardResponder.cpp +++ b/Swiften/Whiteboard/WhiteboardResponder.cpp @@ -7,6 +7,7 @@ #include <Swiften/Whiteboard/WhiteboardResponder.h> #include <Swiften/Whiteboard/WhiteboardSessionManager.h> +#include <Swiften/Whiteboard/IncomingWhiteboardSession.h> #include <Swiften/Whiteboard/WhiteboardSession.h> #include <Swiften/Queries/IQRouter.h> @@ -16,27 +17,20 @@ namespace Swift { bool WhiteboardResponder::handleSetRequest(const JID& from, const JID& to, const std::string& id, boost::shared_ptr<WhiteboardPayload> payload) { if (payload->getType() == WhiteboardPayload::SessionRequest) { - sessionManager_->onRequestReceived(from); - sessionRequests_[from] = id; + if (sessionManager_->getSession(from.toBare())) { + sendError(from, id, ErrorPayload::Conflict, ErrorPayload::Cancel); + } else { + sendResponse(from, id, boost::shared_ptr<WhiteboardPayload>()); + IncomingWhiteboardSession::ref session = boost::make_shared<IncomingWhiteboardSession>(from, router_); + sessionManager_->handleIncomingSession(session); + } } else { sendResponse(from, id, boost::shared_ptr<WhiteboardPayload>()); - WhiteboardSession* session = sessionManager_->getSession(from.toBare()); + WhiteboardSession::ref session = sessionManager_->getSession(from.toBare()); if (session != NULL) { session->handleIncomingAction(payload); } } return true; } - - void WhiteboardResponder::sendRequestResponse(const JID& contact, bool accepted) { - if (sessionRequests_.find(contact) == sessionRequests_.end()) { - return; - } - if (accepted ) { - sendResponse(contact, sessionRequests_[contact], boost::shared_ptr<WhiteboardPayload>()); - } else { - sendError(contact, sessionRequests_[contact], ErrorPayload::Conflict, ErrorPayload::Cancel); - } - sessionRequests_.erase(contact); - } } diff --git a/Swiften/Whiteboard/WhiteboardResponder.h b/Swiften/Whiteboard/WhiteboardResponder.h index d1b712d..b171ef3 100644 --- a/Swiften/Whiteboard/WhiteboardResponder.h +++ b/Swiften/Whiteboard/WhiteboardResponder.h @@ -17,10 +17,8 @@ namespace Swift { public: WhiteboardResponder(WhiteboardSessionManager* sessionManager, IQRouter* router); bool handleSetRequest(const JID& from, const JID& to, const std::string& id, boost::shared_ptr<WhiteboardPayload> payload); - void sendRequestResponse(const JID& contact, bool accepted); private: - std::map<JID, std::string> sessionRequests_; WhiteboardSessionManager* sessionManager_; IQRouter* router_; }; diff --git a/Swiften/Whiteboard/WhiteboardSession.cpp b/Swiften/Whiteboard/WhiteboardSession.cpp index 859f2cd..bfef7c3 100644 --- a/Swiften/Whiteboard/WhiteboardSession.cpp +++ b/Swiften/Whiteboard/WhiteboardSession.cpp @@ -6,7 +6,6 @@ #include <Swiften/Whiteboard/WhiteboardSession.h> -#include <boost/bind.hpp> #include <boost/smart_ptr/make_shared.hpp> #include <Swiften/Elements/WhiteboardPayload.h> #include <Swiften/Elements/ErrorPayload.h> @@ -17,8 +16,23 @@ namespace Swift { WhiteboardSession::WhiteboardSession(const JID& jid, IQRouter* router) : toJID_(jid), router_(router) { } + WhiteboardSession::~WhiteboardSession() { + } + void WhiteboardSession::handleIncomingAction(boost::shared_ptr<WhiteboardPayload> payload) { - onDataReceived(payload->getData()); + if (payload->getType() == WhiteboardPayload::SessionTerminate) { + onSessionTerminateReceived(toJID_); + return; + } + + switch (payload->getType()) { + case WhiteboardPayload::Data: + onDataReceived(payload->getData()); + break; + case WhiteboardPayload::SessionAccept: + onRequestAccepted(toJID_); + break; + } } void WhiteboardSession::sendData(const std::string& data) { @@ -28,17 +42,14 @@ namespace Swift { request->send(); } - void WhiteboardSession::sendSessionRequest() { - boost::shared_ptr<WhiteboardPayload> payload = boost::make_shared<WhiteboardPayload>(WhiteboardPayload::SessionRequest); - sessionRequest = new GenericRequest<WhiteboardPayload>(IQ::Set, toJID_, payload, router_); - sessionRequest->onResponse.connect(boost::bind(&WhiteboardSession::handleSessionRequestResponse, this, _1, _2)); - sessionRequest->send(); + void WhiteboardSession::cancel() { + 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_); } - void WhiteboardSession::handleSessionRequestResponse(boost::shared_ptr<WhiteboardPayload> whiteboardPayload, boost::shared_ptr<ErrorPayload> errorPayload) { - if (errorPayload.get() == 0) { - onRequestAccepted(toJID_, this); - } - delete sessionRequest; + const JID& WhiteboardSession::getTo() const { + return toJID_; } } diff --git a/Swiften/Whiteboard/WhiteboardSession.h b/Swiften/Whiteboard/WhiteboardSession.h index 14d6778..7aa67ca 100644 --- a/Swiften/Whiteboard/WhiteboardSession.h +++ b/Swiften/Whiteboard/WhiteboardSession.h @@ -19,19 +19,24 @@ namespace Swift { class WhiteboardSession { public: + typedef boost::shared_ptr<WhiteboardSession> ref; + + public: WhiteboardSession(const JID& jid, IQRouter* router); + virtual ~WhiteboardSession(); void handleIncomingAction(boost::shared_ptr<WhiteboardPayload> payload); void sendData(const std::string& data); - void sendSessionRequest(); - void handleSessionRequestResponse(boost::shared_ptr<WhiteboardPayload> whiteboardPayload, boost::shared_ptr<ErrorPayload> errorPayload); + void cancel(); + const JID& getTo() const; public: boost::signal< void(const std::string& data)> onDataReceived; - boost::signal< void(const JID& contact, WhiteboardSession* session)> onRequestAccepted; + boost::signal< void(const JID& contact)> onSessionTerminateReceived; + boost::signal< void(const JID& contact)> onRequestAccepted; + boost::signal< void(const JID& contact)> onSessionCancelled; - private: + protected: JID toJID_; IQRouter* router_; - GenericRequest<WhiteboardPayload>* sessionRequest; }; } 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()); } } diff --git a/Swiften/Whiteboard/WhiteboardSessionManager.h b/Swiften/Whiteboard/WhiteboardSessionManager.h index 3cd3aab..d2a59e0 100644 --- a/Swiften/Whiteboard/WhiteboardSessionManager.h +++ b/Swiften/Whiteboard/WhiteboardSessionManager.h @@ -11,34 +11,35 @@ #include <Swiften/Queries/IQRouter.h> #include <Swiften/JID/JID.h> #include <Swiften/Base/boost_bsignals.h> +#include <Swiften/Whiteboard/WhiteboardSession.h> +#include <Swiften/Whiteboard/IncomingWhiteboardSession.h> +#include <Swiften/Whiteboard/OutgoingWhiteboardSession.h> namespace Swift { class IQRouter; - class WhiteboardSession; class WhiteboardResponder; class PresenceOracle; class WhiteboardSessionManager { + friend class WhiteboardResponder; public: WhiteboardSessionManager(IQRouter* router, PresenceOracle* presenceOracle); ~WhiteboardSessionManager(); - - WhiteboardSession* getSession(const JID& to); - WhiteboardSession* acceptSession(const JID& to); - void requestSession(const JID& to); - void cancelSession(const JID& to); - void handleRequestAccepted(const JID& contact, WhiteboardSession* session); + WhiteboardSession::ref getSession(const JID& to); + WhiteboardSession::ref requestSession(const JID& to); public: boost::signal< void (const JID&)> onRequestReceived; - boost::signal< void (const JID&, WhiteboardSession*)> onRequestAccepted; private: JID getFullJID(const JID& bareJID); - WhiteboardSession* createSession(const JID& to); + OutgoingWhiteboardSession::ref createOutgoingSession(const JID& to); + void handleIncomingSession(IncomingWhiteboardSession::ref session); + void handleSessionTerminate(const JID& contact); + void handleSessionCancelled(const JID& contact); private: - std::map<JID, WhiteboardSession*> sessions_; + std::map<JID, boost::shared_ptr<WhiteboardSession> > sessions_; IQRouter* router_; PresenceOracle* presenceOracle_; WhiteboardResponder* responder; |