diff options
author | Pranav Kant <pranavk@collabora.co.uk> | 2017-10-25 00:10:45 -0700 |
---|---|---|
committer | Pranav Kant <pranavk@collabora.co.uk> | 2017-10-25 00:23:03 -0700 |
commit | d7c81cf7c807bb4e2624a02bd304cb75a1924e78 (patch) | |
tree | 91c102f4642d67cd47db3e5ed580f52bd757a6d0 | |
parent | lokdialog: Factor out renderDialog in kit.cpp (diff) | |
download | online-feature/lok_dialog.tar.gz online-feature/lok_dialog.zip |
factor out more code
feature/lok_dialog
-rw-r--r-- | wsd/ClientSession.cpp | 32 | ||||
-rw-r--r-- | wsd/ClientSession.hpp | 4 | ||||
-rw-r--r-- | wsd/DocumentBroker.cpp | 54 | ||||
-rw-r--r-- | wsd/DocumentBroker.hpp | 8 |
4 files changed, 23 insertions, 75 deletions
diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp index 34bcb56728..e19f335283 100644 --- a/wsd/ClientSession.cpp +++ b/wsd/ClientSession.cpp @@ -223,11 +223,11 @@ bool ClientSession::_handleInput(const char *buffer, int length) } else if (tokens[0] == "dialog") { - return sendDialog(buffer, length, tokens, docBroker); + return sendDialog(buffer, length, tokens, docBroker, false); } else if (tokens[0] == "dialogchild") { - return sendDialogChild(buffer, length, tokens, docBroker); + return sendDialog(buffer, length, tokens, docBroker, true); } else if (tokens[0] == "tilecombine") { @@ -436,32 +436,20 @@ bool ClientSession::sendTile(const char * /*buffer*/, int /*length*/, const std: } bool ClientSession::sendDialog(const char * /*buffer*/, int /*length*/, const std::vector<std::string>& tokens, - const std::shared_ptr<DocumentBroker>& docBroker) + const std::shared_ptr<DocumentBroker>& docBroker, bool child) { + const std::string dialogCmd = child ? "dialogchild" : "dialog"; try { - docBroker->handleDialogRequest(tokens[1], shared_from_this()); - } - catch (const std::exception& exc) - { - LOG_ERR("Failed to process dialog command: " << exc.what()); - return sendTextFrame("error: cmd=dialog kind=invalid"); - } - - return true; -} - -bool ClientSession::sendDialogChild(const char * /*buffer*/, int /*length*/, const std::vector<std::string>& tokens, - const std::shared_ptr<DocumentBroker>& docBroker) -{ - try - { - docBroker->handleDialogChildRequest(tokens[1], shared_from_this()); + if (child) + docBroker->handleDialogRequest(tokens[1], shared_from_this(), true); + else + docBroker->handleDialogRequest(tokens[1], shared_from_this(), false); } catch (const std::exception& exc) { - LOG_ERR("Failed to process dialogchild command: " << exc.what()); - return sendTextFrame("error: cmd=dialogchild kind=invalid"); + LOG_ERR("Failed to process " + dialogCmd + " command: " << exc.what()); + return sendTextFrame("error: cmd=" + dialogCmd + " kind=invalid"); } return true; diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp index 48ea303b2d..b16fe448b8 100644 --- a/wsd/ClientSession.hpp +++ b/wsd/ClientSession.hpp @@ -125,9 +125,7 @@ private: bool sendTile(const char* buffer, int length, const std::vector<std::string>& tokens, const std::shared_ptr<DocumentBroker>& docBroker); bool sendDialog(const char* buffer, int length, const std::vector<std::string>& tokens, - const std::shared_ptr<DocumentBroker>& docBroker); - bool sendDialogChild(const char* buffer, int length, const std::vector<std::string>& tokens, - const std::shared_ptr<DocumentBroker>& docBroker); + const std::shared_ptr<DocumentBroker>& docBroker, bool child); bool sendCombinedTiles(const char* buffer, int length, const std::vector<std::string>& tokens, const std::shared_ptr<DocumentBroker>& docBroker); diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp index 56a8c5a496..76255287ec 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -1077,11 +1077,11 @@ bool DocumentBroker::handleInput(const std::vector<char>& payload) } else if (command == "dialogpaint:") { - handleDialogPaintResponse(payload); + handleDialogPaintResponse(payload, false); } else if (command == "dialogchildpaint:") { - handleDialogChildPaintResponse(payload); + handleDialogPaintResponse(payload, true); } else if (command == "errortoall:") { @@ -1175,25 +1175,14 @@ void DocumentBroker::handleTileRequest(TileDesc& tile, } void DocumentBroker::handleDialogRequest(const std::string& dialogId, - const std::shared_ptr<ClientSession>& /*session*/) + const std::shared_ptr<ClientSession>& /*session*/, + bool child) { assertCorrectThread(); std::unique_lock<std::mutex> lock(_mutex); - - LOG_DBG("Sending dialog render request for dialog " << dialogId); - const std::string request = "dialog " + dialogId; - _childProcess->sendTextFrame(request); -} - -void DocumentBroker::handleDialogChildRequest(const std::string& dialogId, - const std::shared_ptr<ClientSession>& /*session*/) -{ - assertCorrectThread(); - std::unique_lock<std::mutex> lock(_mutex); - - LOG_DBG("Sending dialog child render request for dialog " << dialogId); - const std::string request = "dialogchild " + dialogId; - _childProcess->sendTextFrame(request); + const std::string dialogCmd = child ? "dialogchild" : "dialog"; + LOG_DBG("Sending " + dialogCmd + " render request for dialog " << dialogId); + _childProcess->sendTextFrame(dialogCmd + " " + dialogId); } void DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined, @@ -1296,35 +1285,10 @@ void DocumentBroker::handleTileResponse(const std::vector<char>& payload) } } -void DocumentBroker::handleDialogPaintResponse(const std::vector<char>& payload) -{ - const std::string firstLine = getFirstLine(payload); - LOG_DBG("Handling dialogpaint: " << firstLine); - - const auto length = payload.size(); - if (firstLine.size() < static_cast<std::string::size_type>(length) - 1) - { - const auto buffer = payload.data(); - const auto offset = firstLine.size() + 1; - - auto msgPayload = std::make_shared<Message>(firstLine, - Message::Dir::Out, - payload.size()); - msgPayload->append("\n", 1); - msgPayload->append(buffer + offset, payload.size() - offset); - - std::unique_lock<std::mutex> lock(_mutex); - for (const auto& sessionIt : _sessions) - { - sessionIt.second->enqueueSendMessage(msgPayload); - } - } -} - -void DocumentBroker::handleDialogChildPaintResponse(const std::vector<char>& payload) +void DocumentBroker::handleDialogPaintResponse(const std::vector<char>& payload, bool child) { const std::string firstLine = getFirstLine(payload); - LOG_DBG("Handling dialogchildpaint: " << firstLine); + LOG_DBG("Handling " << (child ? "dialogchildpaint" : "dialogpaint") << " " << firstLine); const auto length = payload.size(); if (firstLine.size() < static_cast<std::string::size_type>(length) - 1) diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp index 3f104eda97..75e2979477 100644 --- a/wsd/DocumentBroker.hpp +++ b/wsd/DocumentBroker.hpp @@ -299,15 +299,13 @@ public: void handleTileRequest(TileDesc& tile, const std::shared_ptr<ClientSession>& session); void handleDialogRequest(const std::string& dialogId, - const std::shared_ptr<ClientSession>& session); - void handleDialogChildRequest(const std::string& dialogId, - const std::shared_ptr<ClientSession>& session); + const std::shared_ptr<ClientSession>& session, + bool child); void handleTileCombinedRequest(TileCombined& tileCombined, const std::shared_ptr<ClientSession>& session); void cancelTileRequests(const std::shared_ptr<ClientSession>& session); void handleTileResponse(const std::vector<char>& payload); - void handleDialogPaintResponse(const std::vector<char>& payload); - void handleDialogChildPaintResponse(const std::vector<char>& payload); + void handleDialogPaintResponse(const std::vector<char>& payload, bool child); void handleTileCombinedResponse(const std::vector<char>& payload); void destroyIfLastEditor(const std::string& id); |