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 16import * as fs from 'fs'; 17import * as path from 'path'; 18import { KNativePointer as KPtr, KInt, KUInt } from './InteropTypes'; 19import { loadNativeModuleLibrary, registerNativeModuleLibraryName } from './loadLibraries'; 20import { throwError } from './utils'; 21 22export class InteropNativeModule { 23 _StringLength(ptr: KPtr): KInt { 24 throw new Error('Not implemented'); 25 } 26 27 _StringData(ptr: KPtr, buffer: KPtr, length: KInt): void { 28 throw new Error('Not implemented'); 29 } 30 31 _GetStringFinalizer(): KPtr { 32 throw new Error('Not implemented'); 33 } 34 35 _InvokeFinalizer(ptr: KPtr, finalizer: KPtr): void { 36 throw new Error('Not implemented'); 37 } 38 39 _GetPtrVectorSize(ptr: KPtr): KInt { 40 throw new Error('Not implemented'); 41 } 42 43 _GetPtrVectorElement(ptr: KPtr, index: KInt): KPtr { 44 throw new Error('Not implemented'); 45 } 46 47 _getTypeOfVariant(ptr: KPtr): KInt { 48 throw new Error('Not implemented'); 49 } 50 51 _getIntFromVariant(ptr: KPtr): KInt { 52 throw new Error('Not implemented'); 53 } 54 55 _getStringFromVariant(ptr: KPtr): KPtr { 56 throw new Error('Not implemented'); 57 } 58} 59 60export function initInterop(): InteropNativeModule { 61 let libPath = process.env.BINDINGS_PATH; 62 if (libPath === undefined) { 63 libPath = path.resolve(__dirname, '../ts_bindings.node'); 64 } else { 65 libPath = path.join(libPath, 'ts_bindings.node'); 66 } 67 if (!fs.existsSync(libPath)) { 68 throwError(`Cannot find lib path ${libPath}`); 69 } 70 registerNativeModuleLibraryName('InteropNativeModule', libPath); 71 const instance = new InteropNativeModule(); 72 loadNativeModuleLibrary('InteropNativeModule', instance); 73 return instance; 74} 75 76export function initPublicInterop(): InteropNativeModule { 77 let libPath = process.env.BINDINGS_PATH; 78 if (libPath === undefined) { 79 libPath = path.resolve(__dirname, '../public.node'); 80 } else { 81 libPath = path.join(libPath, 'public.node'); 82 } 83 if (!fs.existsSync(libPath)) { 84 throwError(`Cannot find lib path ${libPath}`); 85 } 86 registerNativeModuleLibraryName('InteropNativeModule', libPath); 87 const instance = new InteropNativeModule(); 88 loadNativeModuleLibrary('InteropNativeModule', instance); 89 return instance; 90} 91