代码拉取完成,页面将自动刷新
#include "agent.hpp"
//using namespace std;
typedef void (*AgentHandler)(cJSON *req, cJSON *resp);
class AgentNode
{
public:
std::vector<AgentHandler> handlers;
//AgentHandler _handler;
std::map<std::string, AgentNode *> childrens;
public:
void Route(std::string path, AgentHandler handler)
{
if (path == "")
{
handlers.push_back(handler);
//_handler = handler;
return;
}
int c = path.find_first_of('/');
std::string node = path.substr(0, c);
std::string next = path.substr(c);
if (childrens.find(node) == childrens.end())
{
childrens[node] = new AgentNode();
}
childrens[node]->Route(next, handler);
}
void Walk(std::string path, cJSON* req, cJSON* resp)
{
if (path == "")
{
//handlers.push_back(handler);
for (auto iter = handlers.cbegin();
iter != handlers.cend(); iter++)
{
(*iter)(req, resp);
}
return;
}
int c = path.find_first_of('/');
std::string node = path.substr(0, c);
std::string next = path.substr(c);
auto iter = childrens.find(node);
if (iter == childrens.end())
{
return;
}
iter->second->Walk(next, req, resp);
}
};
AgentNode root;
void sysInfo(cJSON* req, cJSON* resp)
{
}
void Agent_Init()
{
root.Route("sys/info", sysInfo);
}
void AgentHandle() //(Stream &stream)
{
//return output;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。