[Libreoffice-commits] online.git: loolwsd/ChildProcessSession.cpp loolwsd/LOOLBroker.cpp loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp loolwsd/MasterProcessSession.cpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Fri Dec 25 19:57:40 PST 2015


 loolwsd/ChildProcessSession.cpp  |   13 ++++++++++++-
 loolwsd/LOOLBroker.cpp           |    8 +++++---
 loolwsd/LOOLKit.cpp              |    1 +
 loolwsd/LOOLWSD.cpp              |   19 +++++++++----------
 loolwsd/MasterProcessSession.cpp |   21 +++++++++++----------
 5 files changed, 38 insertions(+), 24 deletions(-)

New commits:
commit 7053091c0e8652ba08dc28b9648b8c2f7290d704
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Fri Dec 25 12:35:23 2015 -0500

    loolwsd: support for views
    
    Change-Id: I9447d97612589efd0e85e30977b80ab720b81702
    Reviewed-on: https://gerrit.libreoffice.org/20945
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/ChildProcessSession.cpp b/loolwsd/ChildProcessSession.cpp
index 2926437..2742fe0 100644
--- a/loolwsd/ChildProcessSession.cpp
+++ b/loolwsd/ChildProcessSession.cpp
@@ -243,13 +243,17 @@ bool ChildProcessSession::loadDocument(const char *buffer, int length, StringTok
         return false;
     }
 
-    Log::info("Loading URI: " + aUri.toString());
     if (aUri.empty())
     {
         sendTextFrame("error: cmd=load kind=uriempty");
         return false;
     }
 
+    if (_loKitDocument == nullptr)
+        Log::info("Loading new document from URI: [" + aUri.toString() + "].");
+    else
+        Log::info("Loading view to document from URI: [" + aUri.toString() + "].");
+
     // The URL in the request is the original one, not visible in the chroot jail.
     // The child process uses the fixed name jailDocumentURL.
 
