提交 2a7e950d authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Improve MS_TRACE

上级 cbd4017d
...@@ -80,7 +80,7 @@ bool Logger::HasDebugLevel() ...@@ -80,7 +80,7 @@ bool Logger::HasDebugLevel()
#define MS_TRACE() \ #define MS_TRACE() \
do \ do \
{ \ { \
dprintf(Logger::fd, "D" _MS_LOG_STR _MS_LOG_SEPARATOR_CHAR, _MS_LOG_ARG); \ dprintf(Logger::fd, "D(trace) " _MS_LOG_STR _MS_LOG_SEPARATOR_CHAR, _MS_LOG_ARG); \
} \ } \
while (0) while (0)
#else #else
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
namespace Channel namespace Channel
{ {
static Json::Value empty_data(Json::objectValue);
/* Static methods. */ /* Static methods. */
Channel::Request* Request::Factory(Channel::UnixStreamSocket* channel, Json::Value& json) Channel::Request* Request::Factory(Channel::UnixStreamSocket* channel, Json::Value& json)
...@@ -73,21 +75,14 @@ namespace Channel ...@@ -73,21 +75,14 @@ namespace Channel
{ {
MS_TRACE(); MS_TRACE();
static Json::Value no_data(Json::nullValue); Accept(empty_data);
Accept(no_data);
} }
void Request::Accept(Json::Value &data) void Request::Accept(Json::Value &data)
{ {
MS_TRACE(); MS_TRACE();
if (this->replied) MS_ASSERT(!this->replied, "Request already replied");
{
MS_ERROR("already replied");
return;
}
this->replied = true; this->replied = true;
Json::Value json; Json::Value json;
...@@ -97,6 +92,8 @@ namespace Channel ...@@ -97,6 +92,8 @@ namespace Channel
if (data.isObject()) if (data.isObject())
json["data"] = data; json["data"] = data;
else
json["data"] = empty_data;
this->channel->Send(json); this->channel->Send(json);
} }
...@@ -108,18 +105,20 @@ namespace Channel ...@@ -108,18 +105,20 @@ namespace Channel
Reject(status, reason.c_str()); Reject(status, reason.c_str());
} }
/**
* Reject the Request.
* @param status 4XX means normal rejection, 5XX means error.
* @param reason Description string.
*/
void Request::Reject(unsigned int status, const char* reason) void Request::Reject(unsigned int status, const char* reason)
{ {
MS_TRACE(); MS_TRACE();
if (this->replied) MS_ASSERT(!this->replied, "Request already replied");
{
MS_ERROR("already replied");
return;
}
this->replied = true; this->replied = true;
MS_ASSERT(status >= 400 && status <= 599, "status must be between 400 and 500");
Json::Value json; Json::Value json;
json["id"] = this->id; json["id"] = this->id;
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论