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@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
This commit is contained in:
Ashod Nakashian 2016-11-17 09:00:05 -05:00 committed by Ashod Nakashian
parent c0e3460c68
commit d3e64b1aa4
4 changed files with 32 additions and 15 deletions

View file

@ -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);

View file

@ -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)

View file

@ -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();
@ -2148,15 +2148,20 @@ 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);
}
}

View file

@ -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&)
{
}