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

Ashod Nakashian ashod.nakashian at collabora.co.uk
Mon Nov 14 05:28:11 UTC 2016


 loolwsd/ClientSession.cpp   |   15 +++++++++++++++
 loolwsd/ClientSession.hpp   |    3 ++-
 loolwsd/DocumentBroker.cpp  |    7 ++-----
 loolwsd/PrisonerSession.cpp |    5 +++--
 loolwsd/PrisonerSession.hpp |    8 +++++---
 5 files changed, 27 insertions(+), 11 deletions(-)

New commits:
commit 71c5f6c303bd6cf72588526fe93937ff3c313911
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sun Nov 13 12:26:00 2016 -0500

    loolwsd: simplify PrisonerSession
    
    Change-Id: If626b9e5ceb206480f29d4b4b70eeffca55a83c2
    Reviewed-on: https://gerrit.libreoffice.org/30823
    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 24b53c5..2ab3e7a 100644
--- a/loolwsd/ClientSession.cpp
+++ b/loolwsd/ClientSession.cpp
@@ -57,6 +57,21 @@ ClientSession::~ClientSession()
     _saveAsQueue.put("");
 }
 
+void ClientSession::bridgePrisonerSession()
+{
+    auto docBroker = getDocumentBroker();
+    if (docBroker)
+    {
+        _peer = std::make_shared<PrisonerSession>(shared_from_this(), docBroker);
+    }
+    else
+    {
+        const std::string msg = "No valid DocBroker while bridging Prisoner Session for " + getName();
+        LOG_ERR(msg);
+        throw std::runtime_error(msg);
+    }
+}
+
 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 4340f46..ae41b63 100644
--- a/loolwsd/ClientSession.hpp
+++ b/loolwsd/ClientSession.hpp
@@ -33,7 +33,8 @@ public:
     void setReadOnly();
     bool isReadOnly() const { return _isReadOnly; }
 
-    void setPeer(const std::shared_ptr<PrisonerSession>& peer) { _peer = peer; }
+    /// Create and connect Prisoner Session between DocumentBroker and us.
+    void bridgePrisonerSession();
     std::shared_ptr<PrisonerSession> getPeer() const { return _peer; }
     bool shutdownPeer(Poco::UInt16 statusCode);
 
diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 4a79836..5412c4b 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -531,11 +531,8 @@ size_t DocumentBroker::addSession(std::shared_ptr<ClientSession>& session)
     // Tell the admin console about this new doc
     Admin::instance().addDoc(_docKey, getPid(), getFilename(), id);
 
-    auto prisonerSession = std::make_shared<PrisonerSession>(id, shared_from_this());
-
-    // Connect the prison session to the client.
-    session->setPeer(prisonerSession);
-    prisonerSession->setPeer(session);
+    // Now we are ready to bridge between the kit and client.
+    session->bridgePrisonerSession();
 
     return count;
 }
diff --git a/loolwsd/PrisonerSession.cpp b/loolwsd/PrisonerSession.cpp
index 76e074c..8696992 100644
--- a/loolwsd/PrisonerSession.cpp
+++ b/loolwsd/PrisonerSession.cpp
@@ -33,10 +33,11 @@ using namespace LOOLProtocol;
 using Poco::Path;
 using Poco::StringTokenizer;
 
-PrisonerSession::PrisonerSession(const std::string& id,
+PrisonerSession::PrisonerSession(std::shared_ptr<ClientSession> clientSession,
                                  std::shared_ptr<DocumentBroker> docBroker) :
-    LOOLSession(id, Kind::ToPrisoner, nullptr),
+    LOOLSession(clientSession->getId(), Kind::ToPrisoner, nullptr),
     _docBroker(std::move(docBroker)),
+    _peer(clientSession),
     _curPart(0)
 {
     LOG_INF("PrisonerSession ctor [" << getName() << "].");
diff --git a/loolwsd/PrisonerSession.hpp b/loolwsd/PrisonerSession.hpp
index 87cba16..55a3de5 100644
--- a/loolwsd/PrisonerSession.hpp
+++ b/loolwsd/PrisonerSession.hpp
@@ -15,19 +15,21 @@
 class DocumentBroker;
 class ClientSession;
 
-/// Represents a session to a Kit process, in the WSD process.
+/// Represents an internal session to a Kit process, in the WSD process.
+/// This doesn't really have a direct connection to any Kit process, rather
+/// all communication to said Kit process is really handled by DocumentBroker.
 class PrisonerSession final : public LOOLSession, public std::enable_shared_from_this<PrisonerSession>
 {
 public:
-    PrisonerSession(const std::string& id,
+    PrisonerSession(std::shared_ptr<ClientSession> clientSession,
                     std::shared_ptr<DocumentBroker> docBroker);
 
     virtual ~PrisonerSession();
 
-    void setPeer(const std::shared_ptr<ClientSession>& peer) { _peer = peer; }
     bool shutdownPeer(Poco::UInt16 statusCode);
 
 private:
+    /// Handle messages from the Kit to the client.
     virtual bool _handleInput(const char* buffer, int length) override;
 
 private:


More information about the Libreoffice-commits mailing list