mirror of
https://gitee.com/openharmony/request_request
synced 2024-11-23 23:10:56 +00:00
commit
4887c289ab
@ -52,7 +52,6 @@ public:
|
||||
UPLOAD_API virtual bool Remove();
|
||||
UPLOAD_API virtual void On(Type type, void *callback);
|
||||
UPLOAD_API virtual void Off(Type type, void *callback);
|
||||
UPLOAD_API virtual void Off(Type type);
|
||||
UPLOAD_API void ExecuteTask();
|
||||
static void Run(void *arg);
|
||||
virtual void OnRun();
|
||||
|
@ -64,13 +64,6 @@ void UploadTask::On(Type type, void *callback)
|
||||
SetCallback(type, callback);
|
||||
}
|
||||
|
||||
void UploadTask::Off(Type type)
|
||||
{
|
||||
UPLOAD_HILOGD(UPLOAD_MODULE_FRAMEWORK, "Off. In.");
|
||||
std::lock_guard<std::mutex> guard(mutex_);
|
||||
SetCallback(type, nullptr);
|
||||
}
|
||||
|
||||
void UploadTask::Off(Type type, void *callback)
|
||||
{
|
||||
UPLOAD_HILOGD(UPLOAD_MODULE_FRAMEWORK, "Off. In.");
|
||||
@ -82,8 +75,6 @@ void UploadTask::Off(Type type, void *callback)
|
||||
|
||||
if (type == TYPE_PROGRESS_CALLBACK && progressCallback_ != nullptr) {
|
||||
((IProgressCallback*)callback)->Progress(uploadedSize_, totalSize_);
|
||||
} else {
|
||||
UPLOAD_HILOGD(UPLOAD_MODULE_FRAMEWORK, "Off. type[%{public}d] not match.", type);
|
||||
}
|
||||
SetCallback(type, nullptr);
|
||||
}
|
||||
|
5
upload/interfaces/kits/js/@ohos.request.d.ts
vendored
5
upload/interfaces/kits/js/@ohos.request.d.ts
vendored
@ -342,10 +342,9 @@ declare namespace request {
|
||||
*/
|
||||
title?: string;
|
||||
/**
|
||||
* Whether to display the background.
|
||||
* Allow download background task notifications.
|
||||
*
|
||||
* @since 9
|
||||
* @permission N/A
|
||||
*/
|
||||
background?: boolean;
|
||||
}
|
||||
@ -829,7 +828,7 @@ declare namespace request {
|
||||
* @permission ohos.permission.INTERNET
|
||||
* @return -
|
||||
*/
|
||||
off(type:'complete' | 'fail'): void;
|
||||
off(type:'complete' | 'fail', callback?: Callback<Array<TaskState>>): void;
|
||||
|
||||
/**
|
||||
* Deletes a upload session.
|
||||
|
@ -117,6 +117,7 @@ private:
|
||||
size_t argc, napi_value *argv, napi_value self, napi_value *result);
|
||||
static napi_status OffFail(napi_env env, size_t argc, napi_value *argv, napi_value self, napi_value *result);
|
||||
static napi_status OffComplete(napi_env env, size_t argc, napi_value *argv, napi_value self, napi_value *result);
|
||||
static napi_status CheckOffCompleteParam(napi_env env, size_t argc, napi_value *argv, napi_value self);
|
||||
|
||||
std::shared_ptr<Upload::IProgressCallback> onProgress_ = nullptr;
|
||||
std::shared_ptr<Upload::IHeaderReceiveCallback> onHeaderReceive_ = nullptr;
|
||||
|
@ -295,30 +295,65 @@ napi_status UploadTaskNapi::OffHeaderReceive(napi_env env,
|
||||
return napi_ok;
|
||||
}
|
||||
|
||||
napi_status UploadTaskNapi::OffFail(napi_env env, size_t argc, napi_value *argv, napi_value self, napi_value *result)
|
||||
napi_status UploadTaskNapi::CheckOffCompleteParam(napi_env env, size_t argc, napi_value *argv, napi_value self)
|
||||
{
|
||||
UPLOAD_HILOGD(UPLOAD_MODULE_JS_NAPI, "Enter OffFail.");
|
||||
NAPI_ASSERT_BASE(env, argc == 0, "argc should be 0", napi_invalid_arg);
|
||||
NAPI_ASSERT_BASE(env, argc == 0 || argc == 1, "argc should be 0 or 1", napi_invalid_arg);
|
||||
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
|
||||
|
||||
UploadTaskNapi *proxy = nullptr;
|
||||
NAPI_CALL_BASE(env, napi_unwrap(env, self, reinterpret_cast<void **>(&proxy)), napi_invalid_arg);
|
||||
NAPI_ASSERT_BASE(env, proxy != nullptr, "there is no native upload task", napi_invalid_arg);
|
||||
proxy->napiUploadTask_->Off(TYPE_FAIL_CALLBACK);
|
||||
if (argc == 1) {
|
||||
UPLOAD_HILOGD(UPLOAD_MODULE_JS_NAPI, "Input. argc == 1.");
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
napi_typeof(env, argv[0], &valueType);
|
||||
NAPI_ASSERT_BASE(env, valueType == napi_function, "callback is not a function", napi_invalid_arg);
|
||||
}
|
||||
return napi_ok;
|
||||
}
|
||||
|
||||
napi_status UploadTaskNapi::OffComplete(napi_env env, size_t argc, napi_value *argv,
|
||||
napi_value self, napi_value *result)
|
||||
napi_status UploadTaskNapi::OffFail(napi_env env,
|
||||
size_t argc, napi_value *argv, napi_value self, napi_value *result)
|
||||
{
|
||||
UPLOAD_HILOGD(UPLOAD_MODULE_JS_NAPI, "Enter OffComplete.");
|
||||
NAPI_ASSERT_BASE(env, argc == 0, "argc should be 0", napi_invalid_arg);
|
||||
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
|
||||
UPLOAD_HILOGD(UPLOAD_MODULE_JS_NAPI, "Enter OffFail.");
|
||||
napi_status status = CheckOffCompleteParam(env, argc, argv, self);
|
||||
if (status != napi_ok) {
|
||||
return status;
|
||||
}
|
||||
|
||||
UploadTaskNapi *proxy = nullptr;
|
||||
NAPI_CALL_BASE(env, napi_unwrap(env, self, reinterpret_cast<void **>(&proxy)), napi_invalid_arg);
|
||||
NAPI_ASSERT_BASE(env, proxy != nullptr, "there is no native upload task", napi_invalid_arg);
|
||||
proxy->napiUploadTask_->Off(TYPE_COMPLETE_CALLBACK);
|
||||
|
||||
if (proxy->onFail_ == nullptr) {
|
||||
UPLOAD_HILOGD(UPLOAD_MODULE_JS_NAPI, "Fail. proxy->onFail_ == nullptr.");
|
||||
return napi_generic_failure;
|
||||
} else {
|
||||
std::shared_ptr<IFailCallback> callback = std::make_shared<FailCallback>(proxy, env, argv[0]);
|
||||
proxy->napiUploadTask_->Off(TYPE_FAIL_CALLBACK, callback.get());
|
||||
proxy->onFail_ = nullptr;
|
||||
}
|
||||
return napi_ok;
|
||||
}
|
||||
|
||||
|
||||
napi_status UploadTaskNapi::OffComplete(napi_env env,
|
||||
size_t argc, napi_value *argv, napi_value self, napi_value *result)
|
||||
{
|
||||
UPLOAD_HILOGD(UPLOAD_MODULE_JS_NAPI, "Enter OffComplete.");
|
||||
napi_status status = CheckOffCompleteParam(env, argc, argv, self);
|
||||
if (status != napi_ok) {
|
||||
return status;
|
||||
}
|
||||
|
||||
UploadTaskNapi *proxy = nullptr;
|
||||
NAPI_CALL_BASE(env, napi_unwrap(env, self, reinterpret_cast<void **>(&proxy)), napi_invalid_arg);
|
||||
NAPI_ASSERT_BASE(env, proxy != nullptr, "there is no native upload task", napi_invalid_arg);
|
||||
if (proxy->onComplete_ == nullptr) {
|
||||
UPLOAD_HILOGD(UPLOAD_MODULE_JS_NAPI, "CompleteCallback. proxy->OffComplete_ == nullptr.");
|
||||
return napi_generic_failure;
|
||||
} else {
|
||||
std::shared_ptr<ICompleteCallback> callback = std::make_shared<CompleteCallback>(proxy, env, argv[0]);
|
||||
proxy->napiUploadTask_->Off(TYPE_COMPLETE_CALLBACK, callback.get());
|
||||
proxy->onComplete_ = nullptr;
|
||||
}
|
||||
return napi_ok;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user