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 MYAPPLICATION_NATIVEMODULE_H 17 #define MYAPPLICATION_NATIVEMODULE_H 18 19 #include <arkui/native_node.h> 20 #include <arkui/native_interface.h> 21 #include <cassert> 22 23 namespace NativeModule { 24 25 class NativeModuleInstance { 26 public: GetInstance()27 static NativeModuleInstance *GetInstance() 28 { 29 static NativeModuleInstance instance; 30 return &instance; 31 } 32 NativeModuleInstance()33 NativeModuleInstance() 34 { 35 // 获取Native接口的函数指针结构体对象,用于后续操作。 36 OH_ArkUI_GetModuleInterface(ARKUI_MULTI_THREAD_NATIVE_NODE, ArkUI_NativeNodeAPI_1, arkUINativeNodeApi_); 37 } 38 // 暴露给其他模块使用。 GetNativeNodeAPI()39 ArkUI_NativeNodeAPI_1 *GetNativeNodeAPI() 40 { 41 return arkUINativeNodeApi_; 42 } 43 44 private: 45 ArkUI_NativeNodeAPI_1 *arkUINativeNodeApi_ = nullptr; 46 }; 47 48 } // namespace NativeModule 49 50 #endif // MYAPPLICATION_NATIVEMODULE_H 51