@@ -260,6 +264,11 @@ bool ChildProcessSession::loadDocument(const char *buffer, int length, StringTok
         aUri = URI( URI("file://"), Path(jailDocumentURL + Path::separator() + std::to_string(Process::id()),
                     Path(aUri.getPath()).getFileName()).toString() );
 
+    if (_loKitDocument != nullptr)
+    {
+        _viewId = _loKitDocument->pClass->createView(_loKitDocument);
+    }
+    else
     if ((_loKitDocument = _loKit->pClass->documentLoad(_loKit, aUri.toString().c_str())) == nullptr)
     {
         sendTextFrame("error: cmd=load kind=failed");
@@ -267,6 +276,8 @@ bool ChildProcessSession::loadDocument(const char *buffer, int length, StringTok
         return false;
     }
 
+    _loKitDocument->pClass->setView(_loKitDocument, _viewId);
+
     std::string renderingOptions;
     if (!_docOptions.empty())
     {
diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index d2bc9fc..ea432b8 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -365,8 +365,10 @@ public:
         StringTokenizer tokens(aMessage, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
         if (tokens[0] == "request" && tokens.count() == 3)
         {
-            std::string aTID = tokens[1];
-            std::string aURL = tokens[2];
+            const std::string aTID = tokens[1];
+            const std::string aURL = tokens[2];
+
+            Log::info("Finding kit for URL [" + aURL + "] on thread [" + aTID + "].");
 
             // check cache
             const auto aIterURL = _cacheURL.find(aURL);
@@ -401,7 +403,7 @@ public:
             if ( _emptyURL.size() > 0 )
             {
                 const auto aItem = _emptyURL.front();
-                Log::trace("No child found.");
+                Log::trace("No child found for URL [" + aURL + "].");
                 if (updateURL(aItem, aURL) < 0)
                 {
                     Log::error("New: Error update URL.");
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index 9b0180e..b246e50 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -585,6 +585,7 @@ void run_lok_main(const std::string &loSubPath, Poco::UInt64 _childId, const std
         }
 
         // Destroy LibreOfficeKit
+        // TODO: destroyView for views.
         loKit->pClass->destroy(loKit);
 
         Log::info("Kit process " + std::to_string(Process::id()) + " finished OK. ");
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 2c9050c..5d57f1a 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -322,7 +322,7 @@ public:
             Log::error("Cannot set thread name.");
 #endif
 
-        if(!(request.find("Upgrade") != request.end() && Poco::icompare(request["Upgrade"], "websocket") == 0))
+        if (!(request.find("Upgrade") != request.end() && Poco::icompare(request["Upgrade"], "websocket") == 0))
         {
             StringTokenizer tokens(request.getURI(), "/?");
             if (tokens.count() >= 2 && tokens[1] == "convert-to")
@@ -341,7 +341,7 @@ public:
                     LOOLSession::Kind kind = LOOLSession::Kind::ToClient;
                     std::shared_ptr<MasterProcessSession> session(new MasterProcessSession(ws, kind));
                     const std::string filePrefix("file://");
-                    std::string load = "load url=" + filePrefix + fromPath;
+                    const std::string load = "load url=" + filePrefix + fromPath;
                     session->handleInput(load.data(), load.size());
 
                     // Convert it to the requested format.
@@ -515,7 +515,7 @@ public:
                     }
                 }
                 while (!LOOLWSD::isShutDown &&
-                        (!pollTimeout || (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE)));
+                       (!pollTimeout || (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE)));
 
                 queue.clear();
                 queue.put("eof");
@@ -555,18 +555,17 @@ public:
 
     HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request) override
     {
-        std::string line = (Util::logPrefix() + "Request from " +
-                            request.clientAddress().toString() + ": " +
-                            request.getMethod() + " " +
-                            request.getURI() + " " +
-                            request.getVersion());
+        auto logger = Log::info();
+        logger << "Request from " << request.clientAddress().toString() << ": "
+               << request.getMethod() << " " << request.getURI() << " "
+               << request.getVersion();
 
         for (HTTPServerRequest::ConstIterator it = request.begin(); it != request.end(); ++it)
         {
-            line += " / " + it->first + ": " + it->second;
+            logger << " / " << it->first << ": " << it->second;
         }
 
-        Log::info(line);
+        logger << Log::end;
         return new RequestHandler();
     }
 };
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index c9ab731..a5c0e14 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -232,6 +232,7 @@ bool MasterProcessSession::handleInput(const char *buffer, int length)
         // Message from child process to be forwarded to client.
 
         // I think we should never get here
+        Log::error("Unexpected request [" + tokens[0] + "].");
         assert(false);
     }
     else if (tokens[0] == "load")
@@ -374,7 +375,8 @@ bool MasterProcessSession::loadDocument(const char* /*buffer*/, int /*length*/,
         URI aUri(_docURL);
 
         // request new URL session
-        std::string aMessage = "request " + std::to_string(Thread::currentTid()) + " " + _docURL + "\r\n";
+        const std::string aMessage = "request " + std::to_string(Thread::currentTid()) + " " + _docURL + "\r\n";
+        Log::info("Sending to Broker: " + aMessage);
         Util::writeFIFO(LOOLWSD::writerBroker, aMessage.c_str(), aMessage.length());
     }
     catch(Poco::SyntaxException&)
@@ -551,7 +553,7 @@ void MasterProcessSession::dispatchChild()
     std::shared_ptr<MasterProcessSession> childSession;
     std::unique_lock<std::mutex> lock(_availableChildSessionMutex);
 
-    std::cout << Util::logPrefix() << "waiting for a child session permission for " << Thread::currentTid() << std::endl;
+    Log::debug() << "Waiting for a child session permission for thead [" << Thread::currentTid() << "]." << Log::end;
     while (nRequest-- && !bFound)
     {
         _availableChildSessionCV.wait_for(
@@ -564,25 +566,25 @@ void MasterProcessSession::dispatchChild()
 
         if (!bFound)
         {
-            std::cout << Util::logPrefix() << "trying ..." << nRequest << std::endl;
+            Log::info() << "Retrying child permission... " << nRequest << Log::end;
             // request again new URL session
-            std::string aMessage = "request " + std::to_string(Thread::currentTid()) + " " + _docURL + "\r\n";
+            const std::string aMessage = "request " + std::to_string(Thread::currentTid()) + " " + _docURL + "\r\n";
             Util::writeFIFO(LOOLWSD::writerBroker, aMessage.c_str(), aMessage.length());
         }
     }
 
-    if ( bFound )
+    if (bFound)
     {
-        std::cout << Util::logPrefix() << "waiting child session permission, done!" << std::endl;
+        Log::debug("Waiting child session permission, done!");
         childSession = _availableChildSessions[Thread::currentTid()];
         _availableChildSessions.erase(Thread::currentTid());
     }
 
     lock.unlock();
 
-    if ( !nRequest && !bFound )
+    if (!nRequest && !bFound)
     {
-        // it cannot get connected.  shutdown.
+        Log::error("Failed to connect to child. Shutting down socket.");
         Util::shutdownWebSocket(*_ws);
         return;
     }
@@ -595,7 +597,7 @@ void MasterProcessSession::dispatchChild()
 
     if (!aUri.empty() && aUri.getScheme() == "file")
     {
-        std::string aJailDoc = jailDocumentURL.substr(1) + Path::separator() + std::to_string(childSession->_pidChild);
+        const std::string aJailDoc = jailDocumentURL.substr(1) + Path::separator() + std::to_string(childSession->_pidChild);
         Path aSrcFile(aUri.getPath());
         Path aDstFile(Path(getJailPath(childSession->_childId), aJailDoc), aSrcFile.getFileName());
         Path aDstPath(getJailPath(childSession->_childId), aJailDoc);
@@ -609,7 +611,6 @@ void MasterProcessSession::dispatchChild()
         {
             Log::error(
                 "createDirectories(\"" + aDstPath.toString() + "\") failed: " + exc.displayText() );
-
         }
 
         // cleanup potential leftovers from the last time


More information about the Libreoffice-commits mailing list