From 4504ce55b917dee4be51dc05f3d1f18fe06dc6c6 Mon Sep 17 00:00:00 2001 From: liujia178 Date: Tue, 25 Feb 2025 21:49:31 +0800 Subject: [PATCH] hilog idlize Signed-off-by: liujia178 --- bundle.json | 3 +- idlhilog/BUILD.gn | 73 +++ idlhilog/dts/@ohos.hilog.d.ts | 380 +++++++++++ idlhilog/generated/arkts/GlobalScope.ts | 38 ++ idlhilog/generated/arkts/HILOGNativeModule.ts | 31 + .../OHGlobalScopeOhosHilogMaterialized.ts | 238 +++++++ idlhilog/generated/arkts/OHHilogNamespace.ts | 25 + idlhilog/generated/arkts/index.ts | 5 + .../arkts/peers/CallbackDeserializeCall.ts | 24 + .../generated/arkts/peers/CallbackKind.ts | 4 + .../generated/arkts/peers/CallbacksChecker.ts | 39 ++ .../generated/arkts/peers/Deserializer.ts | 30 + idlhilog/generated/arkts/peers/Serializer.ts | 59 ++ idlhilog/generated/arkts/peers/type_check.ts | 13 + idlhilog/generated/native/hilog.cc | 592 ++++++++++++++++++ idlhilog/generated/native/hilog.h | 272 ++++++++ idlhilog/generated/native/hilogImpl_temp.cc | 31 + idlhilog/idlize.map | 4 + idlhilog/src/cpp/hilog_impl.cpp | 211 +++++++ 19 files changed, 2071 insertions(+), 1 deletion(-) create mode 100644 idlhilog/BUILD.gn create mode 100644 idlhilog/dts/@ohos.hilog.d.ts create mode 100644 idlhilog/generated/arkts/GlobalScope.ts create mode 100644 idlhilog/generated/arkts/HILOGNativeModule.ts create mode 100644 idlhilog/generated/arkts/OHGlobalScopeOhosHilogMaterialized.ts create mode 100644 idlhilog/generated/arkts/OHHilogNamespace.ts create mode 100644 idlhilog/generated/arkts/index.ts create mode 100644 idlhilog/generated/arkts/peers/CallbackDeserializeCall.ts create mode 100644 idlhilog/generated/arkts/peers/CallbackKind.ts create mode 100644 idlhilog/generated/arkts/peers/CallbacksChecker.ts create mode 100644 idlhilog/generated/arkts/peers/Deserializer.ts create mode 100644 idlhilog/generated/arkts/peers/Serializer.ts create mode 100644 idlhilog/generated/arkts/peers/type_check.ts create mode 100644 idlhilog/generated/native/hilog.cc create mode 100644 idlhilog/generated/native/hilog.h create mode 100644 idlhilog/generated/native/hilogImpl_temp.cc create mode 100644 idlhilog/idlize.map create mode 100644 idlhilog/src/cpp/hilog_impl.cpp diff --git a/bundle.json b/bundle.json index e21c1c7..b22d827 100644 --- a/bundle.json +++ b/bundle.json @@ -41,7 +41,8 @@ "//base/hiviewdfx/hilog/frameworks/hilog_ndk:hilog_ndk", "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog_base", "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", - "//base/hiviewdfx/hilog/interfaces/rust:hilog_rust" + "//base/hiviewdfx/hilog/interfaces/rust:hilog_rust", + "//base/hiviewdfx/hilog/idlhilog:idlhilogsourceset" ], "inner_kits": [ { diff --git a/idlhilog/BUILD.gn b/idlhilog/BUILD.gn new file mode 100644 index 0000000..b946a26 --- /dev/null +++ b/idlhilog/BUILD.gn @@ -0,0 +1,73 @@ +import("//build/ohos.gni") +import("//base/hiviewdfx/hilog/hilog.gni") +import("//build/ohos/idlize/arkts_idlize.gni") +import("//build/config/components/ets_frontend/ets2abc_config.gni") + +template("generate_and_build") { + forward_variables_from(invoker, "*") + + idlize_idl2peer(target_name) { + input_dir = "//base/hiviewdfx/hilog/idlhilog/dts/" + output = "//base/hiviewdfx/hilog/idlhilog" + dirmode = "delete" + default_package = "hilog" + mode = "dts2peer" + } + + config("libhilog_js_cfg") { + # visibility = [ "*:*" ] + include_dirs = [ "include" ] + } + + ohos_source_set("idlhilogsourceset") { + include_dirs = [ + "//base/hiviewdfx/hilog/idlhilog/generated/native", + "//base/hiviewdfx/hilog/frameworks/libhilog/param/include", + "//base/hiviewdfx/hilog/frameworks/libhilog/include", + ] + sources = [ + "//base/hiviewdfx/hilog/idlhilog/src/cpp/hilog_impl.cpp" + ] + external_deps = [ "bounds_checking_function:libsec_shared" ] + deps = [ "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog" ] + cflags_cc = [] + if (is_mingw) { + deps += [ + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog_windows", + ] + defines += [ "__WINDOWS__" ] + cflags_cc += [ "-std=c++17" ] + } else if (is_mac) { + deps += + [ "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog_mac" ] + defines += [ "__MAC__" ] + } else if (is_linux) { + deps += + [ "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog_linux" ] + defines += [ "__LINUX__" ] + } + public_configs = [ ":libhilog_js_cfg" ] + configs = [ ":libhilog_js_cfg" ] + + subsystem_name = "hiviewdfx" + part_name = "hilog" + } + + idlize_shared_library(target_name) { + generated = "//base/hiviewdfx/hilog/idlhilog/generated" + relative_install_dir = "module/idlhilog" + module_install_dir = "module/idlhilog" + deps = [ "//base/hiviewdfx/hilog/idlhilog:idlhilogsourceset" ] + subsystem_name = "hiviewdfx" + part_name = "hilog" + version_script="//base/hiviewdfx/hilog/idlhilog/idlize.map" + classpath_prefix = "@ohos/hilog/HILOGNativeModule/" + } +} + +generate_and_build("HILOGNativeModule") { +} + +group("idlhilog") { + deps = [ ":HILOGNativeModule" ] +} \ No newline at end of file diff --git a/idlhilog/dts/@ohos.hilog.d.ts b/idlhilog/dts/@ohos.hilog.d.ts new file mode 100644 index 0000000..a679324 --- /dev/null +++ b/idlhilog/dts/@ohos.hilog.d.ts @@ -0,0 +1,380 @@ +/* + * Copyright (c) 2025 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. + */ + +/** + * @file + * @kit PerformanceAnalysisKit + */ + +/** +* Provides interfaces to generate system logs. +* +* @namespace hilog +* @syscap SystemCapability.HiviewDFX.HiLog +* @since 7 +*/ +/** +* Provides interfaces to generate system logs. +* +* @namespace hilog +* @syscap SystemCapability.HiviewDFX.HiLog +* @crossplatform +* @since 10 +*/ +/** +* Provides interfaces to generate system logs. +* +* @namespace hilog +* @syscap SystemCapability.HiviewDFX.HiLog +* @crossplatform +* @atomicservice +* @since 11 +*/ +export default declare namespace hilog { + + /** + * Outputs debug-level logs. + * + * @param { number } domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFF + * @param { string } tag Identifies the log tag, length cannot exceed 32 bytes. + * @param { string } format Indicates the log format string. + * @param { any[] }args Indicates the log parameters. + * @syscap SystemCapability.HiviewDFX.HiLog + * @since 7 + */ + /** + * Outputs debug-level logs. + * + * @param { number } domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFF + * @param { string } tag Identifies the log tag, length cannot exceed 32 bytes. + * @param { string } format Indicates the log format string. + * @param { any[] }args Indicates the log parameters. + * @syscap SystemCapability.HiviewDFX.HiLog + * @crossplatform + * @since 10 + */ + /** + * Outputs debug-level logs. + * + * @param { number } domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFF + * @param { string } tag Identifies the log tag, length cannot exceed 32 bytes. + * @param { string } format Indicates the log format string. + * @param { any[] }args Indicates the log parameters. + * @syscap SystemCapability.HiviewDFX.HiLog + * @crossplatform + * @atomicservice + * @since 11 + */ + export function debug(domain: number, tag: string, format: string, ...args: (boolean | number | string | undefined)[]): void; + + /** + * Outputs info-level logs. + * + * @param { number } domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFF + * @param { string } tag Identifies the log tag, length cannot exceed 32 bytes. + * @param { string } format Indicates the log format string. + * @param { any[] }args Indicates the log parameters. + * @syscap SystemCapability.HiviewDFX.HiLog + * @since 7 + */ + /** + * Outputs info-level logs. + * + * @param { number } domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFF + * @param { string } tag Identifies the log tag, length cannot exceed 32 bytes. + * @param { string } format Indicates the log format string. + * @param { any[] }args Indicates the log parameters. + * @syscap SystemCapability.HiviewDFX.HiLog + * @crossplatform + * @since 10 + */ + /** + * Outputs info-level logs. + * + * @param { number } domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFF + * @param { string } tag Identifies the log tag, length cannot exceed 32 bytes. + * @param { string } format Indicates the log format string. + * @param { any[] }args Indicates the log parameters. + * @syscap SystemCapability.HiviewDFX.HiLog + * @crossplatform + * @atomicservice + * @since 11 + */ + export function info(domain: number, tag: string, format: string, ...args: (boolean | number | string | undefined)[]): void; + + /** + * Outputs warning-level logs. + * + * @param { number } domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFF + * @param { string } tag Identifies the log tag, length cannot exceed 32 bytes. + * @param { string } format Indicates the log format string. + * @param { any[] }args Indicates the log parameters. + * @syscap SystemCapability.HiviewDFX.HiLog + * @since 7 + */ + /** + * Outputs warning-level logs. + * + * @param { number } domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFF + * @param { string } tag Identifies the log tag, length cannot exceed 32 bytes. + * @param { string } format Indicates the log format string. + * @param { any[] }args Indicates the log parameters. + * @syscap SystemCapability.HiviewDFX.HiLog + * @crossplatform + * @since 10 + */ + /** + * Outputs warning-level logs. + * + * @param { number } domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFF + * @param { string } tag Identifies the log tag, length cannot exceed 32 bytes. + * @param { string } format Indicates the log format string. + * @param { any[] }args Indicates the log parameters. + * @syscap SystemCapability.HiviewDFX.HiLog + * @crossplatform + * @atomicservice + * @since 11 + */ + export function warn(domain: number, tag: string, format: string, ...args: (boolean | number | string | undefined)[]): void; + + /** + * Outputs error-level logs. + * + * @param { number } domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFF + * @param { string } tag Identifies the log tag, length cannot exceed 32 bytes. + * @param { string } format Indicates the log format string. + * @param { any[] }args Indicates the log parameters. + * @syscap SystemCapability.HiviewDFX.HiLog + * @since 7 + */ + /** + * Outputs error-level logs. + * + * @param { number } domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFF + * @param { string } tag Identifies the log tag, length cannot exceed 32 bytes. + * @param { string } format Indicates the log format string. + * @param { any[] }args Indicates the log parameters. + * @syscap SystemCapability.HiviewDFX.HiLog + * @crossplatform + * @since 10 + */ + /** + * Outputs error-level logs. + * + * @param { number } domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFF + * @param { string } tag Identifies the log tag, length cannot exceed 32 bytes. + * @param { string } format Indicates the log format string. + * @param { any[] }args Indicates the log parameters. + * @syscap SystemCapability.HiviewDFX.HiLog + * @crossplatform + * @atomicservice + * @since 11 + */ + export function error(domain: number, tag: string, format: string, ...args: (boolean | number | string | undefined)[]): void; + + /** + * Outputs fatal-level logs. + * + * @param { number } domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFF + * @param { string } tag Identifies the log tag, length cannot exceed 32 bytes. + * @param { string } format Indicates the log format string. + * @param { any[] }args Indicates the log parameters. + * @syscap SystemCapability.HiviewDFX.HiLog + * @since 7 + */ + /** + * Outputs fatal-level logs. + * + * @param { number } domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFF + * @param { string } tag Identifies the log tag, length cannot exceed 32 bytes. + * @param { string } format Indicates the log format string. + * @param { any[] }args Indicates the log parameters. + * @syscap SystemCapability.HiviewDFX.HiLog + * @crossplatform + * @since 10 + */ + /** + * Outputs fatal-level logs. + * + * @param { number } domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFF + * @param { string } tag Identifies the log tag, length cannot exceed 32 bytes. + * @param { string } format Indicates the log format string. + * @param { any[] }args Indicates the log parameters. + * @syscap SystemCapability.HiviewDFX.HiLog + * @crossplatform + * @atomicservice + * @since 11 + */ + export function fatal(domain: number, tag: string, format: string, ...args: (boolean | number | string | undefined)[]): void; + + /** + * Checks whether logs of the specified tag, and level can be printed. + * + * @param { number } domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFF + * @param { string } tag Identifies the log tag, length cannot exceed 32 bytes. + * @param { LogLevel } level log level + * @returns { boolean } + * @syscap SystemCapability.HiviewDFX.HiLog + * @since 7 + */ + /** + * Checks whether logs of the specified tag, and level can be printed. + * + * @param { number } domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFF + * @param { string } tag Identifies the log tag, length cannot exceed 32 bytes. + * @param { LogLevel } level log level + * @returns { boolean } + * @syscap SystemCapability.HiviewDFX.HiLog + * @atomicservice + * @since 11 + */ + export function isLoggable(domain: number, tag: string, level: LogLevel): boolean; + + /** + * Log level define + * + * @syscap SystemCapability.HiviewDFX.HiLog + * @since 7 + */ + /** + * Log level define + * + * @enum { number } + * @syscap SystemCapability.HiviewDFX.HiLog + * @crossplatform + * @since 10 + */ + /** + * Log level define + * + * @enum { number } + * @syscap SystemCapability.HiviewDFX.HiLog + * @crossplatform + * @atomicservice + * @since 11 + */ + export enum LogLevel { + /** + * DEBUG Log level define + * + * @syscap SystemCapability.HiviewDFX.HiLog + * @since 7 + */ + /** + * DEBUG Log level define + * + * @syscap SystemCapability.HiviewDFX.HiLog + * @crossplatform + * @since 10 + */ + /** + * DEBUG Log level define + * + * @syscap SystemCapability.HiviewDFX.HiLog + * @crossplatform + * @atomicservice + * @since 11 + */ + DEBUG = 3, + /** + * INFO Log level define + * + * @syscap SystemCapability.HiviewDFX.HiLog + * @since 7 + */ + /** + * INFO Log level define + * + * @syscap SystemCapability.HiviewDFX.HiLog + * @crossplatform + * @since 10 + */ + /** + * INFO Log level define + * + * @syscap SystemCapability.HiviewDFX.HiLog + * @crossplatform + * @atomicservice + * @since 11 + */ + INFO = 4, + /** + * WARN Log level define + * + * @syscap SystemCapability.HiviewDFX.HiLog + * @since 7 + */ + /** + * WARN Log level define + * + * @syscap SystemCapability.HiviewDFX.HiLog + * @crossplatform + * @since 10 + */ + /** + * WARN Log level define + * + * @syscap SystemCapability.HiviewDFX.HiLog + * @crossplatform + * @atomicservice + * @since 11 + */ + WARN = 5, + /** + * ERROR Log level define + * + * @syscap SystemCapability.HiviewDFX.HiLog + * @since 7 + */ + /** + * ERROR Log level define + * + * @syscap SystemCapability.HiviewDFX.HiLog + * @crossplatform + * @since 10 + */ + /** + * ERROR Log level define + * + * @syscap SystemCapability.HiviewDFX.HiLog + * @crossplatform + * @atomicservice + * @since 11 + */ + ERROR = 6, + /** + * FATAL Log level define + * + * @syscap SystemCapability.HiviewDFX.HiLog + * @since 7 + */ + /** + * FATAL Log level define + * + * @syscap SystemCapability.HiviewDFX.HiLog + * @crossplatform + * @since 10 + */ + /** + * FATAL Log level define + * + * @syscap SystemCapability.HiviewDFX.HiLog + * @crossplatform + * @atomicservice + * @since 11 + */ + FATAL = 7 + } +} \ No newline at end of file diff --git a/idlhilog/generated/arkts/GlobalScope.ts b/idlhilog/generated/arkts/GlobalScope.ts new file mode 100644 index 0000000..440bf93 --- /dev/null +++ b/idlhilog/generated/arkts/GlobalScope.ts @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024-2025 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. + */ + + +// WARNING! THIS FILE IS AUTO-GENERATED, DO NOT MAKE CHANGES, THEY WILL BE LOST ON NEXT GENERATION! + +import { GlobalScope_ohos_hilog } from "./OHGlobalScopeOhosHilogMaterialized" +import { hilog_LogLevel } from "./OHHilogNamespace" +export function debug(domain: number, tag: string, format: string, args: Array): void { + GlobalScope_ohos_hilog.debug(domain, tag, format, args) +} +export function info(domain: number, tag: string, format: string, args: Array): void { + GlobalScope_ohos_hilog.info(domain, tag, format, args) +} +export function warn(domain: number, tag: string, format: string, args: Array): void { + GlobalScope_ohos_hilog.warn(domain, tag, format, args) +} +export function error(domain: number, tag: string, format: string, args: Array): void { + GlobalScope_ohos_hilog.error(domain, tag, format, args) +} +export function fatal(domain: number, tag: string, format: string, args: Array): void { + GlobalScope_ohos_hilog.fatal(domain, tag, format, args) +} +export function isLoggable(domain: number, tag: string, level: hilog_LogLevel): boolean { + return GlobalScope_ohos_hilog.isLoggable(domain, tag, level) +} diff --git a/idlhilog/generated/arkts/HILOGNativeModule.ts b/idlhilog/generated/arkts/HILOGNativeModule.ts new file mode 100644 index 0000000..20af5a7 --- /dev/null +++ b/idlhilog/generated/arkts/HILOGNativeModule.ts @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024-2025 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 { KInt, KBoolean, KFloat, KUInt, KStringPtr, KPointer, KNativePointer, KInt32ArrayPtr, KUint8ArrayPtr, KFloat32ArrayPtr, pointer, KInteropReturnBuffer, NativeBuffer, loadNativeModuleLibrary, registerNativeModuleLibraryName } from "@koalaui/interop" +import { int32, float32 } from "@koalaui/common" + +export class HILOGNativeModule { + static { + registerNativeModuleLibraryName("InteropNativeModule", "HILOGNativeModule.z") + loadNativeModuleLibrary("HILOGNativeModule.z") + } + native static _AllocateNativeBuffer(len: int32, data: KUint8ArrayPtr, init: KUint8ArrayPtr): NativeBuffer + native static _GlobalScope_ohos_hilog_debug(domain: number, tag: KStringPtr, format: KStringPtr, thisArray: KUint8ArrayPtr, thisLength: int32): void + native static _GlobalScope_ohos_hilog_info(domain: number, tag: KStringPtr, format: KStringPtr, thisArray: KUint8ArrayPtr, thisLength: int32): void + native static _GlobalScope_ohos_hilog_warn(domain: number, tag: KStringPtr, format: KStringPtr, thisArray: KUint8ArrayPtr, thisLength: int32): void + native static _GlobalScope_ohos_hilog_error(domain: number, tag: KStringPtr, format: KStringPtr, thisArray: KUint8ArrayPtr, thisLength: int32): void + native static _GlobalScope_ohos_hilog_fatal(domain: number, tag: KStringPtr, format: KStringPtr, thisArray: KUint8ArrayPtr, thisLength: int32): void + native static _GlobalScope_ohos_hilog_isLoggable(domain: number, tag: KStringPtr, level: KInt): boolean +} \ No newline at end of file diff --git a/idlhilog/generated/arkts/OHGlobalScopeOhosHilogMaterialized.ts b/idlhilog/generated/arkts/OHGlobalScopeOhosHilogMaterialized.ts new file mode 100644 index 0000000..53e9bbc --- /dev/null +++ b/idlhilog/generated/arkts/OHGlobalScopeOhosHilogMaterialized.ts @@ -0,0 +1,238 @@ +/* + * Copyright (c) 2024-2025 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. + */ + + +// WARNING! THIS FILE IS AUTO-GENERATED, DO NOT MAKE CHANGES, THEY WILL BE LOST ON NEXT GENERATION! + +import { hilog_LogLevel } from "./OHHilogNamespace" +import { TypeChecker } from "#components" +import { Finalizable, isResource, isInstanceOf, runtimeType, RuntimeType, SerializerBase, registerCallback, wrapCallback, KPointer, MaterializedBase, NativeBuffer } from "@koalaui/interop" +import { unsafeCast, int32, float32 } from "@koalaui/common" +import { Serializer } from "./peers/Serializer" +import { CallbackKind } from "./peers/CallbackKind" +import { Deserializer } from "./peers/Deserializer" +import { HILOGNativeModule } from "./HILOGNativeModule" +export class GlobalScope_ohos_hilog { + public static debug(domain: number, tag: string, format: string, args: Array): void { + const domain_casted = domain as (number) + const tag_casted = tag as (string) + const format_casted = format as (string) + const args_casted = args as (Array) + GlobalScope_ohos_hilog.debug_serialize(domain_casted, tag_casted, format_casted, args_casted) + return + } + public static info(domain: number, tag: string, format: string, args: Array): void { + const domain_casted = domain as (number) + const tag_casted = tag as (string) + const format_casted = format as (string) + const args_casted = args as (Array) + GlobalScope_ohos_hilog.info_serialize(domain_casted, tag_casted, format_casted, args_casted) + return + } + public static warn(domain: number, tag: string, format: string, args: Array): void { + const domain_casted = domain as (number) + const tag_casted = tag as (string) + const format_casted = format as (string) + const args_casted = args as (Array) + GlobalScope_ohos_hilog.warn_serialize(domain_casted, tag_casted, format_casted, args_casted) + return + } + public static error(domain: number, tag: string, format: string, args: Array): void { + const domain_casted = domain as (number) + const tag_casted = tag as (string) + const format_casted = format as (string) + const args_casted = args as (Array) + GlobalScope_ohos_hilog.error_serialize(domain_casted, tag_casted, format_casted, args_casted) + return + } + public static fatal(domain: number, tag: string, format: string, args: Array): void { + const domain_casted = domain as (number) + const tag_casted = tag as (string) + const format_casted = format as (string) + const args_casted = args as (Array) + GlobalScope_ohos_hilog.fatal_serialize(domain_casted, tag_casted, format_casted, args_casted) + return + } + public static isLoggable(domain: number, tag: string, level: hilog_LogLevel): boolean { + const domain_casted = domain as (number) + const tag_casted = tag as (string) + const level_casted = level as (hilog_LogLevel) + return GlobalScope_ohos_hilog.isLoggable_serialize(domain_casted, tag_casted, level_casted) + } + private static debug_serialize(domain: number, tag: string, format: string, args: Array): void { + const thisSerializer : Serializer = Serializer.hold() + thisSerializer.writeInt32(args.length as int32) + for (let i = 0; i < args.length; i++) { + const args_element : boolean | number | string | undefined = args[i] + let args_element_type : int32 = RuntimeType.UNDEFINED + args_element_type = runtimeType(args_element) + thisSerializer.writeInt8(args_element_type as int32) + if ((RuntimeType.UNDEFINED) != (args_element_type)) { + const args_element_value = args_element! + let args_element_value_type : int32 = RuntimeType.UNDEFINED + args_element_value_type = runtimeType(args_element_value) + if (RuntimeType.BOOLEAN == args_element_value_type) { + thisSerializer.writeInt8(0 as int32) + const args_element_value_0 = args_element_value as boolean + thisSerializer.writeBoolean(args_element_value_0) + } + else if (RuntimeType.NUMBER == args_element_value_type) { + thisSerializer.writeInt8(1 as int32) + const args_element_value_1 = args_element_value as number + thisSerializer.writeNumber(args_element_value_1) + } + else if (RuntimeType.STRING == args_element_value_type) { + thisSerializer.writeInt8(2 as int32) + const args_element_value_2 = args_element_value as string + thisSerializer.writeString(args_element_value_2) + } + } + } + HILOGNativeModule._GlobalScope_ohos_hilog_debug(domain, tag, format, thisSerializer.asArray(), thisSerializer.length()) + thisSerializer.release() + } + private static info_serialize(domain: number, tag: string, format: string, args: Array): void { + const thisSerializer : Serializer = Serializer.hold() + thisSerializer.writeInt32(args.length as int32) + for (let i = 0; i < args.length; i++) { + const args_element : boolean | number | string | undefined = args[i] + let args_element_type : int32 = RuntimeType.UNDEFINED + args_element_type = runtimeType(args_element) + thisSerializer.writeInt8(args_element_type as int32) + if ((RuntimeType.UNDEFINED) != (args_element_type)) { + const args_element_value = args_element! + let args_element_value_type : int32 = RuntimeType.UNDEFINED + args_element_value_type = runtimeType(args_element_value) + if (RuntimeType.BOOLEAN == args_element_value_type) { + thisSerializer.writeInt8(0 as int32) + const args_element_value_0 = args_element_value as boolean + thisSerializer.writeBoolean(args_element_value_0) + } + else if (RuntimeType.NUMBER == args_element_value_type) { + thisSerializer.writeInt8(1 as int32) + const args_element_value_1 = args_element_value as number + thisSerializer.writeNumber(args_element_value_1) + } + else if (RuntimeType.STRING == args_element_value_type) { + thisSerializer.writeInt8(2 as int32) + const args_element_value_2 = args_element_value as string + thisSerializer.writeString(args_element_value_2) + } + } + } + HILOGNativeModule._GlobalScope_ohos_hilog_info(domain, tag, format, thisSerializer.asArray(), thisSerializer.length()) + thisSerializer.release() + } + private static warn_serialize(domain: number, tag: string, format: string, args: Array): void { + const thisSerializer : Serializer = Serializer.hold() + thisSerializer.writeInt32(args.length as int32) + for (let i = 0; i < args.length; i++) { + const args_element : boolean | number | string | undefined = args[i] + let args_element_type : int32 = RuntimeType.UNDEFINED + args_element_type = runtimeType(args_element) + thisSerializer.writeInt8(args_element_type as int32) + if ((RuntimeType.UNDEFINED) != (args_element_type)) { + const args_element_value = args_element! + let args_element_value_type : int32 = RuntimeType.UNDEFINED + args_element_value_type = runtimeType(args_element_value) + if (RuntimeType.BOOLEAN == args_element_value_type) { + thisSerializer.writeInt8(0 as int32) + const args_element_value_0 = args_element_value as boolean + thisSerializer.writeBoolean(args_element_value_0) + } + else if (RuntimeType.NUMBER == args_element_value_type) { + thisSerializer.writeInt8(1 as int32) + const args_element_value_1 = args_element_value as number + thisSerializer.writeNumber(args_element_value_1) + } + else if (RuntimeType.STRING == args_element_value_type) { + thisSerializer.writeInt8(2 as int32) + const args_element_value_2 = args_element_value as string + thisSerializer.writeString(args_element_value_2) + } + } + } + HILOGNativeModule._GlobalScope_ohos_hilog_warn(domain, tag, format, thisSerializer.asArray(), thisSerializer.length()) + thisSerializer.release() + } + private static error_serialize(domain: number, tag: string, format: string, args: Array): void { + const thisSerializer : Serializer = Serializer.hold() + thisSerializer.writeInt32(args.length as int32) + for (let i = 0; i < args.length; i++) { + const args_element : boolean | number | string | undefined = args[i] + let args_element_type : int32 = RuntimeType.UNDEFINED + args_element_type = runtimeType(args_element) + thisSerializer.writeInt8(args_element_type as int32) + if ((RuntimeType.UNDEFINED) != (args_element_type)) { + const args_element_value = args_element! + let args_element_value_type : int32 = RuntimeType.UNDEFINED + args_element_value_type = runtimeType(args_element_value) + if (RuntimeType.BOOLEAN == args_element_value_type) { + thisSerializer.writeInt8(0 as int32) + const args_element_value_0 = args_element_value as boolean + thisSerializer.writeBoolean(args_element_value_0) + } + else if (RuntimeType.NUMBER == args_element_value_type) { + thisSerializer.writeInt8(1 as int32) + const args_element_value_1 = args_element_value as number + thisSerializer.writeNumber(args_element_value_1) + } + else if (RuntimeType.STRING == args_element_value_type) { + thisSerializer.writeInt8(2 as int32) + const args_element_value_2 = args_element_value as string + thisSerializer.writeString(args_element_value_2) + } + } + } + HILOGNativeModule._GlobalScope_ohos_hilog_error(domain, tag, format, thisSerializer.asArray(), thisSerializer.length()) + thisSerializer.release() + } + private static fatal_serialize(domain: number, tag: string, format: string, args: Array): void { + const thisSerializer : Serializer = Serializer.hold() + thisSerializer.writeInt32(args.length as int32) + for (let i = 0; i < args.length; i++) { + const args_element : boolean | number | string | undefined = args[i] + let args_element_type : int32 = RuntimeType.UNDEFINED + args_element_type = runtimeType(args_element) + thisSerializer.writeInt8(args_element_type as int32) + if ((RuntimeType.UNDEFINED) != (args_element_type)) { + const args_element_value = args_element! + let args_element_value_type : int32 = RuntimeType.UNDEFINED + args_element_value_type = runtimeType(args_element_value) + if (RuntimeType.BOOLEAN == args_element_value_type) { + thisSerializer.writeInt8(0 as int32) + const args_element_value_0 = args_element_value as boolean + thisSerializer.writeBoolean(args_element_value_0) + } + else if (RuntimeType.NUMBER == args_element_value_type) { + thisSerializer.writeInt8(1 as int32) + const args_element_value_1 = args_element_value as number + thisSerializer.writeNumber(args_element_value_1) + } + else if (RuntimeType.STRING == args_element_value_type) { + thisSerializer.writeInt8(2 as int32) + const args_element_value_2 = args_element_value as string + thisSerializer.writeString(args_element_value_2) + } + } + } + HILOGNativeModule._GlobalScope_ohos_hilog_fatal(domain, tag, format, thisSerializer.asArray(), thisSerializer.length()) + thisSerializer.release() + } + private static isLoggable_serialize(domain: number, tag: string, level: hilog_LogLevel): boolean { + const retval = HILOGNativeModule._GlobalScope_ohos_hilog_isLoggable(domain, tag, (level.valueOf() as int32)) + return retval + } +} diff --git a/idlhilog/generated/arkts/OHHilogNamespace.ts b/idlhilog/generated/arkts/OHHilogNamespace.ts new file mode 100644 index 0000000..87496f7 --- /dev/null +++ b/idlhilog/generated/arkts/OHHilogNamespace.ts @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024-2025 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. + */ + + +// WARNING! THIS FILE IS AUTO-GENERATED, DO NOT MAKE CHANGES, THEY WILL BE LOST ON NEXT GENERATION! + +export enum hilog_LogLevel { + DEBUG = 3, + INFO = 4, + WARN = 5, + ERROR = 6, + FATAL = 7 +} diff --git a/idlhilog/generated/arkts/index.ts b/idlhilog/generated/arkts/index.ts new file mode 100644 index 0000000..d4d3ea4 --- /dev/null +++ b/idlhilog/generated/arkts/index.ts @@ -0,0 +1,5 @@ +export * from "./OHGlobalScopeOhosHilogMaterialized" +export * from "./OHHilogNamespace" +export * from "./GlobalScope" +export * from "././peers/type_check" +export * from "././HILOGNativeModule" \ No newline at end of file diff --git a/idlhilog/generated/arkts/peers/CallbackDeserializeCall.ts b/idlhilog/generated/arkts/peers/CallbackDeserializeCall.ts new file mode 100644 index 0000000..c4968c5 --- /dev/null +++ b/idlhilog/generated/arkts/peers/CallbackDeserializeCall.ts @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2024-2025 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 { CallbackKind } from "./CallbackKind" +import { Deserializer } from "./Deserializer" +import { int32, float32, int64 } from "@koalaui/common" +import { ResourceHolder, KInt, KStringPtr, wrapSystemCallback, KPointer, RuntimeType } from "@koalaui/interop" + +export function deserializeAndCallCallback(thisDeserializer: Deserializer): void { + const kind : int32 = thisDeserializer.readInt32() + console.log("Unknown callback kind") +} \ No newline at end of file diff --git a/idlhilog/generated/arkts/peers/CallbackKind.ts b/idlhilog/generated/arkts/peers/CallbackKind.ts new file mode 100644 index 0000000..e5de486 --- /dev/null +++ b/idlhilog/generated/arkts/peers/CallbackKind.ts @@ -0,0 +1,4 @@ +import { int32, float32 } from "@koalaui/common" +export enum CallbackKind { + Kind_EMPTY_Callback = -1 +} \ No newline at end of file diff --git a/idlhilog/generated/arkts/peers/CallbacksChecker.ts b/idlhilog/generated/arkts/peers/CallbacksChecker.ts new file mode 100644 index 0000000..994f3f8 --- /dev/null +++ b/idlhilog/generated/arkts/peers/CallbacksChecker.ts @@ -0,0 +1,39 @@ +import { ResourceHolder, KBuffer, InteropNativeModule } from "@koalaui/interop" +import { Deserializer } from "./Deserializer" +import { deserializeAndCallCallback } from "./CallbackDeserializeCall" + +enum CallbackEventKind { + Event_CallCallback = 0, + Event_HoldManagedResource = 1, + Event_ReleaseManagedResource = 2, +} + +const bufferSize = 1024 +const buffer = new KBuffer(bufferSize) +const deserializer = new Deserializer(buffer.buffer, bufferSize) +export function checkArkoalaCallbacks() { + while (true) { + deserializer.resetCurrentPosition() + let result = InteropNativeModule._CheckCallbackEvent(buffer.buffer, bufferSize) + if (result == 0) break + + const eventKind = deserializer.readInt32() as CallbackEventKind + switch (eventKind) { + case CallbackEventKind.Event_CallCallback: { + deserializeAndCallCallback(deserializer) + break; + } + case CallbackEventKind.Event_HoldManagedResource: { + const resourceId = deserializer.readInt32() + ResourceHolder.instance().hold(resourceId) + break; + } + case CallbackEventKind.Event_ReleaseManagedResource: { + const resourceId = deserializer.readInt32() + ResourceHolder.instance().release(resourceId) + break; + } + default: throw new Error(`Unknown callback event kind ${eventKind}`) + } + } +} diff --git a/idlhilog/generated/arkts/peers/Deserializer.ts b/idlhilog/generated/arkts/peers/Deserializer.ts new file mode 100644 index 0000000..e45ff86 --- /dev/null +++ b/idlhilog/generated/arkts/peers/Deserializer.ts @@ -0,0 +1,30 @@ + +/* + * Copyright (c) 2024-2025 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 { KPointer, runtimeType, RuntimeType, CallbackResource, DeserializerBase } from "@koalaui/interop" +import { int32, float32, int64 } from "@koalaui/common" +import { Serializer } from "./Serializer" +import { HILOGNativeModule } from "#components" +import { CallbackKind } from "./CallbackKind" +import { TypeChecker } from "#components" +import { KUint8ArrayPtr, NativeBuffer, InteropNativeModule } from "@koalaui/interop" +import { hilog_LogLevel } from "./../OHHilogNamespace" + +export class Deserializer extends DeserializerBase { + constructor(data: KUint8ArrayPtr, length: int32) { + super(data, length) + } +} diff --git a/idlhilog/generated/arkts/peers/Serializer.ts b/idlhilog/generated/arkts/peers/Serializer.ts new file mode 100644 index 0000000..2eed5b4 --- /dev/null +++ b/idlhilog/generated/arkts/peers/Serializer.ts @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2024-2025 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 { SerializerBase, Tags, RuntimeType, runtimeType, isResource, isInstanceOf, MaterializedBase, nullptr, KPointer } from "@koalaui/interop" +import { int32, float32, unsafeCast, int64 } from "@koalaui/common" +import { TypeChecker } from "#components" +import { KUint8ArrayPtr, NativeBuffer, InteropNativeModule } from "@koalaui/interop" +import { hilog_LogLevel } from "./../OHHilogNamespace" +export class Serializer extends SerializerBase { + private static pool?: Array | undefined = undefined + private static poolTop: int32 = -1 + static hold(): Serializer { + if (!(Serializer.pool != undefined)) + { + Serializer.pool = new Array(8) + const pool : Array = (Serializer.pool)! + for (let idx = 0; idx < 8; idx++) { + pool[idx] = new Serializer() + } + } + const pool : Array = (Serializer.pool)! + if (Serializer.poolTop >= pool.length - 1) + { + throw new Error("Serializer pool is full. Check if you had released serializers before") + } + Serializer.poolTop = Serializer.poolTop + 1 + let serializer = pool[Serializer.poolTop] + return serializer + } + public release(): void { + if (Serializer.poolTop == -1) + { + throw new Error("Serializer pool is empty. Check if you had hold serializers before") + } + const pool : Array = (Serializer.pool)! + if ((this) == (pool[Serializer.poolTop])) + { + Serializer.poolTop = Serializer.poolTop - 1 + super.release() + return + } + throw new Error("Only last serializer should be released") + } + constructor() { + super() + } +} \ No newline at end of file diff --git a/idlhilog/generated/arkts/peers/type_check.ts b/idlhilog/generated/arkts/peers/type_check.ts new file mode 100644 index 0000000..96b98ef --- /dev/null +++ b/idlhilog/generated/arkts/peers/type_check.ts @@ -0,0 +1,13 @@ +import { KBoolean, KStringPtr, NativeBuffer, MaterializedBase } from "@koalaui/interop" +import { hilog_LogLevel } from "./../OHHilogNamespace" +export class TypeChecker { + static typeInstanceOf(value: Object, prop: string): boolean { + return value instanceof T + } + static typeCast(value: Object): T { + return value as T + } + static ishilog_LogLevel(value: object|string|number|undefined|null): boolean { + return value instanceof hilog_LogLevel + } +} \ No newline at end of file diff --git a/idlhilog/generated/native/hilog.cc b/idlhilog/generated/native/hilog.cc new file mode 100644 index 0000000..5d9e48f --- /dev/null +++ b/idlhilog/generated/native/hilog.cc @@ -0,0 +1,592 @@ +/* + * Copyright (c) 2024 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 "hilog.h" + +#define KOALA_INTEROP_MODULE HILOGNativeModule +#include "common-interop.h" +#include "callback-resource.h" +#include "SerializerBase.h" +#include "DeserializerBase.h" +#include + +#if KOALA_USE_PANDA_VM +KOALA_ETS_INTEROP_MODULE_CLASSPATH(KOALA_INTEROP_MODULE, KOALA_QUOTE(ETS_MODULE_CLASSPATH_PREFIX) KOALA_QUOTE(KOALA_INTEROP_MODULE)); +#endif + +CustomDeserializer * DeserializerBase::customDeserializers = nullptr; + +typedef enum CallbackKind { + Kind_EMPTY_Callback = -1, +} CallbackKind; + +OH_NativePointer getManagedCallbackCaller(CallbackKind kind); +OH_NativePointer getManagedCallbackCallerSync(CallbackKind kind); + +struct Counter { + int count; + void* data; +}; + +static int bufferResourceId = 0; +static std::unordered_map refCounterMap; + +int allocate_buffer(int len, void** mem) { + char* data = new char[len]; + (*mem) = data; + int id = ++bufferResourceId; + refCounterMap[id] = Counter { 1, (void*)data }; + return id; +} + +void releaseBuffer(int resourceId) { + if (refCounterMap.find(resourceId) != refCounterMap.end()) { + Counter& record = refCounterMap[resourceId]; + --record.count; + if (record.count <= 0) { + delete[] (char*)record.data; + } + } +} + +void holdBuffer(int resourceId) { + if (refCounterMap.find(resourceId) != refCounterMap.end()) { + Counter& record = refCounterMap[resourceId]; + ++record.count; + } +} + +void impl_AllocateNativeBuffer(KInt len, KByte* ret, KByte* init) { + void* mem; + int resourceId = allocate_buffer(len, &mem); + memcpy((KByte*)mem, init, len); + SerializerBase ser { ret, 40 }; // todo check + ser.writeInt32(resourceId); + ser.writePointer((void*)&holdBuffer); + ser.writePointer((void*)&releaseBuffer); + ser.writePointer(mem); + ser.writeInt64(len); + +} +KOALA_INTEROP_V3(AllocateNativeBuffer, KInt, KByte*, KByte*); +template <> +inline OH_HILOG_RuntimeType runtimeType(const OH_Int32& value) +{ + return INTEROP_RUNTIME_OBJECT; +} +template <> +inline void WriteToString(std::string* result, const Opt_Int32* value) { + result->append("{.tag="); + result->append(tagNameExact((OH_Tag)(value->tag))); + result->append(", .value="); + if (value->tag != INTEROP_TAG_UNDEFINED) { + WriteToString(result, value->value); + } else { + OH_Undefined undefined = { 0 }; + WriteToString(result, undefined); + } + result->append("}"); +} +template <> +inline OH_HILOG_RuntimeType runtimeType(const Opt_Int32& value) +{ + return (value.tag != INTEROP_TAG_UNDEFINED) ? (INTEROP_RUNTIME_OBJECT) : (INTEROP_RUNTIME_UNDEFINED); +} +template <> +inline OH_HILOG_RuntimeType runtimeType(const OH_HILOG_hilog_LogLevel& value) +{ + return INTEROP_RUNTIME_NUMBER; +} +template <> +inline void WriteToString(std::string* result, const OH_HILOG_hilog_LogLevel value) { + result->append("OH_HILOG_hilog_LogLevel("); + WriteToString(result, (OH_Int32) value); + result->append(")"); +} +template <> +inline void WriteToString(std::string* result, const Opt_hilog_LogLevel* value) { + result->append("{.tag="); + result->append(tagNameExact((OH_Tag)(value->tag))); + result->append(", .value="); + if (value->tag != INTEROP_TAG_UNDEFINED) { + WriteToString(result, value->value); + } else { + OH_Undefined undefined = { 0 }; + WriteToString(result, undefined); + } + result->append("}"); +} +template <> +inline OH_HILOG_RuntimeType runtimeType(const Opt_hilog_LogLevel& value) +{ + return (value.tag != INTEROP_TAG_UNDEFINED) ? (INTEROP_RUNTIME_OBJECT) : (INTEROP_RUNTIME_UNDEFINED); +} +template <> +inline OH_HILOG_RuntimeType runtimeType(const OH_String& value) +{ + return INTEROP_RUNTIME_STRING; +} +template <> +inline void WriteToString(std::string* result, const Opt_String* value) { + result->append("{.tag="); + result->append(tagNameExact((OH_Tag)(value->tag))); + result->append(", .value="); + if (value->tag != INTEROP_TAG_UNDEFINED) { + WriteToString(result, &value->value); + } else { + OH_Undefined undefined = { 0 }; + WriteToString(result, undefined); + } + result->append("}"); +} +template <> +inline OH_HILOG_RuntimeType runtimeType(const Opt_String& value) +{ + return (value.tag != INTEROP_TAG_UNDEFINED) ? (INTEROP_RUNTIME_OBJECT) : (INTEROP_RUNTIME_UNDEFINED); +} +template <> +inline OH_HILOG_RuntimeType runtimeType(const OH_Number& value) +{ + return INTEROP_RUNTIME_NUMBER; +} +template <> +inline void WriteToString(std::string* result, const Opt_Number* value) { + result->append("{.tag="); + result->append(tagNameExact((OH_Tag)(value->tag))); + result->append(", .value="); + if (value->tag != INTEROP_TAG_UNDEFINED) { + WriteToString(result, &value->value); + } else { + OH_Undefined undefined = { 0 }; + WriteToString(result, undefined); + } + result->append("}"); +} +template <> +inline OH_HILOG_RuntimeType runtimeType(const Opt_Number& value) +{ + return (value.tag != INTEROP_TAG_UNDEFINED) ? (INTEROP_RUNTIME_OBJECT) : (INTEROP_RUNTIME_UNDEFINED); +} +template <> +inline OH_HILOG_RuntimeType runtimeType(const OH_Boolean& value) +{ + return INTEROP_RUNTIME_BOOLEAN; +} +template <> +inline void WriteToString(std::string* result, const Opt_Boolean* value) { + result->append("{.tag="); + result->append(tagNameExact((OH_Tag)(value->tag))); + result->append(", .value="); + if (value->tag != INTEROP_TAG_UNDEFINED) { + WriteToString(result, value->value); + } else { + OH_Undefined undefined = { 0 }; + WriteToString(result, undefined); + } + result->append("}"); +} +template <> +inline OH_HILOG_RuntimeType runtimeType(const Opt_Boolean& value) +{ + return (value.tag != INTEROP_TAG_UNDEFINED) ? (INTEROP_RUNTIME_OBJECT) : (INTEROP_RUNTIME_UNDEFINED); +} +template <> +inline OH_HILOG_RuntimeType runtimeType(const OH_HILOG_Union_Boolean_Number_String& value) +{ + switch (value.selector) { + case 0: return runtimeType(value.value0); + case 1: return runtimeType(value.value1); + case 2: return runtimeType(value.value2); + default: INTEROP_FATAL("Bad selector in OH_HILOG_Union_Boolean_Number_String: %d", value.selector); + } +} +template <> +inline void WriteToString(std::string* result, const OH_HILOG_Union_Boolean_Number_String* value) { + result->append("{"); + result->append(".selector="); + result->append(std::to_string(value->selector)); + result->append(", "); + // OH_Boolean + if (value->selector == 0) { + result->append(".value0="); + WriteToString(result, value->value0); + } + // OH_Number + if (value->selector == 1) { + result->append(".value1="); + WriteToString(result, &value->value1); + } + // OH_String + if (value->selector == 2) { + result->append(".value2="); + WriteToString(result, &value->value2); + } + result->append("}"); +} +template <> +inline void WriteToString(std::string* result, const Opt_Union_Boolean_Number_String* value) { + result->append("{.tag="); + result->append(tagNameExact((OH_Tag)(value->tag))); + result->append(", .value="); + if (value->tag != INTEROP_TAG_UNDEFINED) { + WriteToString(result, &value->value); + } else { + OH_Undefined undefined = { 0 }; + WriteToString(result, undefined); + } + result->append("}"); +} +template <> +inline OH_HILOG_RuntimeType runtimeType(const Opt_Union_Boolean_Number_String& value) +{ + return (value.tag != INTEROP_TAG_UNDEFINED) ? (INTEROP_RUNTIME_OBJECT) : (INTEROP_RUNTIME_UNDEFINED); +} +template <> +inline OH_HILOG_RuntimeType runtimeType(const Array_Union_Boolean_Number_String& value) +{ + return INTEROP_RUNTIME_OBJECT; +} + +template <> +inline void WriteToString(std::string* result, const Opt_Union_Boolean_Number_String* value); + +inline void WriteToString(std::string* result, const Array_Union_Boolean_Number_String* value) { + int32_t count = value->length; + result->append("{.array=allocArray({{"); + for (int i = 0; i < count; i++) { + if (i > 0) result->append(", "); + WriteToString(result, (const Opt_Union_Boolean_Number_String*)&value->array[i]); + } + result->append("}})"); + result->append(", .length="); + result->append(std::to_string(value->length)); + result->append("}"); +} +template <> +inline void WriteToString(std::string* result, const Opt_Array_Union_Boolean_Number_String* value) { + result->append("{.tag="); + result->append(tagNameExact((OH_Tag)(value->tag))); + result->append(", .value="); + if (value->tag != INTEROP_TAG_UNDEFINED) { + WriteToString(result, &value->value); + } else { + OH_Undefined undefined = { 0 }; + WriteToString(result, undefined); + } + result->append("}"); +} +template <> +inline OH_HILOG_RuntimeType runtimeType(const Opt_Array_Union_Boolean_Number_String& value) +{ + return (value.tag != INTEROP_TAG_UNDEFINED) ? (INTEROP_RUNTIME_OBJECT) : (INTEROP_RUNTIME_UNDEFINED); +} +template <> +inline OH_HILOG_RuntimeType runtimeType(const OH_HILOG_GlobalScope_ohos_hilog& value) +{ + return INTEROP_RUNTIME_OBJECT; +} +template <> +inline void WriteToString(std::string* result, const OH_HILOG_GlobalScope_ohos_hilog value) { + WriteToString(result, static_cast(value)); +} +template <> +inline void WriteToString(std::string* result, const Opt_GlobalScope_ohos_hilog* value) { + result->append("{.tag="); + result->append(tagNameExact((OH_Tag)(value->tag))); + result->append(", .value="); + if (value->tag != INTEROP_TAG_UNDEFINED) { + WriteToString(result, value->value); + } else { + OH_Undefined undefined = { 0 }; + WriteToString(result, undefined); + } + result->append("}"); +} +template <> +inline OH_HILOG_RuntimeType runtimeType(const Opt_GlobalScope_ohos_hilog& value) +{ + return (value.tag != INTEROP_TAG_UNDEFINED) ? (INTEROP_RUNTIME_OBJECT) : (INTEROP_RUNTIME_UNDEFINED); +} +class Serializer : public SerializerBase { + public: + Serializer(CallbackResourceHolder* resourceHolder = nullptr) : SerializerBase(resourceHolder) { + } + public: + Serializer(uint8_t* data, OH_UInt32 dataLength = 0, CallbackResourceHolder* resourceHolder = nullptr) : SerializerBase(data, dataLength, resourceHolder) { + } +}; + +class Deserializer : public DeserializerBase { + public: + Deserializer(uint8_t* data, OH_Int32 length) : DeserializerBase(data, length) { + } +}; +void GlobalScope_ohos_hilog_debugImpl(const OH_Number* domain, const OH_String* tag, const OH_String* format, const Array_Union_Boolean_Number_String* args); +void GlobalScope_ohos_hilog_infoImpl(const OH_Number* domain, const OH_String* tag, const OH_String* format, const Array_Union_Boolean_Number_String* args); +void GlobalScope_ohos_hilog_warnImpl(const OH_Number* domain, const OH_String* tag, const OH_String* format, const Array_Union_Boolean_Number_String* args); +void GlobalScope_ohos_hilog_errorImpl(const OH_Number* domain, const OH_String* tag, const OH_String* format, const Array_Union_Boolean_Number_String* args); +void GlobalScope_ohos_hilog_fatalImpl(const OH_Number* domain, const OH_String* tag, const OH_String* format, const Array_Union_Boolean_Number_String* args); +OH_Boolean GlobalScope_ohos_hilog_isLoggableImpl(const OH_Number* domain, const OH_String* tag, OH_HILOG_hilog_LogLevel level); +const OH_HILOG_Modifier* OH_HILOG_ModifierImpl() { + const static OH_HILOG_Modifier instance = { + &GlobalScope_ohos_hilog_debugImpl, + &GlobalScope_ohos_hilog_infoImpl, + &GlobalScope_ohos_hilog_warnImpl, + &GlobalScope_ohos_hilog_errorImpl, + &GlobalScope_ohos_hilog_fatalImpl, + &GlobalScope_ohos_hilog_isLoggableImpl, + }; + return &instance; +} +const OH_HILOG_API* GetHILOGAPIImpl(int version) { + const static OH_HILOG_API api = { + 1, // version + &OH_HILOG_ModifierImpl, + }; + if (version != api.version) return nullptr; + return &api; +} + +// Accessors + +void impl_GlobalScope_ohos_hilog_debug(KInteropNumber domain, const KStringPtr& tag, const KStringPtr& format, uint8_t* thisArray, int32_t thisLength) { + Deserializer thisDeserializer(thisArray, thisLength); + const OH_Int32 args_value_buf_length = thisDeserializer.readInt32(); + Array_Union_Boolean_Number_String args_value_buf = {}; + thisDeserializer.resizeArray::type, + std::decay::type>(&args_value_buf, args_value_buf_length); + for (int args_value_buf_i = 0; args_value_buf_i < args_value_buf_length; args_value_buf_i++) { + const auto args_value_buf_buf_runtimeType = static_cast(thisDeserializer.readInt8()); + Opt_Union_Boolean_Number_String args_value_buf_buf = {}; + args_value_buf_buf.tag = args_value_buf_buf_runtimeType == INTEROP_RUNTIME_UNDEFINED ? INTEROP_TAG_UNDEFINED : INTEROP_TAG_OBJECT; + if ((INTEROP_RUNTIME_UNDEFINED) != (args_value_buf_buf_runtimeType)) + { + const OH_Int8 args_value_buf_buf__selector = thisDeserializer.readInt8(); + OH_HILOG_Union_Boolean_Number_String args_value_buf_buf_ = {}; + args_value_buf_buf_.selector = args_value_buf_buf__selector; + if (args_value_buf_buf__selector == 0) { + args_value_buf_buf_.selector = 0; + args_value_buf_buf_.value0 = thisDeserializer.readBoolean(); + } + else if (args_value_buf_buf__selector == 1) { + args_value_buf_buf_.selector = 1; + args_value_buf_buf_.value1 = static_cast(thisDeserializer.readNumber()); + } + else if (args_value_buf_buf__selector == 2) { + args_value_buf_buf_.selector = 2; + args_value_buf_buf_.value2 = static_cast(thisDeserializer.readString()); + } + else { + INTEROP_FATAL("One of the branches for args_value_buf_buf_ has to be chosen through deserialisation."); + } + args_value_buf_buf.value = static_cast(args_value_buf_buf_); + } + args_value_buf.array[args_value_buf_i] = args_value_buf_buf; + } + Array_Union_Boolean_Number_String args_value = args_value_buf;; + GetHILOGAPIImpl(HILOG_API_VERSION)->HILOG()->debug((const OH_Number*) (&domain), (const OH_String*) (&tag), (const OH_String*) (&format), (const Array_Union_Boolean_Number_String*)&args_value); +} +KOALA_INTEROP_V5(GlobalScope_ohos_hilog_debug, KInteropNumber, KStringPtr, KStringPtr, uint8_t*, int32_t) +void impl_GlobalScope_ohos_hilog_info(KInteropNumber domain, const KStringPtr& tag, const KStringPtr& format, uint8_t* thisArray, int32_t thisLength) { + Deserializer thisDeserializer(thisArray, thisLength); + const OH_Int32 args_value_buf_length = thisDeserializer.readInt32(); + Array_Union_Boolean_Number_String args_value_buf = {}; + thisDeserializer.resizeArray::type, + std::decay::type>(&args_value_buf, args_value_buf_length); + for (int args_value_buf_i = 0; args_value_buf_i < args_value_buf_length; args_value_buf_i++) { + const auto args_value_buf_buf_runtimeType = static_cast(thisDeserializer.readInt8()); + Opt_Union_Boolean_Number_String args_value_buf_buf = {}; + args_value_buf_buf.tag = args_value_buf_buf_runtimeType == INTEROP_RUNTIME_UNDEFINED ? INTEROP_TAG_UNDEFINED : INTEROP_TAG_OBJECT; + if ((INTEROP_RUNTIME_UNDEFINED) != (args_value_buf_buf_runtimeType)) + { + const OH_Int8 args_value_buf_buf__selector = thisDeserializer.readInt8(); + OH_HILOG_Union_Boolean_Number_String args_value_buf_buf_ = {}; + args_value_buf_buf_.selector = args_value_buf_buf__selector; + if (args_value_buf_buf__selector == 0) { + args_value_buf_buf_.selector = 0; + args_value_buf_buf_.value0 = thisDeserializer.readBoolean(); + } + else if (args_value_buf_buf__selector == 1) { + args_value_buf_buf_.selector = 1; + args_value_buf_buf_.value1 = static_cast(thisDeserializer.readNumber()); + } + else if (args_value_buf_buf__selector == 2) { + args_value_buf_buf_.selector = 2; + args_value_buf_buf_.value2 = static_cast(thisDeserializer.readString()); + } + else { + INTEROP_FATAL("One of the branches for args_value_buf_buf_ has to be chosen through deserialisation."); + } + args_value_buf_buf.value = static_cast(args_value_buf_buf_); + } + args_value_buf.array[args_value_buf_i] = args_value_buf_buf; + } + Array_Union_Boolean_Number_String args_value = args_value_buf;; + GetHILOGAPIImpl(HILOG_API_VERSION)->HILOG()->info((const OH_Number*) (&domain), (const OH_String*) (&tag), (const OH_String*) (&format), (const Array_Union_Boolean_Number_String*)&args_value); +} +KOALA_INTEROP_V5(GlobalScope_ohos_hilog_info, KInteropNumber, KStringPtr, KStringPtr, uint8_t*, int32_t) +void impl_GlobalScope_ohos_hilog_warn(KInteropNumber domain, const KStringPtr& tag, const KStringPtr& format, uint8_t* thisArray, int32_t thisLength) { + Deserializer thisDeserializer(thisArray, thisLength); + const OH_Int32 args_value_buf_length = thisDeserializer.readInt32(); + Array_Union_Boolean_Number_String args_value_buf = {}; + thisDeserializer.resizeArray::type, + std::decay::type>(&args_value_buf, args_value_buf_length); + for (int args_value_buf_i = 0; args_value_buf_i < args_value_buf_length; args_value_buf_i++) { + const auto args_value_buf_buf_runtimeType = static_cast(thisDeserializer.readInt8()); + Opt_Union_Boolean_Number_String args_value_buf_buf = {}; + args_value_buf_buf.tag = args_value_buf_buf_runtimeType == INTEROP_RUNTIME_UNDEFINED ? INTEROP_TAG_UNDEFINED : INTEROP_TAG_OBJECT; + if ((INTEROP_RUNTIME_UNDEFINED) != (args_value_buf_buf_runtimeType)) + { + const OH_Int8 args_value_buf_buf__selector = thisDeserializer.readInt8(); + OH_HILOG_Union_Boolean_Number_String args_value_buf_buf_ = {}; + args_value_buf_buf_.selector = args_value_buf_buf__selector; + if (args_value_buf_buf__selector == 0) { + args_value_buf_buf_.selector = 0; + args_value_buf_buf_.value0 = thisDeserializer.readBoolean(); + } + else if (args_value_buf_buf__selector == 1) { + args_value_buf_buf_.selector = 1; + args_value_buf_buf_.value1 = static_cast(thisDeserializer.readNumber()); + } + else if (args_value_buf_buf__selector == 2) { + args_value_buf_buf_.selector = 2; + args_value_buf_buf_.value2 = static_cast(thisDeserializer.readString()); + } + else { + INTEROP_FATAL("One of the branches for args_value_buf_buf_ has to be chosen through deserialisation."); + } + args_value_buf_buf.value = static_cast(args_value_buf_buf_); + } + args_value_buf.array[args_value_buf_i] = args_value_buf_buf; + } + Array_Union_Boolean_Number_String args_value = args_value_buf;; + GetHILOGAPIImpl(HILOG_API_VERSION)->HILOG()->warn((const OH_Number*) (&domain), (const OH_String*) (&tag), (const OH_String*) (&format), (const Array_Union_Boolean_Number_String*)&args_value); +} +KOALA_INTEROP_V5(GlobalScope_ohos_hilog_warn, KInteropNumber, KStringPtr, KStringPtr, uint8_t*, int32_t) +void impl_GlobalScope_ohos_hilog_error(KInteropNumber domain, const KStringPtr& tag, const KStringPtr& format, uint8_t* thisArray, int32_t thisLength) { + Deserializer thisDeserializer(thisArray, thisLength); + const OH_Int32 args_value_buf_length = thisDeserializer.readInt32(); + Array_Union_Boolean_Number_String args_value_buf = {}; + thisDeserializer.resizeArray::type, + std::decay::type>(&args_value_buf, args_value_buf_length); + for (int args_value_buf_i = 0; args_value_buf_i < args_value_buf_length; args_value_buf_i++) { + const auto args_value_buf_buf_runtimeType = static_cast(thisDeserializer.readInt8()); + Opt_Union_Boolean_Number_String args_value_buf_buf = {}; + args_value_buf_buf.tag = args_value_buf_buf_runtimeType == INTEROP_RUNTIME_UNDEFINED ? INTEROP_TAG_UNDEFINED : INTEROP_TAG_OBJECT; + if ((INTEROP_RUNTIME_UNDEFINED) != (args_value_buf_buf_runtimeType)) + { + const OH_Int8 args_value_buf_buf__selector = thisDeserializer.readInt8(); + OH_HILOG_Union_Boolean_Number_String args_value_buf_buf_ = {}; + args_value_buf_buf_.selector = args_value_buf_buf__selector; + if (args_value_buf_buf__selector == 0) { + args_value_buf_buf_.selector = 0; + args_value_buf_buf_.value0 = thisDeserializer.readBoolean(); + } + else if (args_value_buf_buf__selector == 1) { + args_value_buf_buf_.selector = 1; + args_value_buf_buf_.value1 = static_cast(thisDeserializer.readNumber()); + } + else if (args_value_buf_buf__selector == 2) { + args_value_buf_buf_.selector = 2; + args_value_buf_buf_.value2 = static_cast(thisDeserializer.readString()); + } + else { + INTEROP_FATAL("One of the branches for args_value_buf_buf_ has to be chosen through deserialisation."); + } + args_value_buf_buf.value = static_cast(args_value_buf_buf_); + } + args_value_buf.array[args_value_buf_i] = args_value_buf_buf; + } + Array_Union_Boolean_Number_String args_value = args_value_buf;; + GetHILOGAPIImpl(HILOG_API_VERSION)->HILOG()->error((const OH_Number*) (&domain), (const OH_String*) (&tag), (const OH_String*) (&format), (const Array_Union_Boolean_Number_String*)&args_value); +} +KOALA_INTEROP_V5(GlobalScope_ohos_hilog_error, KInteropNumber, KStringPtr, KStringPtr, uint8_t*, int32_t) +void impl_GlobalScope_ohos_hilog_fatal(KInteropNumber domain, const KStringPtr& tag, const KStringPtr& format, uint8_t* thisArray, int32_t thisLength) { + Deserializer thisDeserializer(thisArray, thisLength); + const OH_Int32 args_value_buf_length = thisDeserializer.readInt32(); + Array_Union_Boolean_Number_String args_value_buf = {}; + thisDeserializer.resizeArray::type, + std::decay::type>(&args_value_buf, args_value_buf_length); + for (int args_value_buf_i = 0; args_value_buf_i < args_value_buf_length; args_value_buf_i++) { + const auto args_value_buf_buf_runtimeType = static_cast(thisDeserializer.readInt8()); + Opt_Union_Boolean_Number_String args_value_buf_buf = {}; + args_value_buf_buf.tag = args_value_buf_buf_runtimeType == INTEROP_RUNTIME_UNDEFINED ? INTEROP_TAG_UNDEFINED : INTEROP_TAG_OBJECT; + if ((INTEROP_RUNTIME_UNDEFINED) != (args_value_buf_buf_runtimeType)) + { + const OH_Int8 args_value_buf_buf__selector = thisDeserializer.readInt8(); + OH_HILOG_Union_Boolean_Number_String args_value_buf_buf_ = {}; + args_value_buf_buf_.selector = args_value_buf_buf__selector; + if (args_value_buf_buf__selector == 0) { + args_value_buf_buf_.selector = 0; + args_value_buf_buf_.value0 = thisDeserializer.readBoolean(); + } + else if (args_value_buf_buf__selector == 1) { + args_value_buf_buf_.selector = 1; + args_value_buf_buf_.value1 = static_cast(thisDeserializer.readNumber()); + } + else if (args_value_buf_buf__selector == 2) { + args_value_buf_buf_.selector = 2; + args_value_buf_buf_.value2 = static_cast(thisDeserializer.readString()); + } + else { + INTEROP_FATAL("One of the branches for args_value_buf_buf_ has to be chosen through deserialisation."); + } + args_value_buf_buf.value = static_cast(args_value_buf_buf_); + } + args_value_buf.array[args_value_buf_i] = args_value_buf_buf; + } + Array_Union_Boolean_Number_String args_value = args_value_buf;; + GetHILOGAPIImpl(HILOG_API_VERSION)->HILOG()->fatal((const OH_Number*) (&domain), (const OH_String*) (&tag), (const OH_String*) (&format), (const Array_Union_Boolean_Number_String*)&args_value); +} +KOALA_INTEROP_V5(GlobalScope_ohos_hilog_fatal, KInteropNumber, KStringPtr, KStringPtr, uint8_t*, int32_t) +OH_Boolean impl_GlobalScope_ohos_hilog_isLoggable(KInteropNumber domain, const KStringPtr& tag, OH_Int32 level) { + return GetHILOGAPIImpl(HILOG_API_VERSION)->HILOG()->isLoggable((const OH_Number*) (&domain), (const OH_String*) (&tag), static_cast(level)); +} +KOALA_INTEROP_3(GlobalScope_ohos_hilog_isLoggable, OH_Boolean, KInteropNumber, KStringPtr, OH_Int32) +void deserializeAndCallCallback(OH_Int32 kind, uint8_t* thisArray, OH_Int32 thisLength) +{ + printf("Unknown callback kind\n"); +} +void deserializeAndCallCallbackSync(OH_HILOG_VMContext vmContext, OH_Int32 kind, uint8_t* thisArray, OH_Int32 thisLength) +{ + printf("Unknown callback kind\n"); +} +OH_NativePointer getManagedCallbackCaller(CallbackKind kind) +{ + return nullptr; +} +OH_NativePointer getManagedCallbackCallerSync(CallbackKind kind) +{ + return nullptr; +} +const OH_AnyAPI* impls[16] = { 0 }; + + +const OH_AnyAPI* GetAnyAPIImpl(int kind, int version) { + switch (kind) { + case OH_HILOG_API_KIND: + return reinterpret_cast(GetHILOGAPIImpl(version)); + default: + return nullptr; + } +} + +extern "C" const OH_AnyAPI* GetAnyAPI(int kind, int version) { + if (kind < 0 || kind > 15) return nullptr; + if (!impls[kind]) { + impls[kind] = GetAnyAPIImpl(kind, version); + } + return impls[kind]; +} diff --git a/idlhilog/generated/native/hilog.h b/idlhilog/generated/native/hilog.h new file mode 100644 index 0000000..e21c167 --- /dev/null +++ b/idlhilog/generated/native/hilog.h @@ -0,0 +1,272 @@ +/* + * Copyright (c) 2024 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 OH_HILOG_H +#define OH_HILOG_H + +#ifndef _INTEROP_TYPES_H_ +#define _INTEROP_TYPES_H_ + +#include + +#define INTEROP_FATAL(msg, ...) do { fprintf(stderr, msg "\n", ##__VA_ARGS__); abort(); } while (0) + +typedef enum InteropTag +{ + INTEROP_TAG_UNDEFINED = 101, + INTEROP_TAG_INT32 = 102, + INTEROP_TAG_FLOAT32 = 103, + INTEROP_TAG_STRING = 104, + INTEROP_TAG_LENGTH = 105, + INTEROP_TAG_RESOURCE = 106, + INTEROP_TAG_OBJECT = 107, +} InteropTag; + +typedef enum InteropRuntimeType +{ + INTEROP_RUNTIME_UNEXPECTED = -1, + INTEROP_RUNTIME_NUMBER = 1, + INTEROP_RUNTIME_STRING = 2, + INTEROP_RUNTIME_OBJECT = 3, + INTEROP_RUNTIME_BOOLEAN = 4, + INTEROP_RUNTIME_UNDEFINED = 5, + INTEROP_RUNTIME_BIGINT = 6, + INTEROP_RUNTIME_FUNCTION = 7, + INTEROP_RUNTIME_SYMBOL = 8, + INTEROP_RUNTIME_MATERIALIZED = 9, +} InteropRuntimeType; + +typedef float InteropFloat32; +typedef double InteropFloat64; +typedef int32_t InteropInt32; +typedef unsigned int InteropUInt32; // TODO: update unsigned int +typedef int64_t InteropInt64; +typedef uint64_t InteropUInt64; +typedef int8_t InteropInt8; +typedef uint8_t InteropUInt8; +typedef int64_t InteropDate; +typedef int8_t InteropBoolean; +typedef const char* InteropCharPtr; +typedef void* InteropNativePointer; + +struct _InteropVMContext; +typedef struct _InteropVMContext* InteropVMContext; +struct _InteropPipelineContext; +typedef struct _InteropPipelineContext* InteropPipelineContext; +struct _InteropVMObject; +typedef struct _InteropVMObject* InteropVMObject; +struct _InteropNode; +typedef struct _InteropNode* InteropNodeHandle; +typedef struct InteropDeferred { + void* handler; + void* context; + void (*resolve)(struct InteropDeferred* thiz, uint8_t* data, int32_t length); + void (*reject)(struct InteropDeferred* thiz, const char* message); +} InteropDeferred; + +// Binary layout of InteropString must match that of KStringPtrImpl. +typedef struct InteropString { + const char* chars; + InteropInt32 length; +} InteropString; + +typedef struct InteropEmpty { + InteropInt32 dummy; // Empty structs are forbidden in C. +} InteropEmpty; + +typedef struct InteropNumber { + InteropInt8 tag; + union { + InteropFloat32 f32; + InteropInt32 i32; + }; +} InteropNumber; + +// Binary layout of InteropLength must match that of KLength. +typedef struct InteropLength +{ + InteropInt8 type; + InteropFloat32 value; + InteropInt32 unit; + InteropInt32 resource; +} InteropLength; + +typedef struct InteropCustomObject { + char kind[20]; + InteropInt32 id; + // Data of custom object. + union { + InteropInt32 ints[4]; + InteropFloat32 floats[4]; + void* pointers[4]; + InteropString string; + }; +} InteropCustomObject; + +typedef struct InteropUndefined { + InteropInt32 dummy; // Empty structs are forbidden in C. +} InteropUndefined; + +typedef struct InteropVoid { + InteropInt32 dummy; // Empty structs are forbidden in C. +} InteropVoid; + +typedef struct InteropFunction { + InteropInt32 id; +} InteropFunction; +typedef InteropFunction InteropCallback; +typedef InteropFunction InteropErrorCallback; + +typedef struct InteropMaterialized { + InteropNativePointer ptr; +} InteropMaterialized; + +typedef struct InteropCallbackResource { + InteropInt32 resourceId; + void (*hold)(InteropInt32 resourceId); + void (*release)(InteropInt32 resourceId); +} InteropCallbackResource; + +typedef struct InteropBuffer { + InteropCallbackResource resource; + InteropNativePointer data; + InteropInt64 length; +} InteropBuffer; + +#endif // _INTEROP_TYPES_H_ + + +#define HILOG_API_VERSION 1 + +#include + +/* clang-format off */ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef InteropTag OH_Tag; +typedef InteropRuntimeType OH_HILOG_RuntimeType; + +typedef InteropFloat32 OH_Float32; +typedef InteropFloat64 OH_Float64; +typedef InteropInt32 OH_Int32; +typedef InteropUInt32 OH_UInt32; +typedef InteropInt64 OH_Int64; +typedef InteropUInt64 OH_UInt64; +typedef InteropInt8 OH_Int8; +typedef InteropBoolean OH_Boolean; +typedef InteropCharPtr OH_CharPtr; +typedef InteropNativePointer OH_NativePointer; +typedef InteropString OH_String; +typedef InteropCallbackResource OH_HILOG_CallbackResource; +typedef InteropNumber OH_Number; +typedef InteropMaterialized OH_Materialized; +typedef InteropCustomObject OH_CustomObject; +typedef InteropUndefined OH_Undefined; +// typedef InteropAPIKind OH_APIKind; +typedef InteropVMContext OH_HILOG_VMContext; +typedef InteropBuffer OH_Buffer; +typedef InteropLength OH_Length; +typedef InteropFunction OH_Function; + +typedef enum OH_APIKind { + OH_HILOG_API_KIND = 100 +} OH_APIKind; + +typedef struct OH_AnyAPI { + OH_Int32 version; +} OH_AnyAPI; + +typedef struct OH_HILOG_Union_Boolean_Number_String OH_HILOG_Union_Boolean_Number_String; +typedef struct Opt_Union_Boolean_Number_String Opt_Union_Boolean_Number_String; +typedef struct Array_Union_Boolean_Number_String Array_Union_Boolean_Number_String; +typedef struct Opt_Array_Union_Boolean_Number_String Opt_Array_Union_Boolean_Number_String; +typedef struct HILOG_GlobalScope_ohos_hilogPeer HILOG_GlobalScope_ohos_hilogPeer; +typedef struct HILOG_GlobalScope_ohos_hilogPeer* OH_HILOG_GlobalScope_ohos_hilog; +typedef struct Opt_GlobalScope_ohos_hilog Opt_GlobalScope_ohos_hilog; +typedef enum OH_HILOG_hilog_LogLevel { + OH_HILOG_HILOG_LOG_LEVEL_DEBUG = 3, + OH_HILOG_HILOG_LOG_LEVEL_INFO = 4, + OH_HILOG_HILOG_LOG_LEVEL_WARN = 5, + OH_HILOG_HILOG_LOG_LEVEL_ERROR = 6, + OH_HILOG_HILOG_LOG_LEVEL_FATAL = 7, +} OH_HILOG_hilog_LogLevel; +typedef struct Opt_hilog_LogLevel { + OH_Tag tag; + OH_HILOG_hilog_LogLevel value; +} Opt_hilog_LogLevel; +typedef struct Opt_Int32 { + OH_Tag tag; + OH_Int32 value; +} Opt_Int32; +typedef struct Opt_String { + OH_Tag tag; + OH_String value; +} Opt_String; +typedef struct Opt_Number { + OH_Tag tag; + OH_Number value; +} Opt_Number; +typedef struct Opt_Boolean { + OH_Tag tag; + OH_Boolean value; +} Opt_Boolean; +typedef struct OH_HILOG_Union_Boolean_Number_String { + OH_Int32 selector; + union { + OH_Boolean value0; + OH_Number value1; + OH_String value2; + }; +} OH_HILOG_Union_Boolean_Number_String; +typedef struct Opt_Union_Boolean_Number_String { + OH_Tag tag; + OH_HILOG_Union_Boolean_Number_String value; +} Opt_Union_Boolean_Number_String; +typedef struct Array_Union_Boolean_Number_String { + Opt_Union_Boolean_Number_String* array; + OH_Int32 length; +} Array_Union_Boolean_Number_String; +typedef struct Opt_Array_Union_Boolean_Number_String { + OH_Tag tag; + Array_Union_Boolean_Number_String value; +} Opt_Array_Union_Boolean_Number_String; +typedef struct Opt_GlobalScope_ohos_hilog { + OH_Tag tag; + OH_HILOG_GlobalScope_ohos_hilog value; +} Opt_GlobalScope_ohos_hilog; +struct OH_HILOG_GlobalScope_ohos_hilogHandleOpaque; +typedef struct OH_HILOG_GlobalScope_ohos_hilogHandleOpaque* OH_HILOG_GlobalScope_ohos_hilogHandle; +typedef struct OH_HILOG_Modifier { + void (*debug)(const OH_Number* domain, const OH_String* tag, const OH_String* format, const Array_Union_Boolean_Number_String* args); + void (*info)(const OH_Number* domain, const OH_String* tag, const OH_String* format, const Array_Union_Boolean_Number_String* args); + void (*warn)(const OH_Number* domain, const OH_String* tag, const OH_String* format, const Array_Union_Boolean_Number_String* args); + void (*error)(const OH_Number* domain, const OH_String* tag, const OH_String* format, const Array_Union_Boolean_Number_String* args); + void (*fatal)(const OH_Number* domain, const OH_String* tag, const OH_String* format, const Array_Union_Boolean_Number_String* args); + OH_Boolean (*isLoggable)(const OH_Number* domain, const OH_String* tag, OH_HILOG_hilog_LogLevel level); +} OH_HILOG_Modifier; +typedef struct OH_HILOG_API { + OH_Int32 version; + const OH_HILOG_Modifier* (*HILOG)(); +} OH_HILOG_API; + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // OH_HILOG_H +/* clang-format on */ \ No newline at end of file diff --git a/idlhilog/generated/native/hilogImpl_temp.cc b/idlhilog/generated/native/hilogImpl_temp.cc new file mode 100644 index 0000000..754480e --- /dev/null +++ b/idlhilog/generated/native/hilogImpl_temp.cc @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024-2025 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. + */ + +#define KOALA_INTEROP_MODULE NotSpecifiedInteropModule +#include "hilog.h" + +void GlobalScope_ohos_hilog_debugImpl(const OH_Number* domain, const OH_String* tag, const OH_String* format, const Array_Union_Boolean_Number_String* args) { +} +void GlobalScope_ohos_hilog_infoImpl(const OH_Number* domain, const OH_String* tag, const OH_String* format, const Array_Union_Boolean_Number_String* args) { +} +void GlobalScope_ohos_hilog_warnImpl(const OH_Number* domain, const OH_String* tag, const OH_String* format, const Array_Union_Boolean_Number_String* args) { +} +void GlobalScope_ohos_hilog_errorImpl(const OH_Number* domain, const OH_String* tag, const OH_String* format, const Array_Union_Boolean_Number_String* args) { +} +void GlobalScope_ohos_hilog_fatalImpl(const OH_Number* domain, const OH_String* tag, const OH_String* format, const Array_Union_Boolean_Number_String* args) { +} +OH_Boolean GlobalScope_ohos_hilog_isLoggableImpl(const OH_Number* domain, const OH_String* tag, OH_HILOG_hilog_LogLevel level) { + return {}; +} \ No newline at end of file diff --git a/idlhilog/idlize.map b/idlhilog/idlize.map new file mode 100644 index 0000000..2491587 --- /dev/null +++ b/idlhilog/idlize.map @@ -0,0 +1,4 @@ +{ + global: + *; +}; \ No newline at end of file diff --git a/idlhilog/src/cpp/hilog_impl.cpp b/idlhilog/src/cpp/hilog_impl.cpp new file mode 100644 index 0000000..9c79602 --- /dev/null +++ b/idlhilog/src/cpp/hilog_impl.cpp @@ -0,0 +1,211 @@ +/* + * Copyright (c) 2024-2025 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 "hilog.h" + +#include "hilog/log.h" +#include "hilog/log_c.h" +#include "hilog/log_cpp.h" +#include "hilog_common.h" +#include "properties.h" +#include "securec.h" + +static constexpr int32_t MIN_NUMBER = 3; +static constexpr int32_t MAX_NUMBER = 100; +static constexpr int32_t PUBLIC_LEN = 6; +static constexpr int32_t PRIVATE_LEN = 7; +static constexpr int32_t PROPERTY_POS = 2; +static constexpr int32_t TYPE_BOOLEAN = 0; +static constexpr int32_t TYPE_NUMBER = 1; +static constexpr int32_t TYPE_STRING = 2; +static const std::string PRIV_STR = ""; + +using argsParam = struct { + OH_HILOG_RuntimeType tag; + std::string val; +}; + +bool ToInt32(const OH_Number* number, int32_t &value) +{ + if (number->tag == OH_Tag::INTEROP_TAG_INT32) { + value = number->i32; + } else if (number->tag == OH_Tag::INTEROP_TAG_FLOAT32) { + value = number->f32; + } else { + return false; + } + return true; +} + +void ParseLogContent(std::string& formatStr, std::vector& params, std::string& logContent) +{ + std::string& ret = logContent; + if (params.empty()) { + ret += formatStr; + return; + } + auto size = params.size(); + auto len = formatStr.size(); + uint32_t pos = 0; + uint32_t count = 0; + bool debug = true; +#if not (defined(__WINDOWS__) || defined(__MAC__) || defined(__LINUX__)) + debug = OHOS::HiviewDFX::IsDebugOn(); +#endif + bool priv = (!debug) && OHOS::HiviewDFX::IsPrivateSwitchOn(); + for (; pos < len; ++pos) { + bool showPriv = true; + if (count >= size) { + break; + } + if (formatStr[pos] != '%') { + ret += formatStr[pos]; + continue; + } + if (((pos + PUBLIC_LEN + PROPERTY_POS) < len) && + formatStr.substr(pos + PROPERTY_POS, PUBLIC_LEN) == "public") { + pos += (PUBLIC_LEN + PROPERTY_POS); + showPriv = false; + } else if (((pos + PRIVATE_LEN + PROPERTY_POS) < len) && + formatStr.substr(pos + PROPERTY_POS, PRIVATE_LEN) == "private") { + pos += (PRIVATE_LEN + PROPERTY_POS); + } + + if (pos + 1 >= len) { + break; + } + switch (formatStr[pos + 1]) { + case 'd': + case 'i': + if (params[count].tag == OH_HILOG_RuntimeType::INTEROP_RUNTIME_NUMBER) { + ret += (priv && showPriv) ? PRIV_STR : params[count].val; + } + count++; + ++pos; + break; + case 's': + if (params[count].tag == OH_HILOG_RuntimeType::INTEROP_RUNTIME_STRING || + params[count].tag == OH_HILOG_RuntimeType::INTEROP_RUNTIME_UNDEFINED || + params[count].tag == OH_HILOG_RuntimeType::INTEROP_RUNTIME_BOOLEAN) { + ret += (priv && showPriv) ? PRIV_STR : params[count].val; + } + count++; + ++pos; + break; + case '%': + ret += formatStr[pos]; + ++pos; + break; + default: + ret += formatStr[pos]; + break; + } + } + if (pos < len) { + ret += formatStr.substr(pos, len - pos); + } + return; +} + +void ParseArgsValue(Opt_Union_Boolean_Number_String element, std::vector& params) +{ + argsParam res = {OH_HILOG_RuntimeType::INTEROP_RUNTIME_UNEXPECTED, ""}; + if (element.tag == OH_Tag::INTEROP_TAG_UNDEFINED) { + res.val = "undefined"; + res.tag = OH_HILOG_RuntimeType::INTEROP_RUNTIME_UNDEFINED; + } + if (element.value.selector == TYPE_BOOLEAN){ + res.val = element.value.value0 ? "true" :"false"; + res.tag = OH_HILOG_RuntimeType::INTEROP_RUNTIME_BOOLEAN; + }else if (element.value.selector == TYPE_NUMBER) { + if (element.value.value1.tag == OH_Tag::INTEROP_TAG_INT32) { + res.val = std::to_string(element.value.value1.i32); + } else if (element.value.value1.tag == OH_Tag::INTEROP_TAG_FLOAT32) { + res.val = std::to_string(element.value.value1.f32); + } + res.tag = OH_HILOG_RuntimeType::INTEROP_RUNTIME_NUMBER; + } else if (element.value.selector == TYPE_STRING) { + res.val = std::string(element.value.value2.chars, element.value.value2.length); + res.tag = OH_HILOG_RuntimeType::INTEROP_RUNTIME_STRING; + } + params.emplace_back(res); + return; +} + +void HilogImpl(const OH_Number* domain, const OH_String* tag, const OH_String* format, + const Array_Union_Boolean_Number_String* args, int level, bool isAppLog) +{ + int32_t realArgc = args->length + MIN_NUMBER; + if (MIN_NUMBER > realArgc || MAX_NUMBER < realArgc) { + return; + } + int32_t domainVal; + if (!ToInt32(domain, domainVal)) { + return; + } + std::string fmtString(format->chars, format->length); + std::string logContent; + std::vector params; + for (int32_t i = 0; i < args->length; i++) { + Opt_Union_Boolean_Number_String argsVal = args->array[i]; + ParseArgsValue(argsVal, params); + } + ParseLogContent(fmtString, params, logContent); + + HiLogPrint((isAppLog ? LOG_APP : LOG_CORE), + static_cast(level), domainVal, tag->chars, "%{public}s", logContent.c_str()); + return; +} + +void GlobalScope_ohos_hilog_debugImpl(const OH_Number* domain, const OH_String* tag, const OH_String* format, + const Array_Union_Boolean_Number_String* args) +{ + HilogImpl(domain, tag, format, args, LOG_DEBUG, true); +} +void GlobalScope_ohos_hilog_infoImpl(const OH_Number* domain, const OH_String* tag, const OH_String* format, + const Array_Union_Boolean_Number_String* args) +{ + HilogImpl(domain, tag, format, args, LOG_INFO, true); +} +void GlobalScope_ohos_hilog_warnImpl(const OH_Number* domain, const OH_String* tag, const OH_String* format, + const Array_Union_Boolean_Number_String* args) +{ + HilogImpl(domain, tag, format, args, LOG_WARN, true); +} +void GlobalScope_ohos_hilog_errorImpl(const OH_Number* domain, const OH_String* tag, const OH_String* format, + const Array_Union_Boolean_Number_String* args) +{ + HilogImpl(domain, tag, format, args, LOG_ERROR, true); +} +void GlobalScope_ohos_hilog_fatalImpl(const OH_Number* domain, const OH_String* tag, const OH_String* format, + const Array_Union_Boolean_Number_String* args) +{ + HilogImpl(domain, tag, format, args, LOG_FATAL, true); +} +OH_Boolean GlobalScope_ohos_hilog_isLoggableImpl(const OH_Number* domain, const OH_String* tag, + OH_HILOG_hilog_LogLevel level) +{ + int32_t domainVal; + if (!ToInt32(domain, domainVal)) { + return static_cast(false); + } + if (domainVal < static_cast(DOMAIN_APP_MIN) || (domainVal > static_cast(DOMAIN_APP_MAX))) { + return static_cast(false); + } + bool res = HiLogIsLoggable(domainVal, tag->chars, static_cast(level)); + return static_cast(res); +} \ No newline at end of file -- Gitee