[Libreoffice-commits] online.git: common/Session.cpp common/Session.hpp kit/ChildSession.cpp kit/ChildSession.hpp wsd/ClientSession.cpp wsd/PrisonerSession.cpp wsd/TileCache.cpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Tue Dec 13 04:35:20 UTC 2016


 common/Session.cpp      |   10 +++-------
 common/Session.hpp      |   39 +--------------------------------------
 kit/ChildSession.cpp    |    2 +-
 kit/ChildSession.hpp    |    8 ++------
 wsd/ClientSession.cpp   |    2 +-
 wsd/PrisonerSession.cpp |    2 +-
 wsd/TileCache.cpp       |    4 +---
 7 files changed, 10 insertions(+), 57 deletions(-)

New commits:
commit 477ca6f414090941d66392d0b3081eb2d8b1f6c2
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Mon Dec 12 20:18:25 2016 -0500

    loolwsd: cleanup the Sessions
    
    Change-Id: I3cd065ab84e17f943fa7de7e094db574ff6fde07
    Reviewed-on: https://gerrit.libreoffice.org/31931
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/common/Session.cpp b/common/Session.cpp
index f2c68ec..0e51de5 100644
--- a/common/Session.cpp
+++ b/common/Session.cpp
@@ -49,14 +49,10 @@ using Poco::Net::Socket;
 using Poco::Net::WebSocket;
 using Poco::StringTokenizer;
 
-Session::Session(const std::string& id, const Kind kind,
-                         std::shared_ptr<LOOLWebSocket> ws) :
+Session::Session(const std::string& name, const std::string& id, const std::shared_ptr<LOOLWebSocket>& ws) :
     _id(id),
-    _kind(kind),
-    _kindString(kind == Kind::ToClient ? "ToClient" :
-                kind == Kind::ToMaster ? "ToMaster" : "ToPrisoner"),
-    _name(_kindString + '-' + id),
-    _ws(std::move(ws)),
+    _name(name),
+    _ws(ws),
     _disconnected(false),
     _isActive(true),
     _lastActivityTime(std::chrono::steady_clock::now()),
diff --git a/common/Session.hpp b/common/Session.hpp
index 617348a..8277c5e 100644
--- a/common/Session.hpp
+++ b/common/Session.hpp
@@ -32,17 +32,6 @@
 class Session
 {
 public:
-    /// We have three kinds of Websocket sessions
-    /// 1) Between the master loolwsd server to the end-user LOOL client
-    /// 2) Between the master loolwsd server and a jailed child process, in the master process
-    /// 3) Ditto, in the jailed process
-    enum class Kind
-    {
-        ToClient,
-        ToPrisoner,
-        ToMaster
-    };
-
     const std::string& getId() const { return _id; }
     const std::string& getName() const { return _name; }
     bool isDisconnected() const { return _disconnected; }
@@ -77,13 +66,10 @@ public:
     void closeFrame() { _isCloseFrame = true; };
     bool isCloseFrame() const { return _isCloseFrame; }
 
-    Kind getKind() const { return _kind; }
-
     bool isHeadless() const { return _ws == nullptr; }
 
 protected:
-    Session(const std::string& id, const Kind kind,
-                std::shared_ptr<LOOLWebSocket> ws);
+    Session(const std::string& name, const std::string& id, const std::shared_ptr<LOOLWebSocket>& ws);
     virtual ~Session();
 
     /// Parses the options of the "load" command, shared between MasterProcessSession::loadDocument() and ChildProcessSession::loadDocument().
@@ -107,12 +93,6 @@ private:
     /// A session ID specific to an end-to-end connection (from user to lokit).
     const std::string _id;
 
-    // Our kind signifies to what we are connected to.
-    const Kind _kind;
-
-    // The kind cached as a string.
-    const std::string _kindString;
-
     /// A readable name that identifies our peer and ID.
     const std::string _name;
 
@@ -158,23 +138,6 @@ protected:
     std::string _userName;
 };
 
