[Libreoffice-commits] online.git: loolwsd/ClientSession.cpp loolwsd/DocumentBroker.cpp loolwsd/DocumentBroker.hpp loolwsd/LOOLKit.cpp

2016-10-10 Thread Ashod Nakashian
 loolwsd/ClientSession.cpp  |   14 +++---
 loolwsd/DocumentBroker.cpp |9 ++---
 loolwsd/DocumentBroker.hpp |2 +-
 loolwsd/LOOLKit.cpp|   12 +++-
 4 files changed, 21 insertions(+), 16 deletions(-)

New commits:
commit 38cbfa96b0f3a197bf7445d4e32c64ac55be2fd0
Author: Ashod Nakashian 
Date:   Sat Oct 8 18:21:35 2016 -0400

loolwsd: forward client message to child via the process WS

Change-Id: I368e727b79b44b509ba49ed30218b8368c5eaad8
Reviewed-on: https://gerrit.libreoffice.org/29637
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/ClientSession.cpp b/loolwsd/ClientSession.cpp
index c4cfcdf..e4623ff 100644
--- a/loolwsd/ClientSession.cpp
+++ b/loolwsd/ClientSession.cpp
@@ -188,11 +188,11 @@ bool ClientSession::_handleInput(const char *buffer, int 
length)
  tokens[0] != "userinactive" && tokens[0] != "useractive")
 {
 std::string dummyFrame = "dummymsg";
-return forwardToPeer(_peer, dummyFrame.c_str(), dummyFrame.size(), 
false);
+return forwardToChild(dummyFrame.c_str(), dummyFrame.size());
 }
 else if (tokens[0] != "requestloksession")
 {
-return forwardToPeer(_peer, buffer, length, false);
+return forwardToChild(buffer, length);
 }
 else
 {
@@ -241,7 +241,7 @@ bool ClientSession::loadDocument(const char* /*buffer*/, 
int /*length*/, StringT
 oss << " options=" << _docOptions;
 
 const auto loadRequest = oss.str();
-return forwardToPeer(_peer, loadRequest.c_str(), loadRequest.size(), 
false);
+return forwardToChild(loadRequest.c_str(), loadRequest.size());
 }
 catch (const Poco::SyntaxException&)
 {
@@ -253,7 +253,7 @@ bool ClientSession::loadDocument(const char* /*buffer*/, 
int /*length*/, StringT
 
 bool ClientSession::getStatus(const char *buffer, int length)
 {
-return forwardToPeer(_peer, buffer, length, false);
+return forwardToChild(buffer, length);
 }
 
 bool ClientSession::getCommandValues(const char *buffer, int length, 
StringTokenizer& tokens)
@@ -270,7 +270,7 @@ bool ClientSession::getCommandValues(const char *buffer, 
int length, StringToken
 return sendTextFrame(cmdValues);
 }
 
-return forwardToPeer(_peer, buffer, length, false);
+return forwardToChild(buffer, length);
 }
 
 bool ClientSession::getPartPageRectangles(const char *buffer, int length)
@@ -281,7 +281,7 @@ bool ClientSession::getPartPageRectangles(const char 
*buffer, int length)
 return sendTextFrame(partPageRectangles);
 }
 
-return forwardToPeer(_peer, buffer, length, false);
+return forwardToChild(buffer, length);
 }
 
 bool ClientSession::sendFontRendering(const char *buffer, int length, 
StringTokenizer& tokens)
@@ -313,7 +313,7 @@ bool ClientSession::sendFontRendering(const char *buffer, 
int length, StringToke
 return sendBinaryFrame(output.data(), output.size());
 }
 
