103 lines
3.2 KiB
C++
103 lines
3.2 KiB
C++
#include "precompile.h"
|
|
|
|
#include <a8/mutable_xobject.h>
|
|
#include <f8/jsonhttprequest.h>
|
|
#include <f8/msgqueue.h>
|
|
|
|
#include "handlermgr.h"
|
|
|
|
#include "GGListener.h"
|
|
#include "app.h"
|
|
#include "gsmgr.h"
|
|
|
|
#include "ss_proto.pb.h"
|
|
|
|
static void _GMOpsSelfChecking(std::shared_ptr<f8::JsonHttpRequest> request)
|
|
{
|
|
request->GetResp()->SetVal("errcode", 0);
|
|
request->GetResp()->SetVal("errmsg", "");
|
|
request->GetResp()->SetVal("healthy", 1);
|
|
request->GetResp()->SetVal("max_rundelay", App::Instance()->perf.max_run_delay_time);
|
|
request->GetResp()->SetVal("max_timer_idle", App::Instance()->perf.max_timer_idle);
|
|
}
|
|
|
|
void HandlerMgr::Init()
|
|
{
|
|
RegisterNetMsgHandlers();
|
|
RegisterGMMsgHandler("Ops@selfChecking", _GMOpsSelfChecking);
|
|
RegisterGMMsgHandler("GS@report",
|
|
[] (std::shared_ptr<f8::JsonHttpRequest> request)
|
|
{
|
|
GSMgr::Instance()->___GSReport(request);
|
|
});
|
|
RegisterGMMsgHandler("GS@list",
|
|
[] (std::shared_ptr<f8::JsonHttpRequest> request)
|
|
{
|
|
GSMgr::Instance()->___GSList(request);
|
|
});
|
|
f8::MsgQueue::Instance()->RegisterCallBack
|
|
(
|
|
IM_ExecGM,
|
|
[] (const a8::Args& args)
|
|
{
|
|
int socket_handle = args.Get<int>(0);
|
|
std::string url = args.Get<std::string>(1);
|
|
std::string query_str = args.Get<std::string>(2);
|
|
unsigned long saddr = args.Get<unsigned long>(3);
|
|
|
|
HandlerMgr::Instance()->ProcGMMsg
|
|
(
|
|
saddr,
|
|
socket_handle,
|
|
url,
|
|
query_str
|
|
);
|
|
});
|
|
}
|
|
|
|
void HandlerMgr::UnInit()
|
|
{
|
|
}
|
|
|
|
void HandlerMgr::RegisterNetMsgHandlers()
|
|
{
|
|
RegisterNetMsgHandler(&ggmsghandler, &GSMgr::_SS_WSP_RequestTargetServer);
|
|
RegisterNetMsgHandler(&ggmsghandler, &GSMgr::_SS_Ping);
|
|
}
|
|
|
|
void HandlerMgr::ProcGMMsg(unsigned long saddr, int sockhandle,
|
|
const std::string& url, const std::string& querystr)
|
|
{
|
|
if (url != "/webapp/index.php") {
|
|
GGListener::Instance()->SendText(sockhandle, a8::HttpResponse(404, ""));
|
|
return;
|
|
}
|
|
|
|
a8::HTTPRequest request;
|
|
a8::ParserUrlQueryString(querystr.c_str(), request);
|
|
|
|
std::string msgname = a8::Get(request, "c").GetString() + "@" + a8::Get(request, "a").GetString();
|
|
auto itr = gmhandlers_.find(msgname);
|
|
if (itr != gmhandlers_.end()) {
|
|
auto request = std::make_shared<f8::JsonHttpRequest>
|
|
(
|
|
saddr,
|
|
url,
|
|
querystr,
|
|
[sockhandle] (const a8::Args& args)
|
|
{
|
|
std::string data = args.Get<std::string>(0);
|
|
GGListener::Instance()->SendText(sockhandle, a8::HttpResponse(data));
|
|
});
|
|
itr->second(request);
|
|
} else {
|
|
GGListener::Instance()->SendText(sockhandle, a8::HttpResponse("{}"));
|
|
}
|
|
}
|
|
|
|
void HandlerMgr::RegisterGMMsgHandler(const std::string& msgname,
|
|
void (*handler)(std::shared_ptr<f8::JsonHttpRequest>))
|
|
{
|
|
gmhandlers_[msgname] = handler;
|
|
}
|