loolwsd/ChildSession.cpp | 10 ++++------ loolwsd/ChildSession.hpp | 27 ++++++++++++++++++++------- loolwsd/LOOLKit.cpp | 13 +++++-------- 3 files changed, 29 insertions(+), 21 deletions(-)
New commits: commit 5af1f18e364068e4b0dc1cac5a71b6dc5afd3bb4 Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> Date: Sun Aug 14 18:02:51 2016 -0400 loolwsd: convert function-object callbacks to abstract interface Change-Id: Ia2e832659f8deddd55b8be6507c2d7406f110085 Reviewed-on: https://gerrit.libreoffice.org/28133 Reviewed-by: Ashod Nakashian <ashnak...@gmail.com> Tested-by: Ashod Nakashian <ashnak...@gmail.com> diff --git a/loolwsd/ChildSession.cpp b/loolwsd/ChildSession.cpp index 07d57ff..d712c07 100644 --- a/loolwsd/ChildSession.cpp +++ b/loolwsd/ChildSession.cpp @@ -35,14 +35,12 @@ std::recursive_mutex ChildSession::Mutex; ChildSession::ChildSession(const std::string& id, std::shared_ptr<WebSocket> ws, const std::string& jailId, - OnLoadCallback onLoad, - OnUnloadCallback onUnload) : + IDocumentManager& docManager) : LOOLSession(id, Kind::ToMaster, ws), _multiView(std::getenv("LOK_VIEW_CALLBACK")), _jailId(jailId), _viewId(0), - _onLoad(std::move(onLoad)), - _onUnload(std::move(onUnload)) + _docManager(docManager) { Log::info("ChildSession ctor [" + getName() + "]."); } @@ -65,7 +63,7 @@ void ChildSession::disconnect() if (_multiView && _loKitDocument) _loKitDocument->setView(_viewId); - _onUnload(getId()); + _docManager.onUnload(getId()); LOOLSession::disconnect(); } @@ -334,7 +332,7 @@ bool ChildSession::loadDocument(const char * /*buffer*/, int /*length*/, StringT std::unique_lock<std::recursive_mutex> lock(Mutex); - _loKitDocument = _onLoad(getId(), _jailedFilePath, _docPassword, renderOpts, _haveDocPassword); + _loKitDocument = _docManager.onLoad(getId(), _jailedFilePath, _docPassword, renderOpts, _haveDocPassword); if (!_loKitDocument) { Log::error("Failed to get LoKitDocument instance."); diff --git a/loolwsd/ChildSession.hpp b/loolwsd/ChildSession.hpp index ce58a4e..3cb3202 100644 --- a/loolwsd/ChildSession.hpp +++ b/loolwsd/ChildSession.hpp @@ -19,9 +19,24 @@ #include "LOOLSession.hpp" #include "LibreOfficeKit.hpp" -class CallbackWorker; -typedef std::function<std::shared_ptr<lok::Document>(const std::string&, const std::string&, const std::string&, const std::string&, bool)> OnLoadCallback; -typedef std::function<void(const std::string&)> OnUnloadCallback; +/// An abstract interface that defines the +/// DocumentManager interface and functionality. +class IDocumentManager +{ +public: + /// Reqest loading a document, or a new view, if one exists. + virtual + std::shared_ptr<lok::Document> onLoad(const std::string& sessionId, + const std::string& jailedFilePath, + const std::string& docPassword, + const std::string& renderOpts, + const bool haveDocPassword) = 0; + + /// Unload a client session, which unloads the document + /// if it is the last and only. + virtual + void onUnload(const std::string& sessionId) = 0; +}; /// Represents a client session, with the socket end-point, /// and handles all incoming UI traffic. @@ -38,8 +53,7 @@ public: ChildSession(const std::string& id, std::shared_ptr<Poco::Net::WebSocket> ws, const std::string& jailId, - OnLoadCallback onLoad, - OnUnloadCallback onUnload); + IDocumentManager& docManager); virtual ~ChildSession(); bool getStatus(const char *buffer, int length); @@ -87,8 +101,7 @@ private: /// View ID, returned by createView() or 0 by default. int _viewId; std::map<int, std::string> _lastDocStates; - OnLoadCallback _onLoad; - OnUnloadCallback _onUnload; + IDocumentManager& _docManager; /// Synchronize _loKitDocument acess. /// This should be owned by Document. diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index a05c7e1..e4fdb44 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -367,7 +367,7 @@ public: /// per process. But for security reasons don't. /// However, we could have a loolkit instance /// per user or group of users (a trusted circle). -class Document : public Runnable +class Document : public Runnable, public IDocumentManager { public: /// We have two types of password protected documents @@ -490,10 +490,7 @@ public: auto ws = std::make_shared<WebSocket>(cs, request, response); ws->setReceiveTimeout(0); - auto session = std::make_shared<ChildSession>(sessionId, ws, _jailId, - [this](const std::string& id, const std::string& uri, const std::string& docPassword, - const std::string& renderOpts, bool haveDocPassword) { return onLoad(id, uri, docPassword, renderOpts, haveDocPassword); }, - [this](const std::string& id) { onUnload(id); }); + auto session = std::make_shared<ChildSession>(sessionId, ws, _jailId, *this); auto thread = std::make_shared<Connection>(session, ws); const auto aInserted = _connections.emplace(intSessionId, thread); @@ -826,7 +823,7 @@ private: const std::string& uri, const std::string& docPassword, const std::string& renderOpts, - bool haveDocPassword) + const bool haveDocPassword) override { Log::info("Session " + sessionId + " is loading. " + std::to_string(_clientViews) + " views loaded."); @@ -864,7 +861,7 @@ private: return _loKitDocument; } - void onUnload(const std::string& sessionId) + void onUnload(const std::string& sessionId) override { Log::info("Unloading [" + sessionId + "]."); const unsigned intSessionId = Util::decodeId(sessionId); @@ -902,7 +899,7 @@ private: const std::string& uri, const std::string& docPassword, const std::string& renderOpts, - bool haveDocPassword) + const bool haveDocPassword) { const unsigned intSessionId = Util::decodeId(sessionId); const auto it = _connections.find(intSessionId); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits