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 COMMON_INTEROP_BASE_H 17 #define COMMON_INTEROP_BASE_H 18 19 #include <vector> 20 21 #include "koala-types.h" 22 23 #define KOALA_INTEROP_PROFILER 0 24 #define KOALA_INTEROP_TRACER 0 25 26 #if KOALA_INTEROP_PROFILER 27 #include "profiler.h" 28 #define KOALA_INTEROP_LOGGER(name) InteropMethodCall logger(#name); 29 #endif 30 31 #if KOALA_INTEROP_TRACER 32 #include "tracer.h" 33 #define KOALA_INTEROP_LOGGER(name) InteropMethodCall logger(#name); 34 #endif 35 36 37 #ifdef KOALA_INTEROP_LOGGER 38 #define KOALA_MAYBE_LOG(name) KOALA_INTEROP_LOGGER(name); 39 #else 40 #define KOALA_MAYBE_LOG(name) 41 #endif 42 43 typedef void (*Callback_Caller_t)(KInt callbackKind, KByte* argsData, KInt argsLength); 44 typedef void (*Callback_Caller_Sync_t)(KVMContext vmContext, KInt callbackKind, KByte* argsData, KInt argsLength); 45 void setCallbackCaller(Callback_Caller_t caller); 46 void setCallbackCallerSync(Callback_Caller_Sync_t callerSync); 47 48 KVMDeferred* CreateDeferred(KVMContext context, KVMObjectHandle* promise); 49 50 std::vector<KStringPtr> makeStringVector(KStringArray strArray); 51 std::vector<KStringPtr> makeStringVector(KNativePointerArray arr, KInt size); 52 53 #if KOALA_USE_NODE_VM || KOALA_USE_HZ_VM 54 #include "convertors-napi.h" 55 #elif KOALA_USE_JSC_VM 56 #include "convertors-jsc.h" 57 #elif KOALA_ETS_NAPI 58 #include "convertors-ets.h" 59 #elif KOALA_USE_JAVA_VM 60 #include "convertors-jni.h" 61 #elif KOALA_WASM 62 #include "convertors-wasm.h" 63 #elif KOALA_CJ 64 #include "convertors-cj.h" 65 #elif KOALA_ANI 66 #include "convertors-ani.h" 67 #else 68 #error "One of above branches must be taken" 69 #endif 70 71 #endif // COMMON_INTEROP_BASE_H 72