From 8f85ae770025fd13e8f39e5097964768396f5b6b Mon Sep 17 00:00:00 2001 From: Mateusz Piekos Date: Wed, 6 Jun 2012 12:04:59 +0200 Subject: Moved whiteboard data handling to WhiteboardSession diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index d9bb249..b3457d8 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -320,7 +320,7 @@ void MainController::handleConnected() { userSearchControllerChat_ = new UserSearchController(UserSearchController::StartChat, jid_, uiEventStream_, client_->getVCardManager(), uiFactory_, client_->getIQRouter(), rosterController_); userSearchControllerAdd_ = new UserSearchController(UserSearchController::AddContact, jid_, uiEventStream_, client_->getVCardManager(), uiFactory_, client_->getIQRouter(), rosterController_); adHocManager_ = new AdHocManager(JID(boundJID_.getDomain()), uiFactory_, client_->getIQRouter(), uiEventStream_, rosterController_->getWindow()); - whiteboardManager_ = new WhiteboardManager(uiFactory_, uiEventStream_, client_->getStanzaChannel()); + whiteboardManager_ = new WhiteboardManager(uiFactory_, uiEventStream_, client_->getStanzaChannel(), client_->getWhiteboardSessionManager()); } loginWindow_->setIsLoggingIn(false); diff --git a/Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h b/Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h index 8b52ee1..7e0fe81 100644 --- a/Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h +++ b/Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h @@ -6,16 +6,14 @@ #pragma once -#include "Swiften/JID/JID.h" - namespace Swift { + class WhiteboardSession; class WhiteboardWindow; - class StanzaChannel; class WhiteboardWindowFactory { public : virtual ~WhiteboardWindowFactory() {}; - virtual WhiteboardWindow* createWhiteboardWindow(StanzaChannel* stanzaChannel, const JID& jid) = 0; + virtual WhiteboardWindow* createWhiteboardWindow(WhiteboardSession* whiteboardSession) = 0; }; } diff --git a/Swift/Controllers/WhiteboardManager.cpp b/Swift/Controllers/WhiteboardManager.cpp index 6237426..86d70d1 100644 --- a/Swift/Controllers/WhiteboardManager.cpp +++ b/Swift/Controllers/WhiteboardManager.cpp @@ -11,11 +11,12 @@ #include #include #include +#include namespace Swift { typedef std::pair JIDWhiteboardWindowPair; - WhiteboardManager::WhiteboardManager(WhiteboardWindowFactory* whiteboardWindowFactory, UIEventStream* uiEventStream, StanzaChannel* stanzaChannel) : whiteboardWindowFactory_(whiteboardWindowFactory), uiEventStream_(uiEventStream), stanzaChannel_(stanzaChannel) { + WhiteboardManager::WhiteboardManager(WhiteboardWindowFactory* whiteboardWindowFactory, UIEventStream* uiEventStream, StanzaChannel* stanzaChannel, WhiteboardSessionManager* whiteboardSessionManager) : whiteboardWindowFactory_(whiteboardWindowFactory), uiEventStream_(uiEventStream), stanzaChannel_(stanzaChannel), whiteboardSessionManager_(whiteboardSessionManager) { uiEventConnection_ = uiEventStream_->onUIEvent.connect(boost::bind(&WhiteboardManager::handleUIEvent, this, _1)); } @@ -33,7 +34,8 @@ namespace Swift { } WhiteboardWindow* WhiteboardManager::createNewWhiteboardWindow(const JID& contact) { - WhiteboardWindow *window = whiteboardWindowFactory_->createWhiteboardWindow(stanzaChannel_, contact); + WhiteboardSession* session = whiteboardSessionManager_->createSession(contact); + WhiteboardWindow *window = whiteboardWindowFactory_->createWhiteboardWindow(session); whiteboardWindows_[contact] = window; return window; } diff --git a/Swift/Controllers/WhiteboardManager.h b/Swift/Controllers/WhiteboardManager.h index c28492c..a5a3dd0 100644 --- a/Swift/Controllers/WhiteboardManager.h +++ b/Swift/Controllers/WhiteboardManager.h @@ -19,10 +19,11 @@ namespace Swift { class StanzaChannel; + class WhiteboardSessionManager; class WhiteboardManager { public: - WhiteboardManager(WhiteboardWindowFactory* whiteboardWindowFactory, UIEventStream* uiEventStream, StanzaChannel* stanzaChannel); + WhiteboardManager(WhiteboardWindowFactory* whiteboardWindowFactory, UIEventStream* uiEventStream, StanzaChannel* stanzaChannel, WhiteboardSessionManager* whiteboardSessionManager); ~WhiteboardManager(); WhiteboardWindow* getWhiteboardWindowOrCreate(const JID& contact); @@ -33,9 +34,10 @@ namespace Swift { private: std::map whiteboardWindows_; - UIEventStream* uiEventStream_; WhiteboardWindowFactory* whiteboardWindowFactory_; + UIEventStream* uiEventStream_; boost::bsignals::scoped_connection uiEventConnection_; StanzaChannel* stanzaChannel_; + WhiteboardSessionManager* whiteboardSessionManager_; }; } diff --git a/Swift/QtUI/QtUIFactory.cpp b/Swift/QtUI/QtUIFactory.cpp index d127791..e0fc532 100644 --- a/Swift/QtUI/QtUIFactory.cpp +++ b/Swift/QtUI/QtUIFactory.cpp @@ -28,7 +28,7 @@ #include "Whiteboard/QtWhiteboardWindow.h" #include #include -#include +#include namespace Swift { @@ -136,8 +136,8 @@ ContactEditWindow* QtUIFactory::createContactEditWindow() { return new QtContactEditWindow(); } -WhiteboardWindow* QtUIFactory::createWhiteboardWindow(StanzaChannel* stanzaChannel, const JID& jid) { - return new QtWhiteboardWindow(stanzaChannel, jid); +WhiteboardWindow* QtUIFactory::createWhiteboardWindow(WhiteboardSession* whiteboardSession) { + return new QtWhiteboardWindow(whiteboardSession); } void QtUIFactory::createAdHocCommandWindow(boost::shared_ptr command) { diff --git a/Swift/QtUI/QtUIFactory.h b/Swift/QtUI/QtUIFactory.h index 0c337f4..951b19c 100644 --- a/Swift/QtUI/QtUIFactory.h +++ b/Swift/QtUI/QtUIFactory.h @@ -24,7 +24,7 @@ namespace Swift { class QtChatWindowFactory; class QtChatWindow; class TimerFactory; - class StanzaChannel; + class WhiteboardSession; class QtUIFactory : public QObject, public UIFactory { Q_OBJECT @@ -43,7 +43,7 @@ namespace Swift { virtual ProfileWindow* createProfileWindow(); virtual ContactEditWindow* createContactEditWindow(); virtual FileTransferListWidget* createFileTransferListWidget(); - virtual WhiteboardWindow* createWhiteboardWindow(StanzaChannel* stanzaChannel, const JID& jid); + virtual WhiteboardWindow* createWhiteboardWindow(WhiteboardSession* whiteboardSession); virtual void createAdHocCommandWindow(boost::shared_ptr command); private slots: diff --git a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp index b991e52..e0e68ba 100644 --- a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp +++ b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp @@ -10,13 +10,13 @@ #include -#include +#include #include using namespace std; namespace Swift { - QtWhiteboardWindow::QtWhiteboardWindow(StanzaChannel* stanzaChannel, const JID& jid) : QWidget(), stanzaChannel_(stanzaChannel), jid_(jid) { + QtWhiteboardWindow::QtWhiteboardWindow(WhiteboardSession* whiteboardSession) : QWidget(), whiteboardSession_(whiteboardSession) { layout = new QVBoxLayout(this); hLayout = new QHBoxLayout; sidebarLayout = new QVBoxLayout; @@ -121,14 +121,7 @@ namespace Swift { layout->addLayout(hLayout); this->setLayout(layout); - stanzaChannel_->onMessageReceived.connect(boost::bind(&QtWhiteboardWindow::handleIncommingMessage, this, _1)); - } - - void QtWhiteboardWindow::handleIncommingMessage(boost::shared_ptr message) { - boost::shared_ptr wb = message->getPayload(); - if(wb) { - addItem(wb->getData()); - } + whiteboardSession_->onDataReceived.connect(boost::bind(&QtWhiteboardWindow::addItem, this, _1)); } void QtWhiteboardWindow::addItem(const std::string& item) { @@ -259,13 +252,14 @@ namespace Swift { } if (!serialized.empty()) { cout << "serialized: " << serialized << endl; - boost::shared_ptr mes(new Message()); +/* boost::shared_ptr mes(new Message()); mes->setTo(jid_); boost::shared_ptr wbPayload(new WhiteboardPayload); wbPayload->setData(serialized); // mes->setType(Swift::Message::Chat); mes->addPayload(wbPayload); - stanzaChannel_->sendMessage(mes); +// stanzaChannel_->sendMessage(mes);*/ + whiteboardSession_->sendData(serialized); } } diff --git a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h index 9ced322..f1a9ed5 100644 --- a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h +++ b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h @@ -8,7 +8,6 @@ #include #include -#include "Swiften/JID/JID.h" #include #include @@ -25,14 +24,13 @@ #include "GView.h" namespace Swift { - class StanzaChannel; + class WhiteboardSession; class QtWhiteboardWindow : public QWidget, public WhiteboardWindow { Q_OBJECT; public: - QtWhiteboardWindow(StanzaChannel *stanzaChannel, const JID& jid); - void handleIncommingMessage(boost::shared_ptr message); + QtWhiteboardWindow(WhiteboardSession* whiteboardSession); void addItem(const std::string& item); void show(); @@ -50,6 +48,7 @@ namespace Swift { void setPolygonMode(); void setSelectMode(); void handleLastItemChanged(QGraphicsItem* item); + private: QGraphicsScene* scene; GView* graphicsView; @@ -73,7 +72,6 @@ namespace Swift { QToolButton* polygonButton; QToolButton* selectButton; - StanzaChannel* stanzaChannel_; - JID jid_; + WhiteboardSession* whiteboardSession_; }; } 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 #include #include +#include #ifndef SWIFT_EXPERIMENTAL_FT #include #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 + +#include +#include +#include + +namespace Swift { + WhiteboardResponder::WhiteboardResponder(WhiteboardSessionManager* sessionManager, IQRouter* router) : SetResponder(router), sessionManager_(sessionManager), router_(router) { + } + + bool WhiteboardResponder::handleSetRequest(const JID& from, const JID& to, const std::string& id, boost::shared_ptr payload) { + sendResponse(from, id, boost::shared_ptr()); + 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 +#include + +namespace Swift { + class IQRouter; + class WhiteboardSessionManager; + + class WhiteboardResponder : public SetResponder { + public: + WhiteboardResponder(WhiteboardSessionManager* sessionManager, IQRouter* router); + bool handleSetRequest(const JID& from, const JID& to, const std::string& id, boost::shared_ptr 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 + +#include +#include +#include + +#include + +namespace Swift { + WhiteboardSession::WhiteboardSession(const JID& jid, IQRouter* router) : toJID_(jid), router_(router) { + } + + void WhiteboardSession::handleIncomingAction(boost::shared_ptr payload) { + onDataReceived(payload->getData()); + } + + void WhiteboardSession::sendData(const std::string& data) { + boost::shared_ptr payload = boost::make_shared(); + payload->setData(data); + boost::shared_ptr > request = boost::make_shared >(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 + +#include +#include + +namespace Swift { + class IQRouter; + class WhiteboardPayload; + + class WhiteboardSession { + public: + WhiteboardSession(const JID& jid, IQRouter* router); + void handleIncomingAction(boost::shared_ptr 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 + +#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) == 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 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 + +#include +#include + +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 sessions_; + IQRouter* router_; + PresenceOracle* presenceOracle_; + WhiteboardResponder* responder; + }; +} -- cgit v0.10.2-6-g49f6