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

Ashod Nakashian ashod.nakashian at collabora.co.uk
Sun Nov 20 00:21:31 UTC 2016


 loolwsd/DocumentBroker.cpp |    7 ++-----
 loolwsd/DocumentBroker.hpp |    7 ++++++-
 loolwsd/LOOLWSD.cpp        |   11 ++++++++---
 loolwsd/Util.hpp           |   22 ++++++++++++++++------
 4 files changed, 32 insertions(+), 15 deletions(-)

New commits:
commit d3e64b1aa478f6b6b5c62cfc5877c7bd29785645
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Thu Nov 17 09:00:05 2016 -0500

    loolwsd: improved alertAllUsers
    
    More flexible reason message and other cleanups
    to help use altertAllUsers in other situations.
    
    Change-Id: I7f0c7b5ac21ffa55923f531d7b28f7537ef42dac
    Reviewed-on: https://gerrit.libreoffice.org/30997
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 6cc4847..1b35377 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -517,7 +517,7 @@ size_t DocumentBroker::addSession(std::shared_ptr<ClientSession>& session)
         // even if in this case it might be a totally different location (file system, or
         // some other type of storage somewhere). This message is not sent to all clients,
         // though, just to all sessions of this document.
-        alertAllUsersOfDocument("internal", "diskfull");
+        alertAllUsers("internal", "diskfull");
         throw;
     }
 
@@ -572,13 +572,10 @@ size_t DocumentBroker::removeSession(const std::string& id)
     return _sessions.size();
 }
 
-void DocumentBroker::alertAllUsersOfDocument(const std::string& cmd, const std::string& kind)
+void DocumentBroker::alertAllUsers(const std::string& msg)
 {
     Util::assertIsLocked(_mutex);
 
-    std::stringstream ss;
-    ss << "error: cmd=" << cmd << " kind=" << kind;
-    const auto msg = ss.str();
     for (auto& it : _sessions)
     {
         it.second->sendTextFrame(msg);
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 7e94fa2..6672aaf 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -242,7 +242,12 @@ public:
     /// Removes a session by ID. Returns the new number of sessions.
     size_t removeSession(const std::string& id);
 
-    void alertAllUsersOfDocument(const std::string& cmd, const std::string& kind);
+    void alertAllUsers(const std::string& msg);
+
+    void alertAllUsers(const std::string& cmd, const std::string& kind)
+    {
+        alertAllUsers("error: cmd=" + cmd + " kind=" + kind);
+    }
 
     /// Invalidate the cursor position.
     void invalidateCursor(int x, int y, int w, int h)
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 8a3fd40..0a34591 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -2078,7 +2078,7 @@ int LOOLWSD::main(const std::vector<std::string>& /*args*/)
     // and wait until sockets close.
     LOG_INF("Stopping server socket listening. ShutdownFlag: " <<
             ShutdownFlag << ", TerminationFlag: " << TerminationFlag);
-    Util::alertAllUsers("internal", "shutdown");
+    Util::alertAllUsers("close: shutdown");
 
     srv.stop();
     srv2.stop();
@@ -2149,14 +2149,19 @@ namespace Util
 
 void alertAllUsers(const std::string& cmd, const std::string& kind)
 {
+    alertAllUsers("error: cmd=" + cmd + " kind=" + kind);
+}
+
+void alertAllUsers(const std::string& msg)
+{
     std::lock_guard<std::mutex> DocBrokersLock(DocBrokersMutex);
 
-    LOG_INF("Alerting all users: cmd=" << cmd << ", kind=" << kind);
+    LOG_INF("Alerting all users: [" << msg << "]");
 
     for (auto& brokerIt : DocBrokers)
     {
         auto lock = brokerIt.second->getLock();
-        brokerIt.second->alertAllUsersOfDocument(cmd, kind);
+        brokerIt.second->alertAllUsers(msg);
     }
 }
 
diff --git a/loolwsd/Util.hpp b/loolwsd/Util.hpp
index 40bcc30..e567972 100644
--- a/loolwsd/Util.hpp
+++ b/loolwsd/Util.hpp
@@ -47,14 +47,24 @@ namespace Util
     bool windowingAvailable();
 
 #ifndef BUILDING_TESTS
-    // Send a 'error:' message with the specified cmd and kind parameters to all connected
-    // clients. This function can be called either in loolwsd or loolkit processes, even if only
-    // loolwsd obviously has contact with the actual clients; in loolkit it will be forwarded to
-    // loolwsd for redistribution. (This function must be implemented separately in each program
-    // that uses it, it is not in Util.cpp.)
+
+    /// Send a message to all clients.
+    void alertAllUsers(const std::string& msg);
+
+    /// Send a 'error:' message with the specified cmd and kind parameters to all connected
+    /// clients. This function can be called either in loolwsd or loolkit processes, even if only
+    /// loolwsd obviously has contact with the actual clients; in loolkit it will be forwarded to
+    /// loolwsd for redistribution. (This function must be implemented separately in each program
+    /// that uses it, it is not in Util.cpp.)
     void alertAllUsers(const std::string& cmd, const std::string& kind);
 #else
-    // No-op implementation in the test programs
+
+    /// No-op implementation in the test programs
+    inline void alertAllUsers(const std::string&)
+    {
+    }
+
+    /// No-op implementation in the test programs
     inline void alertAllUsers(const std::string&, const std::string&)
     {
     }


More information about the Libreoffice-commits mailing list