From 909347569c82c352ef53e80fd28637646047ded7 Mon Sep 17 00:00:00 2001 From: yaomanhai Date: Tue, 28 Dec 2021 02:02:44 +0000 Subject: [PATCH] js api --- interfaces/js/kits/napi/BUILD.gn | 50 +++ .../js/kits/napi/src/common/napi/n_class.cpp | 61 ++++ .../js/kits/napi/src/common/napi/n_class.h | 83 +++++ .../js/kits/napi/src/common/napi/n_exporter.h | 46 +++ .../kits/napi/src/common/napi/n_func_arg.cpp | 104 ++++++ .../js/kits/napi/src/common/napi/n_func_arg.h | 96 ++++++ .../js/kits/napi/src/common/napi/n_val.cpp | 319 ++++++++++++++++++ .../js/kits/napi/src/common/napi/n_val.h | 117 +++++++ .../js/kits/napi/src/common/napi/uni_header.h | 25 ++ .../src/hilog/include/context/hilog_napi.h | 41 +++ .../hilog/include/context/hilog_napi_base.h | 44 +++ interfaces/js/kits/napi/src/hilog/module.cpp | 41 +++ .../js/kits/napi/src/hilog/src/hilog_napi.cpp | 67 ++++ .../napi/src/hilog/src/hilog_napi_base.cpp | 282 ++++++++++++++++ 14 files changed, 1376 insertions(+) create mode 100644 interfaces/js/kits/napi/BUILD.gn create mode 100644 interfaces/js/kits/napi/src/common/napi/n_class.cpp create mode 100644 interfaces/js/kits/napi/src/common/napi/n_class.h create mode 100644 interfaces/js/kits/napi/src/common/napi/n_exporter.h create mode 100644 interfaces/js/kits/napi/src/common/napi/n_func_arg.cpp create mode 100644 interfaces/js/kits/napi/src/common/napi/n_func_arg.h create mode 100644 interfaces/js/kits/napi/src/common/napi/n_val.cpp create mode 100644 interfaces/js/kits/napi/src/common/napi/n_val.h create mode 100644 interfaces/js/kits/napi/src/common/napi/uni_header.h create mode 100644 interfaces/js/kits/napi/src/hilog/include/context/hilog_napi.h create mode 100644 interfaces/js/kits/napi/src/hilog/include/context/hilog_napi_base.h create mode 100644 interfaces/js/kits/napi/src/hilog/module.cpp create mode 100644 interfaces/js/kits/napi/src/hilog/src/hilog_napi.cpp create mode 100644 interfaces/js/kits/napi/src/hilog/src/hilog_napi_base.cpp diff --git a/interfaces/js/kits/napi/BUILD.gn b/interfaces/js/kits/napi/BUILD.gn new file mode 100644 index 0000000..d4fb889 --- /dev/null +++ b/interfaces/js/kits/napi/BUILD.gn @@ -0,0 +1,50 @@ +# Copyright (c) 2020 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. + +import("//build/ohos.gni") + +config("libhilog_pub_config") { + visibility = [ ":*" ] + + include_dirs = [ "include" ] +} + +ohos_source_set("libhilognapi_src") { + include_dirs = [ + "//third_party/node/src", + "//utils/native/base/include", + ] + sources = [ + "src/common/napi/n_class.cpp", + "src/common/napi/n_func_arg.cpp", + "src/common/napi/n_val.cpp", + "src/hilog/module.cpp", + "src/hilog/src/hilog_napi.cpp", + "src/hilog/src/hilog_napi_base.cpp", + ] + + deps = [ "//utils/native/base:utilsecurec" ] + + external_deps = [ + "hilog_native:libhilog", + "napi:ace_napi", + ] +} + +ohos_shared_library("libhilognapi") { + deps = [ ":libhilognapi_src" ] + output_name = "libhilog" + relative_install_dir = "module" + subsystem_name = "hiviewdfx" + part_name = "hilog_native" +} \ No newline at end of file diff --git a/interfaces/js/kits/napi/src/common/napi/n_class.cpp b/interfaces/js/kits/napi/src/common/napi/n_class.cpp new file mode 100644 index 0000000..c69f08d --- /dev/null +++ b/interfaces/js/kits/napi/src/common/napi/n_class.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2021 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 "n_class.h" + +#include +#include + +namespace OHOS { +namespace HiviewDFX { +using namespace std; +NClass &NClass::GetInstance() +{ + static NClass nClass; + return nClass; +} + +tuple NClass::DefineClass(napi_env env, string className, napi_callback constructor, + vector &&properties) +{ + napi_value classVal = nullptr; + napi_status stat = napi_define_class(env, className.c_str(), className.length(), constructor, + nullptr, properties.size(), properties.data(), &classVal); + return { stat == napi_ok, classVal }; +} + +napi_value NClass::InstantiateClass(napi_env env, string className, vector args) +{ + NClass &nClass = NClass::GetInstance(); + lock_guard(nClass.exClassMapLock); + + auto it = nClass.exClassMap.find(className); + if (it == nClass.exClassMap.end()) { + return nullptr; + } + napi_value cons = nullptr; + napi_status status = napi_get_reference_value(env, it->second, &cons); + if (status != napi_ok) { + return nullptr; + } + napi_value instance = nullptr; + status = napi_new_instance(env, cons, args.size(), args.data(), &instance); + if (status != napi_ok) { + return nullptr; + } + return instance; +} +} // namespace HiviewDFX +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/js/kits/napi/src/common/napi/n_class.h b/interfaces/js/kits/napi/src/common/napi/n_class.h new file mode 100644 index 0000000..cb68f97 --- /dev/null +++ b/interfaces/js/kits/napi/src/common/napi/n_class.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2021 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 HIVIEWDFX_NAPI_NCALSS +#define HIVIEWDFX_NAPI_NCALSS + +#pragma once + +#include "uni_header.h" + +#include +#include +#include +#include +#include +#include + +namespace OHOS { +namespace HiviewDFX { +class NClass { +public: + NClass(const NClass &) = delete; + NClass &operator = (const NClass &) = delete; + ~NClass() {}; + static NClass &GetInstance(); + + static std::tuple DefineClass(napi_env env, + std::string className, + napi_callback constructor, + std::vector &&properties); + static bool SaveClass(napi_env env, std::string className, napi_value exClass); + static napi_value InstantiateClass(napi_env env, std::string className, std::vector args); + + template static T *GetEntityOf(napi_env env, napi_value objStat) + { + if (!env || !objStat) { + return nullptr; + } + T *t = nullptr; + napi_status status = napi_unwrap(env, objStat, (void **)&t); + if (status != napi_ok) { + return nullptr; + } + return t; + } + + template static bool SetEntityFor(napi_env env, napi_value obj, std::unique_ptr entity) + { + napi_status status = napi_wrap( + env, + obj, + entity.get(), + [](napi_env env, void *data, void *hint) { + auto entity = static_cast(data); + delete entity; + }, + nullptr, + nullptr); + entity.release(); + return status == napi_ok; + } + +private: + NClass() = default; + std::map exClassMap; + std::mutex exClassMapLock; +}; +} // namespace HiviewDFX +} // namespace OHOS + +#endif // HIVIEWDFX_NAPI_NCALSS \ No newline at end of file diff --git a/interfaces/js/kits/napi/src/common/napi/n_exporter.h b/interfaces/js/kits/napi/src/common/napi/n_exporter.h new file mode 100644 index 0000000..03ee878 --- /dev/null +++ b/interfaces/js/kits/napi/src/common/napi/n_exporter.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2021 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 HIVIEWDFX_NAPI_EXPOTER +#define HIVIEWDFX_NAPI_EXPOTER + +#pragma once + +#include +#include + +#include "n_val.h" + +namespace OHOS { +namespace HiviewDFX { +class NExporter { +public: + NExporter() : exports_(nullptr, nullptr) {}; + + virtual ~NExporter() = default; + + NExporter(napi_env env, napi_value exports) : exports_(env, exports) {}; + + virtual bool Export(napi_env env, napi_value exports) = 0; + + virtual std::string GetClassName() = 0; + +protected: + NVal exports_; +}; +} // namespace HiviewDFX +} // namespace OHOS + +#endif // HIVIEWDFX_NAPI_EXPOTER \ No newline at end of file diff --git a/interfaces/js/kits/napi/src/common/napi/n_func_arg.cpp b/interfaces/js/kits/napi/src/common/napi/n_func_arg.cpp new file mode 100644 index 0000000..45f773b --- /dev/null +++ b/interfaces/js/kits/napi/src/common/napi/n_func_arg.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2021 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 "n_func_arg.h" +#include +#include + +namespace OHOS { +namespace HiviewDFX { +using namespace std; + +NFuncArg::NFuncArg(napi_env env, napi_callback_info info) : env_(env), info_(info) {} + +NFuncArg::~NFuncArg() {} + +void NFuncArg::SetArgc(size_t argc) +{ + argc_ = argc; +} + +void NFuncArg::SetThisVar(napi_value thisVar) +{ + thisVar_ = thisVar; +} + +size_t NFuncArg::GetArgc(void) const +{ + return argc_; +} + +napi_value NFuncArg::GetThisVar(void) const +{ + return thisVar_; +} + +napi_value NFuncArg::GetArg(size_t argPos) const +{ + return (argPos < GetArgc()) ? argv_[argPos] : nullptr; +} + +napi_value NFuncArg::operator[](size_t argPos) const +{ + return GetArg(argPos); +} + +bool NFuncArg::InitArgs(std::function argcChecker) +{ + SetArgc(0); + argv_.reset(); + + size_t argc; + napi_value thisVar; + napi_status status = napi_get_cb_info(env_, info_, &argc, nullptr, &thisVar, nullptr); + if (status != napi_ok) { + return false; + } + if (argc) { + argv_ = make_unique(argc); + status = napi_get_cb_info(env_, info_, &argc, argv_.get(), &thisVar, nullptr); + if (status != napi_ok) { + return false; + } + } + SetArgc(argc); + SetThisVar(thisVar); + + return argcChecker(); +} + +bool NFuncArg::InitArgs(size_t argc) +{ + return InitArgs([argc, this]() { + size_t realArgc = GetArgc(); + if (argc != realArgc) { + return false; + } + return true; + }); +} + +bool NFuncArg::InitArgs(size_t minArgc, size_t maxArgc) +{ + return InitArgs([minArgc, maxArgc, this]() { + size_t realArgc = GetArgc(); + if (minArgc > realArgc || maxArgc < realArgc) { + return false; + } + return true; + }); +} +} // namespace HiviewDFX +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/js/kits/napi/src/common/napi/n_func_arg.h b/interfaces/js/kits/napi/src/common/napi/n_func_arg.h new file mode 100644 index 0000000..0785903 --- /dev/null +++ b/interfaces/js/kits/napi/src/common/napi/n_func_arg.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2021 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 HIVIEWDFX_NAPI_ARG +#define HIVIEWDFX_NAPI_ARG + +#pragma once + +#include +#include +#include +#include +#include "n_val.h" +#include "uni_header.h" + +namespace OHOS { +namespace HiviewDFX { +enum NARG_CNT { + ZERO = 0, + ONE = 1, + TWO = 2, + THREE = 3, + FOUR = 4, + FIVE = 5, + SIX = 6, + SEVEN = 7, + EIGHT = 8, + NINE = 9, + TEN = 10, + ELEVEN = 11, + TWELVE = 12, +}; + +enum NARG_POS { + FIRST = 0, + SECOND = 1, + THIRD = 2, + FOURTH = 3, + FIFTH = 4, + SIXTH = 5, + SEVENTH = 6, + EIGHTH = 7, + NINTH = 8, + TENTH = 9, + ELEVENTH = 10, + TWELVETH = 11, +}; + +class NFuncArg final { +public: + NFuncArg(napi_env env, napi_callback_info info); + + virtual ~NFuncArg(); + + bool InitArgs(size_t argc); + + bool InitArgs(size_t minArgc, size_t maxArgc); + + size_t GetArgc() const; + + napi_value GetThisVar() const; + + napi_value operator[](size_t idx) const; + + napi_value GetArg(size_t argPos) const; + +private: + napi_env env_ = nullptr; + napi_callback_info info_ = nullptr; + + size_t argc_ = 0; + std::unique_ptr argv_ = {nullptr}; + napi_value thisVar_ = nullptr; + + bool InitArgs(std::function argcChecker); + + void SetArgc(size_t argc); + + void SetThisVar(napi_value thisVar); +}; +} // namespace HiviewDFX +} // namespace OHOS + +#endif // HIVIEWDFX_NAPI_ARG \ No newline at end of file diff --git a/interfaces/js/kits/napi/src/common/napi/n_val.cpp b/interfaces/js/kits/napi/src/common/napi/n_val.cpp new file mode 100644 index 0000000..e97f317 --- /dev/null +++ b/interfaces/js/kits/napi/src/common/napi/n_val.cpp @@ -0,0 +1,319 @@ +/* + * Copyright (c) 2021 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 "n_val.h" + +#include +#include + +namespace OHOS { +namespace HiviewDFX { +using namespace std; + +NVal::NVal(napi_env nEnv, napi_value nVal = nullptr) : env_(nEnv), val_(nVal) {} + +NVal::operator bool() const +{ + return env_ && val_; +} + +bool NVal::TypeIs(napi_valuetype expType) const +{ + if (!*this) { + return false; + } + + napi_valuetype valueType; + napi_typeof(env_, val_, &valueType); + + if (expType != valueType) { + return false; + } + return true; +} + +tuple NVal::IsArray() const +{ + bool res = false; + napi_status status = napi_is_array(env_, val_, &res); + return make_tuple(status == napi_ok, res); +} + +tuple, size_t> NVal::ToUTF8String() const +{ + size_t strLen = 0; + napi_status status = napi_get_value_string_utf8(env_, val_, nullptr, -1, &strLen); + if (status != napi_ok) { + return {false, nullptr, 0}; + } + + size_t bufLen = strLen + 1; + unique_ptr str = make_unique(bufLen); + status = napi_get_value_string_utf8(env_, val_, str.get(), bufLen, &strLen); + return make_tuple(status == napi_ok, move(str), strLen); +} + +tuple, size_t> NVal::ToUTF16String() const +{ +#ifdef FILE_SUBSYSTEM_DEV_ON_PC + size_t strLen = 0; + napi_status status = napi_get_value_string_utf16(env_, val_, nullptr, -1, &strLen); + if (status != napi_ok) { + return { false, nullptr, 0 }; + } + + auto str = make_unique(++strLen); + status = napi_get_value_string_utf16(env_, val_, str.get(), strLen, nullptr); + if (status != napi_ok) { + return { false, nullptr, 0 }; + } + + strLen = reinterpret_cast(str.get() + strLen) - reinterpret_cast(str.get()); + auto strRet = unique_ptr(reinterpret_cast(str.release())); + return { true, move(strRet), strLen }; +#else + // Note that quickjs doesn't support utf16 + return ToUTF8String(); +#endif +} + +tuple NVal::ToPointer() const +{ + void *res = nullptr; + napi_status status = napi_get_value_external(env_, val_, &res); + return make_tuple(status == napi_ok, res); +} + +tuple NVal::IsTypeArray() const +{ + bool res = false; + napi_status status = napi_is_typedarray(env_, val_, &res); + return make_tuple(status == napi_ok, res); +} + +tuple NVal::ToBool() const +{ + bool flag = false; + napi_status status = napi_get_value_bool(env_, val_, &flag); + return make_tuple(status == napi_ok, flag); +} + +tuple NVal::ToDouble() const +{ + double res = 0.0; + napi_status status = napi_get_value_double(env_, val_, &res); + return make_tuple(status == napi_ok, res); +} + +tuple NVal::ToInt32() const +{ + int32_t res = 0; + napi_status status = napi_get_value_int32(env_, val_, &res); + return make_tuple(status == napi_ok, res); +} + +tuple NVal::ToInt64() const +{ + int64_t res = 0; + napi_status status = napi_get_value_int64(env_, val_, &res); + return make_tuple(status == napi_ok, res); +} + +tuple NVal::ToArraybuffer() const +{ + void *buf = nullptr; + size_t bufLen = 0; + bool status = napi_get_arraybuffer_info(env_, val_, &buf, &bufLen); + return make_tuple(status == napi_ok, buf, bufLen); +} + +tuple NVal::ToTypedArray() const +{ + napi_typedarray_type type; + napi_value in_array_buffer = nullptr; + size_t byte_offset; + size_t length; + void *data = nullptr; + napi_status status = napi_get_typedarray_info(env_, val_, &type, &length, (void **) &data, &in_array_buffer, + &byte_offset); + return make_tuple(status == napi_ok, type, data, length); +} + +tuple NVal::ToDataview() const +{ + size_t bufLen = 0; + void *buf = nullptr; + napi_value arraybuffer = nullptr; + size_t byteoff = 0; + bool status = napi_get_dataview_info(env_, val_, &bufLen, &buf, &arraybuffer, &byteoff); + return make_tuple(status == napi_ok, buf, bufLen); +} + +tuple NVal::ToTypedArrayInfo() const +{ + napi_typedarray_type type; + napi_value in_array_buffer = nullptr; + size_t byte_offset; + size_t length; + void *data = nullptr; + napi_status status = + napi_get_typedarray_info(env_, val_, &type, &length, (void **)&data, &in_array_buffer, &byte_offset); + return make_tuple(status == napi_ok, data, length, byte_offset, type); +} + +bool NVal::HasProp(string propName) const +{ + bool res = false; + + if (!env_ || !val_ || !TypeIs(napi_object)) + return false; + napi_status status = napi_has_named_property(env_, val_, propName.c_str(), &res); + return (status == napi_ok) && res; +} + +NVal NVal::GetProp(string propName) const +{ + if (!HasProp(propName)) { + return {env_, nullptr}; + } + napi_value prop = nullptr; + napi_status status = napi_get_named_property(env_, val_, propName.c_str(), &prop); + if (status != napi_ok) { + return {env_, nullptr}; + } + return NVal(env_, prop); +} + +bool NVal::AddProp(vector &&propVec) const +{ + if (!TypeIs(napi_valuetype::napi_object)) { + return false; + } + napi_status status = napi_define_properties(env_, val_, propVec.size(), propVec.data()); + if (status != napi_ok) { + return false; + } + return true; +} + +bool NVal::AddProp(string propName, napi_value val) const +{ + if (!TypeIs(napi_valuetype::napi_object) || HasProp(propName)) { + return false; + } + + napi_status status = napi_set_named_property(env_, val_, propName.c_str(), val); + if (status != napi_ok) { + return false; + } + return true; +} + +NVal NVal::CreateUndefined(napi_env env) +{ + napi_value res = nullptr; + napi_get_undefined(env, &res); + return {env, res}; +} + +NVal NVal::CreateNull(napi_env env) +{ + napi_value res = nullptr; + napi_get_null(env, &res); + return {env, res}; +} + +NVal NVal::CreateInt64(napi_env env, int64_t val) +{ + napi_value res = nullptr; + napi_create_int64(env, val, &res); + return {env, res}; +} + +NVal NVal::CreateObject(napi_env env) +{ + napi_value res = nullptr; + napi_create_object(env, &res); + return {env, res}; +} + +NVal NVal::CreateBool(napi_env env, bool val) +{ + napi_value res = nullptr; + napi_get_boolean(env, val, &res); + return {env, res}; +} + +NVal NVal::CreateUTF8String(napi_env env, std::string str) +{ + napi_value res = nullptr; + napi_create_string_utf8(env, str.c_str(), str.length(), &res); + return {env, res}; +} + +NVal NVal::CreateUint8Array(napi_env env, void *buf, size_t bufLen) +{ + napi_value output_buffer = nullptr; + napi_create_external_arraybuffer(env, buf, bufLen, + [](napi_env env, void *finalize_data, void *finalize_hint) { free(finalize_data); }, + NULL, &output_buffer); + napi_value output_array = nullptr; + napi_create_typedarray(env, napi_uint8_array, bufLen, output_buffer, 0, &output_array); + return {env, output_array}; +} + +NVal NVal::CreateDouble(napi_env env, double val) +{ + napi_value res = nullptr; + napi_create_double(env, val, &res); + return {env, res}; +} + +napi_property_descriptor NVal::DeclareNapiProperty(const char *name, napi_value val) +{ + return {(name), nullptr, nullptr, nullptr, nullptr, val, napi_default, nullptr}; +} + +napi_property_descriptor NVal::DeclareNapiStaticProperty(const char *name, napi_value val) +{ + return {(name), nullptr, nullptr, nullptr, nullptr, val, napi_static, nullptr}; +} + +napi_property_descriptor NVal::DeclareNapiFunction(const char *name, napi_callback func) +{ + return {(name), nullptr, (func), nullptr, nullptr, nullptr, napi_default, nullptr}; +} + +napi_property_descriptor NVal::DeclareNapiStaticFunction(const char *name, napi_callback func) +{ + return {(name), nullptr, (func), nullptr, nullptr, nullptr, napi_static, nullptr}; +} + +napi_property_descriptor NVal::DeclareNapiGetter(const char *name, napi_callback getter) +{ + return {(name), nullptr, nullptr, (getter), nullptr, nullptr, napi_default, nullptr}; +} + +napi_property_descriptor NVal::DeclareNapiSetter(const char *name, napi_callback setter) +{ + return {(name), nullptr, nullptr, nullptr, (setter), nullptr, napi_default, nullptr}; +} + +napi_property_descriptor NVal::DeclareNapiGetterSetter(const char *name, napi_callback getter, napi_callback setter) +{ + return {(name), nullptr, nullptr, (getter), (setter), nullptr, napi_default, nullptr}; +} +} // namespace HiviewDFX +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/js/kits/napi/src/common/napi/n_val.h b/interfaces/js/kits/napi/src/common/napi/n_val.h new file mode 100644 index 0000000..571f012 --- /dev/null +++ b/interfaces/js/kits/napi/src/common/napi/n_val.h @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2021 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 HIVIEWDFX_NAPI_VAL +#define HIVIEWDFX_NAPI_VAL + +#pragma once + +#include +#include +#include +#include "uni_header.h" + +namespace OHOS { +namespace HiviewDFX { +class NVal final { +public: + NVal() = default; + + NVal(napi_env nEnv, napi_value nVal); + + NVal &operator=(const NVal &) = default; + + virtual ~NVal() = default; + + // NOTE! env_ and val_ is LIKELY to be null + napi_env env_ = nullptr; + napi_value val_ = nullptr; + + explicit operator bool() const; + + bool TypeIs(napi_valuetype expType) const; + + /* SHOULD ONLY BE USED FOR EXPECTED TYPE */ + std::tuple, size_t> ToUTF8String() const; + + std::tuple, size_t> ToUTF16String() const; + + std::tuple ToPointer() const; + + std::tuple ToBool() const; + + std::tuple ToDouble() const; + + std::tuple ToInt32() const; + + std::tuple ToInt64() const; + + std::tuple ToArraybuffer() const; + + std::tuple ToTypedArray() const; + + std::tuple IsTypeArray() const; + + std::tuple ToDataview() const; + + std::tuple IsArray() const; + + std::tuple ToTypedArrayInfo() const; + + /* Static helpers to create js objects */ + static NVal CreateUndefined(napi_env env); + + static NVal CreateNull(napi_env env); + + static NVal CreateInt64(napi_env env, int64_t val); + + static NVal CreateObject(napi_env env); + + static NVal CreateBool(napi_env env, bool val); + + static NVal CreateUTF8String(napi_env env, std::string str); + + static NVal CreateUint8Array(napi_env env, void *buf, size_t bufLen); + + static NVal CreateDouble(napi_env env, double val); + + /* SHOULD ONLY BE USED FOR OBJECT */ + bool HasProp(std::string propName) const; + + NVal GetProp(std::string propName) const; + + bool AddProp(std::vector &&propVec) const; + + bool AddProp(std::string propName, napi_value nVal) const; + + /* Static helpers to create prop of js objects */ + static napi_property_descriptor DeclareNapiProperty(const char *name, napi_value val); + + static napi_property_descriptor DeclareNapiStaticProperty(const char *name, napi_value val); + + static napi_property_descriptor DeclareNapiFunction(const char *name, napi_callback func); + + static napi_property_descriptor DeclareNapiStaticFunction(const char *name, napi_callback func); + + static napi_property_descriptor DeclareNapiGetter(const char *name, napi_callback getter); + + static napi_property_descriptor DeclareNapiSetter(const char *name, napi_callback setter); + + static inline napi_property_descriptor DeclareNapiGetterSetter(const char *name, + napi_callback getter, napi_callback setter); +}; +} // namespace HiviewDFX +} // namespace OHOS + +#endif // HIVIEWDFX_NAPI_VAL \ No newline at end of file diff --git a/interfaces/js/kits/napi/src/common/napi/uni_header.h b/interfaces/js/kits/napi/src/common/napi/uni_header.h new file mode 100644 index 0000000..23d5fac --- /dev/null +++ b/interfaces/js/kits/napi/src/common/napi/uni_header.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2021 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 HIVIEW_NAPI_HEADER +#define HIVIEW_NAPI_HEADER + +#pragma once + +#include +#else +#include "napi/native_api.h" +#include "napi/native_node_api.h" + +#endif // HIVIEW_NAPI_HEADER \ No newline at end of file diff --git a/interfaces/js/kits/napi/src/hilog/include/context/hilog_napi.h b/interfaces/js/kits/napi/src/hilog/include/context/hilog_napi.h new file mode 100644 index 0000000..fa4fd44 --- /dev/null +++ b/interfaces/js/kits/napi/src/hilog/include/context/hilog_napi.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2021 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 HIVIEWDFX_NAPI_HILOG +#define HIVIEWDFX_NAPI_HILOG + +#include "hilog_napi_base.h" +#include "../../../common/napi/n_exporter.h" + +namespace OHOS { +namespace HiviewDFX { +class HilogNapi : public HilogNapiBase, public NExporter { +public: + inline static const std::string className = "hilog"; + + bool Export(napi_env env, napi_value exports) override; + + std::string GetClassName() override; + + HilogNapi(napi_env env, napi_value exports) : NExporter(env, exports) {}; + + explicit HilogNapi() {}; + + ~HilogNapi() {}; +}; +} // namespace HiviewDFX +} // namespace OHOS + +#endif // HIVIEWDFX_NAPI_HILOG \ No newline at end of file diff --git a/interfaces/js/kits/napi/src/hilog/include/context/hilog_napi_base.h b/interfaces/js/kits/napi/src/hilog/include/context/hilog_napi_base.h new file mode 100644 index 0000000..cf8d943 --- /dev/null +++ b/interfaces/js/kits/napi/src/hilog/include/context/hilog_napi_base.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2021 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 HIVIEWDFX_NAPI_HILOG_BASE +#define HIVIEWDFX_NAPI_HILOG_BASE + +#include "../../../common/napi/n_exporter.h" + +#ifdef __cplusplus +extern "C" { +#endif + +namespace OHOS { +namespace HiviewDFX { +class HilogNapiBase { +public: + static napi_value debug(napi_env env, napi_callback_info info); + static napi_value HilogImpl(napi_env env, napi_callback_info info, int level); + static napi_value info(napi_env env, napi_callback_info info); + static napi_value error(napi_env env, napi_callback_info info); + static napi_value warn(napi_env env, napi_callback_info info); + static napi_value fatal(napi_env env, napi_callback_info info); + static napi_value isLoggable(napi_env env, napi_callback_info info); +}; +} // namespace HiviewDFX +} // namespace OHOS + +#ifdef __cplusplus +} +#endif + +#endif // HIVIEWDFX_NAPI_HILOG_BASE \ No newline at end of file diff --git a/interfaces/js/kits/napi/src/hilog/module.cpp b/interfaces/js/kits/napi/src/hilog/module.cpp new file mode 100644 index 0000000..15537c6 --- /dev/null +++ b/interfaces/js/kits/napi/src/hilog/module.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2021 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 +#include + +#include "include/context/hilog_napi.h" +#include "../common/napi/n_val.h" + +using namespace std; + +namespace OHOS { +namespace HiviewDFX { +static napi_value Export(napi_env env, napi_value exports) +{ + std::vector> products; + products.emplace_back(make_unique(env, exports)); + + for (auto &&product : products) { + if (!product->Export(env, exports)) { + return nullptr; + } + } + return exports; +} + +NAPI_MODULE(hilog, Export) +} // namespace HiviewDFX +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/js/kits/napi/src/hilog/src/hilog_napi.cpp b/interfaces/js/kits/napi/src/hilog/src/hilog_napi.cpp new file mode 100644 index 0000000..08cc4ea --- /dev/null +++ b/interfaces/js/kits/napi/src/hilog/src/hilog_napi.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2021 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 "../include/context/hilog_napi.h" +#include "../../common/napi/n_class.h" +#include "../../common/napi/n_func_arg.h" +#include "hilog/log.h" + +#ifdef __cplusplus +extern "C" { +#endif + +namespace OHOS { +namespace HiviewDFX { +using namespace std; + +bool HilogNapi::Export(napi_env env, napi_value exports) +{ + napi_value DEBUG = nullptr; + napi_value INFO = nullptr; + napi_value WARN = nullptr; + napi_value ERROR = nullptr; + napi_value FATAL = nullptr; + napi_create_int32(env, LogLevel::LOG_DEBUG, &DEBUG); + napi_create_int32(env, LogLevel::LOG_INFO, &INFO); + napi_create_int32(env, LogLevel::LOG_WARN, &WARN); + napi_create_int32(env, LogLevel::LOG_ERROR, &ERROR); + napi_create_int32(env, LogLevel::LOG_FATAL, &FATAL); + + return exports_.AddProp( + { + NVal::DeclareNapiFunction("debug", HilogNapiBase::debug), + NVal::DeclareNapiFunction("info", HilogNapiBase::info), + NVal::DeclareNapiFunction("error", HilogNapiBase::error), + NVal::DeclareNapiFunction("warn", HilogNapiBase::warn), + NVal::DeclareNapiFunction("fatal", HilogNapiBase::fatal), + NVal::DeclareNapiFunction("isLoggable", HilogNapiBase::isLoggable), + NVal::DeclareNapiStaticProperty("DEBUG", DEBUG), + NVal::DeclareNapiStaticProperty("INFO", INFO), + NVal::DeclareNapiStaticProperty("WARN", WARN), + NVal::DeclareNapiStaticProperty("ERROR", ERROR), + NVal::DeclareNapiStaticProperty("FATAL", FATAL), + }); +} + +string HilogNapi::GetClassName() +{ + return HilogNapi::className; +} +} // namespace HiviewDFX +} // namespace OHOS + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/interfaces/js/kits/napi/src/hilog/src/hilog_napi_base.cpp b/interfaces/js/kits/napi/src/hilog/src/hilog_napi_base.cpp new file mode 100644 index 0000000..1198623 --- /dev/null +++ b/interfaces/js/kits/napi/src/hilog/src/hilog_napi_base.cpp @@ -0,0 +1,282 @@ +/* + * Copyright (c) 2021 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 "../include/context/hilog_napi_base.h" +#include "../../common/napi/n_func_arg.h" +#include "../../common/napi/n_class.h" +#include "hilog/log.h" +#ifdef __cplusplus +extern "C" { +#endif +namespace OHOS { +namespace HiviewDFX { +using namespace std; +#define DEFAULT_LOG_TYPE LOG_APP +void Replace(string& base, string src, string dst) +{ + size_t pos = 0; + size_t srclen = src.size(); + size_t dstlen = dst.size(); + while ((pos = base.find(src, pos)) != string::npos) { + base.replace(pos, srclen, dst); + pos += dstlen; + } +} + +void Supersplit(const std::string& s, std::vector& v, const std::string& c) +{ + std::string::size_type pos1, pos2; + pos2 = s.find(c); + pos1 = 0; + while (std::string::npos != pos2) { + pos1 = pos2 + c.size(); + pos2 = s.find(c, pos1); + std::string temp = s.substr(pos1, pos2 - pos1); + v.emplace_back(temp); + } +} + +napi_value HilogNapiBase::isLoggable(napi_env env, napi_callback_info info) +{ + NFuncArg funcArg(env, info); + + if (!funcArg.InitArgs(NARG_CNT::THREE)) { + return nullptr; + } + bool succ = false; + int32_t domain; + tie(succ, domain) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt32(); + if (!succ) { + return nullptr; + } + int32_t level; + tie(succ, level) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt32(); + if (!succ) { + return nullptr; + } + unique_ptr tag; + tie(succ, tag, ignore) = NVal(env, funcArg[NARG_POS::SECOND]).ToUTF8String(); + if (!succ) { + return nullptr; + } + bool res = HiLogIsLoggable(domain, tag.get(), static_cast(level)); + return NVal::CreateBool(env, res).val_; +} + +napi_value HilogNapiBase::debug(napi_env env, napi_callback_info info) +{ + return HilogImpl(env, info, LOG_DEBUG); +} + +napi_value HilogNapiBase::info(napi_env env, napi_callback_info info) +{ + return HilogImpl(env, info, LOG_INFO); +} + +napi_value HilogNapiBase::warn(napi_env env, napi_callback_info info) +{ + return HilogImpl(env, info, LOG_WARN); +} + +napi_value HilogNapiBase::error(napi_env env, napi_callback_info info) +{ + return HilogImpl(env, info, LOG_ERROR); +} + +napi_value HilogNapiBase::fatal(napi_env env, napi_callback_info info) +{ + return HilogImpl(env, info, LOG_FATAL); +} + +napi_value HilogNapiBase::HilogImpl(napi_env env, napi_callback_info info, int level) +{ + NFuncArg funcArg(env, info); + if (!funcArg.InitArgs(NARG_CNT::FOUR)) { + return nullptr; + } + bool succ = false; + int32_t domain; + tie(succ, domain) = NVal(env, funcArg[NARG_POS::FIRST]).ToInt32(); + if (!succ) { + return nullptr; + } + unique_ptr tag; + tie(succ, tag, ignore) = NVal(env, funcArg[NARG_POS::SECOND]).ToUTF8String(); + if (!succ) { + return nullptr; + } + unique_ptr fmt; + tie(succ, fmt, ignore) = NVal(env, funcArg[NARG_POS::THIRD]).ToUTF8String(); + if (!succ) { + return nullptr; + } + string fmtString = fmt.get(); + Replace(fmtString, "%i", "%d"); + Replace(fmtString, "%{private}i", "%{private}d"); + Replace(fmtString, "%{public}i", "%{public}d"); + std::vector vecs = {}; + Supersplit(fmtString, vecs, "%"); + napi_value array = funcArg[NARG_POS::FOURTH]; + uint32_t length; + napi_status lengthStatus = napi_get_array_length(env, array, &length); + if (lengthStatus != napi_ok) { + return nullptr; + } + vector arrayArgs; + uint32_t i; + for (i = 0; i < length; i++) { + napi_value element; + napi_status eleStatus = napi_get_element(env, array, i, &element); + if (eleStatus != napi_ok) { + return nullptr; + } + // 获取element的类型 + napi_valuetype type; + napi_status typeStatus = napi_typeof(env, element, &type); + if (typeStatus != napi_ok) { + return nullptr; + } + if (type == napi_number && (vecs[i].compare(0, strlen("{private}d"), "{private}d") || + vecs[i].compare(0, strlen("{public}d"), "{public}d") || vecs[i].compare("d"))) { + napi_value elmString; + napi_status objectStatus = napi_coerce_to_string(env, element, &elmString); + if (objectStatus != napi_ok) { + return nullptr; + } + unique_ptr name; + tie(succ, name, ignore) = NVal(env, elmString).ToUTF8String(); + if (!succ) { + return nullptr; + } + arrayArgs.push_back(name.get()); + } else if (type == napi_string && (vecs[i].compare(0, strlen("{public}s"), "{public}s") + || vecs[i].compare(0, strlen("{private}s"), "{private}s") || vecs[i].compare("s"))) { + // 匹配字符串 + unique_ptr name; + tie(succ, name, ignore) = NVal(env, element).ToUTF8String(); + if (!succ) { + return nullptr; + } + arrayArgs.push_back(name.get()); + } else if (type == napi_object && (vecs[i].compare(0, strlen("{public}o"), "{public}o") + || vecs[i].compare(0, strlen("{private}o"), "{private}o") || vecs[i].compare("o"))) { + // 匹配对象 [f,n,s,{}] 先转化string然后用string的方式处理 + napi_value elmString; + napi_status objectStatus = napi_coerce_to_string(env, element, &elmString); + if (objectStatus != napi_ok) { + return nullptr; + } + unique_ptr name; + tie(succ, name, ignore) = NVal(env, elmString).ToUTF8String(); + if (!succ) { + return nullptr; + } + arrayArgs.push_back(name.get()); + } + } + Replace(fmtString, "%o", "%s"); + Replace(fmtString, "%{private}o", "%{private}s"); + Replace(fmtString, "%{public}o", "%{public}s"); + Replace(fmtString, "%O", "%s"); + Replace(fmtString, "%{private}O", "%{private}s"); + Replace(fmtString, "%{public}O", "%{public}s"); + Replace(fmtString, "%d", "%s"); + Replace(fmtString, "%{private}d", "%{private}s"); + Replace(fmtString, "%{public}d", "%{public}s"); + Replace(fmtString, "%f", "%s"); + Replace(fmtString, "%{private}f", "%{private}s"); + Replace(fmtString, "%{public}f", "%{public}s"); + uint32_t number = arrayArgs.size(); + switch (number) { + case 0: + HiLogPrint(DEFAULT_LOG_TYPE, static_cast(level), domain, tag.get(), + fmtString.c_str(), ""); + break; + case 1: + HiLogPrint(DEFAULT_LOG_TYPE, static_cast(level), domain, tag.get(), + fmtString.c_str(), arrayArgs[0].c_str()); + break; + case 2: + HiLogPrint(DEFAULT_LOG_TYPE, static_cast(level), domain, tag.get(), + fmtString.c_str(), arrayArgs[0].c_str(), arrayArgs[1].c_str()); + break; + case 3: + HiLogPrint(DEFAULT_LOG_TYPE, static_cast(level), domain, tag.get(), + fmtString.c_str(), arrayArgs[0].c_str(), arrayArgs[1].c_str(), + arrayArgs[2].c_str()); + break; + case 4: + HiLogPrint(DEFAULT_LOG_TYPE, static_cast(level), domain, tag.get(), + fmtString.c_str(), arrayArgs[0].c_str(), arrayArgs[1].c_str(), + arrayArgs[2].c_str(), arrayArgs[3].c_str()); + break; + case 5: + HiLogPrint(DEFAULT_LOG_TYPE, static_cast(level), domain, tag.get(), + fmtString.c_str(), arrayArgs[0].c_str(), arrayArgs[1].c_str(), + arrayArgs[2].c_str(), arrayArgs[3].c_str(), arrayArgs[4].c_str()); + break; + case 6: + HiLogPrint(DEFAULT_LOG_TYPE, static_cast(level), domain, tag.get(), + fmtString.c_str(), arrayArgs[0].c_str(), arrayArgs[1].c_str(), + arrayArgs[2].c_str(), arrayArgs[3].c_str(), arrayArgs[4].c_str(), arrayArgs[5].c_str()); + break; + case 7: + HiLogPrint(DEFAULT_LOG_TYPE, static_cast(level), domain, tag.get(), + fmtString.c_str(), arrayArgs[0].c_str(), arrayArgs[1].c_str(), + arrayArgs[2].c_str(), arrayArgs[3].c_str(), arrayArgs[4].c_str(), arrayArgs[5].c_str(), + arrayArgs[6].c_str()); + break; + case 8: + HiLogPrint(DEFAULT_LOG_TYPE, static_cast(level), domain, tag.get(), + fmtString.c_str(), arrayArgs[0].c_str(), arrayArgs[1].c_str(), + arrayArgs[2].c_str(), arrayArgs[3].c_str(), arrayArgs[4].c_str(), arrayArgs[5].c_str(), + arrayArgs[6].c_str(), arrayArgs[7].c_str()); + break; + case 9: + HiLogPrint(DEFAULT_LOG_TYPE, static_cast(level), domain, tag.get(), + fmtString.c_str(), arrayArgs[0].c_str(), arrayArgs[1].c_str(), + arrayArgs[2].c_str(), arrayArgs[3].c_str(), arrayArgs[4].c_str(), arrayArgs[5].c_str(), + arrayArgs[6].c_str(), arrayArgs[7].c_str(), arrayArgs[8].c_str()); + break; + case 10: + HiLogPrint(DEFAULT_LOG_TYPE, static_cast(level), domain, tag.get(), + fmtString.c_str(), arrayArgs[0].c_str(), arrayArgs[1].c_str(), + arrayArgs[2].c_str(), arrayArgs[3].c_str(), arrayArgs[4].c_str(), arrayArgs[5].c_str(), + arrayArgs[6].c_str(), arrayArgs[7].c_str(), arrayArgs[8].c_str(), arrayArgs[9].c_str()); + break; + case 11: + HiLogPrint(DEFAULT_LOG_TYPE, static_cast(level), domain, tag.get(), + fmtString.c_str(), arrayArgs[0].c_str(), arrayArgs[1].c_str(), + arrayArgs[2].c_str(), arrayArgs[3].c_str(), arrayArgs[4].c_str(), arrayArgs[5].c_str(), + arrayArgs[6].c_str(), arrayArgs[7].c_str(), arrayArgs[8].c_str(), arrayArgs[9].c_str(), + arrayArgs[10].c_str()); + break; + case 12: + HiLogPrint(DEFAULT_LOG_TYPE, static_cast(level), domain, tag.get(), + fmtString.c_str(), arrayArgs[0].c_str(), arrayArgs[1].c_str(), + arrayArgs[2].c_str(), arrayArgs[3].c_str(), arrayArgs[4].c_str(), arrayArgs[5].c_str(), + arrayArgs[6].c_str(), arrayArgs[7].c_str(), arrayArgs[8].c_str(), arrayArgs[9].c_str(), + arrayArgs[10].c_str(), arrayArgs[11].c_str()); + break; + } + return nullptr; +} +} // namespace HiviewDFX +} // namespace OHOS + +#ifdef __cplusplus +} +#endif \ No newline at end of file -- Gitee