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