loolwsd/Admin.cpp | 2 + loolwsd/DocumentBroker.cpp | 5 ++++ loolwsd/DocumentBroker.hpp | 15 ++++++++++++- loolwsd/LOOLWSD.cpp | 1 loolwsd/MasterProcessSession.cpp | 42 +++++++++++++++++++-------------------- loolwsd/MasterProcessSession.hpp | 2 - loolwsd/TileCache.cpp | 1 loolwsd/TileCache.hpp | 2 + 8 files changed, 45 insertions(+), 25 deletions(-)
New commits: commit 48dfce13de1df2f9159a7cb72cf72902b32a37c1 Author: Ashod Nakashian <[email protected]> Date: Fri Mar 25 22:56:18 2016 -0400 loolwsd: moved TileCache into DocumentBroker Change-Id: If44a2d3158801e0910cf0f991c75b5ef845a5a30 Reviewed-on: https://gerrit.libreoffice.org/23532 Reviewed-by: Ashod Nakashian <[email protected]> Tested-by: Ashod Nakashian <[email protected]> diff --git a/loolwsd/Admin.cpp b/loolwsd/Admin.cpp index 92a0dac..562bb58 100644 --- a/loolwsd/Admin.cpp +++ b/loolwsd/Admin.cpp @@ -30,6 +30,8 @@ #include "Admin.hpp" #include "AdminModel.hpp" #include "Common.hpp" +#include "TileCache.hpp" +#include "Storage.hpp" #include "LOOLProtocol.hpp" #include "LOOLWSD.hpp" #include "Util.hpp" diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp index d3f3134..d5af7f6 100644 --- a/loolwsd/DocumentBroker.cpp +++ b/loolwsd/DocumentBroker.cpp @@ -10,6 +10,8 @@ #include <Poco/Path.h> #include "DocumentBroker.hpp" +#include "Storage.hpp" +#include "TileCache.hpp" Poco::URI DocumentBroker::sanitizeURI(std::string uri) { @@ -83,6 +85,9 @@ bool DocumentBroker::load(const std::string& jailId) Log::info("jailPath: " + jailPath.toString() + ", jailRoot: " + jailRoot); + const std::string timestamp = ""; //FIXME: Should come from load options. + _tileCache.reset(new TileCache(_uriPublic.toString(), timestamp)); + _storage = createStorage(jailRoot, jailPath.toString(), _uriPublic); const auto localPath = _storage->loadStorageFileToLocal(); diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp index efbd955..8871e39 100644 --- a/loolwsd/DocumentBroker.hpp +++ b/loolwsd/DocumentBroker.hpp @@ -11,10 +11,17 @@ #define INCLUDED_DOCUMENTBROKER_HPP #include <atomic> +#include <memory> #include <mutex> #include <string> -#include "Storage.hpp" +#include <Poco/URI.h> + +#include <Util.hpp> + +// Forwards. +class StorageBase; +class TileCache; /// DocumentBroker is responsible for setting up a document /// in jail and brokering loading it from Storage @@ -38,7 +45,9 @@ public: ~DocumentBroker() { - Log::info("~DocumentBroker [" + _uriPublic.toString() + "] destroyed."); + Log::info() << "~DocumentBroker [" << _uriPublic.toString() + << "] destroyed with " << _sessionsCount + << " sessions." << Log::end; } void validate(const Poco::URI& uri); @@ -55,6 +64,7 @@ public: unsigned decSessions() { return --_sessionsCount; } unsigned incSessions() { return ++_sessionsCount; } unsigned getSessionsCount() { return _sessionsCount; } + TileCache& tileCache() { return *_tileCache; } std::string getJailRoot() const; @@ -66,6 +76,7 @@ private: std::string _jailId; std::string _filename; std::unique_ptr<StorageBase> _storage; + std::unique_ptr<TileCache> _tileCache; std::mutex _mutex; std::atomic<unsigned> _sessionsCount; }; diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 7412124..b0dcde6 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -119,6 +119,7 @@ DEALINGS IN THE SOFTWARE. #include "LOOLWSD.hpp" #include "MasterProcessSession.hpp" #include "QueueHandler.hpp" +#include "Storage.hpp" #include "Util.hpp" using namespace LOOLProtocol; diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp index 52e96c9..324504c 100644 --- a/loolwsd/MasterProcessSession.cpp +++ b/loolwsd/MasterProcessSession.cpp @@ -19,6 +19,8 @@ #include "LOOLWSD.hpp" #include "MasterProcessSession.hpp" #include "Rectangle.hpp" +#include "Storage.hpp" +#include "TileCache.hpp" #include "Util.hpp" using namespace LOOLProtocol; @@ -207,7 +209,7 @@ bool MasterProcessSession::_handleInput(const char *buffer, int length) } } - if (peer && peer->_tileCache && !_isDocPasswordProtected) + if (peer && !_isDocPasswordProtected) { if (tokens[0] == "tile:") { @@ -223,11 +225,11 @@ bool MasterProcessSession::_handleInput(const char *buffer, int length) assert(false); assert(firstLine.size() < static_cast<std::string::size_type>(length)); - peer->_tileCache->saveTile(part, width, height, tilePosX, tilePosY, tileWidth, tileHeight, buffer + firstLine.size() + 1, length - firstLine.size() - 1); + _docBroker->tileCache().saveTile(part, width, height, tilePosX, tilePosY, tileWidth, tileHeight, buffer + firstLine.size() + 1, length - firstLine.size() - 1); } else if (tokens[0] == "status:") { - peer->_tileCache->saveTextFile(std::string(buffer, length), "status.txt"); + _docBroker->tileCache().saveTextFile(std::string(buffer, length), "status.txt"); } else if (tokens[0] == "commandvalues:") { @@ -244,27 +246,27 @@ bool MasterProcessSession::_handleInput(const char *buffer, int length) commandName.find(".uno:StyleApply") != std::string::npos) { // other commands should not be cached - peer->_tileCache->saveTextFile(stringMsg, "cmdValues" + commandName + ".txt"); + _docBroker->tileCache().saveTextFile(stringMsg, "cmdValues" + commandName + ".txt"); } } } else if (tokens[0] == "partpagerectangles:") { if (tokens.count() > 1 && !tokens[1].empty()) - peer->_tileCache->saveTextFile(std::string(buffer, length), "partpagerectangles.txt"); + _docBroker->tileCache().saveTextFile(std::string(buffer, length), "partpagerectangles.txt"); } else if (tokens[0] == "invalidatecursor:") { - peer->_tileCache->setEditing(true); + _docBroker->tileCache().setEditing(true); } else if (tokens[0] == "invalidatetiles:") { // FIXME temporarily, set the editing on the 1st invalidate, TODO extend // the protocol so that the client can set the editing or view only. - peer->_tileCache->setEditing(true); + _docBroker->tileCache().setEditing(true); assert(firstLine.size() == static_cast<std::string::size_type>(length)); - peer->_tileCache->invalidateTiles(firstLine); + _docBroker->tileCache().invalidateTiles(firstLine); } else if (tokens[0] == "renderfont:") { @@ -274,7 +276,7 @@ bool MasterProcessSession::_handleInput(const char *buffer, int length) assert(false); assert(firstLine.size() < static_cast<std::string::size_type>(length)); - peer->_tileCache->saveRendering(font, "font", buffer + firstLine.size() + 1, length - firstLine.size() - 1); + _docBroker->tileCache().saveRendering(font, "font", buffer + firstLine.size() + 1, length - firstLine.size() - 1); } } @@ -378,7 +380,7 @@ bool MasterProcessSession::_handleInput(const char *buffer, int length) dispatchChild(); if (tokens[0] == "setclientpart") - _tileCache->removeFile("status.txt"); + _docBroker->tileCache().removeFile("status.txt"); if (tokens[0] != "requestloksession") { @@ -387,7 +389,7 @@ bool MasterProcessSession::_handleInput(const char *buffer, int length) if ((tokens.count() > 1 && tokens[0] == "uno" && tokens[1] == ".uno:Save")) { - _tileCache->documentSaved(); + _docBroker->tileCache().documentSaved(); } else if (tokens[0] == "disconnect") { @@ -415,9 +417,9 @@ bool MasterProcessSession::invalidateTiles(const char* /*buffer*/, int /*length* // FIXME temporarily, set the editing on the 1st invalidate, TODO extend // the protocol so that the client can set the editing or view only. - _tileCache->setEditing(true); + _docBroker->tileCache().setEditing(true); - _tileCache->invalidateTiles(_curPart, tilePosX, tilePosY, tileWidth, tileHeight); + _docBroker->tileCache().invalidateTiles(_curPart, tilePosX, tilePosY, tileWidth, tileHeight); return true; } @@ -434,8 +436,6 @@ bool MasterProcessSession::loadDocument(const char* /*buffer*/, int /*length*/, std::string timestamp; parseDocOptions(tokens, _loadPart, timestamp); - _tileCache.reset(new TileCache(_docURL, timestamp)); - // Finally, wait for the Child to connect to Master, // link the document in jail and dispatch load to child. dispatchChild(); @@ -452,7 +452,7 @@ bool MasterProcessSession::loadDocument(const char* /*buffer*/, int /*length*/, bool MasterProcessSession::getStatus(const char *buffer, int length) { - const std::string status = _tileCache->getTextFile("status.txt"); + const std::string status = _docBroker->tileCache().getTextFile("status.txt"); if (status.size() > 0) { sendTextFrame(status); @@ -474,7 +474,7 @@ bool MasterProcessSession::getCommandValues(const char *buffer, int length, Stri return false; } - const std::string cmdValues = _tileCache->getTextFile("cmdValues" + command + ".txt"); + const std::string cmdValues = _docBroker->tileCache().getTextFile("cmdValues" + command + ".txt"); if (cmdValues.size() > 0) { sendTextFrame(cmdValues); @@ -489,7 +489,7 @@ bool MasterProcessSession::getCommandValues(const char *buffer, int length, Stri bool MasterProcessSession::getPartPageRectangles(const char *buffer, int length) { - const std::string partPageRectangles = _tileCache->getTextFile("partpagerectangles.txt"); + const std::string partPageRectangles = _docBroker->tileCache().getTextFile("partpagerectangles.txt"); if (partPageRectangles.size() > 0) { sendTextFrame(partPageRectangles); @@ -523,7 +523,7 @@ void MasterProcessSession::sendFontRendering(const char *buffer, int length, Str output.resize(response.size()); std::memcpy(output.data(), response.data(), response.size()); - std::unique_ptr<std::fstream> cachedRendering = _tileCache->lookupRendering(font, "font"); + std::unique_ptr<std::fstream> cachedRendering = _docBroker->tileCache().lookupRendering(font, "font"); if (cachedRendering && cachedRendering->is_open()) { cachedRendering->seekg(0, std::ios_base::end); @@ -579,7 +579,7 @@ void MasterProcessSession::sendTile(const char *buffer, int length, StringTokeni output.resize(response.size()); std::memcpy(output.data(), response.data(), response.size()); - std::unique_ptr<std::fstream> cachedTile = _tileCache->lookupTile(part, width, height, tilePosX, tilePosY, tileWidth, tileHeight); + std::unique_ptr<std::fstream> cachedTile = _docBroker->tileCache().lookupTile(part, width, height, tilePosX, tilePosY, tileWidth, tileHeight); if (cachedTile && cachedTile->is_open()) { cachedTile->seekg(0, std::ios_base::end); @@ -662,7 +662,7 @@ void MasterProcessSession::sendCombinedTiles(const char* /*buffer*/, int /*lengt return; } - std::unique_ptr<std::fstream> cachedTile = _tileCache->lookupTile(part, pixelWidth, pixelHeight, x, y, tileWidth, tileHeight); + std::unique_ptr<std::fstream> cachedTile = _docBroker->tileCache().lookupTile(part, pixelWidth, pixelHeight, x, y, tileWidth, tileHeight); if (cachedTile && cachedTile->is_open()) { diff --git a/loolwsd/MasterProcessSession.hpp b/loolwsd/MasterProcessSession.hpp index defe5ea..be09337 100644 --- a/loolwsd/MasterProcessSession.hpp +++ b/loolwsd/MasterProcessSession.hpp @@ -78,8 +78,6 @@ class MasterProcessSession final : public LOOLSession, public std::enable_shared // per document being edited (i.e., per child process). std::weak_ptr<MasterProcessSession> _peer; - std::unique_ptr<TileCache> _tileCache; - static Poco::Path getJailPath(const std::string& childId); diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp index 8a3b408..120f985 100644 --- a/loolwsd/TileCache.cpp +++ b/loolwsd/TileCache.cpp @@ -28,6 +28,7 @@ #include <Poco/Timestamp.h> #include <Poco/URI.h> +#include "Storage.hpp" #include "LOOLWSD.hpp" #include "LOOLProtocol.hpp" #include "TileCache.hpp" diff --git a/loolwsd/TileCache.hpp b/loolwsd/TileCache.hpp index 500978b..e5b3aad 100644 --- a/loolwsd/TileCache.hpp +++ b/loolwsd/TileCache.hpp @@ -36,6 +36,8 @@ public: /// When it is missing for non-file:// url, it is assumed the document must be read, and no cached value used. TileCache(const std::string& docURL, const std::string& timestamp); + TileCache(const TileCache&) = delete; + std::unique_ptr<std::fstream> lookupTile(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight); void saveTile(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight, const char *data, size_t size); std::string getTextFile(std::string fileName); _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
