mirror of
https://gitee.com/openharmony/filemanagement_dfs_service
synced 2024-11-23 16:09:58 +00:00
消除静态检查告警,分解大函数
Signed-off-by: Luyao Wang <wangluyao35@huawei.com> Change-Id: I39cfd2e1a137f65ba41455bc942dd6bc92ce8f03
This commit is contained in:
parent
2f4f170abb
commit
0d88df6097
@ -20,6 +20,7 @@
|
|||||||
#include "cloud_sync_manager.h"
|
#include "cloud_sync_manager.h"
|
||||||
#include "dfs_error.h"
|
#include "dfs_error.h"
|
||||||
#include "utils_log.h"
|
#include "utils_log.h"
|
||||||
|
#include "async_work.h"
|
||||||
#include "uv.h"
|
#include "uv.h"
|
||||||
|
|
||||||
namespace OHOS::FileManagement::CloudSync {
|
namespace OHOS::FileManagement::CloudSync {
|
||||||
@ -78,19 +79,9 @@ napi_value CloudFileDownloadNapi::Start(napi_env env, napi_callback_info info)
|
|||||||
return NVal::CreateUndefined(env);
|
return NVal::CreateUndefined(env);
|
||||||
};
|
};
|
||||||
|
|
||||||
NVal thisVar(env, funcArg.GetThisVar());
|
|
||||||
string procedureName = "cloudFileDownload";
|
string procedureName = "cloudFileDownload";
|
||||||
if (funcArg.GetArgc() == (uint)NARG_CNT::ONE) {
|
auto asyncWork = GetPromiseOrCallBackWork(env, funcArg, static_cast<size_t>(NARG_CNT::TWO));
|
||||||
return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbCompl).val_;
|
return asyncWork == nullptr ? nullptr : asyncWork->Schedule(procedureName, cbExec, cbCompl).val_;
|
||||||
} else {
|
|
||||||
NVal cb(env, funcArg[NARG_POS::SECOND]);
|
|
||||||
if (!cb.TypeIs(napi_function)) {
|
|
||||||
LOGE("Argument type mismatch");
|
|
||||||
NError(E_PARAMS).ThrowErr(env);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbCompl).val_;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CloudDownloadCallbackImpl::CloudDownloadCallbackImpl(napi_env env, napi_value fun) : env_(env)
|
CloudDownloadCallbackImpl::CloudDownloadCallbackImpl(napi_env env, napi_value fun) : env_(env)
|
||||||
@ -283,19 +274,9 @@ napi_value CloudFileDownloadNapi::Stop(napi_env env, napi_callback_info info)
|
|||||||
return NVal::CreateUndefined(env);
|
return NVal::CreateUndefined(env);
|
||||||
};
|
};
|
||||||
|
|
||||||
NVal thisVar(env, funcArg.GetThisVar());
|
|
||||||
string procedureName = "cloudFileDownload";
|
string procedureName = "cloudFileDownload";
|
||||||
if (funcArg.GetArgc() == NARG_CNT::ONE) {
|
auto asyncWork = GetPromiseOrCallBackWork(env, funcArg, static_cast<size_t>(NARG_CNT::TWO));
|
||||||
return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbCompl).val_;
|
return asyncWork == nullptr ? nullptr : asyncWork->Schedule(procedureName, cbExec, cbCompl).val_;
|
||||||
} else {
|
|
||||||
NVal cb(env, funcArg[NARG_POS::SECOND]);
|
|
||||||
if (!cb.TypeIs(napi_function)) {
|
|
||||||
LOGE("Argument type mismatch");
|
|
||||||
NError(E_PARAMS).ThrowErr(env);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbCompl).val_;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CloudFileDownloadNapi::Export()
|
bool CloudFileDownloadNapi::Export()
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "cloud_sync_manager.h"
|
#include "cloud_sync_manager.h"
|
||||||
#include "dfs_error.h"
|
#include "dfs_error.h"
|
||||||
#include "utils_log.h"
|
#include "utils_log.h"
|
||||||
|
#include "async_work.h"
|
||||||
#include "uv.h"
|
#include "uv.h"
|
||||||
|
|
||||||
namespace OHOS::FileManagement::CloudSync {
|
namespace OHOS::FileManagement::CloudSync {
|
||||||
@ -164,7 +165,7 @@ napi_value GallerySyncNapi::OnCallback(napi_env env, napi_callback_info info)
|
|||||||
napi_value GallerySyncNapi::OffCallback(napi_env env, napi_callback_info info)
|
napi_value GallerySyncNapi::OffCallback(napi_env env, napi_callback_info info)
|
||||||
{
|
{
|
||||||
NFuncArg funcArg(env, info);
|
NFuncArg funcArg(env, info);
|
||||||
if (!funcArg.InitArgs(NARG_CNT::ONE,NARG_CNT::TWO)) {
|
if (!funcArg.InitArgs(NARG_CNT::ONE, NARG_CNT::TWO)) {
|
||||||
NError(E_PARAMS).ThrowErr(env, "Number of arguments unmatched");
|
NError(E_PARAMS).ThrowErr(env, "Number of arguments unmatched");
|
||||||
LOGE("OffCallback Number of arguments unmatched");
|
LOGE("OffCallback Number of arguments unmatched");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -220,18 +221,8 @@ napi_value GallerySyncNapi::Start(napi_env env, napi_callback_info info)
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::string PROCEDURE_NAME = "Start";
|
std::string PROCEDURE_NAME = "Start";
|
||||||
NVal thisVar(env, funcArg.GetThisVar());
|
auto asyncWork = GetPromiseOrCallBackWork(env, funcArg, static_cast<size_t>(NARG_CNT::TWO));
|
||||||
if (funcArg.GetArgc() == NARG_CNT::ZERO) {
|
return asyncWork == nullptr ? nullptr : asyncWork->Schedule(PROCEDURE_NAME, cbExec, cbComplete).val_;
|
||||||
return NAsyncWorkPromise(env, thisVar).Schedule(PROCEDURE_NAME, cbExec, cbComplete).val_;
|
|
||||||
} else {
|
|
||||||
NVal cb(env, funcArg[NARG_POS::FIRST]);
|
|
||||||
if (!cb.TypeIs(napi_function)) {
|
|
||||||
LOGE("Argument type mismatch");
|
|
||||||
NError(E_PARAMS).ThrowErr(env);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return NAsyncWorkCallback(env, thisVar, cb).Schedule(PROCEDURE_NAME, cbExec, cbComplete).val_;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
napi_value GallerySyncNapi::Stop(napi_env env, napi_callback_info info)
|
napi_value GallerySyncNapi::Stop(napi_env env, napi_callback_info info)
|
||||||
@ -259,18 +250,8 @@ napi_value GallerySyncNapi::Stop(napi_env env, napi_callback_info info)
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::string PROCEDURE_NAME = "Stop";
|
std::string PROCEDURE_NAME = "Stop";
|
||||||
NVal thisVar(env, funcArg.GetThisVar());
|
auto asyncWork = GetPromiseOrCallBackWork(env, funcArg, static_cast<size_t>(NARG_CNT::TWO));
|
||||||
if (funcArg.GetArgc() == NARG_CNT::ZERO) {
|
return asyncWork == nullptr ? nullptr : asyncWork->Schedule(PROCEDURE_NAME, cbExec, cbComplete).val_;
|
||||||
return NAsyncWorkPromise(env, thisVar).Schedule(PROCEDURE_NAME, cbExec, cbComplete).val_;
|
|
||||||
} else {
|
|
||||||
NVal cb(env, funcArg[NARG_POS::FIRST]);
|
|
||||||
if (!cb.TypeIs(napi_function)) {
|
|
||||||
LOGE("Argument type mismatch");
|
|
||||||
NError(E_PARAMS).ThrowErr(env);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return NAsyncWorkCallback(env, thisVar, cb).Schedule(PROCEDURE_NAME, cbExec, cbComplete).val_;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GallerySyncNapi::GetClassName()
|
std::string GallerySyncNapi::GetClassName()
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "cloud_sync_manager.h"
|
#include "cloud_sync_manager.h"
|
||||||
#include "dfs_error.h"
|
#include "dfs_error.h"
|
||||||
#include "utils_log.h"
|
#include "utils_log.h"
|
||||||
|
#include "async_work.h"
|
||||||
|
|
||||||
namespace OHOS::FileManagement::CloudSync {
|
namespace OHOS::FileManagement::CloudSync {
|
||||||
using namespace FileManagement::LibN;
|
using namespace FileManagement::LibN;
|
||||||
@ -79,17 +80,8 @@ napi_value ChangeAppCloudSwitch(napi_env env, napi_callback_info info)
|
|||||||
|
|
||||||
std::string procedureName = "ChangeAppCloudSwitch";
|
std::string procedureName = "ChangeAppCloudSwitch";
|
||||||
NVal thisVar(env, funcArg.GetThisVar());
|
NVal thisVar(env, funcArg.GetThisVar());
|
||||||
if (funcArg.GetArgc() == (uint)NARG_CNT::THREE) {
|
auto asyncWork = GetPromiseOrCallBackWork(env, funcArg, static_cast<size_t>(NARG_CNT::FOUR));
|
||||||
return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_;
|
return asyncWork == nullptr ? nullptr : asyncWork->Schedule(procedureName, cbExec, cbComplete).val_;
|
||||||
} else {
|
|
||||||
NVal cb(env, funcArg[(int)NARG_POS::FOURTH]);
|
|
||||||
if (!cb.TypeIs(napi_function)) {
|
|
||||||
LOGE("Argument type mismatch");
|
|
||||||
NError(E_PARAMS).ThrowErr(env);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
napi_value NotifyDataChange(napi_env env, napi_callback_info info)
|
napi_value NotifyDataChange(napi_env env, napi_callback_info info)
|
||||||
@ -135,18 +127,8 @@ napi_value NotifyDataChange(napi_env env, napi_callback_info info)
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::string procedureName = "NotifyDataChange";
|
std::string procedureName = "NotifyDataChange";
|
||||||
NVal thisVar(env, funcArg.GetThisVar());
|
auto asyncWork = GetPromiseOrCallBackWork(env, funcArg, static_cast<size_t>(NARG_CNT::THREE));
|
||||||
if (funcArg.GetArgc() == (uint)NARG_CNT::TWO) {
|
return asyncWork == nullptr ? nullptr : asyncWork->Schedule(procedureName, cbExec, cbComplete).val_;
|
||||||
return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_;
|
|
||||||
} else {
|
|
||||||
NVal cb(env, funcArg[(int)NARG_POS::THIRD]);
|
|
||||||
if (!cb.TypeIs(napi_function)) {
|
|
||||||
LOGE("Argument type mismatch");
|
|
||||||
NError(E_PARAMS).ThrowErr(env);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
napi_value DisableCloud(napi_env env, napi_callback_info info)
|
napi_value DisableCloud(napi_env env, napi_callback_info info)
|
||||||
@ -185,18 +167,8 @@ napi_value DisableCloud(napi_env env, napi_callback_info info)
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::string procedureName = "DisableCloud";
|
std::string procedureName = "DisableCloud";
|
||||||
NVal thisVar(env, funcArg.GetThisVar());
|
auto asyncWork = GetPromiseOrCallBackWork(env, funcArg, static_cast<size_t>(NARG_CNT::TWO));
|
||||||
if (funcArg.GetArgc() == (uint)NARG_CNT::ONE) {
|
return asyncWork == nullptr ? nullptr : asyncWork->Schedule(procedureName, cbExec, cbComplete).val_;
|
||||||
return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_;
|
|
||||||
} else {
|
|
||||||
NVal cb(env, funcArg[(int)NARG_POS::SECOND]);
|
|
||||||
if (!cb.TypeIs(napi_function)) {
|
|
||||||
LOGE("Argument type mismatch");
|
|
||||||
NError(E_PARAMS).ThrowErr(env);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -277,18 +249,8 @@ napi_value EnableCloud(napi_env env, napi_callback_info info)
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::string procedureName = "EnableCloud";
|
std::string procedureName = "EnableCloud";
|
||||||
NVal thisVar(env, funcArg.GetThisVar());
|
auto asyncWork = GetPromiseOrCallBackWork(env, funcArg, static_cast<size_t>(NARG_CNT::THREE));
|
||||||
if (funcArg.GetArgc() == (uint)NARG_CNT::TWO) {
|
return asyncWork == nullptr ? nullptr : asyncWork->Schedule(procedureName, cbExec, cbComplete).val_;
|
||||||
return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_;
|
|
||||||
} else {
|
|
||||||
NVal cb(env, funcArg[(int)NARG_POS::THIRD]);
|
|
||||||
if (!NVal(env, funcArg[NARG_POS::THIRD]).TypeIs(napi_function)) {
|
|
||||||
LOGE("Argument type mismatch");
|
|
||||||
NError(E_PARAMS).ThrowErr(env);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ParseAppActions(napi_env env, napi_value object, CleanOptions &cleanOptions)
|
bool ParseAppActions(napi_env env, napi_value object, CleanOptions &cleanOptions)
|
||||||
@ -364,18 +326,8 @@ napi_value Clean(napi_env env, napi_callback_info info)
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::string procedureName = "Clean";
|
std::string procedureName = "Clean";
|
||||||
NVal thisVar(env, funcArg.GetThisVar());
|
auto asyncWork = GetPromiseOrCallBackWork(env, funcArg, static_cast<size_t>(NARG_CNT::THREE));
|
||||||
if (funcArg.GetArgc() == (uint)NARG_CNT::TWO) {
|
return asyncWork == nullptr ? nullptr : asyncWork->Schedule(procedureName, cbExec, cbComplete).val_;
|
||||||
return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_;
|
|
||||||
} else {
|
|
||||||
NVal cb(env, funcArg[(int)NARG_POS::THIRD]);
|
|
||||||
if (!cb.TypeIs(napi_function)) {
|
|
||||||
LOGE("Argument type mismatch");
|
|
||||||
NError(E_PARAMS).ThrowErr(env);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace OHOS::FileManagement::CloudSync
|
} // namespace OHOS::FileManagement::CloudSync
|
||||||
|
@ -47,6 +47,7 @@ config("compiler_configs") {
|
|||||||
|
|
||||||
config("utils_public_config") {
|
config("utils_public_config") {
|
||||||
include_dirs = [
|
include_dirs = [
|
||||||
|
"work/include",
|
||||||
"log/include",
|
"log/include",
|
||||||
"preference/include",
|
"preference/include",
|
||||||
"system/include",
|
"system/include",
|
||||||
@ -63,6 +64,7 @@ ohos_shared_library("libdistributedfileutils") {
|
|||||||
"system/src/dfsu_memory_guard.cpp",
|
"system/src/dfsu_memory_guard.cpp",
|
||||||
"system/src/dfsu_mount_argument_descriptors.cpp",
|
"system/src/dfsu_mount_argument_descriptors.cpp",
|
||||||
"system/src/utils_directory.cpp",
|
"system/src/utils_directory.cpp",
|
||||||
|
"work/src/async_work.cpp",
|
||||||
]
|
]
|
||||||
|
|
||||||
configs = [ "//build/config/compiler:exceptions" ]
|
configs = [ "//build/config/compiler:exceptions" ]
|
||||||
@ -84,8 +86,11 @@ ohos_shared_library("libdistributedfileutils") {
|
|||||||
"access_token:libtokenid_sdk",
|
"access_token:libtokenid_sdk",
|
||||||
"c_utils:utils",
|
"c_utils:utils",
|
||||||
"c_utils:utilsbase",
|
"c_utils:utilsbase",
|
||||||
|
"file_api:filemgmt_libhilog",
|
||||||
|
"file_api:filemgmt_libn",
|
||||||
"hilog:libhilog",
|
"hilog:libhilog",
|
||||||
"ipc:ipc_core",
|
"ipc:ipc_core",
|
||||||
|
"napi:ace_napi",
|
||||||
"preferences:native_preferences",
|
"preferences:native_preferences",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
30
utils/work/include/async_work.h
Normal file
30
utils/work/include/async_work.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef OHOS_FILEMGMT_ASYNC_WORK_H
|
||||||
|
#define OHOS_FILEMGMT_ASYNC_WORK_H
|
||||||
|
|
||||||
|
#include "filemgmt_libn.h"
|
||||||
|
#include "n_func_arg.h"
|
||||||
|
#include "n_async_context.h"
|
||||||
|
|
||||||
|
namespace OHOS {
|
||||||
|
namespace FileManagement {
|
||||||
|
namespace LibN {
|
||||||
|
std::unique_ptr<NAsyncWork> GetPromiseOrCallBackWork(napi_env env, const NFuncArg& funcArg, size_t maxArgSize);
|
||||||
|
} // namespace LibN
|
||||||
|
} // namespace FileManagement
|
||||||
|
} // namespace OHOS
|
||||||
|
#endif // OHOS_FILEMGMT_ASYNC_WORK_H
|
42
utils/work/src/async_work.cpp
Normal file
42
utils/work/src/async_work.cpp
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "async_work.h"
|
||||||
|
#include "utils_log.h"
|
||||||
|
|
||||||
|
namespace OHOS {
|
||||||
|
namespace FileManagement {
|
||||||
|
namespace LibN {
|
||||||
|
|
||||||
|
std::unique_ptr<NAsyncWork> GetPromiseOrCallBackWork(napi_env env, const NFuncArg &funcArg, size_t maxArgSize)
|
||||||
|
{
|
||||||
|
std::unique_ptr<NAsyncWork> asyncWork = nullptr;
|
||||||
|
NVal thisVar(env, funcArg.GetThisVar());
|
||||||
|
if (funcArg.GetArgc() != maxArgSize) {
|
||||||
|
asyncWork = std::make_unique<NAsyncWorkPromise>(env, thisVar);
|
||||||
|
} else {
|
||||||
|
NVal cb(env, funcArg[(int)maxArgSize - 1]);
|
||||||
|
if (cb.TypeIs(napi_function)) {
|
||||||
|
asyncWork = std::make_unique<NAsyncWorkCallback>(env, thisVar, cb);
|
||||||
|
} else {
|
||||||
|
LOGE("Argument type mismatch");
|
||||||
|
NError(E_PARAMS).ThrowErr(env);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return asyncWork;
|
||||||
|
}
|
||||||
|
} // namespace LibN
|
||||||
|
} // namespace FileManagement
|
||||||
|
} // namespace OHOS
|
Loading…
Reference in New Issue
Block a user