完成GM指令

This commit is contained in:
aozhiwei 2019-01-12 19:11:11 +08:00
parent b0b795a824
commit ebe690a5d8
4 changed files with 34 additions and 20 deletions

View File

@ -54,7 +54,9 @@ public:
a8::XParams()
.SetSender(socket_handle)
.SetParam1(url)
.SetParam2(querystr));
.SetParam2(querystr)
.SetParam3(saddr)
);
}
virtual void OnDisConnect() override

View File

@ -336,7 +336,8 @@ void App::ProcessIMMsg()
switch (im_work_node_->msgid) {
case IM_ExecGM:
{
HandlerMgr::Instance()->ProcGMMsg(pdelnode->params.sender,
HandlerMgr::Instance()->ProcGMMsg(pdelnode->params.param3,
pdelnode->params.sender,
pdelnode->params.param1.GetString(),
pdelnode->params.param2.GetString()
);

View File

@ -7,17 +7,18 @@
#include "dbpool.h"
#include "ss_proto.pb.h"
void _GMAppEcho(a8::HTTPRequest& request, a8::MutableXObject* xobj)
static void _GMOpsSelfChecking(f8::JsonHttpRequest* request)
{
xobj->SetVal("error_code", 1);
xobj->SetVal("error_msg", "");
xobj->SetVal("error_msg", a8::Get(request, "msg"));
request->resp_xobj->SetVal("errcode", 1);
request->resp_xobj->SetVal("errmsg", "");
request->resp_xobj->SetVal("healthy", 1);
request->resp_xobj->SetVal("max_rundelay", 10);
}
void HandlerMgr::Init()
{
RegisterNetMsgHandlers();
RegisterGMMsgHandler("app$echo", _GMAppEcho);
RegisterGMMsgHandler("Ops@selfChecking", _GMOpsSelfChecking);
}
void HandlerMgr::UnInit()
@ -30,9 +31,10 @@ void HandlerMgr::RegisterNetMsgHandlers()
RegisterNetMsgHandler(&gsmsghandler, &DBPool::_SS_GSM_ExecAsyncSql);
}
void HandlerMgr::ProcGMMsg(int sockhandle, const std::string& url, const std::string& querystr)
void HandlerMgr::ProcGMMsg(unsigned long saddr, int sockhandle,
const std::string& url, const std::string& querystr)
{
if (url != "/index.php") {
if (url != "/webapp/index.php") {
GSListener::Instance()->SendText(sockhandle, a8::HttpResponse(404, ""));
return;
}
@ -40,24 +42,32 @@ void HandlerMgr::ProcGMMsg(int sockhandle, const std::string& url, const std::st
a8::HTTPRequest request;
a8::ParserUrlQueryString(querystr.c_str(), request);
std::string msgname = a8::Get(request, "c").GetString() + "$" + a8::Get(request, "a").GetString();
std::string msgname = a8::Get(request, "c").GetString() + "@" + a8::Get(request, "a").GetString();
auto itr = gmhandlers_.find(msgname);
if (itr != gmhandlers_.end()) {
a8::MutableXObject* xobj = a8::MutableXObject::NewObject();
itr->second(request, xobj);
f8::JsonHttpRequest* request = new f8::JsonHttpRequest;
request->saddr = saddr;
request->socket_handle = sockhandle;
request->query_str = querystr;
request->request.ReadFromUrlQueryString(querystr);
request->resp_xobj->SetVal("errcode", 0);
request->resp_xobj->SetVal("errmsg", "");
itr->second(request);
if (!request->pending){
std::string response;
xobj->ToJsonStr(response);
request->resp_xobj->ToJsonStr(response);
GSListener::Instance()->SendText(sockhandle, a8::HttpResponse(response));
delete xobj;
delete request;
}
} else {
GSListener::Instance()->SendText(sockhandle, a8::HttpResponse("{}"));
}
}
void HandlerMgr::RegisterGMMsgHandler(const std::string& msgname,
void (*handler)(a8::HTTPRequest&, a8::MutableXObject*))
void (*handler)(f8::JsonHttpRequest*))
{
gmhandlers_[msgname] = handler;
}

View File

@ -23,12 +23,13 @@ class HandlerMgr : public a8::Singleton<HandlerMgr>
f8::NetMsgHandlerObject gsmsghandler;
void ProcGMMsg(int sockhandle, const std::string& url, const std::string& quyerstr);
void ProcGMMsg(unsigned long saddr, int sockhandle,
const std::string& url, const std::string& quyerstr);
private:
void RegisterNetMsgHandlers();
void RegisterGMMsgHandler(const std::string& msgname,
void (*)(a8::HTTPRequest&, a8::MutableXObject*));
void (*)(f8::JsonHttpRequest*));
std::map<std::string, void (*)(a8::HTTPRequest&, a8::MutableXObject*)> gmhandlers_;
std::map<std::string, void (*)(f8::JsonHttpRequest*)> gmhandlers_;
};