NIM PC Cross Platform SDK
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>
15#include "nim_define_include.h"
21namespace nim {
22
24struct NIM_SDK_CPPWRAPPER_DLL_API EventData {
30 std::string client_msg_id_;
32 std::string config_;
34 int64_t ttl_;
39
40public:
55
56public:
60 std::string readonly_consid_;
61
64 : event_type_(0)
65 , event_value_(0)
66 , ttl_(0)
67 , broadcast_type_(kNIMEventBroadcastTypeOnline)
68 , sync_self_(kNIMEventSyncTypeNoSelf)
69 , readonly_ttl_type(0)
70 , readonly_durable_(0)
71 , readonly_event_time_(0)
72 , readonly_client_type_(0) {}
73
78 std::string ToJsonString() const {
80 values[kNIMEventEventType] = event_type_;
81 values[kNIMEventEventValue] = event_value_;
82 values[kNIMEventMsgIdClient] = client_msg_id_;
83 values[kNIMEventConfig] = config_;
84 values[kNIMEventTTL] = ttl_;
85 values[kNIMEventBroadcastType] = broadcast_type_;
86 values[kNIMEventSyncSelf] = sync_self_;
87
88 return GetJsonStringWithNoStyled(values);
89 }
90};
91
93struct NIM_SDK_CPPWRAPPER_DLL_API EventOnlineClientType {
95 std::set<NIMClientType> online_client_type_;
96
102 bool ParseConfig(const std::string& multi_config_json) {
104 if (nim::ParseJsonValue(multi_config_json, values) && values.isObject()) {
107 if (online_values.isArray()) {
108 for (int i = 0; i < (int)online_values.size(); ++i) {
109 NIMClientType client_type = (NIMClientType)online_values[i].asUInt();
110 online_client_type_.insert(client_type);
111 }
112
113 return true;
114 }
115 }
116 }
117
118 return false;
119 }
120};
121
123struct NIM_SDK_CPPWRAPPER_DLL_API EventSubscribeData {
127 int64_t ttl_;
130
132 std::string publisher_accid_;
134 std::string subscribe_accid_;
139 : event_type_(0)
140 , ttl_(0)
142 , subscribe_time_(0) {}
143};
144
151NIM_SDK_CPPWRAPPER_DLL_API bool ParseEventData(const std::string& event_json, EventData& event_data);
152
159NIM_SDK_CPPWRAPPER_DLL_API bool ParseEventData(const nim_cpp_wrapper_util::Json::Value& values, EventData& event_data);
160
167NIM_SDK_CPPWRAPPER_DLL_API bool ParseEventDataList(const std::string& event_list_json, std::list<EventData>& event_data_list);
168
175NIM_SDK_CPPWRAPPER_DLL_API bool ParseEventSubscribeData(const nim_cpp_wrapper_util::Json::Value& values, EventSubscribeData& event_subscribe);
176
183NIM_SDK_CPPWRAPPER_DLL_API bool ParseEventSubscribeDataList(const std::string& subscribe_list_json,
184 std::list<EventSubscribeData>& event_subscribe_list);
185
186} // namespace nim
187
188#endif //_NIM_SDK_CPP_SUBSCRIBE_EVENT_HELPER_H_
Represents a JSON value.
Definition: value.h:196
bool isMember(const char *key) const
Definition: json_value.cpp:1241
bool insert(ArrayIndex index, const Value &newValue)
Insert value in array at specific index.
Definition: json_value.cpp:1154
ArrayIndex size() const
Number of values in array or object.
Definition: json_value.cpp:885
namespace nim
bool ParseEventSubscribeDataList(const std::string &subscribe_list_json, std::list< EventSubscribeData > &event_subscribe_list)
解析事件订阅数据列表
Definition: nim_subscribe_event_helper.cpp:108
bool ParseJsonValue(const std::string &content, nim_cpp_wrapper_util::Json::Value &values)
解析JsonString
Definition: nim_json_util.cpp:70
bool ParseEventDataList(const std::string &event_list_json, std::list< EventData > &event_data_list)
解析批量事件数据
Definition: nim_subscribe_event_helper.cpp:72
bool ParseEventData(const std::string &event_json, EventData &event_data)
解析事件数据
Definition: nim_subscribe_event_helper.cpp:11
bool ParseEventSubscribeData(const nim_cpp_wrapper_util::Json::Value &values, EventSubscribeData &event_subscribe)
解析事件订阅数据
Definition: nim_subscribe_event_helper.cpp:86
std::string GetJsonStringWithNoStyled(const nim_cpp_wrapper_util::Json::Value &values)
获得非格式化的Json string,传入SDK的json string格式要求为非格式化的,如果是格式化的json string可能会影响功能
Definition: nim_json_util.cpp:89
NIMClientType
Definition: nim_client_def.h:113
NIM 公共数据类型定义总的包含文件
JSON辅助方法
定义导出宏
static const char * kNIMEventEventType
int,事件类型
Definition: nim_subscribe_event_def.h:20
static const char * kNIMEventTTL
long,事件有效期,单位:秒,时间范围:60s到7天
Definition: nim_subscribe_event_def.h:28
static const char * kNIMEventBroadcastType
int,事件广播类型:1:仅在线 2:在线和离线
Definition: nim_subscribe_event_def.h:30
static const char * kNIMEventMsgIdClient
string,客户端生成的消息id
Definition: nim_subscribe_event_def.h:24
NIMEventSyncType
Definition: nim_subscribe_event_def.h:87
@ kNIMEventSyncTypeNoSelf
事件不同步给自己其他端
Definition: nim_subscribe_event_def.h:89
static const char * kNIMEventNimConfigOnlineClient
string,预定义事件的扩展字段中的在线的客户端类型
Definition: nim_subscribe_event_def.h:57
NIMEventBroadcastType
Definition: nim_subscribe_event_def.h:79
@ kNIMEventBroadcastTypeOnline
仅在线
Definition: nim_subscribe_event_def.h:81
static const char * kNIMEventEventValue
int,事件值
Definition: nim_subscribe_event_def.h:22
NIMEventSubscribeSyncEventType
Definition: nim_subscribe_event_def.h:95
@ kNIMEventSubscribeSyncTypeUnSync
订阅后不同步最新事件
Definition: nim_subscribe_event_def.h:97
static const char * kNIMEventSyncSelf
int,0:不同步给自己的其他端,1:同步给自己的其他端
Definition: nim_subscribe_event_def.h:32
static const char * kNIMEventConfig
string,用户自定义事件扩展属性,最长4K
Definition: nim_subscribe_event_def.h:26
事件数据
Definition: nim_subscribe_event_helper.h:24
NIMEventBroadcastType broadcast_type_
事件广播类型
Definition: nim_subscribe_event_helper.h:36
std::string readonly_multi_config_
多端配置信息字段,JSON格式{"clent_type":"clent_config","1":"xxx","2":"xxx"}
Definition: nim_subscribe_event_helper.h:54
std::string config_
用户自定义事件扩展属性,最长4K
Definition: nim_subscribe_event_helper.h:32
int64_t readonly_event_time_
事件发布的时间戳,服务器补充
Definition: nim_subscribe_event_helper.h:46
EventData()
Definition: nim_subscribe_event_helper.h:63
int event_value_
事件状态,在线状态事件服务器保留1~9999的事件值,客户端自定义事件值需大于9999
Definition: nim_subscribe_event_helper.h:28
std::string readonly_server_msg_id_
服务端生成的消息id
Definition: nim_subscribe_event_helper.h:48
std::string client_msg_id_
客户端生成的消息id
Definition: nim_subscribe_event_helper.h:30
int event_type_
事件类型,服务器保留1~99999的事件类型,客户端自定义事件类型需大于99999
Definition: nim_subscribe_event_helper.h:26
std::string ToJsonString() const
组装Json Value字符串
Definition: nim_subscribe_event_helper.h:78
int64_t ttl_
事件有效期,单位:秒,时间范围:60s到7天
Definition: nim_subscribe_event_helper.h:34
std::string readonly_nim_config_
预定义事件的扩展字段(在线状态事件:在线的客户端类型Json)
Definition: nim_subscribe_event_helper.h:52
int readonly_client_type_
发送客户端类型
Definition: nim_subscribe_event_helper.h:50
std::string readonly_consid_
发送设备id
Definition: nim_subscribe_event_helper.h:60
int readonly_durable_
是否需要持久化(可选字段),默认为需要持久化,0:不需要持久化,1:需要持久化
Definition: nim_subscribe_event_helper.h:44
int readonly_ttl_type
TtlType枚举值
Definition: nim_subscribe_event_helper.h:42
NIMEventSyncType sync_self_
事件同步类型
Definition: nim_subscribe_event_helper.h:38
std::string readonly_publisher_accid_
事件发布者的accid
Definition: nim_subscribe_event_helper.h:58
在线客户端类型,此结构体只用于在线状态事件的kNIMEventNimConfig字段
Definition: nim_subscribe_event_helper.h:93
std::set< NIMClientType > online_client_type_
在线客户端类型集合
Definition: nim_subscribe_event_helper.h:95
bool ParseConfig(const std::string &multi_config_json)
针对在线状态事件,从kNIMEventNimConfig的Json Value解析出在线客户端类型
Definition: nim_subscribe_event_helper.h:102
事件订阅数据
Definition: nim_subscribe_event_helper.h:123
EventSubscribeData()
Definition: nim_subscribe_event_helper.h:138
int event_type_
事件类型
Definition: nim_subscribe_event_helper.h:125
std::string publisher_accid_
被订阅人(事件发布人)的accid
Definition: nim_subscribe_event_helper.h:132
std::string subscribe_accid_
订阅人的accid
Definition: nim_subscribe_event_helper.h:134
int64_t subscribe_time_
订阅时间戳
Definition: nim_subscribe_event_helper.h:136
int64_t ttl_
订阅有效期,单位:秒,范围:60s到30天
Definition: nim_subscribe_event_helper.h:127
NIMEventSubscribeSyncEventType sync_event_
订阅的事件的同步类型
Definition: nim_subscribe_event_helper.h:129