• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 /**
17  * @addtogroup ArkUI_NativeModule
18  * @{
19  *
20  * @brief Provides UI capabilities of ArkUI on the native side, such as UI component creation and destruction,
21  * tree node operations, attribute setting, and event listening.
22  *
23  * @since 12
24  */
25 
26 /**
27  * @file native_interface.h
28  *
29  * @brief Provides a unified entry for the native module APIs.
30  *
31  * @library libace_ndk.z.so
32  * @syscap SystemCapability.ArkUI.ArkUI.Full
33  * @since 12
34  */
35 
36 #ifndef ARKUI_NATIVE_INTERFACE_H
37 #define ARKUI_NATIVE_INTERFACE_H
38 
39 #include <stdint.h>
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 /**
46  * @brief Defines the native API types.
47  *
48  * @since 12
49  */
50 typedef enum {
51     /** API related to UI components. For details, see the struct definition in <arkui/native_node.h>. */
52     ARKUI_NATIVE_NODE,
53     /** API related to dialog boxes. For details, see the struct definition in <arkui/native_dialog.h>. */
54     ARKUI_NATIVE_DIALOG,
55     /** API related to gestures. For details, see the struct definition in <arkui/native_gesture.h>. */
56     ARKUI_NATIVE_GESTURE,
57     /** API related to animations. For details, see the struct definition in <arkui/native_animate.h>.*/
58     ARKUI_NATIVE_ANIMATE,
59     /**
60      * API related to supported multi thread UI components.
61      * For details, see the struct definition in <arkui/native_node.h>.
62      * @since 20
63      */
64     ARKUI_MULTI_THREAD_NATIVE_NODE,
65 } ArkUI_NativeAPIVariantKind;
66 
67 /**
68  * @brief Obtains the native API set of a specified type.
69  *
70  * @param type Indicates the type of the native API set provided by ArkUI, for example, <b>ARKUI_NATIVE_NODE</b>
71  * and <b>ARKUI_NATIVE_GESTURE</b>.
72  * @param sturctName Indicates the name of a native struct defined in the corresponding header file, for example,
73  * <b>ArkUI_NativeNodeAPI_1</b> in <arkui/native_node.h>.
74  * @return Returns the pointer to the abstract native API, which can be used after being converted into a specific type.
75  * @code {.cpp}
76  * #include<arkui/native_interface.h>
77  * #include<arkui/native_node.h>
78  * #include<arkui/native_gesture.h>
79  *
80  * auto* anyNativeAPI = OH_ArkUI_QueryModuleInterfaceByName(ARKUI_NATIVE_NODE, "ArkUI_NativeNodeAPI_1");
81  * if (anyNativeAPI) {
82  *     auto nativeNodeApi = reinterpret_cast<ArkUI_NativeNodeAPI_1*>(anyNativeAPI);
83  * }
84  * auto anyGestureAPI = OH_ArkUI_QueryModuleInterface(ARKUI_NATIVE_GESTURE, "ArkUI_NativeGestureAPI_1");
85  * if (anyNativeAPI) {
86  *     auto basicGestureApi = reinterpret_cast<ArkUI_NativeGestureAPI_1*>(anyGestureAPI);
87  * }
88  * @endcode
89  *
90  * @since 12
91  */
92 void* OH_ArkUI_QueryModuleInterfaceByName(ArkUI_NativeAPIVariantKind type, const char* structName);
93 
94 /**
95  * @brief Obtains the macro function corresponding to a struct pointer based on the struct type.
96  *
97  * @code {.cpp}
98  * #include<arkui/native_interface.h>
99  * #include<arkui/native_node.h>
100  *
101  * ArkUI_NativeNodeAPI_1* nativeNodeApi = nullptr;
102  * OH_ArkUI_GetModuleInterface(ARKUI_NATIVE_NODE, ArkUI_NativeNodeAPI_1, nativeNodeApi);
103  * @endcode
104  *
105  * @since 12
106  */
107 #define OH_ArkUI_GetModuleInterface(nativeAPIVariantKind, structType, structPtr)                     \
108     do {                                                                                             \
109         void* anyNativeAPI = OH_ArkUI_QueryModuleInterfaceByName(nativeAPIVariantKind, #structType); \
110         if (anyNativeAPI) {                                                                          \
111             structPtr = (structType*)(anyNativeAPI);                                                 \
112         }                                                                                            \
113     } while (0)
114 
115 #ifdef __cplusplus
116 };
117 #endif
118 
119 #endif // ARKUI_NATIVE_INTERFACE_H
120 /** @} */
121