NIM SDK API  8.5.1
nim_subscribe_event_helper.h
Go to the documentation of this file.
1 
7 #ifndef _NIM_SDK_CPP_SUBSCRIBE_EVENT_HELPER_H_
8 #define _NIM_SDK_CPP_SUBSCRIBE_EVENT_HELPER_H_
9 
10 #include <functional>
11 #include <list>
12 #include <set>
13 #include <string>
14 #include "nim_define_include.h"
16 #include "nim_wrapper_util/nim_json_util.h"
21 namespace nim {
22 
24 struct NIM_SDK_CPPWRAPPER_DLL_API EventData {
27  std::string client_msg_id_;
28  std::string config_;
29  int64_t ttl_;
30  NIMEventBroadcastType broadcast_type_;
31  NIMEventSyncType sync_self_;
33 public:
39  std::string readonly_nim_config_;
40  std::string readonly_multi_config_;
42 public:
44  std::string readonly_consid_;
48  : event_type_(0)
49  , event_value_(0)
50  , ttl_(0)
51  , broadcast_type_(kNIMEventBroadcastTypeOnline)
52  , sync_self_(kNIMEventSyncTypeNoSelf)
53  , readonly_ttl_type(0)
54  , readonly_durable_(0)
55  , readonly_event_time_(0)
56  , readonly_client_type_(0) {}
57 
62  std::string ToJsonString() const {
63  nim_cpp_wrapper_util::Json::Value values;
64  values[kNIMEventEventType] = event_type_;
65  values[kNIMEventEventValue] = event_value_;
66  values[kNIMEventMsgIdClient] = client_msg_id_;
67  values[kNIMEventConfig] = config_;
68  values[kNIMEventTTL] = ttl_;
69  values[kNIMEventBroadcastType] = broadcast_type_;
70  values[kNIMEventSyncSelf] = sync_self_;
71 
72  return GetJsonStringWithNoStyled(values);
73  }
74 };
75 
77 struct NIM_SDK_CPPWRAPPER_DLL_API EventOnlineClientType {
78  std::set<NIMClientType> online_client_type_;
85  bool ParseConfig(const std::string& multi_config_json) {
86  nim_cpp_wrapper_util::Json::Value values;
87  nim_cpp_wrapper_util::Json::Reader reader;
88  if (reader.parse(multi_config_json, values) && values.isObject()) {
89  if (values.isMember(kNIMEventNimConfigOnlineClient)) {
90  nim_cpp_wrapper_util::Json::Value online_values = values[kNIMEventNimConfigOnlineClient];
91  if (online_values.isArray()) {
92  for (int i = 0; i < (int)online_values.size(); ++i) {
93  NIMClientType client_type = (NIMClientType)online_values[i].asUInt();
94  online_client_type_.insert(client_type);
95  }
96 
97  return true;
98  }
99  }
100  }
101 
102  return false;
103  }
104 };
105 
107 struct NIM_SDK_CPPWRAPPER_DLL_API EventSubscribeData {
109  int64_t ttl_;
110  NIMEventSubscribeSyncEventType sync_event_;
112  std::string publisher_accid_;
113  std::string subscribe_accid_;
114  int64_t subscribe_time_;
117  : event_type_(0)
118  , ttl_(0)
119  , sync_event_(kNIMEventSubscribeSyncTypeUnSync)
120  , subscribe_time_(0) {}
121 };
122 
129 NIM_SDK_CPPWRAPPER_DLL_API bool ParseEventData(const std::string& event_json, EventData& event_data);
130 
137 NIM_SDK_CPPWRAPPER_DLL_API bool ParseEventData(const nim_cpp_wrapper_util::Json::Value& values, EventData& event_data);
138 
145 NIM_SDK_CPPWRAPPER_DLL_API bool ParseEventDataList(const std::string& event_list_json, std::list<EventData>& event_data_list);
146 
153 NIM_SDK_CPPWRAPPER_DLL_API bool ParseEventSubscribeData(const nim_cpp_wrapper_util::Json::Value& values, EventSubscribeData& event_subscribe);
154 
161 NIM_SDK_CPPWRAPPER_DLL_API bool ParseEventSubscribeDataList(const std::string& subscribe_list_json,
162  std::list<EventSubscribeData>& event_subscribe_list);
163 
164 } // namespace nim
165 
166 #endif //_NIM_SDK_CPP_SUBSCRIBE_EVENT_HELPER_H_
nim::EventData::broadcast_type_
NIMEventBroadcastType broadcast_type_
Definition: nim_subscribe_event_helper.h:30
nim::EventOnlineClientType
在线客户端类型,此结构体只用于在线状态事件的kNIMEventNimConfig字段
Definition: nim_subscribe_event_helper.h:77
nim::EventData::event_type_
int event_type_
Definition: nim_subscribe_event_helper.h:25
nim::EventData::readonly_nim_config_
std::string readonly_nim_config_
Definition: nim_subscribe_event_helper.h:39
nim::EventSubscribeData::EventSubscribeData
EventSubscribeData()
Definition: nim_subscribe_event_helper.h:116
nim::EventSubscribeData::sync_event_
NIMEventSubscribeSyncEventType sync_event_
Definition: nim_subscribe_event_helper.h:110
nim::EventData::readonly_event_time_
int64_t readonly_event_time_
Definition: nim_subscribe_event_helper.h:36
nim::EventData::EventData
EventData()
Definition: nim_subscribe_event_helper.h:47
nim::EventSubscribeData::publisher_accid_
std::string publisher_accid_
Definition: nim_subscribe_event_helper.h:112
nim::ParseEventDataList
NIM_SDK_CPPWRAPPER_DLL_API bool ParseEventDataList(const std::string &event_list_json, std::list< EventData > &event_data_list)
解析批量事件数据
nim::ParseEventSubscribeData
NIM_SDK_CPPWRAPPER_DLL_API bool ParseEventSubscribeData(const nim_cpp_wrapper_util::Json::Value &values, EventSubscribeData &event_subscribe)
解析事件订阅数据
nim::EventData::readonly_client_type_
int readonly_client_type_
Definition: nim_subscribe_event_helper.h:38
nim::EventSubscribeData::subscribe_accid_
std::string subscribe_accid_
Definition: nim_subscribe_event_helper.h:113
nim::EventData::readonly_durable_
int readonly_durable_
Definition: nim_subscribe_event_helper.h:35
nim::EventData::readonly_multi_config_
std::string readonly_multi_config_
Definition: nim_subscribe_event_helper.h:40
nim::ParseEventData
NIM_SDK_CPPWRAPPER_DLL_API bool ParseEventData(const std::string &event_json, EventData &event_data)
解析事件数据
nim::EventData::readonly_ttl_type
int readonly_ttl_type
Definition: nim_subscribe_event_helper.h:34
nim::EventData::sync_self_
NIMEventSyncType sync_self_
Definition: nim_subscribe_event_helper.h:31
nim::EventSubscribeData
事件订阅数据
Definition: nim_subscribe_event_helper.h:107
nim::EventSubscribeData::subscribe_time_
int64_t subscribe_time_
Definition: nim_subscribe_event_helper.h:114
nim
namespace nim
nim::EventSubscribeData::event_type_
int event_type_
Definition: nim_subscribe_event_helper.h:108
nim::EventData::client_msg_id_
std::string client_msg_id_
Definition: nim_subscribe_event_helper.h:27
nim::EventData::ttl_
int64_t ttl_
Definition: nim_subscribe_event_helper.h:29
nim::EventData::readonly_publisher_accid_
std::string readonly_publisher_accid_
Definition: nim_subscribe_event_helper.h:43
nim::EventSubscribeData::ttl_
int64_t ttl_
Definition: nim_subscribe_event_helper.h:109
nim::EventData::readonly_consid_
std::string readonly_consid_
Definition: nim_subscribe_event_helper.h:44
nim::EventData::readonly_server_msg_id_
std::string readonly_server_msg_id_
Definition: nim_subscribe_event_helper.h:37
nim::EventOnlineClientType::online_client_type_
std::set< NIMClientType > online_client_type_
Definition: nim_subscribe_event_helper.h:78
nim::EventData
事件数据
Definition: nim_subscribe_event_helper.h:24
nim::ParseEventSubscribeDataList
NIM_SDK_CPPWRAPPER_DLL_API bool ParseEventSubscribeDataList(const std::string &subscribe_list_json, std::list< EventSubscribeData > &event_subscribe_list)
解析事件订阅数据列表
nim::EventData::config_
std::string config_
Definition: nim_subscribe_event_helper.h:28
nim::EventData::event_value_
int event_value_
Definition: nim_subscribe_event_helper.h:26
nim::EventOnlineClientType::ParseConfig
bool ParseConfig(const std::string &multi_config_json)
针对在线状态事件,从kNIMEventNimConfig的Json Value解析出在线客户端类型
Definition: nim_subscribe_event_helper.h:85
nim_sdk_cpp_wrapper.h
定义导出宏
nim::EventData::ToJsonString
std::string ToJsonString() const
组装Json Value字符串
Definition: nim_subscribe_event_helper.h:62