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

Pranav Kant pranavk at collabora.com
Fri Apr 15 09:14:20 UTC 2016


 loolwsd/Admin.cpp          |   10 +++++-----
 loolwsd/Admin.hpp          |    5 ++---
 loolwsd/AdminModel.cpp     |   16 ++++++++--------
 loolwsd/AdminModel.hpp     |   38 ++++++++++++++++++++------------------
 loolwsd/DocumentBroker.hpp |    2 ++
 loolwsd/LOOLWSD.cpp        |   26 +++++++++++++-------------
 loolwsd/LOOLWSD.hpp        |    3 +++
 7 files changed, 53 insertions(+), 47 deletions(-)

New commits:
commit 91c6154fc0900331dbe075207896ae9914ad4fb0
Author: Pranav Kant <pranavk at collabora.com>
Date:   Fri Apr 15 14:30:22 2016 +0530

    loolwsd: Use docKey as key for Admin instead of PID
    
    Also change some variable names to be consistent with rest of the
    coding style.
    
    Change-Id: Icca9a9aec9bfb34c1edd5b6533d7646b05fe814f

diff --git a/loolwsd/Admin.cpp b/loolwsd/Admin.cpp
index 1202e95..3feec33 100644
--- a/loolwsd/Admin.cpp
+++ b/loolwsd/Admin.cpp
@@ -188,7 +188,7 @@ void AdminRequestHandler::handleWSRequests(HTTPServerRequest& request, HTTPServe
                         {
                             if (std::stoi(tokens[1]))
                             {
-                                IoUtil::writeFIFO(LOOLWSD::ForKitWritePipe, firstLine + "\n");
+                                LOOLWSD::killKit(std::stoi(tokens[1]));
                             }
                         }
                         catch(std::exception& e)
@@ -384,16 +384,16 @@ Admin::~Admin()
     _cpuStatsTask->cancel();
 }
 
-void Admin::addDoc(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 int sessionId)
 {
     std::unique_lock<std::mutex> modelLock(_modelMutex);
-    _model.addDocument(pid, filename, sessionId);
+    _model.addDocument(docKey, pid, filename, sessionId);
 }
 
-void Admin::rmDoc(Poco::Process::PID pid, const int sessionId)
+void Admin::rmDoc(const std::string& docKey, const int sessionId)
 {
     std::unique_lock<std::mutex> modelLock(_modelMutex);
-    _model.removeDocument(pid, sessionId);
+    _model.removeDocument(docKey, sessionId);
 }
 
 void MemoryStats::run()
diff --git a/loolwsd/Admin.hpp b/loolwsd/Admin.hpp
index 9f4d838..a281ba5 100644
--- a/loolwsd/Admin.hpp
+++ b/loolwsd/Admin.hpp
@@ -54,12 +54,11 @@ public:
     void update(const std::string& message);
 
     /// Calls with same pid will increment view count, if pid already exists
-    void addDoc(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 int sessionId);
 
     /// Decrement view count till becomes zero after which doc is removed
-    void rmDoc(Poco::Process::PID pid, const int nSessionId);
+    void rmDoc(const std::string& docKey, const int nSessionId);
 
-    /// Set the forkit process id.
     void setForKitPid(const int forKitPid) { _forKitPid = forKitPid; }
 
     /// Callers must ensure that modelMutex is acquired
diff --git a/loolwsd/AdminModel.cpp b/loolwsd/AdminModel.cpp
index 3ff9477..fec35d9 100644
--- a/loolwsd/AdminModel.cpp
+++ b/loolwsd/AdminModel.cpp
@@ -33,7 +33,7 @@ void Document::addView(int sessionId)
     }
     else
     {
-        _nActiveViews++;
+        _activeViews++;
     }
 }
 
@@ -45,11 +45,11 @@ int Document::expireView(int sessionId)
         it->second.expire();
 
         // If last view, expire the Document also
