diff options
author | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-06-06 10:04:59 (GMT) |
---|---|---|
committer | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-06-06 10:04:59 (GMT) |
commit | 8f85ae770025fd13e8f39e5097964768396f5b6b (patch) | |
tree | b4eadab32223577657dced8361c21358d6dbb24d /Swiften | |
parent | fa2edf2f9dfa77129e749373d7045b98d1dcced5 (diff) | |
download | swift-contrib-8f85ae770025fd13e8f39e5097964768396f5b6b.zip swift-contrib-8f85ae770025fd13e8f39e5097964768396f5b6b.tar.bz2 |
Moved whiteboard data handling to WhiteboardSession
Diffstat (limited to 'Swiften')
-rw-r--r-- | Swiften/Client/Client.cpp | 9 | ||||
-rw-r--r-- | Swiften/Client/Client.h | 4 | ||||
-rw-r--r-- | Swiften/SConscript | 3 | ||||
-rw-r--r-- | Swiften/Whiteboard/WhiteboardResponder.cpp | 25 | ||||
-rw-r--r-- | Swiften/Whiteboard/WhiteboardResponder.h | 25 | ||||
-rw-r--r-- | Swiften/Whiteboard/WhiteboardSession.cpp | 29 | ||||
-rw-r--r-- | Swiften/Whiteboard/WhiteboardSession.h | 31 | ||||
-rw-r--r-- | Swiften/Whiteboard/WhiteboardSessionManager.cpp | 43 | ||||
-rw-r--r-- | Swiften/Whiteboard/WhiteboardSessionManager.h | 36 |
9 files changed, 205 insertions, 0 deletions
diff --git a/Swiften/Client/Client.cpp b/Swiften/Client/Client.cpp index 4d3ee04..cc853b2 100644 --- a/Swiften/Client/Client.cpp +++ b/Swiften/Client/Client.cpp @@ -29,6 +29,7 @@ #include <Swiften/Jingle/JingleSessionManager.h> #include <Swiften/Network/NetworkFactories.h> #include <Swiften/FileTransfer/FileTransferManagerImpl.h> +#include <Swiften/Whiteboard/WhiteboardSessionManager.h> #ifndef SWIFT_EXPERIMENTAL_FT #include <Swiften/FileTransfer/UnitTest/DummyFileTransferManager.h> #endif @@ -68,9 +69,13 @@ Client::Client(const JID& jid, const SafeString& password, NetworkFactories* net jingleSessionManager = new JingleSessionManager(getIQRouter()); fileTransferManager = NULL; + + whiteboardSessionManager = new WhiteboardSessionManager(getIQRouter(), presenceOracle); } Client::~Client() { + delete whiteboardSessionManager; + delete fileTransferManager; delete jingleSessionManager; @@ -164,4 +169,8 @@ FileTransferManager* Client::getFileTransferManager() const { return fileTransferManager; } +WhiteboardSessionManager* Client::getWhiteboardSessionManager() const { + return whiteboardSessionManager; +} + } diff --git a/Swiften/Client/Client.h b/Swiften/Client/Client.h index 940a526..bf127b0 100644 --- a/Swiften/Client/Client.h +++ b/Swiften/Client/Client.h @@ -36,6 +36,7 @@ namespace Swift { class FileTransferManager; class JingleSessionManager; class FileTransferManager; + class WhiteboardSessionManager; /** * Provides the core functionality for writing XMPP client software. @@ -150,6 +151,8 @@ namespace Swift { * using setCertificateTrustChecker(). */ void setAlwaysTrustCertificates(); + + WhiteboardSessionManager* getWhiteboardSessionManager() const; public: /** @@ -185,5 +188,6 @@ namespace Swift { JingleSessionManager* jingleSessionManager; FileTransferManager* fileTransferManager; BlindCertificateTrustChecker* blindCertificateTrustChecker; + WhiteboardSessionManager* whiteboardSessionManager; }; } diff --git a/Swiften/SConscript b/Swiften/SConscript index 2e0b73b..9b31304 100644 --- a/Swiften/SConscript +++ b/Swiften/SConscript @@ -200,6 +200,9 @@ if env["SCONS_STAGE"] == "build" : "StringCodecs/SHA256.cpp", "StringCodecs/MD5.cpp", "StringCodecs/Hexify.cpp", + "Whiteboard/WhiteboardResponder.cpp", + "Whiteboard/WhiteboardSession.cpp", + "Whiteboard/WhiteboardSessionManager.cpp", ] SConscript(dirs = [ diff --git a/Swiften/Whiteboard/WhiteboardResponder.cpp b/Swiften/Whiteboard/WhiteboardResponder.cpp new file mode 100644 index 0000000..2e4905a --- /dev/null +++ b/Swiften/Whiteboard/WhiteboardResponder.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2012 Mateusz Piękos + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Whiteboard/WhiteboardResponder.h> + +#include <Swiften/Whiteboard/WhiteboardSessionManager.h> +#include <Swiften/Whiteboard/WhiteboardSession.h> +#include <Swiften/Queries/IQRouter.h> + +namespace Swift { + WhiteboardResponder::WhiteboardResponder(WhiteboardSessionManager* sessionManager, IQRouter* router) : SetResponder<WhiteboardPayload>(router), sessionManager_(sessionManager), router_(router) { + } + + bool WhiteboardResponder::handleSetRequest(const JID& from, const JID& to, const std::string& id, boost::shared_ptr<WhiteboardPayload> payload) { + sendResponse(from, id, boost::shared_ptr<WhiteboardPayload>()); + WhiteboardSession* session = sessionManager_->getSession(from.toBare()); + if (session != NULL) { + session->handleIncomingAction(payload); + } + return true; + } +} diff --git a/Swiften/Whiteboard/WhiteboardResponder.h b/Swiften/Whiteboard/WhiteboardResponder.h new file mode 100644 index 0000000..b171ef3 --- /dev/null +++ b/Swiften/Whiteboard/WhiteboardResponder.h @@ -0,0 +1,25 @@ +/* + * 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/Queries/SetResponder.h> +#include <Swiften/Elements/WhiteboardPayload.h> + +namespace Swift { + class IQRouter; + class WhiteboardSessionManager; + + class WhiteboardResponder : public SetResponder<WhiteboardPayload> { + public: + WhiteboardResponder(WhiteboardSessionManager* sessionManager, IQRouter* router); + bool handleSetRequest(const JID& from, const JID& to, const std::string& id, boost::shared_ptr<WhiteboardPayload> payload); + + private: + WhiteboardSessionManager* sessionManager_; + IQRouter* router_; + }; +} diff --git a/Swiften/Whiteboard/WhiteboardSession.cpp b/Swiften/Whiteboard/WhiteboardSession.cpp new file mode 100644 index 0000000..7d95af0 --- /dev/null +++ b/Swiften/Whiteboard/WhiteboardSession.cpp @@ -0,0 +1,29 @@ +/* + * 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/smart_ptr/make_shared.hpp> +#include <Swiften/Elements/WhiteboardPayload.h> +#include <Swiften/Queries/GenericRequest.h> + +#include <iostream> + +namespace Swift { + WhiteboardSession::WhiteboardSession(const JID& jid, IQRouter* router) : toJID_(jid), router_(router) { + } + + void WhiteboardSession::handleIncomingAction(boost::shared_ptr<WhiteboardPayload> payload) { + onDataReceived(payload->getData()); + } + + void WhiteboardSession::sendData(const std::string& data) { + boost::shared_ptr<WhiteboardPayload> payload = boost::make_shared<WhiteboardPayload>(); + payload->setData(data); + boost::shared_ptr<GenericRequest<WhiteboardPayload> > request = boost::make_shared<GenericRequest<WhiteboardPayload> >(IQ::Set, toJID_, payload, router_); + request->send(); + } +} diff --git a/Swiften/Whiteboard/WhiteboardSession.h b/Swiften/Whiteboard/WhiteboardSession.h new file mode 100644 index 0000000..c36e729 --- /dev/null +++ b/Swiften/Whiteboard/WhiteboardSession.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2012 Mateusz Piękos + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <Swiften/JID/JID.h> +#include <Swiften/Base/boost_bsignals.h> + +namespace Swift { + class IQRouter; + class WhiteboardPayload; + + class WhiteboardSession { + public: + WhiteboardSession(const JID& jid, IQRouter* router); + void handleIncomingAction(boost::shared_ptr<WhiteboardPayload> payload); + void sendData(const std::string& data); + + public: + boost::signal< void(const std::string& data)> onDataReceived; + + private: + JID toJID_; + IQRouter* router_; + }; +} diff --git a/Swiften/Whiteboard/WhiteboardSessionManager.cpp b/Swiften/Whiteboard/WhiteboardSessionManager.cpp new file mode 100644 index 0000000..3b82cda --- /dev/null +++ b/Swiften/Whiteboard/WhiteboardSessionManager.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2012 Mateusz Piękos + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + + +#include <Swiften/Whiteboard/WhiteboardSessionManager.h> + +#include <Swiften/Queries/IQRouter.h> +#include <Swiften/Whiteboard/WhiteboardSession.h> +#include <Swiften/Whiteboard/WhiteboardResponder.h> +#include <Swiften/Presence/PresenceOracle.h> + +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) == sessions_.end()) { + return NULL; + } + return sessions_[to]; + } + + WhiteboardSession* WhiteboardSessionManager::createSession(const JID& to) { + WhiteboardSession* session = new WhiteboardSession(getFullJID(to), router_); + sessions_[to] = session; + return session; + } + + JID WhiteboardSessionManager::getFullJID(const JID& bareJID) { + std::vector<Presence::ref> presences = presenceOracle_->getAllPresence(bareJID); + return presences[0]->getFrom(); + } +} diff --git a/Swiften/Whiteboard/WhiteboardSessionManager.h b/Swiften/Whiteboard/WhiteboardSessionManager.h new file mode 100644 index 0000000..93d2f19 --- /dev/null +++ b/Swiften/Whiteboard/WhiteboardSessionManager.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012 Mateusz Piękos + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <map> + +#include <Swiften/Queries/IQRouter.h> +#include <Swiften/JID/JID.h> + +namespace Swift { + class IQRouter; + class WhiteboardSession; + class WhiteboardResponder; + class PresenceOracle; + + class WhiteboardSessionManager { + public: + WhiteboardSessionManager(IQRouter* router, PresenceOracle* presenceOracle); + ~WhiteboardSessionManager(); + + WhiteboardSession* getSession(const JID& to); + WhiteboardSession* createSession(const JID& to); + private: + JID getFullJID(const JID& bareJID); + + private: + std::map<JID, WhiteboardSession*> sessions_; + IQRouter* router_; + PresenceOracle* presenceOracle_; + WhiteboardResponder* responder; + }; +} |