Permalink
Browse files

mq, refactor: move Message.response to HttpRequest.response.

  • Loading branch information...
xicilion committed Dec 3, 2017
1 parent 46dd85f commit a9a78dd7a6ee6e169672edac3537973be1c0bad0
@@ -46,7 +46,6 @@ class HttpRequest : public HttpRequest_base {
virtual result_t sendTo(Stream_base* stm, AsyncEvent* ac);
virtual result_t readFrom(Stream_base* stm, AsyncEvent* ac);
virtual result_t get_stream(obj_ptr<Stream_base>& retVal);
virtual result_t get_response(obj_ptr<Message_base>& retVal);
virtual result_t get_lastError(exlib::string& retVal);
virtual result_t set_lastError(exlib::string newVal);
@@ -75,6 +74,7 @@ class HttpRequest : public HttpRequest_base {
public:
// HttpRequest_base
virtual result_t get_response(obj_ptr<HttpResponse_base>& retVal);
virtual result_t get_method(exlib::string& retVal);
virtual result_t set_method(exlib::string newVal);
virtual result_t get_address(exlib::string& retVal);
@@ -106,6 +106,7 @@ class HttpRequest : public HttpRequest_base {
}
private:
obj_ptr<HttpResponse_base> m_response;
obj_ptr<HttpMessage> m_message;
exlib::string m_method;
exlib::string m_address;
@@ -45,7 +45,6 @@ class HttpResponse : public HttpResponse_base {
virtual result_t sendTo(Stream_base* stm, AsyncEvent* ac);
virtual result_t readFrom(Stream_base* stm, AsyncEvent* ac);
virtual result_t get_stream(obj_ptr<Stream_base>& retVal);
virtual result_t get_response(obj_ptr<Message_base>& retVal);
virtual result_t get_lastError(exlib::string& retVal);
virtual result_t set_lastError(exlib::string newVal);
View
@@ -36,7 +36,6 @@ class Message : public Message_base {
virtual result_t sendTo(Stream_base* stm, AsyncEvent* ac);
virtual result_t readFrom(Stream_base* stm, AsyncEvent* ac);
virtual result_t get_stream(obj_ptr<Stream_base>& retVal);
virtual result_t get_response(obj_ptr<Message_base>& retVal);
virtual result_t get_lastError(exlib::string& retVal);
virtual result_t set_lastError(exlib::string newVal);
@@ -54,9 +53,6 @@ class Message : public Message_base {
return m_body;
}
public:
obj_ptr<Message_base> m_response;
private:
int32_t m_type;
obj_ptr<NArray> m_params;
@@ -51,7 +51,6 @@ class WebSocketMessage : public WebSocketMessage_base {
virtual result_t sendTo(Stream_base* stm, AsyncEvent* ac);
virtual result_t readFrom(Stream_base* stm, AsyncEvent* ac);
virtual result_t get_stream(obj_ptr<Stream_base>& retVal);
virtual result_t get_response(obj_ptr<Message_base>& retVal);
virtual result_t get_lastError(exlib::string& retVal);
virtual result_t set_lastError(exlib::string newVal);
@@ -42,7 +42,6 @@ class WorkerMessage : public Message_base {
virtual result_t sendTo(Stream_base* stm, AsyncEvent* ac);
virtual result_t readFrom(Stream_base* stm, AsyncEvent* ac);
virtual result_t get_stream(obj_ptr<Stream_base>& retVal);
virtual result_t get_response(obj_ptr<Message_base>& retVal);
virtual result_t get_lastError(exlib::string& retVal);
virtual result_t set_lastError(exlib::string newVal);
@@ -18,6 +18,7 @@
namespace fibjs {
class HttpMessage_base;
class HttpResponse_base;
class HttpCollection_base;
class HttpRequest_base : public HttpMessage_base {
@@ -26,6 +27,7 @@ class HttpRequest_base : public HttpMessage_base {
public:
// HttpRequest_base
static result_t _new(obj_ptr<HttpRequest_base>& retVal, v8::Local<v8::Object> This = v8::Local<v8::Object>());
virtual result_t get_response(obj_ptr<HttpResponse_base>& retVal) = 0;
virtual result_t get_method(exlib::string& retVal) = 0;
virtual result_t set_method(exlib::string newVal) = 0;
virtual result_t get_address(exlib::string& retVal) = 0;
@@ -42,6 +44,7 @@ class HttpRequest_base : public HttpMessage_base {
public:
static void s__new(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_get_response(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_get_method(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_set_method(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& args);
static void s_get_address(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
@@ -54,12 +57,14 @@ class HttpRequest_base : public HttpMessage_base {
};
}
#include "HttpResponse.h"
#include "HttpCollection.h"
namespace fibjs {
inline ClassInfo& HttpRequest_base::class_info()
{
static ClassData::ClassProperty s_property[] = {
{ "response", s_get_response, block_set, false },
{ "method", s_get_method, s_set_method, false },
{ "address", s_get_address, s_set_address, false },
{ "queryString", s_get_queryString, s_set_queryString, false },
@@ -99,6 +104,19 @@ void HttpRequest_base::__new(const T& args)
CONSTRUCT_RETURN();
}
inline void HttpRequest_base::s_get_response(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args)
{
obj_ptr<HttpResponse_base> vr;
METHOD_NAME("HttpRequest.response");
METHOD_INSTANCE(HttpRequest_base);
PROPERTY_ENTER();
hr = pInst->get_response(vr);
METHOD_RETURN();
}
inline void HttpRequest_base::s_get_method(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args)
{
exlib::string vr;
@@ -52,7 +52,6 @@ class Message_base : public object_base {
virtual result_t sendTo(Stream_base* stm, AsyncEvent* ac) = 0;
virtual result_t readFrom(Stream_base* stm, AsyncEvent* ac) = 0;
virtual result_t get_stream(obj_ptr<Stream_base>& retVal) = 0;
virtual result_t get_response(obj_ptr<Message_base>& retVal) = 0;
virtual result_t get_lastError(exlib::string& retVal) = 0;
virtual result_t set_lastError(exlib::string newVal) = 0;
@@ -81,7 +80,6 @@ class Message_base : public object_base {
static void s_sendTo(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_readFrom(const v8::FunctionCallbackInfo<v8::Value>& args);
static void s_get_stream(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_get_response(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_get_lastError(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args);
static void s_set_lastError(v8::Local<v8::String> property, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& args);
@@ -126,7 +124,6 @@ inline ClassInfo& Message_base::class_info()
{ "body", s_get_body, s_set_body, false },
{ "length", s_get_length, block_set, false },
{ "stream", s_get_stream, block_set, false },
{ "response", s_get_response, block_set, false },
{ "lastError", s_get_lastError, s_set_lastError, false }
};
@@ -452,19 +449,6 @@ inline void Message_base::s_get_stream(v8::Local<v8::String> property, const v8:
METHOD_RETURN();
}
inline void Message_base::s_get_response(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args)
{
obj_ptr<Message_base> vr;
METHOD_NAME("Message.response");
METHOD_INSTANCE(Message_base);
PROPERTY_ENTER();
hr = pInst->get_response(vr);
METHOD_RETURN();
}
inline void Message_base::s_get_lastError(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value>& args)
{
exlib::string vr;
@@ -97,11 +97,6 @@ result_t WorkerMessage::get_stream(obj_ptr<Stream_base>& retVal)
return m_message->get_stream(retVal);
}
result_t WorkerMessage::get_response(obj_ptr<Message_base>& retVal)
{
return m_message->get_response(retVal);
}
result_t WorkerMessage::get_type(int32_t& retVal)
{
return m_message->get_type(retVal);
@@ -155,9 +155,7 @@ result_t HttpFileHandler::invoke(object_base* v, obj_ptr<Handler_base>& retVal,
, m_index(false)
, m_dirPos(0)
{
obj_ptr<Message_base> m;
req->get_response(m);
m_rep = (HttpResponse_base*)(Message_base*)m;
req->get_response(m_rep);
Variant hdr;
@@ -73,10 +73,7 @@ result_t HttpHandler::invoke(object_base* v, obj_ptr<Handler_base>& retVal,
m_stmBuffered->set_EOL("\r\n");
m_req = new HttpRequest();
obj_ptr<Message_base> m;
m_req->get_response(m);
m_rep = (HttpResponse_base*)(Message_base*)m;
m_req->get_response(m_rep);
m_req->set_maxHeadersCount(pThis->m_maxHeadersCount);
m_req->set_maxBodySize(pThis->m_maxBodySize);
@@ -206,11 +206,20 @@ result_t HttpRequest::end()
result_t HttpRequest::isEnded(bool& retVal)
{
if (m_response) {
m_response->isEnded(retVal);
if (retVal)
return 0;
}
return m_message->isEnded(retVal);
}
result_t HttpRequest::clear()
{
if (m_response)
m_response->clear();
m_message->clear();
m_method.assign("GET", 3);
@@ -371,12 +380,13 @@ result_t HttpRequest::set_queryString(exlib::string newVal)
return 0;
}
result_t HttpRequest::get_response(obj_ptr<Message_base>& retVal)
result_t HttpRequest::get_response(obj_ptr<HttpResponse_base>& retVal)
{
if (!m_message->m_response)
m_message->m_response = new HttpResponse();
if (!m_response)
m_response = new HttpResponse();
return m_message->get_response(retVal);
retVal = m_response;
return 0;
}
result_t HttpRequest::get_cookies(obj_ptr<HttpCollection_base>& retVal)
@@ -391,11 +391,6 @@ result_t HttpResponse::get_stream(obj_ptr<Stream_base>& retVal)
return m_message->get_stream(retVal);
}
result_t HttpResponse::get_response(obj_ptr<Message_base>& retVal)
{
return CHECK_ERROR(CALL_E_INVALID_CALL);
}
result_t HttpResponse::get_statusCode(int32_t& retVal)
{
retVal = m_statusCode;
View
@@ -172,9 +172,6 @@ result_t Message::end()
result_t Message::isEnded(bool& retVal)
{
retVal = m_end;
if (!m_end && m_response)
m_response->isEnded(retVal);
return 0;
}
@@ -185,9 +182,6 @@ result_t Message::clear()
m_value.clear();
m_body.Release();
if (m_response)
m_response->clear();
return 0;
}
@@ -206,18 +200,6 @@ result_t Message::get_stream(obj_ptr<Stream_base>& retVal)
return CHECK_ERROR(CALL_E_INVALID_CALL);
}
result_t Message::get_response(obj_ptr<Message_base>& retVal)
{
if (m_bRep)
return CHECK_ERROR(CALL_E_INVALID_CALL);
if (!m_response)
m_response = new Message(true);
retVal = m_response;
return 0;
}
result_t Message::get_lastError(exlib::string& retVal)
{
retVal = m_lastError;
@@ -42,11 +42,7 @@ result_t WebSocketHandler::invoke(object_base* v, obj_ptr<Handler_base>& retVal,
, m_httpreq(req)
, m_compress(false)
{
obj_ptr<Message_base> rep;
m_httpreq->get_response(rep);
m_httprep = (HttpResponse_base*)(Message_base*)rep;
m_httpreq->get_response(m_httprep);
m_httpreq->get_stream(m_stm);
set(handshake);
@@ -566,11 +566,6 @@ result_t WebSocketMessage::get_stream(obj_ptr<Stream_base>& retVal)
return 0;
}
result_t WebSocketMessage::get_response(obj_ptr<Message_base>& retVal)
{
return CHECK_ERROR(CALL_E_INVALID_CALL);
}
result_t WebSocketMessage::get_type(int32_t& retVal)
{
return m_message->get_type(retVal);
@@ -5,6 +5,9 @@ interface HttpRequest : HttpMessage
/*! @brief HttpRequest 构造函数,创建一个新的 HttpRequest 对象 */
HttpRequest();
/*! @brief 获取响应消息对象*/
readonly HttpResponse response;
/*! @brief 查询和设置请求方法 */
String method;
View
@@ -87,9 +87,6 @@ interface Message : object
/*! @brief 查询消息 readFrom 时的流对象 */
readonly Stream stream;
/*! @brief 获取响应消息对象*/
readonly Message response;
/*! @brief 查询和设置消息处理的最后错误 */
String lastError;
};
View
@@ -673,7 +673,7 @@ describe("mq", () => {
}
]);
var req = new mq.Message();
var req = new http.Request();
mq.invoke(handler1, req);
assert.equal(2, n);
});

0 comments on commit a9a78dd

Please sign in to comment.