-return forwardToPeer(_peer, buffer, length, false);
+return forwardToChild(buffer, length);
 }
 
 bool ClientSession::sendTile(const char * /*buffer*/, int /*length*/, 
StringTokenizer& tokens)
diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index e2e5423..6c6cbb8 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -725,12 +725,15 @@ void DocumentBroker::setModified(const bool value)
 bool DocumentBroker::forwardToChild(const std::string& viewId, const char 
*buffer, int length)
 {
 const auto message = std::string(buffer, length);
-Log::trace() << "Forwarding payload to child [" << viewId << "]: " << 
message << Log::end;
+Log::warn() << "Forwarding payload to child [" << viewId << "]: " << 
message << Log::end;
 
 const auto it = _sessions.find(viewId);
 if (it != _sessions.end())
 {
-return it->second->sendTextFrame("child-" + viewId + ' ' + message);
+const auto msg = "child-" + viewId + ' ' + message;
+Log::debug("DocBroker to Child: " + msg);
+_childProcess->getWebSocket()->sendFrame(msg.data(), msg.size());
+return true;
 }
 else
 {
@@ -743,7 +746,7 @@ bool DocumentBroker::forwardToChild(const std::string& 
viewId, const char *buffe
 bool DocumentBroker::forwardToClient(const std::string& prefix, const 
std::vector& payload)
 {
 const std::string message(payload.data() + prefix.size(), payload.size() - 
prefix.size());
-Log::trace("Forwarding payload to client: " + message);
+Log::warn("Forwarding payload to client: " + message);
 
 std::string name;
 std::string sid;
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index bd0f7f3..66ec29c 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -241,7 +241,7 @@ private:
 /// Saves the document to Storage (assuming 

[Libreoffice-commits] online.git: loolwsd/ClientSession.cpp loolwsd/DocumentBroker.cpp loolwsd/DocumentBroker.hpp loolwsd/LOOLKit.cpp

2016-05-22 Thread Ashod Nakashian
 loolwsd/ClientSession.cpp  |   66 +---
 loolwsd/DocumentBroker.cpp |  106 ++
 loolwsd/DocumentBroker.hpp |3 
 loolwsd/LOOLKit.cpp|  178 -
 4 files changed, 182 insertions(+), 171 deletions(-)

New commits:
commit 114a6bc373a8bd8ea1af3144b8b500f92060f2d0
Author: Ashod Nakashian 
Date:   Sun May 22 11:45:28 2016 -0400

loolwsd: combined tile rendering

Tiles can be rendered in large batches and sent back
as combined payloads, all reduce latency and overhead
significantly.

Initial tests show a reduction in total latency by 2x.
This without sending tiles back to the client in combined
form, which will reduce latency further.

Change-Id: Iee06503f2a6c741fadb2c890266ea514c809c0dc
Reviewed-on: https://gerrit.libreoffice.org/25339
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/ClientSession.cpp b/loolwsd/ClientSession.cpp
index 7158a97..1fb1ec7 100644
--- a/loolwsd/ClientSession.cpp
+++ b/loolwsd/ClientSession.cpp
@@ -337,69 +337,15 @@ bool ClientSession::sendTile(const char * /*buffer*/, int 
/*length*/, StringToke
 
 bool ClientSession::sendCombinedTiles(const char* /*buffer*/, int /*length*/, 
StringTokenizer& tokens)
 {
-int part, pixelWidth, pixelHeight, tileWidth, tileHeight;
-std::string tilePositionsX, tilePositionsY;
-if (tokens.count() < 8 ||
-!getTokenInteger(tokens[1], "part", part) ||
-!getTokenInteger(tokens[2], "width", pixelWidth) ||
-!getTokenInteger(tokens[3], "height", pixelHeight) ||
-!getTokenString (tokens[4], "tileposx", tilePositionsX) ||
-!getTokenString (tokens[5], "tileposy", tilePositionsY) ||
-!getTokenInteger(tokens[6], "tilewidth", tileWidth) ||
-!getTokenInteger(tokens[7], "tileheight", tileHeight))
-{
-return sendTextFrame("error: cmd=tilecombine kind=syntax");
-}
-
-if (part < 0 || pixelWidth <= 0 || pixelHeight <= 0 ||
-tileWidth <= 0 || tileHeight <= 0 ||
-tilePositionsX.empty() || tilePositionsY.empty())
-{
-return sendTextFrame("error: cmd=tilecombine kind=invalid");
-}
-
-std::string reqTimestamp;
-size_t index = 8;
-if (tokens.count() > index && tokens[index].find("timestamp") == 0)
-{
-getTokenString(tokens[index], "timestamp", reqTimestamp);
-++index;
-}
-
-int id = -1;
-if (tokens.count() > index && tokens[index].find("id") == 0)
-{
-getTokenInteger(tokens[index], "id", id);
-++index;
-}
-
-StringTokenizer positionXtokens(tilePositionsX, ",", 
StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
-StringTokenizer positionYtokens(tilePositionsY, ",", 
StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
-
-size_t numberOfPositions = positionYtokens.count();
-
-// check that number of positions for X and Y is the same
-if (numberOfPositions != positionXtokens.count())
+try
 {
-return sendTextFrame("error: cmd=tilecombine kind=invalid");
+auto tileCombined = TileCombined::parse(tokens);
+_docBroker->handleTileCombinedRequest(tileCombined, 
shared_from_this());
 }
-
-for (size_t i = 0; i < numberOfPositions; ++i)
+catch (const std::exception& exc)
 {
-int x = 0;
-if (!stringToInteger(positionXtokens[i], x))
-{
-return sendTextFrame("error: cmd=tilecombine kind=syntax");
-}
-
-int y = 0;
-if (!stringToInteger(positionYtokens[i], y))
-{
-return sendTextFrame("error: cmd=tilecombine kind=syntax");
-}
-
-const TileDesc tile(part, pixelWidth, pixelHeight, x, y, tileWidth, 
tileHeight);
-_docBroker->handleTileRequest(tile, shared_from_this());
+Log::error(std::string("Failed to process tilecombine command: ") + 
exc.what() + ".");
+return sendTextFrame("error: cmd=tile kind=invalid");
 }
 
 return true;
diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 4c69a36..62dfe60 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -403,6 +403,10 @@ bool DocumentBroker::handleInput(const std::vector& 
payload)
 {
 handleTileResponse(payload);
 }
+else if (command == "tilecombine:")
+{
+   handleTileCombinedResponse(payload);
+}
 
 return true;
 }
@@ -453,6 +457,69 @@ void DocumentBroker::handleTileRequest(const TileDesc& 
tile,
 _childProcess->getWebSocket()->sendFrame(request.data(), request.size());
 }
 
+void DocumentBroker::handleTileCombinedRequest(TileCombined& tileCombined,
+   const 
std::shared_ptr& session)
+{
+Log::trace() << "TileCombined request for " << tileCombined.serialize() << 
Log::end;
+