|
@@ -135,6 +135,7 @@ private:
|
|
{
|
|
{
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+public:
|
|
/**
|
|
/**
|
|
* @brief 用来处理WEB发送的请求(web请求回调函数)
|
|
* @brief 用来处理WEB发送的请求(web请求回调函数)
|
|
* @param ID
|
|
* @param ID
|
|
@@ -143,14 +144,20 @@ private:
|
|
* @param need_ack
|
|
* @param need_ack
|
|
* @param ack_resp
|
|
* @param ack_resp
|
|
*/
|
|
*/
|
|
- void accept( int ID, std::string const& name,
|
|
|
|
|
|
+ static void accept( int ID, std::string const& name,
|
|
sio::message::ptr const& data, bool need_ack, sio::message::list &ack_resp );
|
|
sio::message::ptr const& data, bool need_ack, sio::message::list &ack_resp );
|
|
|
|
|
|
/**
|
|
/**
|
|
* @brief 注册web请求回调函数
|
|
* @brief 注册web请求回调函数
|
|
* @param MsgFuncList
|
|
* @param MsgFuncList
|
|
*/
|
|
*/
|
|
- void init(std::map<std::string, YA::MSG_HANDLE_FUNC_TYPE>& MsgFuncList);
|
|
|
|
|
|
+ void init(std::map<std::string, YA::MSG_HANDLE_FUNC_TYPE>& MsgFuncList)
|
|
|
|
+ {
|
|
|
|
+ MsgFuncList.insert( std::make_pair( JSON_CMD_VALUE_REQUEST_ALL_DATA, &module_web::accept ) );
|
|
|
|
+ MsgFuncList.insert( std::make_pair( JSON_CMD_VALUE_DEAL_HELP, &module_web::accept ) );
|
|
|
|
+ MsgFuncList.insert( std::make_pair( JSON_CMD_VALUE_CALL_CARD_REQUEST, &module_web::accept ) );
|
|
|
|
+ MsgFuncList.insert( std::make_pair( JSON_CMD_VALUE_CALL_CARD_CANCEL_REQUEST, &module_web::accept ) );
|
|
|
|
+ }
|
|
|
|
|
|
/// web前端有用户登录时,反馈给web所有信息
|
|
/// web前端有用户登录时,反馈给web所有信息
|
|
void response_login();
|
|
void response_login();
|
|
@@ -159,15 +166,28 @@ private:
|
|
class tool_json
|
|
class tool_json
|
|
{
|
|
{
|
|
public:
|
|
public:
|
|
- static bool try_get_value(int& d, const char* k, const rapidjson::Value& data)
|
|
|
|
|
|
+ static bool try_get_iter(const char* key, const rapidjson::Value& node,
|
|
|
|
+ rapidjson::Value::ConstMemberIterator& out_iter)
|
|
{
|
|
{
|
|
- if(data.IsObject())
|
|
|
|
|
|
+ if(node.IsObject())
|
|
{
|
|
{
|
|
- auto iter = data.FindMember(k);
|
|
|
|
- if(data.MemberEnd() == iter)
|
|
|
|
|
|
+ out_iter = node.FindMember(key);
|
|
|
|
+ if(node.MemberEnd() == out_iter)
|
|
{
|
|
{
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ static bool try_get_value(int& d, const char* key, const rapidjson::Value& node)
|
|
|
|
+ {
|
|
|
|
+ rapidjson::Value::ConstMemberIterator iter;
|
|
|
|
+ if(try_get_iter(key, node, iter))
|
|
|
|
+ {
|
|
if(iter->value.IsInt())
|
|
if(iter->value.IsInt())
|
|
{
|
|
{
|
|
d = iter->value.GetInt();
|
|
d = iter->value.GetInt();
|
|
@@ -178,15 +198,11 @@ public:
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
- static bool try_get_value(uint64_t& d, const char* k, const rapidjson::Value& data)
|
|
|
|
|
|
+ static bool try_get_value(uint64_t& d, const char* key, const rapidjson::Value& node)
|
|
{
|
|
{
|
|
- if(data.IsObject())
|
|
|
|
|
|
+ rapidjson::Value::ConstMemberIterator iter;
|
|
|
|
+ if(try_get_iter(key, node, iter))
|
|
{
|
|
{
|
|
- auto iter = data.FindMember(k);
|
|
|
|
- if(data.MemberEnd() == iter)
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
if(iter->value.IsUint64())
|
|
if(iter->value.IsUint64())
|
|
{
|
|
{
|
|
d = iter->value.GetUint64();
|
|
d = iter->value.GetUint64();
|
|
@@ -196,15 +212,25 @@ public:
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
- static bool try_get_value(std::string& d, const char* k, const rapidjson::Value& data)
|
|
|
|
|
|
+ static bool try_get_value(double& d, const char* key, const rapidjson::Value& node)
|
|
{
|
|
{
|
|
- if(data.IsObject())
|
|
|
|
|
|
+ rapidjson::Value::ConstMemberIterator iter;
|
|
|
|
+ if(try_get_iter(key, node, iter))
|
|
{
|
|
{
|
|
- auto iter = data.FindMember(k);
|
|
|
|
- if(data.MemberEnd() == iter)
|
|
|
|
|
|
+ if(iter->value.IsDouble())
|
|
{
|
|
{
|
|
- return false;
|
|
|
|
|
|
+ d = iter->value.GetDouble();
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ static bool try_get_value(std::string& d, const char* key, const rapidjson::Value& node)
|
|
|
|
+ {
|
|
|
|
+ rapidjson::Value::ConstMemberIterator iter;
|
|
|
|
+ if(try_get_iter(key, node, iter))
|
|
|
|
+ {
|
|
if(iter->value.IsString())
|
|
if(iter->value.IsString())
|
|
{
|
|
{
|
|
d = iter->value.GetString();
|
|
d = iter->value.GetString();
|
|
@@ -215,54 +241,32 @@ public:
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
-// static bool is_equal(const char* k, const char* v, const rapidjson::Value& data){
|
|
|
|
-// auto iter = data.FindMember(k);
|
|
|
|
-// if(data.MemberEnd() == iter){
|
|
|
|
-// return false;
|
|
|
|
-// }
|
|
|
|
-// return 0 == strcmp(v, iter->value.GetString());
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
-// static bool is_equal(const char* k, const std::string& v, const rapidjson::Value& data){
|
|
|
|
-// return is_equal(k, v.c_str(), data);
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
-// static int get_value(const char* k, const int& d, const rapidjson::Value& data){
|
|
|
|
-// auto iter = data.FindMember(k);
|
|
|
|
-// if(data.MemberEnd() == iter){
|
|
|
|
-// return d;
|
|
|
|
-// }
|
|
|
|
-// if(iter->value.IsInt()){
|
|
|
|
-// return iter->value.GetInt();
|
|
|
|
-// }
|
|
|
|
-// return d;
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
-// static std::string get_value(const char* k, const std::string& d, const rapidjson::Value& data){
|
|
|
|
-// auto iter = data.FindMember(k);
|
|
|
|
-// if(data.MemberEnd() == iter){
|
|
|
|
-// return d;
|
|
|
|
-// }
|
|
|
|
-// if(iter->value.IsArray() || iter->value.IsObject()){
|
|
|
|
-// return d;
|
|
|
|
-// }
|
|
|
|
-// return iter->value.GetString();
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-// static void push_back(const std::string& v, rapidjson::Value& data, rapidjson::Document::AllocatorType& allocator){
|
|
|
|
-// rapidjson::Value value_tmp;
|
|
|
|
-// value_tmp.SetString(v.c_str(), static_cast<rapidjson::SizeType>(v.size()), allocator);
|
|
|
|
-// data.PushBack(value_tmp, allocator);
|
|
|
|
-// }
|
|
|
|
|
|
+ static int get_value(const char* key, const int& default_data, const rapidjson::Value& node)
|
|
|
|
+ {
|
|
|
|
+ rapidjson::Value::ConstMemberIterator iter;
|
|
|
|
+ if(try_get_iter(key, node, iter))
|
|
|
|
+ {
|
|
|
|
+ if(iter->value.IsInt())
|
|
|
|
+ {
|
|
|
|
+ return iter->value.GetInt();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- static std::string ev_to_json(std::shared_ptr<ya_event> ev_ptr)
|
|
|
|
|
|
+ return default_data;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ static std::string get_value(const char* key, const std::string& default_data, const rapidjson::Value& node)
|
|
{
|
|
{
|
|
- std::vector<std::shared_ptr<ya_event>> evs;
|
|
|
|
- evs.push_back(ev_ptr);
|
|
|
|
- return evs_to_json(evs);
|
|
|
|
|
|
+ rapidjson::Value::ConstMemberIterator iter;
|
|
|
|
+ if(try_get_iter(key, node, iter))
|
|
|
|
+ {
|
|
|
|
+ if(iter->value.IsString())
|
|
|
|
+ {
|
|
|
|
+ return iter->value.GetString();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return default_data;
|
|
}
|
|
}
|
|
|
|
|
|
static std::string doc_to_json(rapidjson::Document& doc)
|
|
static std::string doc_to_json(rapidjson::Document& doc)
|
|
@@ -274,6 +278,13 @@ public:
|
|
return sb.GetString();
|
|
return sb.GetString();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ static std::string ev_to_json(std::shared_ptr<ya_event> ev_ptr)
|
|
|
|
+ {
|
|
|
|
+ std::vector<std::shared_ptr<ya_event>> evs;
|
|
|
|
+ evs.push_back(ev_ptr);
|
|
|
|
+ return evs_to_json(evs);
|
|
|
|
+ }
|
|
|
|
+
|
|
static std::string evs_to_json(std::vector<std::shared_ptr<ya_event>> evs)
|
|
static std::string evs_to_json(std::vector<std::shared_ptr<ya_event>> evs)
|
|
{
|
|
{
|
|
rapidjson::Document doc(rapidjson::kObjectType);
|
|
rapidjson::Document doc(rapidjson::kObjectType);
|