• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024-2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16package Interop
17
18import std.collection.*
19
20foreign {
21        func CheckCallbackEvent(buffer: CPointer<UInt8>, bufferLength: Int32): Int32
22
23        func GetGroupedLog(index: Int32): UInt64
24        func StartGroupedLog(index: Int32): Unit
25        func StopGroupedLog(index: Int32): Unit
26        func AppendGroupedLog(index: Int32, message: CString): Unit
27        func PrintGroupedLog(index: Int32): Unit
28        func GetStringFinalizer(): UInt64
29        func InvokeFinalizer(ptr1: UInt64, ptr2: UInt64): Unit
30        func GetPtrVectorElement(ptr1: UInt64, arg: Int32): UInt64
31        func StringLength(ptr1: UInt64): Int32
32        func StringData(ptr1: UInt64, arr: CPointer<UInt8>, i: Int32): Unit
33        func StringMake(str1: CString): UInt64
34        func GetPtrVectorSize(ptr1: UInt64): Int32
35        func ManagedStringWrite(str1: CString, arr: CPointer<UInt8>, arg: Int32): Int32
36        func NativeLog(str1: CString): Unit
37        func Utf8ToString(data: CPointer<UInt8>, offset: Int32, length: Int32): CString
38        func StdStringToString(cstring: UInt64): CString
39        func CallCallback(callbackKind: Int32, args: CPointer<UInt8>, argsSize: Int32): Unit
40        func CallCallbackSync(callbackKind: Int32, args: CPointer<UInt8>, argsSize: Int32): Unit
41        func CallCallbackResourceHolder(holder: UInt64, resourceId: Int32): Unit
42        func CallCallbackResourceReleaser(releaser: UInt64, resourceId: Int32): Unit
43        func LoadVirtualMachine(arg0: Int32, arg1: CString, arg2: CString): Int32
44        func RunApplication(arg0: Int32, arg1: Int32): Bool
45        func StartApplication(appUrl: CString, appParams: CString): UInt64
46        func EmitEvent(eventType: Int32, target: Int32, arg0: Int32, arg1: Int32): Unit
47}
48
49public open class InteropNativeModule {
50    public static func _CheckCallbackEvent(buffer: Array<UInt8>, bufferLength: Int32): Int32 {
51        unsafe {
52            let handle_0 = acquireArrayRawData(buffer)
53            let result = CheckCallbackEvent(handle_0.pointer, bufferLength)
54            releaseArrayRawData(handle_0);
55            return result
56        }
57    }
58    public static func _GetGroupedLog(index: Int32): UInt64 {
59        unsafe {
60            let result = GetGroupedLog(index)
61            return result
62        }
63    }
64    public static func _StartGroupedLog(index: Int32): Unit {
65        unsafe {
66            StartGroupedLog(index)
67        }
68    }
69    public static func _StopGroupedLog(index: Int32): Unit {
70        unsafe {
71            StopGroupedLog(index)
72        }
73    }
74    public static func _AppendGroupedLog(index: Int32, message: String): Unit {
75        unsafe {
76            let message =  LibC.mallocCString(message)
77            AppendGroupedLog(index, message)
78            LibC.free(message)
79        }
80    }
81    public static func _PrintGroupedLog(index: Int32): Unit {
82        unsafe {
83            PrintGroupedLog(index)
84        }
85    }
86    public static func _GetStringFinalizer(): UInt64 {
87        unsafe {
88            let result = GetStringFinalizer()
89            return result
90        }
91    }
92    public static func _InvokeFinalizer(ptr1: UInt64, ptr2: UInt64): Unit {
93        unsafe {
94            InvokeFinalizer(ptr1, ptr2)
95        }
96    }
97    public static func _GetPtrVectorElement(ptr1: UInt64, arg: Int32): UInt64 {
98        unsafe {
99            let result = GetPtrVectorElement(ptr1, arg)
100            return result
101        }
102    }
103    public static func _StringLength(ptr1: UInt64): Int32 {
104        unsafe {
105            let result = StringLength(ptr1)
106            return result
107        }
108    }
109    public static func _StringData(ptr1: UInt64, arr: ArrayList<UInt8>, i: Int32): Unit {
110        unsafe {
111            let handle_1 = acquireArrayRawData(arr.toArray())
112            StringData(ptr1, handle_1.pointer, i)
113            releaseArrayRawData(handle_1)
114        }
115    }
116    public static func _StringMake(str1: String): UInt64 {
117        unsafe {
118            let str1 =  LibC.mallocCString(str1)
119            let result = StringMake(str1)
120            LibC.free(str1)
121            return result
122        }
123    }
124    public static func _GetPtrVectorSize(ptr1: UInt64): Int32 {
125        unsafe {
126            let result = GetPtrVectorSize(ptr1)
127            return result
128        }
129    }
130    public static func _ManagedStringWrite(str1: String, arr: ArrayList<UInt8>, arg: Int32): Int32 {
131        unsafe {
132            let str1 =  LibC.mallocCString(str1)
133            let handle_1 = acquireArrayRawData(arr.toArray())
134            let result = ManagedStringWrite(str1, handle_1.pointer, arg)
135            LibC.free(str1)
136            releaseArrayRawData(handle_1)
137            return result
138        }
139    }
140    public static func _NativeLog(str1: String): Unit {
141        unsafe {
142            let str1 =  LibC.mallocCString(str1)
143            NativeLog(str1)
144            LibC.free(str1)
145        }
146    }
147    public static func _Utf8ToString(data: Array<UInt8>, offset: Int32, length: Int32): String {
148        unsafe {
149            let handle_0 = acquireArrayRawData(data)
150            let result = Utf8ToString(handle_0.pointer, offset, length)
151            releaseArrayRawData(handle_0)
152            return result.toString()
153        }
154    }
155    public static func _StdStringToString(cstring: UInt64): String {
156        unsafe {
157            let result = StdStringToString(cstring)
158            return result.toString()
159        }
160    }
161    public static func _CallCallback(callbackKind: Int32, args: ArrayList<UInt8>, argsSize: Int32): Unit {
162        unsafe {
163            let handle_1 = acquireArrayRawData(args.toArray())
164            CallCallback(callbackKind, handle_1.pointer, argsSize)
165            releaseArrayRawData(handle_1)
166        }
167    }
168    public static func _CallCallbackSync(callbackKind: Int32, args: ArrayList<UInt8>, argsSize: Int32): Unit {
169        unsafe {
170            let handle_1 = acquireArrayRawData(args.toArray())
171            CallCallbackSync(callbackKind, handle_1.pointer, argsSize)
172            releaseArrayRawData(handle_1)
173        }
174    }
175    public static func _CallCallbackResourceHolder(holder: UInt64, resourceId: Int32): Unit {
176        unsafe {
177            CallCallbackResourceHolder(holder, resourceId)
178        }
179    }
180    public static func _CallCallbackResourceReleaser(releaser: UInt64, resourceId: Int32): Unit {
181        unsafe {
182            CallCallbackResourceReleaser(releaser, resourceId)
183        }
184    }
185    public static func _LoadVirtualMachine(arg0: Int32, arg1: String, arg2: String): Int32 {
186        unsafe {
187            let arg1 =  LibC.mallocCString(arg1)
188            let arg2 =  LibC.mallocCString(arg2)
189            let result = LoadVirtualMachine(arg0, arg1, arg2)
190            LibC.free(arg1)
191            LibC.free(arg1)
192            return result
193        }
194    }
195    public static func _RunApplication(arg0: Int32, arg1: Int32): Bool {
196        unsafe {
197            let result = RunApplication(arg0, arg1)
198            return result
199        }
200    }
201    public static func _StartApplication(appUrl: String, appParams: String): UInt64 {
202        unsafe {
203            let appUrl =  LibC.mallocCString(appUrl)
204            let appParams =  LibC.mallocCString(appParams)
205            let result = StartApplication(appUrl, appParams)
206            LibC.free(appUrl)
207            LibC.free(appUrl)
208            return result
209        }
210    }
211    public static func _EmitEvent(eventType: Int32, target: Int32, arg0: Int32, arg1: Int32): Unit {
212        unsafe {
213            EmitEvent(eventType, target, arg0, arg1)
214        }
215    }
216    public static func _StringData(ptr: KPointer, data: Array<UInt8>, arg2: Int32): Unit {
217        unsafe {
218            let handle_1 = acquireArrayRawData(data)
219            StringData(ptr, handle_1.pointer, arg2)
220            releaseArrayRawData(handle_1)
221        }
222    }
223}