From 6ea5293e94ae7b1c72ee5302aab25ebc542be241 Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Mon, 27 Jan 2025 17:49:50 +0300 Subject: [PATCH 1/3] Fix build Signed-off-by: Nikolay Igotti --- arkoala-arkts/arkui/src/LazyForEach.ts | 8 +-- .../src/generated/peers/ArkCommonPeer.ts | 2 + .../src/generated/peers/CallbacksChecker.ts | 8 +-- .../native/src/generated/bridge_generated.cc | 1 + interop/src/arkts/DeserializerBase.sts | 53 ++++++++++--------- interop/src/arkts/SerializerBase.sts | 4 +- interop/src/interop/SerializerBase.ts | 11 ++-- 7 files changed, 47 insertions(+), 40 deletions(-) diff --git a/arkoala-arkts/arkui/src/LazyForEach.ts b/arkoala-arkts/arkui/src/LazyForEach.ts index 9488d4fb9..699e72ee9 100644 --- a/arkoala-arkts/arkui/src/LazyForEach.ts +++ b/arkoala-arkts/arkui/src/LazyForEach.ts @@ -52,9 +52,9 @@ class LazyForEachManager { static isDummy: boolean = false // Special pointer to mark that more elements needed. static specialPointer: pointer = 1 - static OnRangeUpdate(parent: pointer, totalCount: int32, updater: (currentIndex: int32, currentMark: pointer) => void) { + static OnRangeUpdate(parent: pointer, totalCount: int32, updater: (currentIndex: int32, currentMark: pointer, end: int32) => void) { if (LazyForEachManager.isDummy) - scheduleCallback(() => updater(0, LazyForEachManager.specialPointer)) + scheduleCallback(() => updater(0, LazyForEachManager.specialPointer, 100)) else LazyForEachOps.OnRangeUpdate(parent, totalCount, updater) } @@ -118,8 +118,8 @@ export function LazyForEach(dataSource: IDataSource, let parent = contextNode() const visibleRange = new VisibleRange(parent, current.value, current.value) remember(() => { - LazyForEachManager.OnRangeUpdate(visibleRange.parent, dataSource.totalCount() as int32, (currentIndex: int32, currentMark: pointer) => { - console.log(`LazyForEach[${parent}]: current updated to ${currentIndex} ${currentMark}`) + LazyForEachManager.OnRangeUpdate(visibleRange.parent, dataSource.totalCount() as int32, (currentIndex: int32, currentMark: pointer, end: int32) => { + console.log(`LazyForEach[${parent}]: current updated to ${currentIndex} ${currentMark} end=${end}`) current.value = currentIndex mark.value = currentMark version.value++ diff --git a/arkoala-arkts/arkui/src/generated/peers/ArkCommonPeer.ts b/arkoala-arkts/arkui/src/generated/peers/ArkCommonPeer.ts index 0c811f5b1..e43feee06 100644 --- a/arkoala-arkts/arkui/src/generated/peers/ArkCommonPeer.ts +++ b/arkoala-arkts/arkui/src/generated/peers/ArkCommonPeer.ts @@ -341,6 +341,7 @@ export class ArkCommonMethodPeer extends PeerNode { const thisSerializer : Serializer = Serializer.hold() let value_type : int32 = RuntimeType.UNDEFINED value_type = runtimeType(value) + console.log(`backgroundColorAttribute v=${value} t=${value_type}`) if (TypeChecker.isColor(value)) { thisSerializer.writeInt8(0 as int32) const value_0 = value as Color @@ -361,6 +362,7 @@ export class ArkCommonMethodPeer extends PeerNode { const value_3 = value as Resource thisSerializer.writeResource(value_3) } + console.log(`total ${thisSerializer.length()}`) ArkUIGeneratedNativeModule._CommonMethod_backgroundColor(this.peer.ptr, thisSerializer.asArray(), thisSerializer.length()) thisSerializer.release() } diff --git a/arkoala-arkts/arkui/src/generated/peers/CallbacksChecker.ts b/arkoala-arkts/arkui/src/generated/peers/CallbacksChecker.ts index eeb2df1b7..2a3abb241 100644 --- a/arkoala-arkts/arkui/src/generated/peers/CallbacksChecker.ts +++ b/arkoala-arkts/arkui/src/generated/peers/CallbacksChecker.ts @@ -13,7 +13,7 @@ * limitations under the License. */ -import { KBuffer } from "@koalaui/interop" +import { InteropNativeModule, KBuffer } from "@koalaui/interop" import { Deserializer } from "./Deserializer"; import { deserializeAndCallCallback } from "./CallbackDeserializeCall" import { ResourceHolder, KUint8ArrayPtr } from "@koalaui/interop" @@ -31,7 +31,7 @@ const deserializer = new Deserializer(buffer.buffer, bufferSize) export function checkArkoalaCallbacks() { while (true) { deserializer.resetCurrentPosition() - let result = ArkUINativeModule._CheckCallbackEvent(buffer.buffer, bufferSize) + let result = InteropNativeModule._CheckCallbackEvent(buffer.buffer, bufferSize) if (result == 0) break const eventKind = deserializer.readInt32() as CallbackEventKind @@ -39,12 +39,12 @@ export function checkArkoalaCallbacks() { 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) diff --git a/arkoala/framework/native/src/generated/bridge_generated.cc b/arkoala/framework/native/src/generated/bridge_generated.cc index c0717c777..836dca408 100644 --- a/arkoala/framework/native/src/generated/bridge_generated.cc +++ b/arkoala/framework/native/src/generated/bridge_generated.cc @@ -1683,6 +1683,7 @@ void impl_CommonMethod_margin(Ark_NativePointer thisPtr, uint8_t* thisArray, int } KOALA_INTEROP_V3(CommonMethod_margin, Ark_NativePointer, uint8_t*, int32_t) void impl_CommonMethod_backgroundColor(Ark_NativePointer thisPtr, uint8_t* thisArray, int32_t thisLength) { + fprintf(stderr, "impl_CommonMethod_backgroundColor len=%d\n", thisLength); Ark_NodeHandle self = reinterpret_cast(thisPtr); Deserializer thisDeserializer(thisArray, thisLength); const Ark_Int8 value_value_buf_selector = thisDeserializer.readInt8(); diff --git a/interop/src/arkts/DeserializerBase.sts b/interop/src/arkts/DeserializerBase.sts index e11dbab70..4f8f0f9f3 100644 --- a/interop/src/arkts/DeserializerBase.sts +++ b/interop/src/arkts/DeserializerBase.sts @@ -20,36 +20,11 @@ import { NativeBuffer } from "./NativeBuffer" import { InteropNativeModule } from "./InteropNativeModule" import { Tags, CallbackResource } from "./SerializerBase"; -export abstract class CustomDeserializer { - protected supported: string - protected constructor(supported_: string) { - this.supported = supported_ - } - - supports(kind: string): boolean { - return this.supported.includes(kind) - } - - abstract deserialize(serializer: DeserializerBase, kind: string): object - - next: CustomDeserializer | undefined = undefined -} - -class DateDeserializer extends CustomDeserializer { - constructor() { - super("Date") - } - - deserialize(serializer: DeserializerBase, kind: string): Date { - return new Date(serializer.readString()) - } -} - export class DeserializerBase { private position = 0 private readonly buffer: KBuffer private readonly length: int32 - private static customDeserializers: CustomDeserializer | undefined = new DateDeserializer() + private static customDeserializers: CustomDeserializer | undefined = undefined static registerCustomDeserializer(deserializer: CustomDeserializer) { let current = DeserializerBase.customDeserializers @@ -243,3 +218,29 @@ export class DeserializerBase { throw new Error("Not implemented") } } + +export abstract class CustomDeserializer { + protected supported: string + protected constructor(supported_: string) { + this.supported = supported_ + } + + supports(kind: string): boolean { + return this.supported.includes(kind) + } + + abstract deserialize(serializer: DeserializerBase, kind: string): object + + next: CustomDeserializer | undefined = undefined +} + +class DateDeserializer extends CustomDeserializer { + constructor() { + super("Date") + } + + deserialize(serializer: DeserializerBase, kind: string): Date { + return new Date(serializer.readString()) + } +} +DeserializerBase.registerCustomDeserializer(new DateDeserializer()) diff --git a/interop/src/arkts/SerializerBase.sts b/interop/src/arkts/SerializerBase.sts index 4bd20f756..1ef6dc9af 100644 --- a/interop/src/arkts/SerializerBase.sts +++ b/interop/src/arkts/SerializerBase.sts @@ -110,13 +110,13 @@ class DateSerializer extends CustomSerializer { serializer.writeString((value as Date).toISOString()) } } +SerializerBase.registerCustomSerializer(new DateSerializer()) export class SerializerBase { private position = 0 private buffer: KBuffer private static customSerializers: CustomSerializer | undefined = new DateSerializer() - static registerCustomSerializer(serializer: CustomSerializer) { if (SerializerBase.customSerializers == undefined) { SerializerBase.customSerializers = serializer @@ -308,6 +308,7 @@ export class SerializerBase { this.checkCapacity((4 + value.length * 4 + 1) as int32) // length, data let encodedLength = InteropNativeModule._ManagedStringWrite(value, this.asArray(), this.position + 4) this.setInt32(this.position, encodedLength) + this.position += encodedLength + 4 } //TODO: Needs to be implemented writeBuffer(value: NativeBuffer) { @@ -320,3 +321,4 @@ export class SerializerBase { this.writeInt64(value.length as int64) } } + diff --git a/interop/src/interop/SerializerBase.ts b/interop/src/interop/SerializerBase.ts index 565f6368f..2ab2a1171 100644 --- a/interop/src/interop/SerializerBase.ts +++ b/interop/src/interop/SerializerBase.ts @@ -66,10 +66,10 @@ export function runtimeType(value: any): int32 { } export function isResource(value: unknown): boolean { - return value !== undefined - && typeof value === 'object' - && value !== null - && value.hasOwnProperty("bundleName") + return value !== undefined + && typeof value === 'object' + && value !== null + && value.hasOwnProperty("bundleName") && value.hasOwnProperty("moduleName") } @@ -261,6 +261,7 @@ export class SerializerBase { this.writeInt32(registerCallback(value)) } writeString(value: string) { + if (true) throw new Error("1 " + value) this.checkCapacity(4 + value.length * 4) // length, data let encodedLength = InteropNativeModule._ManagedStringWrite(value, new Uint8Array(this.view.buffer, 0), this.position + 4) @@ -270,7 +271,7 @@ export class SerializerBase { writeBuffer(buffer: ArrayBuffer) { const resourceId = ResourceHolder.instance().registerAndHold(buffer) this.writeCallbackResource({ - resourceId, + resourceId, hold: 0, release: 0 }) -- Gitee From eb47bf1f1a6cbd78cff1258ad3c11b7d2d6e4d39 Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Mon, 27 Jan 2025 18:07:09 +0300 Subject: [PATCH 2/3] Fix typos Signed-off-by: Nikolay Igotti --- arkoala/framework/native/src/generated/bridge_generated.cc | 1 - interop/src/interop/SerializerBase.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/arkoala/framework/native/src/generated/bridge_generated.cc b/arkoala/framework/native/src/generated/bridge_generated.cc index 836dca408..c0717c777 100644 --- a/arkoala/framework/native/src/generated/bridge_generated.cc +++ b/arkoala/framework/native/src/generated/bridge_generated.cc @@ -1683,7 +1683,6 @@ void impl_CommonMethod_margin(Ark_NativePointer thisPtr, uint8_t* thisArray, int } KOALA_INTEROP_V3(CommonMethod_margin, Ark_NativePointer, uint8_t*, int32_t) void impl_CommonMethod_backgroundColor(Ark_NativePointer thisPtr, uint8_t* thisArray, int32_t thisLength) { - fprintf(stderr, "impl_CommonMethod_backgroundColor len=%d\n", thisLength); Ark_NodeHandle self = reinterpret_cast(thisPtr); Deserializer thisDeserializer(thisArray, thisLength); const Ark_Int8 value_value_buf_selector = thisDeserializer.readInt8(); diff --git a/interop/src/interop/SerializerBase.ts b/interop/src/interop/SerializerBase.ts index 2ab2a1171..cfd0af659 100644 --- a/interop/src/interop/SerializerBase.ts +++ b/interop/src/interop/SerializerBase.ts @@ -261,7 +261,6 @@ export class SerializerBase { this.writeInt32(registerCallback(value)) } writeString(value: string) { - if (true) throw new Error("1 " + value) this.checkCapacity(4 + value.length * 4) // length, data let encodedLength = InteropNativeModule._ManagedStringWrite(value, new Uint8Array(this.view.buffer, 0), this.position + 4) -- Gitee From 05d8c3cb349e48a609db6ed36e1667ed2b353c36 Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Mon, 27 Jan 2025 18:08:29 +0300 Subject: [PATCH 3/3] Remove log Signed-off-by: Nikolay Igotti --- arkoala-arkts/arkui/src/generated/peers/ArkCommonPeer.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/arkoala-arkts/arkui/src/generated/peers/ArkCommonPeer.ts b/arkoala-arkts/arkui/src/generated/peers/ArkCommonPeer.ts index e43feee06..0c811f5b1 100644 --- a/arkoala-arkts/arkui/src/generated/peers/ArkCommonPeer.ts +++ b/arkoala-arkts/arkui/src/generated/peers/ArkCommonPeer.ts @@ -341,7 +341,6 @@ export class ArkCommonMethodPeer extends PeerNode { const thisSerializer : Serializer = Serializer.hold() let value_type : int32 = RuntimeType.UNDEFINED value_type = runtimeType(value) - console.log(`backgroundColorAttribute v=${value} t=${value_type}`) if (TypeChecker.isColor(value)) { thisSerializer.writeInt8(0 as int32) const value_0 = value as Color @@ -362,7 +361,6 @@ export class ArkCommonMethodPeer extends PeerNode { const value_3 = value as Resource thisSerializer.writeResource(value_3) } - console.log(`total ${thisSerializer.length()}`) ArkUIGeneratedNativeModule._CommonMethod_backgroundColor(this.peer.ptr, thisSerializer.asArray(), thisSerializer.length()) thisSerializer.release() } -- Gitee