• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 
16 #ifndef INTEROP_TYPES_H_
17 #define INTEROP_TYPES_H_
18 
19 #include <cstdint>
20 
21 // NOLINTBEGIN
22 
23 typedef enum InteropTag {
24     INTEROP_TAG_UNDEFINED = 101,
25     INTEROP_TAG_INT32 = 102,
26     INTEROP_TAG_FLOAT32 = 103,
27     INTEROP_TAG_STRING = 104,
28     INTEROP_TAG_LENGTH = 105,
29     INTEROP_TAG_RESOURCE = 106,
30     INTEROP_TAG_OBJECT = 107,
31 } InteropTag;
32 
33 typedef enum InteropRuntimeType {
34     INTEROP_RUNTIME_UNEXPECTED = -1,
35     INTEROP_RUNTIME_NUMBER = 1,
36     INTEROP_RUNTIME_STRING = 2,
37     INTEROP_RUNTIME_OBJECT = 3,
38     INTEROP_RUNTIME_BOOLEAN = 4,
39     INTEROP_RUNTIME_UNDEFINED = 5,
40     INTEROP_RUNTIME_BIGINT = 6,
41     INTEROP_RUNTIME_FUNCTION = 7,
42     INTEROP_RUNTIME_SYMBOL = 8,
43     INTEROP_RUNTIME_MATERIALIZED = 9,
44 } InteropRuntimeType;
45 
46 typedef float InteropFloat32;
47 typedef double InteropFloat64;
48 typedef int32_t InteropInt32;
49 typedef unsigned int InteropUInt32;
50 typedef int64_t InteropInt64;
51 typedef int8_t InteropInt8;
52 typedef uint8_t InteropUInt8;
53 typedef int64_t InteropDate;
54 typedef int8_t InteropBoolean;
55 typedef const char *InteropCharPtr;
56 typedef void *InteropNativePointer;
57 
58 struct InteropVMContextRaw;
59 typedef struct InteropVMContextRaw *InteropVMContext;
60 struct InteropPipelineContextRaw;
61 typedef struct InteropPipelineContextRaw *InteropPipelineContext;
62 struct InteropVMObjectRaw;
63 typedef struct InteropVMObjectRaw *InteropVMObject;
64 struct InteropNode;
65 typedef struct InteropNode *InteropNodeHandle;
66 typedef struct InteropDeferred {
67     void *handler;
68     void *context;
69     void (*resolve)(struct InteropDeferred *thiz, uint8_t *data, int32_t length);
70     void (*reject)(struct InteropDeferred *thiz, const char *message);
71 } InteropDeferred;
72 
73 // Binary layout of InteropString must match that of KStringPtrImpl.
74 typedef struct InteropString {
75     const char *chars;
76     InteropInt32 length;
77 } InteropString;
78 
79 typedef struct InteropEmpty {
80     InteropInt32 dummy;  // Empty structs are forbidden in C.
81 } InteropEmpty;
82 
83 typedef struct InteropNumber {
84     InteropInt8 tag;
85     union {
86         InteropFloat32 f32;
87         InteropInt32 i32;
88     };
89 } InteropNumber;
90 
91 // Binary layout of InteropLength must match that of KLength.
92 typedef struct InteropLength {
93     InteropInt8 type;
94     InteropFloat32 value;
95     InteropInt32 unit;
96     InteropInt32 resource;
97 } InteropLength;
98 
99 typedef struct InteropCustomObject {
100     char kind[20];
101     InteropInt32 id;
102     // Data of custom object.
103     union {
104         InteropInt32 ints[4];
105         InteropFloat32 floats[4];
106         void *pointers[4];
107         InteropString string;
108     };
109 } InteropCustomObject;
110 
111 typedef struct InteropUndefined {
112     InteropInt32 dummy;  // Empty structs are forbidden in C.
113 } InteropUndefined;
114 
115 typedef struct InteropVoid {
116     InteropInt32 dummy;  // Empty structs are forbidden in C.
117 } InteropVoid;
118 
119 typedef struct InteropFunction {
120     InteropInt32 id;
121 } InteropFunction;
122 typedef InteropFunction InteropCallback;
123 typedef InteropFunction InteropErrorCallback;
124 
125 typedef struct InteropMaterialized {
126     InteropNativePointer ptr;
127 } InteropMaterialized;
128 
129 typedef struct InteropCallbackResource {
130     InteropInt32 resourceId;
131     void (*hold)(InteropInt32 resourceId);
132     void (*release)(InteropInt32 resourceId);
133 } InteropCallbackResource;
134 
135 typedef struct InteropBuffer {
136     InteropCallbackResource resource;
137     InteropNativePointer data;
138     InteropInt64 length;
139 } InteropBuffer;
140 
141 // NOLINTEND
142 
143 #endif  // INTEROP_TYPES_H_
144