diff options
author | Tobias Hunger <tobias.hunger@qt.io> | 2016-09-09 10:01:44 +0200 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@qt.io> | 2016-09-20 20:52:38 +0200 |
commit | 537efe0561ef6a690fd7aac34ce1e4a46614f2e4 (patch) | |
tree | 3affd22e6db5f02e4227153adb37b0c626869045 /Source/cmServer.cxx | |
parent | ca7799482cbbb38b667fd5d045a0fc95d09a8cf2 (diff) | |
download | cmake-537efe0561ef6a690fd7aac34ce1e4a46614f2e4.tar.gz |
server-mode: Report Messages from cmake to clients
Pass messages sent from cmake via Error(...) or Message(...) on
to clients.
Diffstat (limited to 'Source/cmServer.cxx')
-rw-r--r-- | Source/cmServer.cxx | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/Source/cmServer.cxx b/Source/cmServer.cxx index 8fb452b96f..5d1c73cabb 100644 --- a/Source/cmServer.cxx +++ b/Source/cmServer.cxx @@ -14,6 +14,7 @@ #include "cmServer.h" #include "cmServerProtocol.h" +#include "cmSystemTools.h" #include "cmVersionMacros.h" #include "cmake.h" @@ -30,6 +31,7 @@ static const std::string kERROR_MESSAGE_KEY = "errorMessage"; static const std::string kERROR_TYPE = "error"; static const std::string kREPLY_TYPE = "reply"; static const std::string kPROGRESS_TYPE = "progress"; +static const std::string kMESSAGE_TYPE = "message"; static const std::string kSTART_MAGIC = "[== CMake Server ==["; static const std::string kEND_MAGIC = "]== CMake Server ==]"; @@ -134,6 +136,8 @@ void cmServer::PopOne() return; } + cmSystemTools::SetMessageCallback(reportMessage, + const_cast<cmServerRequest*>(&request)); if (this->Protocol) { this->Protocol->CMakeInstance()->SetProgressCallback( reportProgress, const_cast<cmServerRequest*>(&request)); @@ -220,12 +224,25 @@ void cmServer::reportProgress(const char* msg, float progress, void* data) const cmServerRequest* request = static_cast<const cmServerRequest*>(data); assert(request); if (progress < 0.0 || progress > 1.0) { - request->ReportProgress(0, 0, 0, msg); + request->ReportMessage(msg, ""); } else { request->ReportProgress(0, static_cast<int>(progress * 1000), 1000, msg); } } +void cmServer::reportMessage(const char* msg, const char* title, + bool& /* cancel */, void* data) +{ + const cmServerRequest* request = static_cast<const cmServerRequest*>(data); + assert(request); + assert(msg); + std::string titleString; + if (title) { + titleString = title; + } + request->ReportMessage(std::string(msg), titleString); +} + cmServerResponse cmServer::SetProtocolVersion(const cmServerRequest& request) { if (request.Type != "handshake") @@ -354,6 +371,25 @@ void cmServer::WriteProgress(const cmServerRequest& request, int min, this->WriteJsonObject(obj); } +void cmServer::WriteMessage(const cmServerRequest& request, + const std::string& message, + const std::string& title) const +{ + if (message.empty()) + return; + + Json::Value obj = Json::objectValue; + obj[kTYPE_KEY] = kMESSAGE_TYPE; + obj[kREPLY_TO_KEY] = request.Type; + obj[kCOOKIE_KEY] = request.Cookie; + obj["message"] = message; + if (!title.empty()) { + obj["title"] = title; + } + + WriteJsonObject(obj); +} + void cmServer::WriteParseError(const std::string& message) const { Json::Value obj = Json::objectValue; |