-        if (--_nActiveViews == 0)
+        if (--_activeViews == 0)
             _end = std::time(nullptr);
     }
 
-    return _nActiveViews;
+    return _activeViews;
 }
 
 ///////////////////
@@ -243,9 +243,9 @@ void AdminModel::notify(const std::string& message)
     }
 }
 
-void AdminModel::addDocument(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 int sessionId)
 {
-    const auto ret = _documents.emplace(pid, Document(pid, filename));
+    const auto ret = _documents.emplace(docKey, Document(docKey, pid, filename));
     ret.first->second.addView(sessionId);
 
     // Notify the subscribers
@@ -260,15 +260,15 @@ void AdminModel::addDocument(Poco::Process::PID pid, const std::string& filename
     notify(oss.str());
 }
 
-void AdminModel::removeDocument(Poco::Process::PID pid, const int sessionId)
+void AdminModel::removeDocument(const std::string& docKey, const int sessionId)
 {
-    auto docIt = _documents.find(pid);
+    auto docIt = _documents.find(docKey);
     if (docIt != _documents.end() && !docIt->second.isExpired())
     {
         // Notify the subscribers
         std::ostringstream oss;
         oss << "rmdoc" << " "
-            << pid << " "
+            << docIt->second.getPid() << " "
             << sessionId;
         Log::info("Message to admin console: " + oss.str());
         notify(oss.str());
diff --git a/loolwsd/AdminModel.hpp b/loolwsd/AdminModel.hpp
index 843320d..806fb5c 100644
--- a/loolwsd/AdminModel.hpp
+++ b/loolwsd/AdminModel.hpp
@@ -23,7 +23,7 @@ class View
 {
 public:
     View(int sessionId)
-        : _nSessionId(sessionId),
+        : _sessionId(sessionId),
           _start(std::time(nullptr))
     {    }
 
@@ -32,7 +32,7 @@ public:
     bool isExpired() { return _end != 0 && std::time(nullptr) >= _end; }
 
 private:
-    int _nSessionId;
+    int _sessionId;
 
     std::time_t _start;
     std::time_t _end = 0;
@@ -41,22 +41,23 @@ private:
 class Document
 {
 public:
-    Document(Poco::Process::PID pid, std::string filename)
-        : _nPid(pid),
-          _sFilename(filename),
+    Document(std::string docKey, Poco::Process::PID pid, std::string filename)
+        : _docKey(docKey),
+          _pid(pid),
+          _filename(filename),
           _start(std::time(nullptr))
     {
-        Log::info("Document " + std::to_string(_nPid) + " ctor.");
+        Log::info("Document " + _docKey + " ctor.");
     }
 
     ~Document()
     {
-        Log::info("Document " + std::to_string(_nPid) + " dtor.");
+        Log::info("Document " + _docKey + " dtor.");
     }
 
-    Poco::Process::PID getPid() const { return _nPid; }
+    Poco::Process::PID getPid() const { return _pid; }
 
-    std::string getFilename() const { return _sFilename; }
+    std::string getFilename() const { return _filename; }
 
     bool isExpired() const { return _end != 0 && std::time(nullptr) >= _end; }
 
@@ -66,16 +67,17 @@ public:
 
     int expireView(int sessionId);
 
-    unsigned getActiveViews() const { return _nActiveViews; }
+    unsigned getActiveViews() const { return _activeViews; }
 
 private:
-    Poco::Process::PID _nPid;
+    const std::string _docKey;
+    const Poco::Process::PID _pid;
     /// SessionId mapping to View object
     std::map<int, View> _views;
     /// Total number of active views
-    unsigned _nActiveViews = 0;
+    unsigned _activeViews = 0;
     /// Hosted filename
-    std::string _sFilename;
+    std::string _filename;
 
     std::time_t _start;
     std::time_t _end = 0;
@@ -85,7 +87,7 @@ class Subscriber
 {
 public:
     Subscriber(int sessionId, std::shared_ptr<Poco::Net::WebSocket>& ws)
-        : _nSessionId(sessionId),
+        : _sessionId(sessionId),
           _ws(ws),
           _start(std::time(nullptr))
     {
@@ -109,7 +111,7 @@ public:
 
 private:
     /// Admin session Id
-    int _nSessionId;
+    int _sessionId;
     /// WebSocket to use to send messages to session
     std::weak_ptr<Poco::Net::WebSocket> _ws;
 
@@ -156,9 +158,9 @@ public:
 
     void notify(const std::string& message);
 
-    void addDocument(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 int sessionId);
 
-    void removeDocument(Poco::Process::PID pid, const int sessionId);
+    void removeDocument(const std::string& docKey, const int sessionId);
 
 private:
 
@@ -172,7 +174,7 @@ private:
 
 private:
     std::map<int, Subscriber> _subscribers;
-    std::map<Poco::Process::PID, Document> _documents;
+    std::map<std::string, Document> _documents;
 
     std::list<unsigned> _memStats;
     unsigned _memStatsSize = 100;
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 998ea91..599fb3f 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -172,6 +172,8 @@ public:
 
     unsigned getWSSessionsCount() { return _wsSessions.size(); }
 
+    void kill() { _childProcess->close(true); };
+
 private:
     const Poco::URI _uriPublic;
     const std::string _docKey;
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 0cf254d..5d2ca8c 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -805,10 +805,10 @@ public:
 
         std::string sessionId;
         std::string jailId;
+        std::string docKey;
         try
         {
             const auto params = Poco::URI(request.getURI()).getQueryParameters();
-            std::string docKey;
             for (const auto& param : params)
             {
                 if (param.first == "sessionId")
@@ -875,16 +875,17 @@ public:
             const auto uri = request.getURI();
 
             // Jail id should be the PID, beacuse Admin need it to calculate the memory
+            Poco::Process::PID pid;
             try
             {
-                Log::info("Adding doc " + jailId + " to Admin");
-                Admin::instance().addDoc(std::stoi(jailId), docBroker->getFilename(), std::stoi(sessionId));
+                pid = std::stoi(jailId);
             }
             catch (std::invalid_argument& exc)
             {
                 assert(false);
             }
-
+            Log::info("Adding doc " + docKey + " to Admin");
+            Admin::instance().addDoc(docKey, pid, docBroker->getFilename(), Util::decodeId(sessionId));
 
             if (waitBridgeCompleted(session))
             {
@@ -919,15 +920,8 @@ public:
 
         if (!jailId.empty())
         {
-            try
-            {
-                Log::info("Removing doc " + jailId + " from Admin");
-                Admin::instance().rmDoc(std::stoi(jailId), std::stoi(sessionId));
-            }
-            catch (std::invalid_argument& exc)
-            {
-                assert(false);
-            }
+            Log::info("Removing doc " + docKey + " from Admin");
+            Admin::instance().rmDoc(docKey, Util::decodeId(sessionId));
         }
 
         Log::debug("Thread finished.");
@@ -1307,6 +1301,12 @@ Process::PID LOOLWSD::createForKit()
     return child.id();
 }
 
+void LOOLWSD::killKit(const Process::PID /*pid*/)
+{
+    std::unique_lock<std::mutex> docBrokersLock(docBrokersMutex);
+    // TODO
+}
+
 int LOOLWSD::main(const std::vector<std::string>& /*args*/)
 {
     Log::initialize("wsd");
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index ae290e4..33c8c97 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -55,6 +55,9 @@ public:
         return Util::encodeId(++NextSessionId, 4);
     }
 
+    static
+    void killKit(const Poco::Process::PID pid);
+
 protected:
     void initialize(Poco::Util::Application& self) override;
     void uninitialize() override;


More information about the Libreoffice-commits mailing list