ソースを参照

server-mode: Allow for sending signals

Enable the server to send signals.
Tobias Hunger 9 年 前
コミット
e22d30e25a

+ 8 - 0
Help/manual/cmake-server.7.rst

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

+ 13 - 0
Source/cmServer.cxx

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

+ 1 - 0
Source/cmServer.h

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

+ 2 - 0
Source/cmServerDictionary.h

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

+ 7 - 0
Source/cmServerProtocol.cxx

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

+ 2 - 0
Source/cmServerProtocol.h

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