-template <typename charT, typename traits>
-inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& stream, Session::Kind kind)
-{
-    switch (kind)
-    {
-    case Session::Kind::ToClient:
-        return stream << "TO_CLIENT";
-    case Session::Kind::ToPrisoner:
-        return stream << "TO_PRISONER";
-    case Session::Kind::ToMaster:
-        return stream << "TO_MASTER";
-    default:
-        assert(false);
-        return stream << "UNK_" + std::to_string(static_cast<int>(kind));
-    }
-}
-
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp
index 9df2b56..cd1f404 100644
--- a/kit/ChildSession.cpp
+++ b/kit/ChildSession.cpp
@@ -37,7 +37,7 @@ std::recursive_mutex ChildSession::Mutex;
 ChildSession::ChildSession(const std::string& id,
                            const std::string& jailId,
                            IDocumentManager& docManager) :
-    Session(id, Kind::ToMaster, nullptr),
+    Session("ToMaster-" + id, id, nullptr),
     _jailId(jailId),
     _docManager(docManager),
     _viewId(-1),
diff --git a/kit/ChildSession.hpp b/kit/ChildSession.hpp
index 19005ac..c41426a 100644
--- a/kit/ChildSession.hpp
+++ b/kit/ChildSession.hpp
@@ -35,8 +35,7 @@ public:
                         const std::string& userName,
                         const std::string& docPassword,
                         const std::string& renderOpts,
-                        const bool haveDocPassword)
-        = 0;
+                        const bool haveDocPassword) = 0;
 
     /// Unload a client session, which unloads the document
     /// if it is the last and only.
@@ -94,10 +93,7 @@ public:
         return _docManager.sendTextFrame(msg);
     }
 
-    bool sendTextFrame(const std::string& text)
-    {
-        return sendTextFrame(text.data(), text.size());
-    }
+    using Session::sendTextFrame;
 
 private:
     bool loadDocument(const char* buffer, int length, Poco::StringTokenizer& tokens);
diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 3befec5..1707650 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -39,7 +39,7 @@ ClientSession::ClientSession(const std::string& id,
                              const std::shared_ptr<DocumentBroker>& docBroker,
                              const Poco::URI& uriPublic,
                              const bool readOnly) :
-    Session(id, Kind::ToClient, ws),
+    Session("ToClient-" + id, id, ws),
     _docBroker(docBroker),
     _uriPublic(uriPublic),
     _isReadOnly(readOnly),
diff --git a/wsd/PrisonerSession.cpp b/wsd/PrisonerSession.cpp
index 2bd9c41..69eafad 100644
--- a/wsd/PrisonerSession.cpp
+++ b/wsd/PrisonerSession.cpp
@@ -36,7 +36,7 @@ using Poco::StringTokenizer;
 
 PrisonerSession::PrisonerSession(std::shared_ptr<ClientSession> clientSession,
                                  std::shared_ptr<DocumentBroker> docBroker) :
-    Session(clientSession->getId(), Kind::ToPrisoner, nullptr),
+    Session("ToPrisoner-" + clientSession->getId(), clientSession->getId(), nullptr),
     _docBroker(std::move(docBroker)),
     _peer(clientSession),
     _curPart(0)
diff --git a/wsd/TileCache.cpp b/wsd/TileCache.cpp
index 010ce00..60123a7 100644
--- a/wsd/TileCache.cpp
+++ b/wsd/TileCache.cpp
@@ -434,10 +434,8 @@ void TileCache::saveLastModified(const Timestamp& timestamp)
 }
 
 // FIXME: to be further simplified when we centralize tile messages.
-void TileCache::subscribeToTileRendering(const TileDesc& tile, const std::shared_ptr<ClientSession> &subscriber)
+void TileCache::subscribeToTileRendering(const TileDesc& tile, const std::shared_ptr<ClientSession>& subscriber)
 {
-    assert(subscriber->getKind() == Session::Kind::ToClient);
-
     std::ostringstream oss;
     oss << '(' << tile.getPart() << ',' << tile.getTilePosX() << ',' << tile.getTilePosY() << ')';
     const auto name = oss.str();


More information about the Libreoffice-commits mailing list