[Libreoffice-commits] online.git: loolwsd/ClientSession.cpp loolwsd/ClientSession.hpp loolwsd/DocumentBroker.cpp loolwsd/DocumentBroker.hpp loolwsd/LOOLWSD.cpp loolwsd/MasterProcessSession.cpp loolwsd/MasterProcessSession.hpp loolwsd/PrisonerSession.hpp loolwsd/TileCache.cpp loolwsd/TileCache.hpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Tue May 17 03:22:02 UTC 2016


 loolwsd/ClientSession.cpp        |   16 ++++++++++++++++
 loolwsd/ClientSession.hpp        |   21 ++++++++++++++-------
 loolwsd/DocumentBroker.cpp       |   16 ++++++----------
 loolwsd/DocumentBroker.hpp       |    3 ++-
 loolwsd/LOOLWSD.cpp              |    6 +++---
 loolwsd/MasterProcessSession.cpp |    7 ++-----
 loolwsd/MasterProcessSession.hpp |    9 ++-------
 loolwsd/PrisonerSession.hpp      |    5 +++--
 loolwsd/TileCache.cpp            |   13 ++++---------
 loolwsd/TileCache.hpp            |    4 ++--
 10 files changed, 54 insertions(+), 46 deletions(-)

New commits:
commit b2881306f1fba6e9267d2c6435885dc6237bd2cb
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Mon May 16 20:49:36 2016 -0400

    loolwsd: MasterProcessSession splitting: moved input queue
    
    Change-Id: Id1c2b0f76a96ca48905d354c02a96b35ba29fadc
    Reviewed-on: https://gerrit.libreoffice.org/25046
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/ClientSession.cpp b/loolwsd/ClientSession.cpp
index 3676aa0..721a253 100644
--- a/loolwsd/ClientSession.cpp
+++ b/loolwsd/ClientSession.cpp
@@ -33,6 +33,17 @@ using namespace LOOLProtocol;
 using Poco::Path;
 using Poco::StringTokenizer;
 
+ClientSession::ClientSession(const std::string& id,
+                             std::shared_ptr<Poco::Net::WebSocket> ws,
+                             std::shared_ptr<DocumentBroker> docBroker,
+                             std::shared_ptr<BasicTileQueue> queue) :
+    MasterProcessSession(id, Kind::ToClient, ws, docBroker),
+    _queue(queue),
+    _loadFailed(false)
+{
+    Log::info("ClientSession ctor [" + getName() + "].");
+}
+
 ClientSession::~ClientSession()
 {
     Log::info("~PrisonerSession dtor [" + getName() + "].");
@@ -41,6 +52,11 @@ ClientSession::~ClientSession()
     _saveAsQueue.put("");
 }
 
