NIM PC Cross Platform SDK
nim_qchat_attachment_cpp_def.h
Go to the documentation of this file.
1
11#ifndef __NIM_QCHAT_ATTACHMENT_CPP_DEF_H__
12#define __NIM_QCHAT_ATTACHMENT_CPP_DEF_H__
13
14#include <functional>
15#include <list>
16#include <map>
17#include <string>
18#include <vector>
23
24namespace nim_qchat {
26struct NIM_QCHAT_SDK_CPPWRAPPER_DLL_API QChatAttachmentCustomTokenResp {
28 std::string url{""};
30 std::string token{""};
33 url = c_resp.url ? c_resp.url : "";
34 token = "";
35 }
38 c_resp.url = const_cast<char*>(url.c_str());
39 c_resp.token = const_cast<char*>(token.c_str());
40 return c_resp;
41 }
42};
43
45struct NIM_QCHAT_SDK_CPPWRAPPER_DLL_API QChatAttachmentUploadResp {
47 uint32_t res_code{0};
49 std::string task_id{""};
51 std::string url{""};
52 QChatAttachmentUploadResp() = default;
54 res_code = c_resp.res_code;
55 if (c_resp.res_code != kNIMResSuccess)
56 return;
57 task_id = c_resp.task_id ? c_resp.task_id : "";
58 url = c_resp.url ? c_resp.url : "";
59 }
60};
61
63struct NIM_QCHAT_SDK_CPPWRAPPER_DLL_API QChatAttachmentDownloadResp {
65 uint32_t res_code{0};
69 std::string task_id{""};
71 std::string file_path{""};
74 res_code = c_resp.res_code;
75 if (c_resp.res_code != kNIMResSuccess)
76 return;
77 res_type = c_resp.res_type;
78 task_id = c_resp.task_id ? c_resp.task_id : "";
79 file_path = c_resp.file_path ? c_resp.file_path : "";
80 }
81};
82
84struct NIM_QCHAT_SDK_CPPWRAPPER_DLL_API QChatAttachmentProgressResp {
86 uint32_t res_code{0};
87
89 std::string task_id{""};
91 uint64_t total_size{0};
93 uint64_t cur_size{0};
96 res_code = c_resp.res_code;
97 if (c_resp.res_code != kNIMResSuccess)
98 return;
99 task_id = c_resp.task_id ? c_resp.task_id : "";
100 total_size = c_resp.total_size;
101 cur_size = c_resp.cur_size;
102 }
103};
104
108typedef std::function<void(const QChatAttachmentUploadResp&)> AttachmentUploadCallback;
110typedef std::function<void(const QChatAttachmentDownloadResp&)> AttachmentDownloadCallback;
112typedef std::function<void(const QChatAttachmentProgressResp&)> AttachmentProgressCallback;
113
115struct NIM_QCHAT_SDK_CPPWRAPPER_DLL_API QChatAttachmentRegCustomTokenCbParam {
118 const NIMQChatAttachmentRegCustomTokenCbParam ToCParam() const {
119 static AttachmentCustomTokenCallback cb_holder = nullptr;
120 static QChatAttachmentCustomTokenResp resp_holder{};
121 cb_holder = cb;
123 param.cb = [](const NIMQChatAttachmentCustomTokenResp& resp) {
124 if (cb_holder)
125 resp_holder = cb_holder(resp);
126 return resp_holder.ToCParam();
127 };
128 return param;
129 }
130};
131
133struct NIM_QCHAT_SDK_CPPWRAPPER_DLL_API QChatAttachmentRegUploadCbParam {
136 const NIMQChatAttachmentRegUploadCbParam ToCParam() const {
137 static AttachmentUploadCallback cb_holder = nullptr;
138 static AttachmentProgressCallback progress_cb_holder = nullptr;
139 cb_holder = cb;
141 param.cb = [](const NIMQChatAttachmentUploadResp& resp) {
142 if (cb_holder)
143 cb_holder(resp);
144 };
145 return param;
146 }
147};
148
150struct NIM_QCHAT_SDK_CPPWRAPPER_DLL_API QChatAttachmentRegDownloadCbParam {
153 const NIMQChatAttachmentRegDownloadCbParam ToCParam() const {
154 static AttachmentDownloadCallback cb_holder = nullptr;
155 cb_holder = cb;
157 param.cb = [](const NIMQChatAttachmentDownloadResp& resp) {
158 if (cb_holder)
159 cb_holder(resp);
160 };
161 return param;
162 }
163};
164
166struct NIM_QCHAT_SDK_CPPWRAPPER_DLL_API QChatAttachmentRegProgressCbParam {
169 const NIMQChatAttachmentRegProgressCbParam ToCParam() const {
170 static AttachmentProgressCallback cb_holder = nullptr;
171 cb_holder = cb;
173 param.cb = [](const NIMQChatAttachmentProgressResp& resp) {
174 if (cb_holder)
175 cb_holder(resp);
176 };
177 return param;
178 }
179};
180
183 AttachmentUploadCallback* completed_cb = nullptr;
184 AttachmentProgressCallback* progress_cb = nullptr;
185};
186
188struct NIM_QCHAT_SDK_CPPWRAPPER_DLL_API QChatAttachmentUploadParam {
192 AttachmentProgressCallback progress_cb{nullptr};
194 std::string task_id;
196 std::string file_path{""};
197 const NIMQChatAttachmentUploadParam ToCParam() const {
198 auto attachment_cbs = new UploadAttachementCallbacks;
199 attachment_cbs->completed_cb = new AttachmentUploadCallback(cb);
200 attachment_cbs->progress_cb = new AttachmentProgressCallback(progress_cb);
202 param.user_data = attachment_cbs;
203 param.cb = [](const NIMQChatAttachmentUploadResp& resp) {
204 auto attachment_cbs = reinterpret_cast<UploadAttachementCallbacks*>(resp.user_data);
205 if (attachment_cbs && attachment_cbs->completed_cb)
206 (*attachment_cbs->completed_cb)(resp);
207 delete attachment_cbs->completed_cb;
208 delete attachment_cbs->progress_cb;
209 delete attachment_cbs;
210 };
211 param.progress_cb = [](const NIMQChatAttachmentProgressResp& progress) {
212 auto attachment_cbs = reinterpret_cast<UploadAttachementCallbacks*>(progress.user_data);
213 if (attachment_cbs && attachment_cbs->progress_cb)
214 (*attachment_cbs->progress_cb)(progress);
215 };
216 param.task_id = const_cast<char*>(task_id.c_str());
217 param.file_path = const_cast<char*>(file_path.c_str());
218 return param;
219 }
220};
221
223struct NIM_QCHAT_SDK_CPPWRAPPER_DLL_API QChatAttachmentStopUploadParam {
225 std::string task_id;
226 const NIMQChatAttachmentStopUploadParam ToCParam() const {
228 param.task_id = const_cast<char*>(task_id.c_str());
229 return param;
230 }
231};
232
235 AttachmentDownloadCallback* completed_cb = nullptr;
236 AttachmentProgressCallback* progress_cb = nullptr;
237};
238
240struct NIM_QCHAT_SDK_CPPWRAPPER_DLL_API QChatAttachmentDownloadParam {
244 AttachmentProgressCallback progress_cb{nullptr};
248 std::string task_id;
250 std::string url{""};
252 std::string file_path{""};
253 const NIMQChatAttachmentDownloadParam ToCParam() const {
254 auto attachment_cbs = new DownloadAttachementCallbacks;
255 attachment_cbs->completed_cb = new AttachmentDownloadCallback(cb);
256 attachment_cbs->progress_cb = new AttachmentProgressCallback(progress_cb);
258 param.user_data = attachment_cbs;
259 param.cb = [](const NIMQChatAttachmentDownloadResp& resp) {
260 auto attachment_cbs = reinterpret_cast<DownloadAttachementCallbacks*>(resp.user_data);
261 if (attachment_cbs && attachment_cbs->completed_cb) {
262 (*attachment_cbs->completed_cb)(resp);
263 }
264 delete attachment_cbs->completed_cb;
265 delete attachment_cbs->progress_cb;
266 delete attachment_cbs;
267 };
268 param.progress_cb = [](const NIMQChatAttachmentProgressResp& progress) {
269 auto attachment_cbs = reinterpret_cast<DownloadAttachementCallbacks*>(progress.user_data);
270 if (attachment_cbs && attachment_cbs->progress_cb) {
271 (*attachment_cbs->progress_cb)(progress);
272 }
273 };
274 param.res_type = res_type;
275 param.task_id = const_cast<char*>(task_id.c_str());
276 param.url = const_cast<char*>(url.c_str());
277 param.file_path = const_cast<char*>(file_path.c_str());
278 return param;
279 }
280};
281
283struct NIM_QCHAT_SDK_CPPWRAPPER_DLL_API QChatAttachmentStopDownloadParam {
285 std::string task_id;
286 const NIMQChatAttachmentStopDownloadParam ToCParam() const {
288 param.task_id = const_cast<char*>(task_id.c_str());
289 return param;
290 }
291};
292} // namespace nim_qchat
293
294#endif // __NIM_QCHAT_ATTACHMENT_CPP_DEF_H__
namespace nim_qchat
std::function< void(const QChatAttachmentDownloadResp &)> AttachmentDownloadCallback
下载附件回调
Definition: nim_qchat_attachment_cpp_def.h:110
std::function< QChatAttachmentCustomTokenResp(const QChatAttachmentCustomTokenResp &)> AttachmentCustomTokenCallback
获取附件自定义token回调
Definition: nim_qchat_attachment_cpp_def.h:106
std::function< void(const QChatAttachmentUploadResp &)> AttachmentUploadCallback
上传附件回调
Definition: nim_qchat_attachment_cpp_def.h:108
std::function< void(const QChatAttachmentProgressResp &)> AttachmentProgressCallback
上传/下载附件进度回调
Definition: nim_qchat_attachment_cpp_def.h:112
@ kNIMResSuccess
Definition: nim_chatroom_res_code_def.h:18
JSON辅助方法
NIMQChatDownloadResType
Definition: nim_qchat_attachment_def.h:19
@ NIMQChatDownloadResTypeSource
原文件
Definition: nim_qchat_attachment_def.h:21
Definition: nim_qchat_attachment_def.h:29
char * token
将该指针指向零结尾的token字符串的起始地址
Definition: nim_qchat_attachment_def.h:35
char * url
上传/下载的url
Definition: nim_qchat_attachment_def.h:33
Definition: nim_qchat_attachment_def.h:140
nim_qchat_attachment_progress_cb_func progress_cb
下载附件进度回调
Definition: nim_qchat_attachment_def.h:144
char * file_path
附件路径
Definition: nim_qchat_attachment_def.h:154
nim_qchat_attachment_download_cb_func cb
下载附件异步回调
Definition: nim_qchat_attachment_def.h:142
char * task_id
任务id, 为空时自动生成
Definition: nim_qchat_attachment_def.h:150
void * user_data
自定义用户数据
Definition: nim_qchat_attachment_def.h:146
char * url
附件url
Definition: nim_qchat_attachment_def.h:152
NIMQChatDownloadResType res_type
下载资源类型
Definition: nim_qchat_attachment_def.h:148
Definition: nim_qchat_attachment_def.h:51
uint32_t res_code
操作结果, 参考NIMResCode
Definition: nim_qchat_attachment_def.h:53
NIMQChatDownloadResType res_type
下载资源类型
Definition: nim_qchat_attachment_def.h:57
char * task_id
任务id, 自动下载的任务则为消息id
Definition: nim_qchat_attachment_def.h:59
char * file_path
下载后的文件路径
Definition: nim_qchat_attachment_def.h:61
Definition: nim_qchat_attachment_def.h:65
uint32_t res_code
操作结果, 参考NIMResCode
Definition: nim_qchat_attachment_def.h:67
uint64_t cur_size
当前已经上传/下载的大小
Definition: nim_qchat_attachment_def.h:75
uint64_t total_size
文件总大小
Definition: nim_qchat_attachment_def.h:73
char * task_id
下载任务id
Definition: nim_qchat_attachment_def.h:71
Definition: nim_qchat_attachment_def.h:88
nim_qchat_attachment_custom_token_cb_func cb
自定义token回调
Definition: nim_qchat_attachment_def.h:90
Definition: nim_qchat_attachment_def.h:104
nim_qchat_attachment_download_cb_func cb
下载附件全局异步回调
Definition: nim_qchat_attachment_def.h:106
Definition: nim_qchat_attachment_def.h:112
nim_qchat_attachment_progress_cb_func cb
上传/下载全局进度回调
Definition: nim_qchat_attachment_def.h:114
Definition: nim_qchat_attachment_def.h:96
nim_qchat_attachment_upload_cb_func cb
上传附件全局异步回调
Definition: nim_qchat_attachment_def.h:98
Definition: nim_qchat_attachment_def.h:158
char * task_id
任务id, 为空时自动生成
Definition: nim_qchat_attachment_def.h:160
Definition: nim_qchat_attachment_def.h:134
char * task_id
任务id, 为空时自动生成
Definition: nim_qchat_attachment_def.h:136
Definition: nim_qchat_attachment_def.h:120
nim_qchat_attachment_progress_cb_func progress_cb
上传附件进度回调
Definition: nim_qchat_attachment_def.h:124
char * file_path
附件路径
Definition: nim_qchat_attachment_def.h:130
nim_qchat_attachment_upload_cb_func cb
上传附件异步回调
Definition: nim_qchat_attachment_def.h:122
void * user_data
自定义用户数据
Definition: nim_qchat_attachment_def.h:126
char * task_id
任务id, 为空时自动生成
Definition: nim_qchat_attachment_def.h:128
Definition: nim_qchat_attachment_def.h:39
uint32_t res_code
操作结果, 参考NIMResCode
Definition: nim_qchat_attachment_def.h:41
char * task_id
任务id
Definition: nim_qchat_attachment_def.h:45
char * url
上传后的url
Definition: nim_qchat_attachment_def.h:47
Definition: nim_qchat_attachment_cpp_def.h:234
Definition: nim_qchat_attachment_cpp_def.h:26
Definition: nim_qchat_attachment_cpp_def.h:240
std::string task_id
任务id, 为空时自动生成
Definition: nim_qchat_attachment_cpp_def.h:248
Definition: nim_qchat_attachment_cpp_def.h:63
Definition: nim_qchat_attachment_cpp_def.h:84
Definition: nim_qchat_attachment_cpp_def.h:115
Definition: nim_qchat_attachment_cpp_def.h:150
Definition: nim_qchat_attachment_cpp_def.h:166
Definition: nim_qchat_attachment_cpp_def.h:133
Definition: nim_qchat_attachment_cpp_def.h:283
std::string task_id
任务id
Definition: nim_qchat_attachment_cpp_def.h:285
Definition: nim_qchat_attachment_cpp_def.h:223
std::string task_id
任务id
Definition: nim_qchat_attachment_cpp_def.h:225
Definition: nim_qchat_attachment_cpp_def.h:188
std::string task_id
任务id, 为空时自动生成
Definition: nim_qchat_attachment_cpp_def.h:194
Definition: nim_qchat_attachment_cpp_def.h:45
Definition: nim_qchat_attachment_cpp_def.h:182