server-mode: Allow for sending signals

Enable the server to send signals.
This commit is contained in:
Tobias Hunger 2016-09-09 10:01:45 +02:00
parent cc576c2c7f
commit e22d30e25a
6 changed files with 33 additions and 0 deletions

View File

@ -186,6 +186,14 @@ Example::
]== CMake Server ==]
Type "signal"
^^^^^^^^^^^^^
The server can send signals when it detects changes in the system state. Signals
are of type "signal", have an empty "cookie" and "inReplyTo" field and always
have a "name" set to show which signal was sent.
Specific Message Types
----------------------

View File

@ -343,6 +343,19 @@ void cmServer::WriteParseError(const std::string& message) const
this->WriteJsonObject(obj, nullptr);
}
void cmServer::WriteSignal(const std::string& name,
const Json::Value& data) const
{
assert(data.isObject());
Json::Value obj = data;
obj[kTYPE_KEY] = kSIGNAL_TYPE;
obj[kREPLY_TO_KEY] = "";
obj[kCOOKIE_KEY] = "";
obj[kNAME_KEY] = name;
WriteJsonObject(obj, nullptr);
}
void cmServer::WriteResponse(const cmServerResponse& response,
const DebugInfo* debug) const
{

View File

@ -63,6 +63,7 @@ private:
void WriteResponse(const cmServerResponse& response,
const DebugInfo* debug) const;
void WriteParseError(const std::string& message) const;
void WriteSignal(const std::string& name, const Json::Value& obj) const;
void WriteJsonObject(Json::Value const& jsonValue,
const DebugInfo* debug) const;

View File

@ -21,6 +21,7 @@ static const std::string kHANDSHAKE_TYPE = "handshake";
static const std::string kMESSAGE_TYPE = "message";
static const std::string kPROGRESS_TYPE = "progress";
static const std::string kREPLY_TYPE = "reply";
static const std::string kSIGNAL_TYPE = "signal";
static const std::string kBUILD_DIRECTORY_KEY = "buildDirectory";
static const std::string kCOOKIE_KEY = "cookie";
@ -31,6 +32,7 @@ static const std::string kIS_EXPERIMENTAL_KEY = "isExperimental";
static const std::string kMAJOR_KEY = "major";
static const std::string kMESSAGE_KEY = "message";
static const std::string kMINOR_KEY = "minor";
static const std::string kNAME_KEY = "name";
static const std::string kPROGRESS_CURRENT_KEY = "progressCurrent";
static const std::string kPROGRESS_MAXIMUM_KEY = "progressMaximum";
static const std::string kPROGRESS_MESSAGE_KEY = "progressMessage";

View File

@ -122,6 +122,13 @@ bool cmServerProtocol::Activate(cmServer* server,
return result;
}
void cmServerProtocol::SendSignal(const std::string& name,
const Json::Value& data) const
{
if (this->m_Server)
this->m_Server->WriteSignal(name, data);
}
cmake* cmServerProtocol::CMakeInstance() const
{
return this->m_CMakeInstance.get();

View File

@ -90,6 +90,8 @@ public:
bool Activate(cmServer* server, const cmServerRequest& request,
std::string* errorMessage);
void SendSignal(const std::string& name, const Json::Value& data) const;
protected:
cmake* CMakeInstance() const;
// Implement protocol specific activation tasks here. Called from Activate().