+void ClientSession::setPeer(const std::shared_ptr<PrisonerSession>& peer)
+{
+    MasterProcessSession::_peer = _peer = peer;
+}
+
 bool ClientSession::_handleInput(const char *buffer, int length)
 {
     const std::string firstLine = getFirstLine(buffer, length);
diff --git a/loolwsd/ClientSession.hpp b/loolwsd/ClientSession.hpp
index 7ef2dfa..dc9278b 100644
--- a/loolwsd/ClientSession.hpp
+++ b/loolwsd/ClientSession.hpp
@@ -21,10 +21,13 @@
 class DocumentBroker;
 class PrisonerSession;
 
-class ClientSession final : public MasterProcessSession//, public std::enable_shared_from_this<ClientSession>
+class ClientSession final : public MasterProcessSession, public std::enable_shared_from_this<ClientSession>
 {
 public:
-    using MasterProcessSession::MasterProcessSession;
+    ClientSession(const std::string& id,
+                  std::shared_ptr<Poco::Net::WebSocket> ws,
+                  std::shared_ptr<DocumentBroker> docBroker,
+                  std::shared_ptr<BasicTileQueue> queue);
 
     virtual ~ClientSession();
 
@@ -32,7 +35,7 @@ public:
     void markEditLock(const bool value) { _bEditLock = value; }
     bool isEditLocked() const { return _bEditLock; }
 
-    void setPeer(const std::shared_ptr<PrisonerSession>& peer) { MasterProcessSession::_peer = _peer = peer; }
+    void setPeer(const std::shared_ptr<PrisonerSession>& peer);
 
     /**
      * Return the URL of the saved-as document when it's ready. If called
@@ -56,6 +59,11 @@ public:
         _loadFailed = true;
     }
 
+    void sendToInputQueue(const std::string& message)
+    {
+        _queue->put(message);
+    }
+
 private:
 
     virtual bool _handleInput(const char *buffer, int length) override;
@@ -81,24 +89,23 @@ private:
     /// Store URLs of completed 'save as' documents.
     MessageQueue _saveAsQueue;
 
+    /// The incoming message queue.
+    std::shared_ptr<BasicTileQueue> _queue;
+
     /// Marks if document loading failed.
     bool _loadFailed;
 
 #if 0
     std::shared_ptr<DocumentBroker> getDocumentBroker() const { return _docBroker; }
 
-    std::shared_ptr<BasicTileQueue> getQueue() const { return _queue; }
-
     bool shutdownPeer(Poco::UInt16 statusCode, const std::string& message);
 
  private:
     void dispatchChild();
     void forwardToPeer(const char *buffer, int length);
 
-    int _curPart;
     int _loadPart;
     std::shared_ptr<DocumentBroker> _docBroker;
-    std::shared_ptr<BasicTileQueue> _queue;
 #endif
 };
 
diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 19eaa5b..a7abd38 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -280,16 +280,12 @@ bool DocumentBroker::sendUnoSave()
     {
         if (sessionIt.second->isEditLocked())
         {
-            auto queue = sessionIt.second->getQueue();
-            if (queue)
-            {
-                // Invalidate the timestamp to force persisting.
-                _lastFileModifiedTime.fromEpochTime(0);
+            // Invalidate the timestamp to force persisting.
+            _lastFileModifiedTime.fromEpochTime(0);
 
-                // We do not want save to terminate editing mode if we are in edit mode now
-                queue->put("uno .uno:Save {\"DontTerminateEdit\":{\"type\":\"boolean\",\"value\":true}}");
-                return true;
-            }
+            // We do not want save to terminate editing mode if we are in edit mode now
+            sessionIt.second->sendToInputQueue("uno .uno:Save {\"DontTerminateEdit\":{\"type\":\"boolean\",\"value\":true}}");
+            return true;
         }
     }
 
@@ -402,7 +398,7 @@ bool DocumentBroker::handleInput(const std::vector<char>& payload)
 }
 
 void DocumentBroker::handleTileRequest(const TileDesc& tile,
-                                       const std::shared_ptr<MasterProcessSession>& session)
+                                       const std::shared_ptr<ClientSession>& session)
 {
     const auto tileMsg = tile.serialize();
     Log::trace() << "Tile request for " << tileMsg << Log::end;
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index a41778d..7092b55 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -30,6 +30,7 @@
 // Forwards.
 class StorageBase;
 class TileCache;
+class DocumentBroker;
 
 /// Represents a new LOK child that is read
 /// to host a document.
@@ -201,7 +202,7 @@ public:
     size_t removeSession(const std::string& id);
 
     void handleTileRequest(const TileDesc& tile,
-                           const std::shared_ptr<MasterProcessSession>& session);
+                           const std::shared_ptr<ClientSession>& session);
 
     void handleTileResponse(const std::vector<char>& payload);
 
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 1be3f94..793f401 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -384,7 +384,7 @@ private:
 
                     // Load the document.
                     std::shared_ptr<WebSocket> ws;
-                    auto session = std::make_shared<ClientSession>(id, LOOLSession::Kind::ToClient, ws, docBroker, nullptr);
+                    auto session = std::make_shared<ClientSession>(id, ws, docBroker, nullptr);
 
                     // Request the child to connect to us and add this session.
                     auto sessionsCount = docBroker->addSession(session);
@@ -616,7 +616,7 @@ private:
             // For ToClient sessions, we store incoming messages in a queue and have a separate
             // thread to pump them. This is to empty the queue when we get a "canceltiles" message.
             auto queue = std::make_shared<BasicTileQueue>();
-            session = std::make_shared<ClientSession>(id, LOOLSession::Kind::ToClient, ws, docBroker, queue);
+            session = std::make_shared<ClientSession>(id, ws, docBroker, queue);
 
             // Request the child to connect to us and add this session.
             auto sessionsCount = docBroker->addSession(session);
@@ -986,7 +986,7 @@ public:
             docBroker->load(jailId);
 
             auto ws = std::make_shared<WebSocket>(request, response);
-            auto session = std::make_shared<PrisonerSession>(sessionId, LOOLSession::Kind::ToPrisoner, ws, docBroker, nullptr);
+            auto session = std::make_shared<PrisonerSession>(sessionId, LOOLSession::Kind::ToPrisoner, ws, docBroker);
 
             // Connect the prison session to the client.
             docBroker->connectPeers(session);
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index 9888832..888e2ae 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -34,13 +34,10 @@ using Poco::StringTokenizer;
 MasterProcessSession::MasterProcessSession(const std::string& id,
                                            const Kind kind,
                                            std::shared_ptr<Poco::Net::WebSocket> ws,
-                                           std::shared_ptr<DocumentBroker> docBroker,
-                                           std::shared_ptr<BasicTileQueue> queue) :
+                                           std::shared_ptr<DocumentBroker> docBroker) :
     LOOLSession(id, kind, ws),
-    _curPart(0),
     _loadPart(-1),
-    _docBroker(docBroker),
-    _queue(queue)
+    _docBroker(docBroker)
 {
     Log::info("MasterProcessSession ctor [" + getName() + "].");
 }
diff --git a/loolwsd/MasterProcessSession.hpp b/loolwsd/MasterProcessSession.hpp
index 92f2484..9a59c21 100644
--- a/loolwsd/MasterProcessSession.hpp
+++ b/loolwsd/MasterProcessSession.hpp
@@ -19,20 +19,17 @@
 
 class DocumentBroker;
 
-class MasterProcessSession : public LOOLSession, public std::enable_shared_from_this<MasterProcessSession>
+class MasterProcessSession : public LOOLSession
 {
  public:
     MasterProcessSession(const std::string& id,
                          const Kind kind,
                          std::shared_ptr<Poco::Net::WebSocket> ws,
-                         std::shared_ptr<DocumentBroker> docBroker,
-                         std::shared_ptr<BasicTileQueue> queue);
+                         std::shared_ptr<DocumentBroker> docBroker);
     virtual ~MasterProcessSession();
 
     std::shared_ptr<DocumentBroker> getDocumentBroker() const { return _docBroker; }
 
-    std::shared_ptr<BasicTileQueue> getQueue() const { return _queue; }
-
     bool shutdownPeer(Poco::UInt16 statusCode, const std::string& message);
 
  protected:
@@ -48,10 +45,8 @@ class MasterProcessSession : public LOOLSession, public std::enable_shared_from_
     // per document being edited (i.e., per child process).
     std::weak_ptr<MasterProcessSession> _peer;
 
-    int _curPart;
     int _loadPart;
     std::shared_ptr<DocumentBroker> _docBroker;
-    std::shared_ptr<BasicTileQueue> _queue;
 };
 
 #endif
diff --git a/loolwsd/PrisonerSession.hpp b/loolwsd/PrisonerSession.hpp
index 0de9c87..8d853b2 100644
--- a/loolwsd/PrisonerSession.hpp
+++ b/loolwsd/PrisonerSession.hpp
@@ -21,7 +21,7 @@
 class DocumentBroker;
 class ClientSession;
 
-class PrisonerSession final : public MasterProcessSession//, public std::enable_shared_from_this<PrisonerSession>
+class PrisonerSession final : public MasterProcessSession, public std::enable_shared_from_this<PrisonerSession>
 {
 public:
     using MasterProcessSession::MasterProcessSession;
@@ -37,6 +37,8 @@ private:
 private:
 
     std::weak_ptr<ClientSession> _peer;
+    int _curPart;
+
 #if 0
     std::shared_ptr<DocumentBroker> getDocumentBroker() const { return _docBroker; }
 
@@ -48,7 +50,6 @@ private:
     void dispatchChild();
     void forwardToPeer(const char *buffer, int length);
 
-    int _curPart;
     int _loadPart;
     std::shared_ptr<DocumentBroker> _docBroker;
     std::shared_ptr<BasicTileQueue> _queue;
diff --git a/loolwsd/TileCache.cpp b/loolwsd/TileCache.cpp
index 44213e6..836cb5f 100644
--- a/loolwsd/TileCache.cpp
+++ b/loolwsd/TileCache.cpp
@@ -34,7 +34,7 @@
 #include "LOOLProtocol.hpp"
 #include "TileCache.hpp"
 #include "Util.hpp"
-#include "MasterProcessSession.hpp"
+#include "ClientSession.hpp"
 #include "Unit.hpp"
 
 using Poco::DirectoryIterator;
@@ -125,7 +125,7 @@ TileCache::~TileCache()
 
 struct TileCache::TileBeingRendered
 {
-    std::vector<std::weak_ptr<MasterProcessSession>> _subscribers;
+    std::vector<std::weak_ptr<ClientSession>> _subscribers;
     TileBeingRendered()
      : _startTime(std::chrono::steady_clock::now())
     {
@@ -405,15 +405,10 @@ void TileCache::notifyAndRemoveSubscribers(const TileDesc& tile)
         if (subscriber)
         {
             //FIXME: This is inefficient; should just send directly to each client (although that is risky as well!
-            std::shared_ptr<BasicTileQueue> queue;
-            queue = subscriber->getQueue();
             // Re-emit the tile command in the other thread(s) to re-check and hit
             // the cache. Construct the message from scratch to contain only the
             // mandatory parts of the message.
-            if (queue)
-            {
-                queue->put(message);
-            }
+            subscriber->sendToInputQueue(message);
         }
     }
 
@@ -421,7 +416,7 @@ void TileCache::notifyAndRemoveSubscribers(const TileDesc& tile)
 }
 
 // FIXME: to be further simplified when we centralize tile messages.
-bool TileCache::isTileBeingRenderedIfSoSubscribe(const TileDesc& tile, const std::shared_ptr<MasterProcessSession> &subscriber)
+bool TileCache::isTileBeingRenderedIfSoSubscribe(const TileDesc& tile, const std::shared_ptr<ClientSession> &subscriber)
 {
     std::unique_lock<std::mutex> lock(_tilesBeingRenderedMutex);
 
diff --git a/loolwsd/TileCache.hpp b/loolwsd/TileCache.hpp
index 8b102e8..617ca67 100644
--- a/loolwsd/TileCache.hpp
+++ b/loolwsd/TileCache.hpp
@@ -25,7 +25,7 @@
 /** Handles the cache for tiles of one document.
 */
 
-class MasterProcessSession;
+class ClientSession;
 
 /// Tile Descriptor
 /// Represents a tile's coordinates and dimensions.
@@ -94,7 +94,7 @@ public:
 
     TileCache(const TileCache&) = delete;
 
-    bool isTileBeingRenderedIfSoSubscribe(const TileDesc& tile, const std::shared_ptr<MasterProcessSession> &subscriber);
+    bool isTileBeingRenderedIfSoSubscribe(const TileDesc& tile, const std::shared_ptr<ClientSession> &subscriber);
 
     std::unique_ptr<std::fstream> lookupTile(const TileDesc& tile);
 


More information about the Libreoffice-commits mailing list