loolwsd/ChildProcessSession.cpp | 7 +++++-- loolwsd/ChildProcessSession.hpp | 4 ++-- loolwsd/LOOLKit.cpp | 26 ++++++++++++++++++++------ 3 files changed, 27 insertions(+), 10 deletions(-)
New commits: commit 96c7fdd0f8427f70d9ab04128a5c667868bd0bdb Author: Ashod Nakashian <[email protected]> Date: Sun Jan 10 10:33:58 2016 -0500 loolwsd: onUnload takes Session ID Change-Id: I63dd21441a11981f09f6b4c2d36560094fc81f1f Reviewed-on: https://gerrit.libreoffice.org/21327 Reviewed-by: Ashod Nakashian <[email protected]> Tested-by: Ashod Nakashian <[email protected]> diff --git a/loolwsd/ChildProcessSession.cpp b/loolwsd/ChildProcessSession.cpp index 4fa08a9..9424769 100644 --- a/loolwsd/ChildProcessSession.cpp +++ b/loolwsd/ChildProcessSession.cpp @@ -46,7 +46,7 @@ ChildProcessSession::ChildProcessSession(const std::string& id, LibreOfficeKitDocument * loKitDocument, const std::string& jailId, std::function<LibreOfficeKitDocument*(const std::string&, const std::string&)> onLoad, - std::function<void(int)> onUnload) : + std::function<void(const std::string&)> onUnload) : LOOLSession(id, Kind::ToMaster, ws), _loKitDocument(loKitDocument), _multiView(getenv("LOK_VIEW_CALLBACK")), @@ -66,7 +66,10 @@ ChildProcessSession::~ChildProcessSession() Poco::Mutex::ScopedLock lock(_mutex); - _onUnload(_viewId); + if (_multiView) + _loKitDocument->pClass->setView(_loKitDocument, _viewId); + + _onUnload(getId()); } bool ChildProcessSession::_handleInput(const char *buffer, int length) diff --git a/loolwsd/ChildProcessSession.hpp b/loolwsd/ChildProcessSession.hpp index 9b5dcfa..4313d81 100644 --- a/loolwsd/ChildProcessSession.hpp +++ b/loolwsd/ChildProcessSession.hpp @@ -35,7 +35,7 @@ public: LibreOfficeKitDocument * loKitDocument, const std::string& jailId, std::function<LibreOfficeKitDocument*(const std::string&, const std::string&)> onLoad, - std::function<void(int)> onUnload); + std::function<void(const std::string&)> onUnload); virtual ~ChildProcessSession(); virtual bool getStatus(const char *buffer, int length) override; @@ -88,7 +88,7 @@ private: int _viewId; int _clientPart; std::function<LibreOfficeKitDocument*(const std::string&, const std::string&)> _onLoad; - std::function<void(int)> _onUnload; + std::function<void(const std::string&)> _onUnload; }; #endif diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 0dc3fd6..35fc483 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -317,7 +317,7 @@ public: Connection(LibreOfficeKit *loKit, LibreOfficeKitDocument *loKitDocument, const std::string& jailId, const std::string& sessionId, std::function<LibreOfficeKitDocument*(const std::string&, const std::string&)> onLoad, - std::function<void(int)> onUnload) : + std::function<void(const std::string&)> onUnload) : _loKit(loKit), _loKitDocument(loKitDocument), _jailId(jailId), @@ -452,7 +452,7 @@ private: std::shared_ptr<ChildProcessSession> _session; volatile bool _stop; std::function<LibreOfficeKitDocument*(const std::string&, const std::string&)> _onLoad; - std::function<void(int)> _onUnload; + std::function<void(const std::string&)> _onUnload; std::shared_ptr<WebSocket> _ws; }; @@ -552,7 +552,7 @@ public: auto thread = std::make_shared<Connection>(_loKit, _loKitDocument, _jailId, sessionId, [this](const std::string& id, const std::string& uri) { return onLoad(id, uri); }, - [this](const int viewId) { onUnload(viewId); }); + [this](const std::string& id) { onUnload(id); }); const auto aInserted = _connections.emplace(intSessionId, thread); @@ -657,16 +657,30 @@ private: return _loKitDocument; } - void onUnload(const int viewId) + void onUnload(const std::string& sessionId) { + std::unique_lock<std::mutex> lock(_mutex); + + Log::info("Session " + sessionId + " is unloading. " + std::to_string(_clientViews - 1) + " views left."); + + const unsigned intSessionId = Util::decodeId(sessionId); + const auto it = _connections.find(intSessionId); + if (it == _connections.end() || !it->second) + { + Log::error("Cannot find session [" + sessionId + "] which decoded to " + std::to_string(intSessionId)); + return; + } + + --_clientViews; + if (_multiView && _loKitDocument) { --_clientViews; Log::info() << "Document [" << _url << "] view [" - << viewId << "] unloaded, leaving " + << sessionId << "] unloaded, leaving " << _clientViews << " views." << Log::end; - _loKitDocument->pClass->setView(_loKitDocument, viewId); + const auto viewId = _loKitDocument->pClass->getView(_loKitDocument); _loKitDocument->pClass->registerCallback(_loKitDocument, nullptr, nullptr); _loKitDocument->pClass->destroyView(_loKitDocument, viewId); } _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
