From ce446f875cb8ab74385d61ae1996cc1d0ad47439 Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Wed, 19 Feb 2025 21:05:06 +0300 Subject: [PATCH 1/2] Fix generation --- .../src/generated/ArkInspectorInterfaces.ts | 24 +++++ .../arkui/src/generated/CallbackRegistry.ts | 90 ------------------- .../generated/peers/CallbackTransformer.ts | 53 ----------- .../src/generated/ArkInspectorInterfaces.ts | 17 ++-- .../src/generated/arkoala_api_generated.h | 2 +- arkoala/tools/peer-generator/package.json | 4 +- 6 files changed, 36 insertions(+), 154 deletions(-) create mode 100644 arkoala-arkts/arkui/src/generated/ArkInspectorInterfaces.ts delete mode 100644 arkoala-arkts/arkui/src/generated/CallbackRegistry.ts delete mode 100644 arkoala-arkts/arkui/src/generated/peers/CallbackTransformer.ts rename arkoala-arkts/arkui/src/generated/Events.ts => arkoala/arkui/src/generated/ArkInspectorInterfaces.ts (52%) diff --git a/arkoala-arkts/arkui/src/generated/ArkInspectorInterfaces.ts b/arkoala-arkts/arkui/src/generated/ArkInspectorInterfaces.ts new file mode 100644 index 000000000..df70cea9b --- /dev/null +++ b/arkoala-arkts/arkui/src/generated/ArkInspectorInterfaces.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. + */ + + +// WARNING! THIS FILE IS AUTO-GENERATED, DO NOT MAKE CHANGES, THEY WILL BE LOST ON NEXT GENERATION! + +import { int32, int64, float32 } from "@koalaui/common" +import { KInt, KPointer, KBoolean, KStringPtr, wrapCallback, NativeBuffer } from "@koalaui/interop" +import { NodeAttach, remember } from "@koalaui/runtime" +declare function getInspectorNodes(): Object +declare function getInspectorNodeById(arg0: number): Object +declare function setAppBgColor(arg0: string): void diff --git a/arkoala-arkts/arkui/src/generated/CallbackRegistry.ts b/arkoala-arkts/arkui/src/generated/CallbackRegistry.ts deleted file mode 100644 index 07fb8f45d..000000000 --- a/arkoala-arkts/arkui/src/generated/CallbackRegistry.ts +++ /dev/null @@ -1,90 +0,0 @@ -/* - * 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. - */ - -import { int32 } from "@koalaui/common" -import { KUint8ArrayPtr } from "@koalaui/interop" - -// todo: do we need an Uint8Array version? -export type CallbackType = (args: KUint8ArrayPtr, length: int32) => int32 - -class CallbackRecord { - public callback: CallbackType - public autoDisposable: boolean - - constructor(callback: CallbackType, autoDisposable: boolean) { - this.callback = callback - this.autoDisposable = autoDisposable - } -} - -class CallbackRegistry { - - static INSTANCE = new CallbackRegistry() - - private callbacks = new Map() - private id = 1024 - - constructor() { - this.callbacks.set(0, new CallbackRecord( - (args: KUint8ArrayPtr, length: int32): int32 => { - // console.log(`Callback 0 called with args = ${args} and length = ${length}`) - throw new Error(`Null callback called`) - }, false) - ) - } - - wrap(callback: CallbackType, autoDisposable: boolean): int32 { - const id = this.id++ - this.callbacks.set(id, new CallbackRecord(callback, autoDisposable)) - return id - } - - wrapSystem(id: int32, callback: CallbackType, autoDisposable: boolean): int32 { - this.callbacks.set(id, new CallbackRecord(callback, autoDisposable)) - return id - } - - call(id: int32, args: KUint8ArrayPtr, length: int32): int32 { - if (!this.callbacks.has(id)) { - // console.log(`Callback ${id} is not known`) - throw new Error(`Disposed or unwrapped callback called (id = ${id})`) - } - const record = this.callbacks.get(id)! - if (record.autoDisposable) { - this.dispose(id) - } - return record.callback(args, length) - } - - dispose(id: int32) { - this.callbacks.delete(id) - } -} - -export function wrapCallback(callback: CallbackType, autoDisposable: boolean = true): int32 { - return CallbackRegistry.INSTANCE.wrap(callback, autoDisposable) -} - -export function disposeCallback(id: int32) { - CallbackRegistry.INSTANCE.dispose(id) -} - -export function wrapSystemCallback(id:int32, callback: CallbackType): int32 { - return CallbackRegistry.INSTANCE.wrapSystem(id, callback, false) -} - -export function callCallback(id: int32, args: KUint8ArrayPtr, length: int32): int32 { - return CallbackRegistry.INSTANCE.call(id, args, length) -} diff --git a/arkoala-arkts/arkui/src/generated/peers/CallbackTransformer.ts b/arkoala-arkts/arkui/src/generated/peers/CallbackTransformer.ts deleted file mode 100644 index 344a26bcf..000000000 --- a/arkoala-arkts/arkui/src/generated/peers/CallbackTransformer.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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. - */ - -import { KPointer } from "@koalaui/interop" -import { PeerNode } from "../../PeerNode" -import { CustomBuilder } from "../ArkCommonInterfaces" -import { CustomNodeBuilder } from "../ArkCustomBuilderInterfaces" -import { ArkComponentRootPeer } from "./ArkStaticComponentsPeer" - -// TODO need invert dependency: createUiDetachedRoot should be imported from @koalaui/arkoala same as in TS -export type UIDetachedRootCreator = ( - peerFactory: () => PeerNode, - /** @memo */ - builder: () => void -) => PeerNode -let createUiDetachedRoot: UIDetachedRootCreator = ( - factory: () => PeerNode, - /** @memo */ - builder: () => void -): PeerNode => { - throw new Error("Not implemented") -} -export function setUIDetachedRootCreator(creator: UIDetachedRootCreator): void { - createUiDetachedRoot = creator -} - -function componentRootPeerFactory(): PeerNode { - return ArkComponentRootPeer.create() -} - -export class CallbackTransformer { - static transformFromCustomBuilder(value: CustomBuilder): CustomNodeBuilder { - return (parentNodeId: KPointer): KPointer => { - const peer = createUiDetachedRoot(componentRootPeerFactory, value) - return peer.peer.ptr - } - } - static transformToCustomBuilder(value: CustomNodeBuilder): CustomBuilder { - throw new Error("Not implemented") - } -} \ No newline at end of file diff --git a/arkoala-arkts/arkui/src/generated/Events.ts b/arkoala/arkui/src/generated/ArkInspectorInterfaces.ts similarity index 52% rename from arkoala-arkts/arkui/src/generated/Events.ts rename to arkoala/arkui/src/generated/ArkInspectorInterfaces.ts index b8e37c8e5..a9e69bb1f 100644 --- a/arkoala-arkts/arkui/src/generated/Events.ts +++ b/arkoala/arkui/src/generated/ArkInspectorInterfaces.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * 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 @@ -13,11 +13,12 @@ * limitations under the License. */ -export function checkEvents() { - customEventsChecker() -} -let customEventsChecker = () => {} -export function setCustomEventsChecker(eventsChecker: () => void) { - customEventsChecker = eventsChecker -} +// WARNING! THIS FILE IS AUTO-GENERATED, DO NOT MAKE CHANGES, THEY WILL BE LOST ON NEXT GENERATION! + +import { int32, int64, float32 } from "@koalaui/common" +import { KInt, KPointer, KBoolean, KStringPtr, wrapCallback } from "@koalaui/interop" +import { NodeAttach, remember } from "@koalaui/runtime" +declare function getInspectorNodes(): Object +declare function getInspectorNodeById(arg0: number): Object +declare function setAppBgColor(arg0: string): void diff --git a/arkoala/framework/native/src/generated/arkoala_api_generated.h b/arkoala/framework/native/src/generated/arkoala_api_generated.h index 579261b2b..e085de495 100644 --- a/arkoala/framework/native/src/generated/arkoala_api_generated.h +++ b/arkoala/framework/native/src/generated/arkoala_api_generated.h @@ -156,7 +156,7 @@ typedef struct InteropBuffer { // The only include allowed in this file! Do not add anything else ever. #include -#define GENERATED_ARKUI_FULL_API_VERSION 119 +#define GENERATED_ARKUI_FULL_API_VERSION 120 #define GENERATED_ARKUI_NODE_API_VERSION GENERATED_ARKUI_FULL_API_VERSION #define GENERATED_ARKUI_BASIC_NODE_API_VERSION 1 diff --git a/arkoala/tools/peer-generator/package.json b/arkoala/tools/peer-generator/package.json index bdd8cc3cf..c1e11ffa4 100644 --- a/arkoala/tools/peer-generator/package.json +++ b/arkoala/tools/peer-generator/package.json @@ -2,8 +2,8 @@ "name": "peer-generator", "description": "", "config": { - "idlize_version": "2.0.31", - "api_version": "119", + "idlize_version": "2.0.32", + "api_version": "120", "input_dir": "../../arkui-common/interface_sdk-js/api/@internal/component/ets/,../../arkui-common/interface_sdk-js/api/global" }, "scripts": { -- Gitee From 702251a0166b68689808e84b342d5edc607c44b3 Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Wed, 19 Feb 2025 21:11:56 +0300 Subject: [PATCH 2/2] Fix --- .../arkui/src/generated/CallbackRegistry.ts | 90 +++++++++++++++++++ arkoala-arkts/arkui/src/generated/Events.ts | 23 +++++ .../generated/peers/CallbackTransformer.ts | 53 +++++++++++ 3 files changed, 166 insertions(+) create mode 100644 arkoala-arkts/arkui/src/generated/CallbackRegistry.ts create mode 100644 arkoala-arkts/arkui/src/generated/Events.ts create mode 100644 arkoala-arkts/arkui/src/generated/peers/CallbackTransformer.ts diff --git a/arkoala-arkts/arkui/src/generated/CallbackRegistry.ts b/arkoala-arkts/arkui/src/generated/CallbackRegistry.ts new file mode 100644 index 000000000..07fb8f45d --- /dev/null +++ b/arkoala-arkts/arkui/src/generated/CallbackRegistry.ts @@ -0,0 +1,90 @@ +/* + * 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. + */ + +import { int32 } from "@koalaui/common" +import { KUint8ArrayPtr } from "@koalaui/interop" + +// todo: do we need an Uint8Array version? +export type CallbackType = (args: KUint8ArrayPtr, length: int32) => int32 + +class CallbackRecord { + public callback: CallbackType + public autoDisposable: boolean + + constructor(callback: CallbackType, autoDisposable: boolean) { + this.callback = callback + this.autoDisposable = autoDisposable + } +} + +class CallbackRegistry { + + static INSTANCE = new CallbackRegistry() + + private callbacks = new Map() + private id = 1024 + + constructor() { + this.callbacks.set(0, new CallbackRecord( + (args: KUint8ArrayPtr, length: int32): int32 => { + // console.log(`Callback 0 called with args = ${args} and length = ${length}`) + throw new Error(`Null callback called`) + }, false) + ) + } + + wrap(callback: CallbackType, autoDisposable: boolean): int32 { + const id = this.id++ + this.callbacks.set(id, new CallbackRecord(callback, autoDisposable)) + return id + } + + wrapSystem(id: int32, callback: CallbackType, autoDisposable: boolean): int32 { + this.callbacks.set(id, new CallbackRecord(callback, autoDisposable)) + return id + } + + call(id: int32, args: KUint8ArrayPtr, length: int32): int32 { + if (!this.callbacks.has(id)) { + // console.log(`Callback ${id} is not known`) + throw new Error(`Disposed or unwrapped callback called (id = ${id})`) + } + const record = this.callbacks.get(id)! + if (record.autoDisposable) { + this.dispose(id) + } + return record.callback(args, length) + } + + dispose(id: int32) { + this.callbacks.delete(id) + } +} + +export function wrapCallback(callback: CallbackType, autoDisposable: boolean = true): int32 { + return CallbackRegistry.INSTANCE.wrap(callback, autoDisposable) +} + +export function disposeCallback(id: int32) { + CallbackRegistry.INSTANCE.dispose(id) +} + +export function wrapSystemCallback(id:int32, callback: CallbackType): int32 { + return CallbackRegistry.INSTANCE.wrapSystem(id, callback, false) +} + +export function callCallback(id: int32, args: KUint8ArrayPtr, length: int32): int32 { + return CallbackRegistry.INSTANCE.call(id, args, length) +} diff --git a/arkoala-arkts/arkui/src/generated/Events.ts b/arkoala-arkts/arkui/src/generated/Events.ts new file mode 100644 index 000000000..b8e37c8e5 --- /dev/null +++ b/arkoala-arkts/arkui/src/generated/Events.ts @@ -0,0 +1,23 @@ +/* + * 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. + */ + +export function checkEvents() { + customEventsChecker() +} + +let customEventsChecker = () => {} +export function setCustomEventsChecker(eventsChecker: () => void) { + customEventsChecker = eventsChecker +} diff --git a/arkoala-arkts/arkui/src/generated/peers/CallbackTransformer.ts b/arkoala-arkts/arkui/src/generated/peers/CallbackTransformer.ts new file mode 100644 index 000000000..344a26bcf --- /dev/null +++ b/arkoala-arkts/arkui/src/generated/peers/CallbackTransformer.ts @@ -0,0 +1,53 @@ +/* + * 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. + */ + +import { KPointer } from "@koalaui/interop" +import { PeerNode } from "../../PeerNode" +import { CustomBuilder } from "../ArkCommonInterfaces" +import { CustomNodeBuilder } from "../ArkCustomBuilderInterfaces" +import { ArkComponentRootPeer } from "./ArkStaticComponentsPeer" + +// TODO need invert dependency: createUiDetachedRoot should be imported from @koalaui/arkoala same as in TS +export type UIDetachedRootCreator = ( + peerFactory: () => PeerNode, + /** @memo */ + builder: () => void +) => PeerNode +let createUiDetachedRoot: UIDetachedRootCreator = ( + factory: () => PeerNode, + /** @memo */ + builder: () => void +): PeerNode => { + throw new Error("Not implemented") +} +export function setUIDetachedRootCreator(creator: UIDetachedRootCreator): void { + createUiDetachedRoot = creator +} + +function componentRootPeerFactory(): PeerNode { + return ArkComponentRootPeer.create() +} + +export class CallbackTransformer { + static transformFromCustomBuilder(value: CustomBuilder): CustomNodeBuilder { + return (parentNodeId: KPointer): KPointer => { + const peer = createUiDetachedRoot(componentRootPeerFactory, value) + return peer.peer.ptr + } + } + static transformToCustomBuilder(value: CustomNodeBuilder): CustomBuilder { + throw new Error("Not implemented") + } +} \ No newline at end of file -- Gitee