From 95e06681a1e2029fdb227b617428c40e51d43642 Mon Sep 17 00:00:00 2001 From: fengjq Date: Thu, 14 Dec 2023 11:46:02 +0800 Subject: [PATCH] Fallback async-interface code framework Signed-off-by: fengjq --- .../js/src/mod_fileio/properties/chmod.cpp | 18 +++++++++++++++++- .../js/src/mod_fileio/properties/chown.cpp | 19 ++++++++++++++++++- .../js/src/mod_fileio/properties/fchmod.cpp | 19 +++++++++++++++++-- .../js/src/mod_fileio/properties/fchown.cpp | 18 +++++++++++++++++- .../js/src/mod_fileio/properties/lchown.cpp | 18 +++++++++++++++++- 5 files changed, 86 insertions(+), 6 deletions(-) diff --git a/interfaces/kits/js/src/mod_fileio/properties/chmod.cpp b/interfaces/kits/js/src/mod_fileio/properties/chmod.cpp index bfef7ca25..3a75eb8bd 100644 --- a/interfaces/kits/js/src/mod_fileio/properties/chmod.cpp +++ b/interfaces/kits/js/src/mod_fileio/properties/chmod.cpp @@ -36,7 +36,23 @@ napi_value Chmod::Sync(napi_env env, napi_callback_info info) napi_value Chmod::Async(napi_env env, napi_callback_info info) { - return NVal::CreateUndefined(env).val_; + NFuncArg funcArg(env, info); + auto cbExec = [](napi_env env) -> UniError { + return UniError(ERRNO_NOERR); + }; + + auto cbComplete = [](napi_env env, UniError err) -> NVal { + return { NVal::CreateUndefined(env) }; + }; + + NVal thisVar(env, funcArg.GetThisVar()); + const string procedureName = "FileIOChmod"; + if (funcArg.GetArgc() == NARG_CNT::TWO) { + return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_; + } else { + NVal cb(env, funcArg[NARG_POS::THIRD]); + return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; + } } } // namespace ModuleFileIO } // namespace DistributedFS diff --git a/interfaces/kits/js/src/mod_fileio/properties/chown.cpp b/interfaces/kits/js/src/mod_fileio/properties/chown.cpp index 8cac52c70..cf2887d1e 100644 --- a/interfaces/kits/js/src/mod_fileio/properties/chown.cpp +++ b/interfaces/kits/js/src/mod_fileio/properties/chown.cpp @@ -35,7 +35,24 @@ napi_value Chown::Sync(napi_env env, napi_callback_info info) napi_value Chown::Async(napi_env env, napi_callback_info info) { - return NVal::CreateUndefined(env).val_; + NFuncArg funcArg(env, info); + auto cbExec = [](napi_env env) -> UniError { + return UniError(ERRNO_NOERR); + }; + + auto cbCompl = [](napi_env env, UniError err) -> NVal { + return { NVal::CreateUndefined(env) }; + }; + + const string procedureName = "FileIOChown"; + NVal thisVar(env, funcArg.GetThisVar()); + if (funcArg.GetArgc() == NARG_CNT::THREE) { + return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbCompl).val_; + } else { + int cbIdx = NARG_POS::FOURTH; + NVal cb(env, funcArg[cbIdx]); + return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbCompl).val_; + } } } // namespace ModuleFileIO } // namespace DistributedFS diff --git a/interfaces/kits/js/src/mod_fileio/properties/fchmod.cpp b/interfaces/kits/js/src/mod_fileio/properties/fchmod.cpp index 159ef1b40..837fac637 100644 --- a/interfaces/kits/js/src/mod_fileio/properties/fchmod.cpp +++ b/interfaces/kits/js/src/mod_fileio/properties/fchmod.cpp @@ -33,10 +33,25 @@ napi_value Fchmod::Sync(napi_env env, napi_callback_info info) return NVal::CreateUndefined(env).val_; } - napi_value Fchmod::Async(napi_env env, napi_callback_info info) { - return NVal::CreateUndefined(env).val_; + NFuncArg funcArg(env, info); + auto cbExec = [](napi_env env) -> UniError { + return UniError(ERRNO_NOERR); + }; + + auto cbComplCallback = [](napi_env env, UniError err) -> NVal { + return { NVal::CreateUndefined(env) }; + }; + + const string procedureName = "FileIOFchmod"; + NVal thisVar(env, funcArg.GetThisVar()); + if (funcArg.GetArgc() == NARG_CNT::TWO) { + return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplCallback).val_; + } else { + NVal cb(env, funcArg[NARG_POS::THIRD]); + return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplCallback).val_; + } } } // namespace ModuleFileIO } // namespace DistributedFS diff --git a/interfaces/kits/js/src/mod_fileio/properties/fchown.cpp b/interfaces/kits/js/src/mod_fileio/properties/fchown.cpp index a3295b092..0ced63073 100644 --- a/interfaces/kits/js/src/mod_fileio/properties/fchown.cpp +++ b/interfaces/kits/js/src/mod_fileio/properties/fchown.cpp @@ -34,7 +34,23 @@ napi_value Fchown::Sync(napi_env env, napi_callback_info info) napi_value Fchown::Async(napi_env env, napi_callback_info info) { - return NVal::CreateUndefined(env).val_; + NFuncArg funcArg(env, info); + auto cbExec = [](napi_env env) -> UniError { + return UniError(ERRNO_NOERR); + }; + + auto cbComplCallback = [](napi_env env, UniError err) -> NVal { + return { NVal::CreateUndefined(env) }; + }; + + const string procedureName = "FileIOFchown"; + NVal thisVar(env, funcArg.GetThisVar()); + if (funcArg.GetArgc() == NARG_CNT::THREE) { + return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplCallback).val_; + } else { + NVal cb(env, funcArg[NARG_POS::FOURTH]); + return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplCallback).val_; + } } } // namespace ModuleFileIO } // namespace DistributedFS diff --git a/interfaces/kits/js/src/mod_fileio/properties/lchown.cpp b/interfaces/kits/js/src/mod_fileio/properties/lchown.cpp index 2113bdfc2..459c6a50d 100644 --- a/interfaces/kits/js/src/mod_fileio/properties/lchown.cpp +++ b/interfaces/kits/js/src/mod_fileio/properties/lchown.cpp @@ -34,7 +34,23 @@ napi_value Lchown::Sync(napi_env env, napi_callback_info info) napi_value Lchown::Async(napi_env env, napi_callback_info info) { - return NVal::CreateUndefined(env).val_; + NFuncArg funcArg(env, info); + auto cbExec = [](napi_env env) -> UniError { + return UniError(ERRNO_NOERR); + }; + + auto cbCompl = [](napi_env env, UniError err) -> NVal { + return { NVal::CreateUndefined(env) }; + }; + + const string procedureName = "FileIOLchown"; + NVal thisVar(env, funcArg.GetThisVar()); + if (funcArg.GetArgc() == NARG_CNT::THREE) { + return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbCompl).val_; + } else { + NVal cb(env, funcArg[NARG_POS::FOURTH]); + return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbCompl).val_; + } } } // namespace ModuleFileIO } // namespace DistributedFS -- Gitee