loolwsd/LOOLKit.cpp | 54 ++++++++++++++++++++-------------------------------- 1 file changed, 21 insertions(+), 33 deletions(-)
New commits: commit d20e9399fc194143d71383d4bfefb5f3eef2a947 Author: Henry Castro <[email protected]> Date: Sat Jan 9 07:27:57 2016 -0400 loolwsd: revert, refactor lokit Document I did not consider shared document case. diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 32c8f4d..ff7c3c3 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -470,13 +470,14 @@ private: class Document { public: - Document(LibreOfficeKit *loKit, const std::string& jailId) + Document(LibreOfficeKit *loKit, const std::string& jailId, + const std::string& url) : _loKit(loKit), _jailId(jailId), - _url(""), + _url(url), _loKitDocument(nullptr) { - Log::info("Document ctor on child [" + jailId + "]."); + Log::info("Document ctor for url [" + url + "] on child [" + jailId + "]."); } ~Document() @@ -505,10 +506,9 @@ public: } } - void createSession(const std::string& sessionId, const std::string& url) + void createSession(const std::string& sessionId) { const auto& aItem = _connections.find(sessionId); - _url = url; if (aItem != _connections.end()) { @@ -579,19 +579,13 @@ public: return _connections.size() > 0; } - const std::string& getURL() - { - return _url; - } - private: void onLoad(LibreOfficeKitDocument *loKitDocument, const int viewId) { Log::info("Document [" + _url + "] loaded as view #" + std::to_string(viewId) + "."); - // TODO. destroy lokit document when changed URL - // if (_loKitDocument != nullptr) - // assert(_loKitDocument == loKitDocument); + if (_loKitDocument != nullptr) + assert(_loKitDocument == loKitDocument); _loKitDocument = loKitDocument; } @@ -604,7 +598,7 @@ private: LibreOfficeKit *_loKit; const std::string _jailId; - std::string _url; + const std::string _url; LibreOfficeKitDocument *_loKitDocument; @@ -627,6 +621,8 @@ void lokit_main(const std::string &loSubPath, const std::string& jailId, const s assert(!jailId.empty()); assert(!loSubPath.empty()); + std::map<std::string, std::shared_ptr<Document>> _documents; + static const std::string process_name = "loolkit"; #ifdef __linux if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(process_name.c_str()), 0, 0, 0) != 0) @@ -650,9 +646,6 @@ void lokit_main(const std::string &loSubPath, const std::string& jailId, const s exit(-1); } - // Singlenton instance - std::shared_ptr<Document> pDocument(std::make_shared<Document>(loKit.get(), jailId)); - try { int writerBroker; @@ -729,16 +722,14 @@ void lokit_main(const std::string &loSubPath, const std::string& jailId, const s if (tokens[0] == "search") { - // remove unloaded documents - pDocument->purgeSessions(); - - if (!pDocument->hasConnections()) + if (_documents.empty()) { aResponse += "empty \r\n"; } else { - aResponse += (pDocument->getURL() == tokens[1] ? "ok \r\n" : "no \r\n"); + const auto& it = _documents.find(tokens[1]); + aResponse += (it != _documents.end() ? "ok \r\n" : "no \r\n"); } } else if (tokens[0] == "thread") @@ -746,16 +737,13 @@ void lokit_main(const std::string &loSubPath, const std::string& jailId, const s const std::string& sessionId = tokens[1]; const std::string& url = tokens[2]; - if (!pDocument->hasConnections() || pDocument->getURL() == url) - { - Log::debug("Thread request for session [" + sessionId + "], url: [" + url + "]."); - pDocument->createSession(sessionId, url); - aResponse += "ok \r\n"; - } - else - { - aResponse += "no \r\n"; - } + Log::debug("Thread request for session [" + sessionId + "], url: [" + url + "]."); + auto it = _documents.lower_bound(url); + if (it == _documents.end()) + it = _documents.emplace_hint(it, url, std::make_shared<Document>(loKit.get(), jailId, url)); + + it->second->createSession(sessionId); + aResponse += "ok \r\n"; } else { @@ -786,7 +774,7 @@ void lokit_main(const std::string &loSubPath, const std::string& jailId, const s Log::error(std::string("Exception: ") + exc.what()); } - pDocument.reset(); + _documents.clear(); // Destroy LibreOfficeKit loKit->pClass->destroy(loKit.get()); _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
