cmake-server: Use consistent constant naming style

This commit is contained in:
Tobias Hunger 2016-09-20 15:29:33 +02:00
parent 6b8812c27e
commit 70b8ba9a0f
2 changed files with 27 additions and 31 deletions

View File

@ -22,17 +22,17 @@
#include "cm_jsoncpp_value.h" #include "cm_jsoncpp_value.h"
#endif #endif
const char kTYPE_KEY[] = "type"; static const std::string kTYPE_KEY = "type";
const char kCOOKIE_KEY[] = "cookie"; static const std::string kCOOKIE_KEY = "cookie";
const char REPLY_TO_KEY[] = "inReplyTo"; static const std::string kREPLY_TO_KEY = "inReplyTo";
const char ERROR_MESSAGE_KEY[] = "errorMessage"; static const std::string kERROR_MESSAGE_KEY = "errorMessage";
const char ERROR_TYPE[] = "error"; static const std::string kERROR_TYPE = "error";
const char REPLY_TYPE[] = "reply"; static const std::string kREPLY_TYPE = "reply";
const char PROGRESS_TYPE[] = "progress"; static const std::string kPROGRESS_TYPE = "progress";
const char START_MAGIC[] = "[== CMake Server ==["; static const std::string kSTART_MAGIC = "[== CMake Server ==[";
const char END_MAGIC[] = "]== CMake Server ==]"; static const std::string kEND_MAGIC = "]== CMake Server ==]";
typedef struct typedef struct
{ {
@ -154,11 +154,11 @@ void cmServer::handleData(const std::string& data)
line.erase(ls - 1, 1); line.erase(ls - 1, 1);
this->DataBuffer.erase(this->DataBuffer.begin(), this->DataBuffer.erase(this->DataBuffer.begin(),
this->DataBuffer.begin() + needle + 1); this->DataBuffer.begin() + needle + 1);
if (line == START_MAGIC) { if (line == kSTART_MAGIC) {
this->JsonData.clear(); this->JsonData.clear();
continue; continue;
} }
if (line == END_MAGIC) { if (line == kEND_MAGIC) {
this->Queue.push_back(this->JsonData); this->Queue.push_back(this->JsonData);
this->JsonData.clear(); this->JsonData.clear();
if (!this->Writing) { if (!this->Writing) {
@ -296,9 +296,8 @@ void cmServer::WriteJsonObject(const Json::Value& jsonValue) const
{ {
Json::FastWriter writer; Json::FastWriter writer;
std::string result = std::string("\n") + std::string(START_MAGIC) + std::string result = std::string("\n") + kSTART_MAGIC + std::string("\n") +
std::string("\n") + writer.write(jsonValue) + std::string(END_MAGIC) + writer.write(jsonValue) + kEND_MAGIC + std::string("\n");
std::string("\n");
this->Writing = true; this->Writing = true;
write_data(this->OutputStream, result, on_stdout_write); write_data(this->OutputStream, result, on_stdout_write);
@ -328,8 +327,8 @@ void cmServer::WriteProgress(const cmServerRequest& request, int min,
assert(message.length() != 0); assert(message.length() != 0);
Json::Value obj = Json::objectValue; Json::Value obj = Json::objectValue;
obj[kTYPE_KEY] = PROGRESS_TYPE; obj[kTYPE_KEY] = kPROGRESS_TYPE;
obj[REPLY_TO_KEY] = request.Type; obj[kREPLY_TO_KEY] = request.Type;
obj[kCOOKIE_KEY] = request.Cookie; obj[kCOOKIE_KEY] = request.Cookie;
obj["progressMessage"] = message; obj["progressMessage"] = message;
obj["progressMinimum"] = min; obj["progressMinimum"] = min;
@ -342,9 +341,9 @@ void cmServer::WriteProgress(const cmServerRequest& request, int min,
void cmServer::WriteParseError(const std::string& message) const void cmServer::WriteParseError(const std::string& message) const
{ {
Json::Value obj = Json::objectValue; Json::Value obj = Json::objectValue;
obj[kTYPE_KEY] = ERROR_TYPE; obj[kTYPE_KEY] = kERROR_TYPE;
obj[ERROR_MESSAGE_KEY] = message; obj[kERROR_MESSAGE_KEY] = message;
obj[REPLY_TO_KEY] = ""; obj[kREPLY_TO_KEY] = "";
obj[kCOOKIE_KEY] = ""; obj[kCOOKIE_KEY] = "";
this->WriteJsonObject(obj); this->WriteJsonObject(obj);
@ -356,10 +355,10 @@ void cmServer::WriteResponse(const cmServerResponse& response) const
Json::Value obj = response.Data(); Json::Value obj = response.Data();
obj[kCOOKIE_KEY] = response.Cookie; obj[kCOOKIE_KEY] = response.Cookie;
obj[kTYPE_KEY] = response.IsError() ? ERROR_TYPE : REPLY_TYPE; obj[kTYPE_KEY] = response.IsError() ? kERROR_TYPE : kREPLY_TYPE;
obj[REPLY_TO_KEY] = response.Type; obj[kREPLY_TO_KEY] = response.Type;
if (response.IsError()) { if (response.IsError()) {
obj[ERROR_MESSAGE_KEY] = response.ErrorMessage(); obj[kERROR_MESSAGE_KEY] = response.ErrorMessage();
} }
this->WriteJsonObject(obj); this->WriteJsonObject(obj);

View File

@ -22,17 +22,14 @@
#include "cm_jsoncpp_value.h" #include "cm_jsoncpp_value.h"
#endif #endif
namespace {
// Vocabulary: // Vocabulary:
const std::string kBUILD_DIRECTORY_KEY = "buildDirectory"; static const std::string kBUILD_DIRECTORY_KEY = "buildDirectory";
const std::string kCOOKIE_KEY = "cookie"; static const std::string kCOOKIE_KEY = "cookie";
const std::string kEXTRA_GENERATOR_KEY = "extraGenerator"; static const std::string kEXTRA_GENERATOR_KEY = "extraGenerator";
const std::string kGENERATOR_KEY = "generator"; static const std::string kGENERATOR_KEY = "generator";
const std::string kSOURCE_DIRECTORY_KEY = "sourceDirectory"; static const std::string kSOURCE_DIRECTORY_KEY = "sourceDirectory";
const std::string kTYPE_KEY = "type"; static const std::string kTYPE_KEY = "type";
} // namespace
cmServerRequest::cmServerRequest(cmServer* server, const std::string& t, cmServerRequest::cmServerRequest(cmServer* server, const std::string& t,
const std::string& c, const Json::Value& d) const std::string& c, const Json::Value& d)