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