[Libreoffice-commits] online.git: loolwsd/Admin.cpp loolwsd/Admin.hpp loolwsd/AdminModel.cpp loolwsd/AdminModel.hpp loolwsd/LOOLWSD.cpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Mon Apr 18 03:35:12 UTC 2016


 loolwsd/Admin.cpp      |    4 ++--
 loolwsd/Admin.hpp      |    4 ++--
 loolwsd/AdminModel.cpp |   17 +++++++++--------
 loolwsd/AdminModel.hpp |   27 +++++++++++++--------------
 loolwsd/LOOLWSD.cpp    |    4 ++--
 5 files changed, 28 insertions(+), 28 deletions(-)

New commits:
commit 52959b728920ea5e70ea29f543ab60961dab1724
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sun Apr 17 22:11:10 2016 -0400

    loolwsd: admin cleanups
    
    Change-Id: Ib8a488ef08d345f768323e1303f7a053e54464d5
    Reviewed-on: https://gerrit.libreoffice.org/24182
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/Admin.cpp b/loolwsd/Admin.cpp
index 3ba553a..951acb3 100644
--- a/loolwsd/Admin.cpp
+++ b/loolwsd/Admin.cpp
@@ -385,13 +385,13 @@ Admin::~Admin()
     _cpuStatsTask->cancel();
 }
 
-void Admin::addDoc(const std::string& docKey, Poco::Process::PID pid, const std::string& filename, const int sessionId)
+void Admin::addDoc(const std::string& docKey, Poco::Process::PID pid, const std::string& filename, const std::string& sessionId)
 {
     std::unique_lock<std::mutex> modelLock(_modelMutex);
     _model.addDocument(docKey, pid, filename, sessionId);
 }
 
-void Admin::rmDoc(const std::string& docKey, const int sessionId)
+void Admin::rmDoc(const std::string& docKey, const std::string& sessionId)
 {
     std::unique_lock<std::mutex> modelLock(_modelMutex);
     _model.removeDocument(docKey, sessionId);
diff --git a/loolwsd/Admin.hpp b/loolwsd/Admin.hpp
index a281ba5..e4d3aca 100644
--- a/loolwsd/Admin.hpp
+++ b/loolwsd/Admin.hpp
@@ -54,10 +54,10 @@ public:
     void update(const std::string& message);
 
     /// Calls with same pid will increment view count, if pid already exists
-    void addDoc(const std::string& docKey, Poco::Process::PID pid, const std::string& filename, const int sessionId);
+    void addDoc(const std::string& docKey, Poco::Process::PID pid, const std::string& filename, const std::string& sessionId);
 
     /// Decrement view count till becomes zero after which doc is removed
-    void rmDoc(const std::string& docKey, const int nSessionId);
+    void rmDoc(const std::string& docKey, const std::string& sessionId);
 
     void setForKitPid(const int forKitPid) { _forKitPid = forKitPid; }
 
diff --git a/loolwsd/AdminModel.cpp b/loolwsd/AdminModel.cpp
index fec35d9..4bba2d7 100644
--- a/loolwsd/AdminModel.cpp
+++ b/loolwsd/AdminModel.cpp
@@ -24,20 +24,20 @@ using Poco::StringTokenizer;
 /////////////////
 // Document Impl
 ////////////////
-void Document::addView(int sessionId)
+void Document::addView(const std::string& sessionId)
 {
     const auto ret = _views.emplace(sessionId, View(sessionId));
     if (!ret.second)
     {
-        Log::warn() << "View with SessionID [" + std::to_string(sessionId) + "] already exists." << Log::end;
+        Log::warn() << "View with SessionID [" + sessionId + "] already exists." << Log::end;
     }
     else
     {
-        _activeViews++;
+        ++_activeViews;
     }
 }
 
-int Document::expireView(int sessionId)
+int Document::expireView(const std::string& sessionId)
 {
     auto it = _views.find(sessionId);
     if (it != _views.end())
@@ -243,7 +243,8 @@ void AdminModel::notify(const std::string& message)
     }
 }
 
