NIM 跨平台 C++ SDK
载入中...
搜索中...
未找到
nim_qchat_attachment_cpp_def.h
浏览该文件的文档.
1
11#ifndef __NIM_QCHAT_ATTACHMENT_CPP_DEF_H__
12#define __NIM_QCHAT_ATTACHMENT_CPP_DEF_H__
13
15
16namespace nim {
20 std::string url{""};
22 std::string token{""};
25 url = c_resp.url ? c_resp.url : "";
26 token = "";
27 }
30 c_resp.url = const_cast<char*>(url.c_str());
31 c_resp.token = const_cast<char*>(token.c_str());
32 return c_resp;
33 }
34};
35
39 uint32_t res_code{0};
41 std::string task_id{""};
43 std::string url{""};
46 res_code = c_resp.res_code;
47 if (c_resp.res_code != kNIMResSuccess)
48 return;
49 task_id = c_resp.task_id ? c_resp.task_id : "";
50 url = c_resp.url ? c_resp.url : "";
51 }
52};
53
57 uint32_t res_code{0};
61 std::string task_id{""};
63 std::string file_path{""};
66 res_code = c_resp.res_code;
67 if (c_resp.res_code != kNIMResSuccess)
68 return;
69 res_type = c_resp.res_type;
70 task_id = c_resp.task_id ? c_resp.task_id : "";
71 file_path = c_resp.file_path ? c_resp.file_path : "";
72 }
73};
74
78 uint32_t res_code{0};
79
81 std::string task_id{""};
83 uint64_t total_size{0};
85 uint64_t cur_size{0};
88 res_code = c_resp.res_code;
89 if (c_resp.res_code != kNIMResSuccess)
90 return;
91 task_id = c_resp.task_id ? c_resp.task_id : "";
92 total_size = c_resp.total_size;
93 cur_size = c_resp.cur_size;
94 }
95};
96
100typedef std::function<void(const QChatAttachmentUploadResp&)> AttachmentUploadCallback;
102typedef std::function<void(const QChatAttachmentDownloadResp&)> AttachmentDownloadCallback;
104typedef std::function<void(const QChatAttachmentProgressResp&)> AttachmentProgressCallback;
105
111 static AttachmentCustomTokenCallback cb_holder = nullptr;
112 static QChatAttachmentCustomTokenResp resp_holder{};
113 cb_holder = cb;
115 param.cb = [](const NIMQChatAttachmentCustomTokenResp* resp) {
116 if (cb_holder)
117 resp_holder = cb_holder(*resp);
118 return resp_holder.ToCParam();
119 };
120 return param;
121 }
122};
123
129 static AttachmentUploadCallback cb_holder = nullptr;
130 static AttachmentProgressCallback progress_cb_holder = nullptr;
131 cb_holder = cb;
133 param.cb = [](const NIMQChatAttachmentUploadResp* resp) {
134 if (cb_holder)
135 cb_holder(*resp);
136 };
137 return param;
138 }
139};
140
146 static AttachmentDownloadCallback cb_holder = nullptr;
147 cb_holder = cb;
149 param.cb = [](const NIMQChatAttachmentDownloadResp* resp) {
150 if (cb_holder)
151 cb_holder(*resp);
152 };
153 return param;
154 }
155};
156
162 static AttachmentProgressCallback cb_holder = nullptr;
163 cb_holder = cb;
165 param.cb = [](const NIMQChatAttachmentProgressResp* resp) {
166 if (cb_holder)
167 cb_holder(*resp);
168 };
169 return param;
170 }
171};
172
178
184 AttachmentProgressCallback progress_cb{nullptr};
186 std::string task_id;
188 std::string file_path{""};
190 auto attachment_cbs = new UploadAttachementCallbacks;
191 attachment_cbs->completed_cb = new AttachmentUploadCallback(cb);
192 attachment_cbs->progress_cb = new AttachmentProgressCallback(progress_cb);
194 param.user_data = attachment_cbs;
195 param.cb = [](const NIMQChatAttachmentUploadResp* resp) {
196 auto attachment_cbs = reinterpret_cast<UploadAttachementCallbacks*>(resp->user_data);
197 if (attachment_cbs && attachment_cbs->completed_cb)
198 (*attachment_cbs->completed_cb)(*resp);
199 delete attachment_cbs->completed_cb;
200 delete attachment_cbs->progress_cb;
201 delete attachment_cbs;
202 };
203 param.progress_cb = [](const NIMQChatAttachmentProgressResp* progress) {
204 auto attachment_cbs = reinterpret_cast<UploadAttachementCallbacks*>(progress->user_data);
205 if (attachment_cbs && attachment_cbs->progress_cb)
206 (*attachment_cbs->progress_cb)(*progress);
207 };
208 param.task_id = const_cast<char*>(task_id.c_str());
209 param.file_path = const_cast<char*>(file_path.c_str());
210 return param;
211 }
212};
213
217 std::string task_id;
220 param.task_id = const_cast<char*>(task_id.c_str());
221 return param;
222 }
223};
224
230
236 AttachmentProgressCallback progress_cb{nullptr};
240 std::string task_id;
242 std::string url{""};
244 std::string file_path{""};
246 auto attachment_cbs = new DownloadAttachementCallbacks;
247 attachment_cbs->completed_cb = new AttachmentDownloadCallback(cb);
248 attachment_cbs->progress_cb = new AttachmentProgressCallback(progress_cb);
250 param.user_data = attachment_cbs;
251 param.cb = [](const NIMQChatAttachmentDownloadResp* resp) {
252 auto attachment_cbs = reinterpret_cast<DownloadAttachementCallbacks*>(resp->user_data);
253 if (attachment_cbs && attachment_cbs->completed_cb) {
254 (*attachment_cbs->completed_cb)(*resp);
255 }
256 delete attachment_cbs->completed_cb;
257 delete attachment_cbs->progress_cb;
258 delete attachment_cbs;
259 };
260 param.progress_cb = [](const NIMQChatAttachmentProgressResp* progress) {
261 auto attachment_cbs = reinterpret_cast<DownloadAttachementCallbacks*>(progress->user_data);
262 if (attachment_cbs && attachment_cbs->progress_cb) {
263 (*attachment_cbs->progress_cb)(*progress);
264 }
265 };
266 param.res_type = res_type;
267 param.task_id = const_cast<char*>(task_id.c_str());
268 param.url = const_cast<char*>(url.c_str());
269 param.file_path = const_cast<char*>(file_path.c_str());
270 return param;
271 }
272};
273
277 std::string task_id;
280 param.task_id = const_cast<char*>(task_id.c_str());
281 return param;
282 }
283};
284} // namespace nim
285
286#endif // __NIM_QCHAT_ATTACHMENT_CPP_DEF_H__
namespace nim
std::function< QChatAttachmentCustomTokenResp(const QChatAttachmentCustomTokenResp &) AttachmentCustomTokenCallback)
获取附件自定义token回调
Definition nim_qchat_attachment_cpp_def.h:98
std::function< void(const QChatAttachmentDownloadResp &) AttachmentDownloadCallback)
下载附件回调
Definition nim_qchat_attachment_cpp_def.h:102
std::function< void(const QChatAttachmentUploadResp &) AttachmentUploadCallback)
上传附件回调
Definition nim_qchat_attachment_cpp_def.h:100
std::function< void(const QChatAttachmentProgressResp &) AttachmentProgressCallback)
上传/下载附件进度回调
Definition nim_qchat_attachment_cpp_def.h:104
NIMQChatDownloadResType
Definition nim_qchat_attachment_def.h:19
@ NIMQChatDownloadResTypeSource
原文件
Definition nim_qchat_attachment_def.h:21
#define NIM_QCHAT_SDK_CPPWRAPPER_DLL_API
Definition nim_qchat_sdk_cpp_wrapper.h:38
@ kNIMResSuccess
没有错误,一切正常
Definition public_defines.h:26
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:226
AttachmentDownloadCallback * completed_cb
Definition nim_qchat_attachment_cpp_def.h:227
AttachmentProgressCallback * progress_cb
Definition nim_qchat_attachment_cpp_def.h:228
Definition nim_qchat_attachment_cpp_def.h:18
NIMQChatAttachmentCustomTokenResp ToCParam()
Definition nim_qchat_attachment_cpp_def.h:28
QChatAttachmentCustomTokenResp(const NIMQChatAttachmentCustomTokenResp &c_resp)
Definition nim_qchat_attachment_cpp_def.h:24
Definition nim_qchat_attachment_cpp_def.h:232
std::string task_id
任务id, 为空时自动生成
Definition nim_qchat_attachment_cpp_def.h:240
NIMQChatAttachmentDownloadParam ToCParam() const
Definition nim_qchat_attachment_cpp_def.h:245
Definition nim_qchat_attachment_cpp_def.h:55
QChatAttachmentDownloadResp(const NIMQChatAttachmentDownloadResp &c_resp)
Definition nim_qchat_attachment_cpp_def.h:65
Definition nim_qchat_attachment_cpp_def.h:76
QChatAttachmentProgressResp(const NIMQChatAttachmentProgressResp &c_resp)
Definition nim_qchat_attachment_cpp_def.h:87
Definition nim_qchat_attachment_cpp_def.h:107
NIMQChatAttachmentRegCustomTokenCbParam ToCParam() const
Definition nim_qchat_attachment_cpp_def.h:110
Definition nim_qchat_attachment_cpp_def.h:142
NIMQChatAttachmentRegDownloadCbParam ToCParam() const
Definition nim_qchat_attachment_cpp_def.h:145
Definition nim_qchat_attachment_cpp_def.h:158
NIMQChatAttachmentRegProgressCbParam ToCParam() const
Definition nim_qchat_attachment_cpp_def.h:161
Definition nim_qchat_attachment_cpp_def.h:125
NIMQChatAttachmentRegUploadCbParam ToCParam() const
Definition nim_qchat_attachment_cpp_def.h:128
Definition nim_qchat_attachment_cpp_def.h:275
NIMQChatAttachmentStopDownloadParam ToCParam() const
Definition nim_qchat_attachment_cpp_def.h:278
std::string task_id
任务id
Definition nim_qchat_attachment_cpp_def.h:277
Definition nim_qchat_attachment_cpp_def.h:215
std::string task_id
任务id
Definition nim_qchat_attachment_cpp_def.h:217
NIMQChatAttachmentStopUploadParam ToCParam() const
Definition nim_qchat_attachment_cpp_def.h:218
Definition nim_qchat_attachment_cpp_def.h:180
std::string task_id
任务id, 为空时自动生成
Definition nim_qchat_attachment_cpp_def.h:186
NIMQChatAttachmentUploadParam ToCParam() const
Definition nim_qchat_attachment_cpp_def.h:189
Definition nim_qchat_attachment_cpp_def.h:37
QChatAttachmentUploadResp(const NIMQChatAttachmentUploadResp &c_resp)
Definition nim_qchat_attachment_cpp_def.h:45
Definition nim_qchat_attachment_cpp_def.h:174
AttachmentUploadCallback * completed_cb
Definition nim_qchat_attachment_cpp_def.h:175
AttachmentProgressCallback * progress_cb
Definition nim_qchat_attachment_cpp_def.h:176