123b3eb3cSopenharmony_ci/*
223b3eb3cSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
323b3eb3cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
423b3eb3cSopenharmony_ci * you may not use this file except in compliance with the License.
523b3eb3cSopenharmony_ci * You may obtain a copy of the License at
623b3eb3cSopenharmony_ci *
723b3eb3cSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
823b3eb3cSopenharmony_ci *
923b3eb3cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1023b3eb3cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1123b3eb3cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1223b3eb3cSopenharmony_ci * See the License for the specific language governing permissions and
1323b3eb3cSopenharmony_ci * limitations under the License.
1423b3eb3cSopenharmony_ci */
1523b3eb3cSopenharmony_ci
1623b3eb3cSopenharmony_ci/**
1723b3eb3cSopenharmony_ci * @addtogroup ArkUI_NativeModule
1823b3eb3cSopenharmony_ci * @{
1923b3eb3cSopenharmony_ci *
2023b3eb3cSopenharmony_ci * @brief Provides UI capabilities of ArkUI on the native side, such as UI component creation and destruction,
2123b3eb3cSopenharmony_ci * tree node operations, attribute setting, and event listening.
2223b3eb3cSopenharmony_ci *
2323b3eb3cSopenharmony_ci * @since 12
2423b3eb3cSopenharmony_ci */
2523b3eb3cSopenharmony_ci
2623b3eb3cSopenharmony_ci/**
2723b3eb3cSopenharmony_ci * @file native_interface.h
2823b3eb3cSopenharmony_ci *
2923b3eb3cSopenharmony_ci * @brief Provides a unified entry for the native module APIs.
3023b3eb3cSopenharmony_ci *
3123b3eb3cSopenharmony_ci * @library libace_ndk.z.so
3223b3eb3cSopenharmony_ci * @syscap SystemCapability.ArkUI.ArkUI.Full
3323b3eb3cSopenharmony_ci * @since 12
3423b3eb3cSopenharmony_ci */
3523b3eb3cSopenharmony_ci
3623b3eb3cSopenharmony_ci#ifndef ARKUI_NATIVE_INTERFACE_H
3723b3eb3cSopenharmony_ci#define ARKUI_NATIVE_INTERFACE_H
3823b3eb3cSopenharmony_ci
3923b3eb3cSopenharmony_ci#include <stdint.h>
4023b3eb3cSopenharmony_ci
4123b3eb3cSopenharmony_ci#ifdef __cplusplus
4223b3eb3cSopenharmony_ciextern "C" {
4323b3eb3cSopenharmony_ci#endif
4423b3eb3cSopenharmony_ci
4523b3eb3cSopenharmony_ci/**
4623b3eb3cSopenharmony_ci * @brief Defines the native API types.
4723b3eb3cSopenharmony_ci *
4823b3eb3cSopenharmony_ci * @since 12
4923b3eb3cSopenharmony_ci */
5023b3eb3cSopenharmony_citypedef enum {
5123b3eb3cSopenharmony_ci    /** API related to UI components. For details, see the struct definition in <arkui/native_node.h>. */
5223b3eb3cSopenharmony_ci    ARKUI_NATIVE_NODE,
5323b3eb3cSopenharmony_ci    /** API related to dialog boxes. For details, see the struct definition in <arkui/native_dialog.h>. */
5423b3eb3cSopenharmony_ci    ARKUI_NATIVE_DIALOG,
5523b3eb3cSopenharmony_ci    /** API related to gestures. For details, see the struct definition in <arkui/native_gesture.h>. */
5623b3eb3cSopenharmony_ci    ARKUI_NATIVE_GESTURE,
5723b3eb3cSopenharmony_ci    /** API related to animations. For details, see the struct definition in <arkui/native_animate.h>.*/
5823b3eb3cSopenharmony_ci    ARKUI_NATIVE_ANIMATE,
5923b3eb3cSopenharmony_ci} ArkUI_NativeAPIVariantKind;
6023b3eb3cSopenharmony_ci
6123b3eb3cSopenharmony_ci/**
6223b3eb3cSopenharmony_ci * @brief Obtains the native API set of a specified type.
6323b3eb3cSopenharmony_ci *
6423b3eb3cSopenharmony_ci * @param type Indicates the type of the native API set provided by ArkUI, for example, <b>ARKUI_NATIVE_NODE</b>
6523b3eb3cSopenharmony_ci * and <b>ARKUI_NATIVE_GESTURE</b>.
6623b3eb3cSopenharmony_ci * @param sturctName Indicates the name of a native struct defined in the corresponding header file, for example,
6723b3eb3cSopenharmony_ci * <b>ArkUI_NativeNodeAPI_1</b> in <arkui/native_node.h>.
6823b3eb3cSopenharmony_ci * @return Returns the pointer to the abstract native API, which can be used after being converted into a specific type.
6923b3eb3cSopenharmony_ci * @code {.cpp}
7023b3eb3cSopenharmony_ci * #include<arkui/native_interface.h>
7123b3eb3cSopenharmony_ci * #include<arkui/native_node.h>
7223b3eb3cSopenharmony_ci * #include<arkui/native_gesture.h>
7323b3eb3cSopenharmony_ci *
7423b3eb3cSopenharmony_ci * auto* anyNativeAPI = OH_ArkUI_QueryModuleInterfaceByName(ARKUI_NATIVE_NODE, "ArkUI_NativeNodeAPI_1");
7523b3eb3cSopenharmony_ci * if (anyNativeAPI) {
7623b3eb3cSopenharmony_ci *     auto nativeNodeApi = reinterpret_cast<ArkUI_NativeNodeAPI_1*>(anyNativeAPI);
7723b3eb3cSopenharmony_ci * }
7823b3eb3cSopenharmony_ci * auto anyGestureAPI = OH_ArkUI_QueryModuleInterface(ARKUI_NATIVE_GESTURE, "ArkUI_NativeGestureAPI_1");
7923b3eb3cSopenharmony_ci * if (anyNativeAPI) {
8023b3eb3cSopenharmony_ci *     auto basicGestureApi = reinterpret_cast<ArkUI_NativeGestureAPI_1*>(anyGestureAPI);
8123b3eb3cSopenharmony_ci * }
8223b3eb3cSopenharmony_ci * @endcode
8323b3eb3cSopenharmony_ci *
8423b3eb3cSopenharmony_ci * @since 12
8523b3eb3cSopenharmony_ci */
8623b3eb3cSopenharmony_civoid* OH_ArkUI_QueryModuleInterfaceByName(ArkUI_NativeAPIVariantKind type, const char* structName);
8723b3eb3cSopenharmony_ci
8823b3eb3cSopenharmony_ci/**
8923b3eb3cSopenharmony_ci * @brief Obtains the macro function corresponding to a struct pointer based on the struct type.
9023b3eb3cSopenharmony_ci *
9123b3eb3cSopenharmony_ci * @code {.cpp}
9223b3eb3cSopenharmony_ci * #include<arkui/native_interface.h>
9323b3eb3cSopenharmony_ci * #include<arkui/native_node.h>
9423b3eb3cSopenharmony_ci *
9523b3eb3cSopenharmony_ci * ArkUI_NativeNodeAPI_1* nativeNodeApi = nullptr;
9623b3eb3cSopenharmony_ci * OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nativeNodeApi);
9723b3eb3cSopenharmony_ci * @endcode
9823b3eb3cSopenharmony_ci *
9923b3eb3cSopenharmony_ci * @since 12
10023b3eb3cSopenharmony_ci */
10123b3eb3cSopenharmony_ci#define OH_ArkUI_GetModuleInterface(nativeAPIVariantKind, structType, structPtr)                     \
10223b3eb3cSopenharmony_ci    do {                                                                                             \
10323b3eb3cSopenharmony_ci        void* anyNativeAPI = OH_ArkUI_QueryModuleInterfaceByName(nativeAPIVariantKind, #structType); \
10423b3eb3cSopenharmony_ci        if (anyNativeAPI) {                                                                          \
10523b3eb3cSopenharmony_ci            structPtr = (structType*)(anyNativeAPI);                                                 \
10623b3eb3cSopenharmony_ci        }                                                                                            \
10723b3eb3cSopenharmony_ci    } while (0)
10823b3eb3cSopenharmony_ci
10923b3eb3cSopenharmony_ci#ifdef __cplusplus
11023b3eb3cSopenharmony_ci};
11123b3eb3cSopenharmony_ci#endif
11223b3eb3cSopenharmony_ci
11323b3eb3cSopenharmony_ci#endif // ARKUI_NATIVE_INTERFACE_H
11423b3eb3cSopenharmony_ci/** @} */
115