-void AdminModel::addDocument(const std::string& docKey, Poco::Process::PID pid, const std::string& filename, const int sessionId)
+void AdminModel::addDocument(const std::string& docKey, Poco::Process::PID pid,
+                             const std::string& filename, const std::string& sessionId)
 {
     const auto ret = _documents.emplace(docKey, Document(docKey, pid, filename));
     ret.first->second.addView(sessionId);
@@ -251,7 +252,7 @@ void AdminModel::addDocument(const std::string& docKey, Poco::Process::PID pid,
     // Notify the subscribers
     unsigned memUsage = Util::getMemoryUsage(pid);
     std::ostringstream oss;
-    oss << "adddoc" << " "
+    oss << "adddoc "
         << pid << " "
         << filename << " "
         << sessionId << " "
@@ -260,14 +261,14 @@ void AdminModel::addDocument(const std::string& docKey, Poco::Process::PID pid,
     notify(oss.str());
 }
 
-void AdminModel::removeDocument(const std::string& docKey, const int sessionId)
+void AdminModel::removeDocument(const std::string& docKey, const std::string& sessionId)
 {
     auto docIt = _documents.find(docKey);
     if (docIt != _documents.end() && !docIt->second.isExpired())
     {
         // Notify the subscribers
         std::ostringstream oss;
-        oss << "rmdoc" << " "
+        oss << "rmdoc "
             << docIt->second.getPid() << " "
             << sessionId;
         Log::info("Message to admin console: " + oss.str());
diff --git a/loolwsd/AdminModel.hpp b/loolwsd/AdminModel.hpp
index 806fb5c..0ce5931 100644
--- a/loolwsd/AdminModel.hpp
+++ b/loolwsd/AdminModel.hpp
@@ -22,19 +22,18 @@
 class View
 {
 public:
-    View(int sessionId)
-        : _sessionId(sessionId),
-          _start(std::time(nullptr))
-    {    }
+    View(const std::string& sessionId) :
+        _sessionId(sessionId),
+        _start(std::time(nullptr))
+    {
+    }
 
     void expire() { _end = std::time(nullptr); }
-
-    bool isExpired() { return _end != 0 && std::time(nullptr) >= _end; }
+    bool isExpired() const { return _end != 0 && std::time(nullptr) >= _end; }
 
 private:
-    int _sessionId;
-
-    std::time_t _start;
+    const std::string _sessionId;
+    const std::time_t _start;
     std::time_t _end = 0;
 };
 
@@ -63,9 +62,9 @@ public:
 
     std::time_t getElapsedTime() const { return std::time(nullptr) - _start; }
 
-    void addView(int sessionId);
+    void addView(const std::string& sessionId);
 
-    int expireView(int sessionId);
+    int expireView(const std::string& sessionId);
 
     unsigned getActiveViews() const { return _activeViews; }
 
@@ -73,7 +72,7 @@ private:
     const std::string _docKey;
     const Poco::Process::PID _pid;
     /// SessionId mapping to View object
-    std::map<int, View> _views;
+    std::map<std::string, View> _views;
     /// Total number of active views
     unsigned _activeViews = 0;
     /// Hosted filename
@@ -158,9 +157,9 @@ public:
 
     void notify(const std::string& message);
 
-    void addDocument(const std::string& docKey, Poco::Process::PID pid, const std::string& filename, const int sessionId);
+    void addDocument(const std::string& docKey, Poco::Process::PID pid, const std::string& filename, const std::string& sessionId);
 
-    void removeDocument(const std::string& docKey, const int sessionId);
+    void removeDocument(const std::string& docKey, const std::string& sessionId);
 
 private:
 
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 42a0149..34b031e 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -880,7 +880,7 @@ public:
             }
 
             Log::info("Adding doc " + docKey + " to Admin");
-            Admin::instance().addDoc(docKey, pid, docBroker->getFilename(), Util::decodeId(sessionId));
+            Admin::instance().addDoc(docKey, pid, docBroker->getFilename(), sessionId);
 
             if (waitBridgeCompleted(session))
             {
@@ -914,7 +914,7 @@ public:
         if (!jailId.empty())
         {
             Log::info("Removing doc " + docKey + " from Admin");
-            Admin::instance().rmDoc(docKey, Util::decodeId(sessionId));
+            Admin::instance().rmDoc(docKey, sessionId);
         }
 
         Log::debug("Thread finished.");


More information about the Libreoffice-commits mailing list