Commit 0da033fc by 李维杰

修改请求相关逻辑

parent 8a3b42dd
#include "cmd_processer_server.h" #include "cmd_processer_server.h"
#include "mqtt_request.h"
namespace offcn namespace offcn
{ {
......
#pragma once #pragma once
#include "mqtt_wrapper.h" #include "mqtt_wrapper.h"
#include <map>
namespace offcn namespace offcn
{ {
...@@ -26,5 +27,8 @@ namespace offcn ...@@ -26,5 +27,8 @@ namespace offcn
private: private:
MqttWrapper *mqtt_wrapper_; MqttWrapper *mqtt_wrapper_;
private:
std::map<std::string, std::string> client_lists_;
}; };
} }
\ No newline at end of file
...@@ -74,6 +74,28 @@ namespace offcn ...@@ -74,6 +74,28 @@ namespace offcn
return Json::writeString(wBuilder, root); return Json::writeString(wBuilder, root);
} }
static bool GetJsonValue(std::string &response, Json::Value &root)
{
Json::CharReaderBuilder readerBuilder;
std::unique_ptr<Json::CharReader> const reader(readerBuilder.newCharReader());
const char *start_pos = response.c_str();
std::string err;
if (!reader->parse(start_pos, start_pos + response.length(), &root, &err))
{
return false;
}
return true;
}
bool MqttRequest::ParseRequest(std::string &req, std::string &path, ReqValue &values)
{
Json::Value root;
if (!GetJsonValue(req, root)) return false;
}
std::string MqttRequest::JoinResponse(std::string ids, std::string result) std::string MqttRequest::JoinResponse(std::string ids, std::string result)
{ {
Json::Value root; Json::Value root;
......
#pragma once #pragma once
#include <string> #include <string>
#include <map>
namespace offcn namespace offcn
{ {
typedef std::map<std::string, std::string> ReqValue;
class MqttRequest class MqttRequest
{ {
public: public:
static std::string JoinRequest(std::string local_id); static std::string JoinRequest(std::string local_id);
static std::string UpdateRequest(std::string local_id, std::string pull_type); static std::string UpdateRequest(std::string local_id, std::string pull_type);
static std::string Candidate(std::string local_id, std::string remote_id, std::string type, std::string candidate); static std::string Candidate(std::string local_id, std::string remote_id, std::string type, std::string candidate);
static bool ParseRequest(std::string &req, std::string &path, ReqValue &values);
static std::string JoinResponse(std::string ids, std::string result); static std::string JoinResponse(std::string ids, std::string result);
static std::string UpdateResponse(std::string result); static std::string UpdateResponse(std::string result);
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment