• 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 #include "native_node_napi.h"
17 
18 
19 #include "node/node_extened.h"
20 #include "node/node_model.h"
21 
22 #include "base/error/error_code.h"
23 #include "core/components_ng/base/frame_node.h"
24 
25 extern "C" {
26 
OH_ArkUI_GetNodeHandleFromNapiValue(napi_env env,napi_value value,ArkUI_NodeHandle * handle)27 int32_t OH_ArkUI_GetNodeHandleFromNapiValue(napi_env env, napi_value value, ArkUI_NodeHandle* handle)
28 {
29     bool hasProperty = false;
30     auto result = napi_has_named_property(env, value, "nodePtr_", &hasProperty);
31     const auto* impl = OHOS::Ace::NodeModel::GetFullImpl();
32     if (result == napi_ok && hasProperty) {
33         napi_value frameNodePtr = nullptr;
34         auto result = napi_get_named_property(env, value, "nodePtr_", &frameNodePtr);
35         if (result != napi_ok) {
36             LOGE("fail to get nodePtr");
37             return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
38         }
39         // BuilderNode case.
40         void* nativePtr = nullptr;
41         result = napi_get_value_external(env, frameNodePtr, &nativePtr);
42         if (result != napi_ok || nativePtr == nullptr) {
43             LOGE("fail to get nodePtr external value");
44             return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
45         }
46         auto* uiNodePtr = reinterpret_cast<OHOS::Ace::NG::UINode*>(nativePtr);
47         uiNodePtr->IncRefCount();
48         // check whether it is bind to native XComponent.
49         bool isBindNativeXComponent = impl && impl->getNodeModifiers()->getXComponentModifier()
50             ->getXComponentIsBindNative(reinterpret_cast<ArkUINodeHandle>(nativePtr));
51         *handle = new ArkUI_Node({ .type = -1,
52             .uiNodeHandle = reinterpret_cast<ArkUINodeHandle>(nativePtr),
53             .cNode = false,
54             .buildNode = true });
55         if (isBindNativeXComponent) {
56             OHOS::Ace::NodeModel::RegisterBindNativeNode(*handle);
57             (*handle)->isBindNative = true;
58         }
59         if (impl) {
60             impl->getExtendedAPI()->setAttachNodePtr((*handle)->uiNodeHandle, reinterpret_cast<void*>(*handle));
61         }
62         return OHOS::Ace::ERROR_CODE_NO_ERROR;
63     }
64     result = napi_has_named_property(env, value, "builderNode_", &hasProperty);
65     if (result == napi_ok && hasProperty) {
66         // Component Content case.
67         napi_value builderNode = nullptr;
68         auto result = napi_get_named_property(env, value, "builderNode_", &builderNode);
69         if (result != napi_ok) {
70             LOGE("fail to get builderNode");
71             return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
72         }
73         napi_value nodePtr = nullptr;
74         result = napi_get_named_property(env, builderNode, "nodePtr_", &nodePtr);
75         if (result != napi_ok) {
76             LOGE("fail to get nodePtr in builderNode");
77             return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
78         }
79         void* nativePtr = nullptr;
80         result = napi_get_value_external(env, nodePtr, &nativePtr);
81         if (result != napi_ok) {
82             LOGE("fail to get nodePtr external value in builderNode");
83             return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
84         }
85         auto* uiNode = reinterpret_cast<OHOS::Ace::NG::UINode*>(nativePtr);
86         OHOS::Ace::NG::FrameNode* frameNode = OHOS::Ace::AceType::DynamicCast<OHOS::Ace::NG::FrameNode>(uiNode);
87         if (frameNode == nullptr) {
88             LOGE("fail to get frameNode value in builderNode");
89             return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
90         }
91         if (frameNode->GetTag() == "BuilderProxyNode") {
92             // need to get the really frameNode.
93             if (!impl) {
94                 return OHOS::Ace::ERROR_CODE_NATIVE_IMPL_LIBRARY_NOT_FOUND;
95             }
96             auto* child = impl->getNodeModifiers()->getFrameNodeModifier()->getChild(
97                 reinterpret_cast<ArkUINodeHandle>(frameNode), 0, true);
98             if (!child) {
99                 LOGE("fail to get child in BuilderProxyNode");
100                 return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
101             }
102             frameNode = reinterpret_cast<OHOS::Ace::NG::FrameNode*>(child);
103         }
104         frameNode->IncRefCount();
105         *handle = new ArkUI_Node({ .type = -1,
106             .uiNodeHandle = reinterpret_cast<ArkUINodeHandle>(frameNode),
107             .cNode = false,
108             .buildNode = true });
109         if (impl) {
110             impl->getExtendedAPI()->setAttachNodePtr((*handle)->uiNodeHandle, reinterpret_cast<void*>(*handle));
111         }
112         return OHOS::Ace::ERROR_CODE_NO_ERROR;
113     }
114     return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
115 }
116 
OH_ArkUI_GetContextFromNapiValue(napi_env env,napi_value value,ArkUI_ContextHandle * context)117 int32_t OH_ArkUI_GetContextFromNapiValue(napi_env env, napi_value value, ArkUI_ContextHandle* context)
118 {
119     bool hasProperty = false;
120     auto result = napi_has_named_property(env, value, "instanceId_", &hasProperty);
121     if (result != napi_ok || !hasProperty) {
122         LOGE("fail to get Context value");
123         return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
124     }
125 
126     napi_value contextPtr = nullptr;
127     result = napi_get_named_property(env, value, "instanceId_", &contextPtr);
128     if (result != napi_ok) {
129         return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
130     }
131 
132     napi_valuetype valuetype;
133     if (napi_typeof(env, contextPtr, &valuetype) != napi_ok) {
134         return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
135     }
136     if (valuetype != napi_number) {
137         return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
138     }
139     int32_t instanceId = -1;
140     result = napi_get_value_int32(env, contextPtr, &instanceId);
141     if (result != napi_ok) {
142         return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
143     }
144     *context = new ArkUI_Context({ .id = instanceId });
145     return OHOS::Ace::ERROR_CODE_NO_ERROR;
146 }
147 
OH_ArkUI_GetNodeContentFromNapiValue(napi_env env,napi_value value,ArkUI_NodeContentHandle * content)148 int32_t OH_ArkUI_GetNodeContentFromNapiValue(napi_env env, napi_value value, ArkUI_NodeContentHandle* content)
149 {
150     bool hasProperty = false;
151     auto result = napi_has_named_property(env, value, "nativePtr_", &hasProperty);
152     if (result != napi_ok || !hasProperty) {
153         LOGE("fail to get native content value");
154         return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
155     }
156     napi_value nativeContent = nullptr;
157     result = napi_get_named_property(env, value, "nativePtr_", &nativeContent);
158     if (result != napi_ok) {
159         LOGE("fail to get native content");
160         return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
161     }
162     void* nativePtr = nullptr;
163     result = napi_get_value_external(env, nativeContent, &nativePtr);
164     if (result != napi_ok) {
165         LOGE("fail to get native content ptr");
166         return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
167     }
168     *content = reinterpret_cast<ArkUI_NodeContentHandle>(nativePtr);
169     return OHOS::Ace::ERROR_CODE_NO_ERROR;
170 }
171 
OH_ArkUI_GetDrawableDescriptorFromNapiValue(napi_env env,napi_value value,ArkUI_DrawableDescriptor ** drawableDescriptor)172 int32_t OH_ArkUI_GetDrawableDescriptorFromNapiValue(
173     napi_env env, napi_value value, ArkUI_DrawableDescriptor** drawableDescriptor)
174 {
175     void* objectNapi = nullptr;
176     napi_unwrap(env, value, &objectNapi);
177     if (!objectNapi) {
178         return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
179     }
180     ArkUI_DrawableDescriptor* drawable =
181         new ArkUI_DrawableDescriptor { nullptr, nullptr, 0, nullptr, nullptr, nullptr, nullptr };
182     auto* descriptor = reinterpret_cast<OHOS::Ace::Napi::DrawableDescriptor*>(objectNapi);
183     if (!descriptor) {
184         return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
185     }
186     auto drawableType = descriptor->GetDrawableType();
187     if (drawableType == OHOS::Ace::Napi::DrawableDescriptor::DrawableType::ANIMATED) {
188         auto* animatedDrawable = static_cast<OHOS::Ace::Napi::AnimatedDrawableDescriptor*>(descriptor);
189         if (!animatedDrawable) {
190             return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
191         }
192         int32_t duration = animatedDrawable->GetDuration();
193         int32_t iteration = animatedDrawable->GetIterations();
194         drawable->animatedDrawableDescriptor = std::make_shared<OHOS::Ace::Napi::AnimatedDrawableDescriptor>(
195             animatedDrawable->GetPixelMapList(), duration, iteration);
196         *drawableDescriptor = drawable;
197         return OHOS::Ace::ERROR_CODE_NO_ERROR;
198     }
199     drawable->drawableDescriptor = std::make_shared<OHOS::Ace::Napi::DrawableDescriptor>(descriptor->GetPixelMap());
200     *drawableDescriptor = drawable;
201     return OHOS::Ace::ERROR_CODE_NO_ERROR;
202 }
203 
OH_ArkUI_GetDrawableDescriptorFromResourceNapiValue(napi_env env,napi_value value,ArkUI_DrawableDescriptor ** drawableDescriptor)204 int32_t OH_ArkUI_GetDrawableDescriptorFromResourceNapiValue(
205     napi_env env, napi_value value, ArkUI_DrawableDescriptor** drawableDescriptor)
206 {
207     auto parseApi = reinterpret_cast<void (*)(void*, void*)>(OHOS::Ace::NodeModel::GetParseJsMedia());
208     if (!parseApi) {
209         return OHOS::Ace::ERROR_CODE_PARAM_INVALID;
210     }
211 
212     ArkUI_DrawableDescriptor* drawable =
213         new ArkUI_DrawableDescriptor { nullptr, nullptr, 0, nullptr, nullptr, nullptr, nullptr };
214     drawable->resource = std::make_shared<ArkUI_Resource>();
215     parseApi(value, drawable->resource.get());
216     *drawableDescriptor = drawable;
217     return OHOS::Ace::ERROR_CODE_NO_ERROR;
218 }
219 
OH_ArkUI_GetNavigationId(ArkUI_NodeHandle node,char * buffer,int32_t bufferSize,int32_t * writeLength)220 ArkUI_ErrorCode  OH_ArkUI_GetNavigationId(
221     ArkUI_NodeHandle node, char* buffer, int32_t bufferSize, int32_t* writeLength)
222 {
223     CHECK_NULL_RETURN(node, ARKUI_ERROR_CODE_PARAM_INVALID);
224     CHECK_NULL_RETURN(buffer, ARKUI_ERROR_CODE_PARAM_INVALID);
225     CHECK_NULL_RETURN(writeLength, ARKUI_ERROR_CODE_PARAM_INVALID);
226     auto* fullImpl = OHOS::Ace::NodeModel::GetFullImpl();
227     CHECK_NULL_RETURN(fullImpl, ARKUI_ERROR_CODE_GET_INFO_FAILED);
228     auto navigationAPI = fullImpl->getNavigation();
229     CHECK_NULL_RETURN(navigationAPI, ARKUI_ERROR_CODE_GET_INFO_FAILED);
230     auto ret =
231         navigationAPI->getNavigationId(node->uiNodeHandle, buffer, bufferSize, writeLength);
232     return static_cast<ArkUI_ErrorCode>(ret);
233 }
234 
OH_ArkUI_GetNavDestinationName(ArkUI_NodeHandle node,char * buffer,int32_t bufferSize,int32_t * writeLength)235 ArkUI_ErrorCode OH_ArkUI_GetNavDestinationName(
236     ArkUI_NodeHandle node, char* buffer, int32_t bufferSize, int32_t* writeLength)
237 {
238     CHECK_NULL_RETURN(node, ARKUI_ERROR_CODE_PARAM_INVALID);
239     CHECK_NULL_RETURN(buffer, ARKUI_ERROR_CODE_PARAM_INVALID);
240     CHECK_NULL_RETURN(writeLength, ARKUI_ERROR_CODE_PARAM_INVALID);
241     auto* fullImpl = OHOS::Ace::NodeModel::GetFullImpl();
242     CHECK_NULL_RETURN(fullImpl, ARKUI_ERROR_CODE_GET_INFO_FAILED);
243     auto navigationAPI = fullImpl->getNavigation();
244     CHECK_NULL_RETURN(navigationAPI, ARKUI_ERROR_CODE_GET_INFO_FAILED);
245     auto ret =
246         navigationAPI->getNavDestinationName(node->uiNodeHandle, buffer, bufferSize, writeLength);
247     return static_cast<ArkUI_ErrorCode>(ret);
248 }
249 
OH_ArkUI_GetNavStackLength(ArkUI_NodeHandle node,int32_t * length)250 ArkUI_ErrorCode OH_ArkUI_GetNavStackLength(ArkUI_NodeHandle node, int32_t* length)
251 {
252     CHECK_NULL_RETURN(node, ARKUI_ERROR_CODE_PARAM_INVALID);
253     CHECK_NULL_RETURN(length, ARKUI_ERROR_CODE_PARAM_INVALID);
254     auto* fullImpl = OHOS::Ace::NodeModel::GetFullImpl();
255     auto stacklength = fullImpl->getNavigation()->getStackLength(node->uiNodeHandle);
256     if (stacklength < 0) {
257         return ARKUI_ERROR_CODE_GET_INFO_FAILED;
258     }
259     *length = stacklength;
260     return ARKUI_ERROR_CODE_NO_ERROR;
261 }
262 
OH_ArkUI_GetNavDestinationNameByIndex(ArkUI_NodeHandle node,int32_t index,char * buffer,int32_t bufferSize,int32_t * writeLength)263 ArkUI_ErrorCode OH_ArkUI_GetNavDestinationNameByIndex(
264     ArkUI_NodeHandle node, int32_t index, char* buffer, int32_t bufferSize, int32_t* writeLength)
265 {
266     CHECK_NULL_RETURN(node, ARKUI_ERROR_CODE_PARAM_INVALID);
267     CHECK_NULL_RETURN(buffer, ARKUI_ERROR_CODE_PARAM_INVALID);
268     CHECK_NULL_RETURN(writeLength, ARKUI_ERROR_CODE_PARAM_INVALID);
269     auto* fullImpl = OHOS::Ace::NodeModel::GetFullImpl();
270     CHECK_NULL_RETURN(fullImpl, ARKUI_ERROR_CODE_GET_INFO_FAILED);
271     auto navigationAPI = fullImpl->getNavigation();
272     CHECK_NULL_RETURN(navigationAPI, ARKUI_ERROR_CODE_GET_INFO_FAILED);
273     auto ret =
274         navigationAPI->getNavDesNameByIndex(node->uiNodeHandle, index, buffer, bufferSize, writeLength);
275     return static_cast<ArkUI_ErrorCode>(ret);
276 }
277 
OH_ArkUI_GetNavDestinationId(ArkUI_NodeHandle node,char * buffer,int32_t bufferSize,int32_t * writeLength)278 ArkUI_ErrorCode OH_ArkUI_GetNavDestinationId(
279     ArkUI_NodeHandle node, char* buffer, int32_t bufferSize, int32_t* writeLength)
280 {
281     CHECK_NULL_RETURN(node, ARKUI_ERROR_CODE_PARAM_INVALID);
282     CHECK_NULL_RETURN(buffer, ARKUI_ERROR_CODE_PARAM_INVALID);
283     CHECK_NULL_RETURN(writeLength, ARKUI_ERROR_CODE_PARAM_INVALID);
284     auto* fullImpl = OHOS::Ace::NodeModel::GetFullImpl();
285     CHECK_NULL_RETURN(fullImpl, ARKUI_ERROR_CODE_GET_INFO_FAILED);
286     auto navigationAPI = fullImpl->getNavigation();
287     CHECK_NULL_RETURN(navigationAPI, ARKUI_ERROR_CODE_GET_INFO_FAILED);
288     auto ret =
289         navigationAPI->getNavDestinationId(node->uiNodeHandle, buffer, bufferSize, writeLength);
290     return static_cast<ArkUI_ErrorCode>(ret);
291 }
292 
OH_ArkUI_GetNavDestinationState(ArkUI_NodeHandle node,ArkUI_NavDestinationState * state)293 ArkUI_ErrorCode OH_ArkUI_GetNavDestinationState(ArkUI_NodeHandle node, ArkUI_NavDestinationState* state)
294 {
295     CHECK_NULL_RETURN(node, ARKUI_ERROR_CODE_PARAM_INVALID);
296     CHECK_NULL_RETURN(state, ARKUI_ERROR_CODE_PARAM_INVALID);
297     auto* fullImpl = OHOS::Ace::NodeModel::GetFullImpl();
298     CHECK_NULL_RETURN(fullImpl, ARKUI_ERROR_CODE_GET_INFO_FAILED);
299     auto navigationAPI = fullImpl->getNavigation();
300     CHECK_NULL_RETURN(navigationAPI, ARKUI_ERROR_CODE_GET_INFO_FAILED);
301 
302     auto navDestinationState = navigationAPI->getNavDestinationState(node->uiNodeHandle);
303     if (navDestinationState < 0) {
304         return ARKUI_ERROR_CODE_GET_INFO_FAILED;
305     }
306     *state = static_cast<ArkUI_NavDestinationState>(navDestinationState);
307     return ARKUI_ERROR_CODE_NO_ERROR;
308 }
309 
OH_ArkUI_GetNavDestinationIndex(ArkUI_NodeHandle node,int32_t * index)310 ArkUI_ErrorCode OH_ArkUI_GetNavDestinationIndex(ArkUI_NodeHandle node, int32_t* index)
311 {
312     CHECK_NULL_RETURN(node, ARKUI_ERROR_CODE_PARAM_INVALID);
313     CHECK_NULL_RETURN(index, ARKUI_ERROR_CODE_PARAM_INVALID);
314     auto* fullImpl = OHOS::Ace::NodeModel::GetFullImpl();
315     CHECK_NULL_RETURN(fullImpl, ARKUI_ERROR_CODE_GET_INFO_FAILED);
316     auto navigationAPI = fullImpl->getNavigation();
317     CHECK_NULL_RETURN(navigationAPI, ARKUI_ERROR_CODE_GET_INFO_FAILED);
318 
319     auto retIndex = navigationAPI->getNavDestinationIndex(node->uiNodeHandle);
320     if (retIndex < 0) {
321         return ARKUI_ERROR_CODE_GET_INFO_FAILED;
322     }
323     *index = retIndex;
324     return ARKUI_ERROR_CODE_NO_ERROR;
325 }
326 
OH_ArkUI_GetNavDestinationParam(ArkUI_NodeHandle node)327 napi_value OH_ArkUI_GetNavDestinationParam(ArkUI_NodeHandle node)
328 {
329     CHECK_NULL_RETURN(node, nullptr);
330     auto* fullImpl = OHOS::Ace::NodeModel::GetFullImpl();
331     CHECK_NULL_RETURN(fullImpl, nullptr);
332     auto navigationAPI = fullImpl->getNavigation();
333     CHECK_NULL_RETURN(navigationAPI, nullptr);
334     return reinterpret_cast<napi_value>(navigationAPI->getNavDestinationParam(node->uiNodeHandle));
335 }
336 
OH_ArkUI_GetRouterPageIndex(ArkUI_NodeHandle node,int32_t * index)337 ArkUI_ErrorCode OH_ArkUI_GetRouterPageIndex(ArkUI_NodeHandle node, int32_t* index)
338 {
339     CHECK_NULL_RETURN(node, ARKUI_ERROR_CODE_PARAM_INVALID);
340     CHECK_NULL_RETURN(index, ARKUI_ERROR_CODE_PARAM_INVALID);
341     auto* fullImpl = OHOS::Ace::NodeModel::GetFullImpl();
342     CHECK_NULL_RETURN(fullImpl, ARKUI_ERROR_CODE_GET_INFO_FAILED);
343     auto navigationAPI = fullImpl->getNavigation();
344     CHECK_NULL_RETURN(navigationAPI, ARKUI_ERROR_CODE_GET_INFO_FAILED);
345 
346     auto retIndex = navigationAPI->getRouterPageIndex(node->uiNodeHandle);
347     if (retIndex < 0) {
348         return ARKUI_ERROR_CODE_GET_INFO_FAILED;
349     }
350     *index = retIndex;
351     return ARKUI_ERROR_CODE_NO_ERROR;
352 }
353 
OH_ArkUI_GetRouterPageName(ArkUI_NodeHandle node,char * buffer,int32_t bufferSize,int32_t * writeLength)354 ArkUI_ErrorCode OH_ArkUI_GetRouterPageName(
355     ArkUI_NodeHandle node, char* buffer, int32_t bufferSize, int32_t* writeLength)
356 {
357     CHECK_NULL_RETURN(node, ARKUI_ERROR_CODE_PARAM_INVALID);
358     CHECK_NULL_RETURN(buffer, ARKUI_ERROR_CODE_PARAM_INVALID);
359     CHECK_NULL_RETURN(writeLength, ARKUI_ERROR_CODE_PARAM_INVALID);
360     auto* fullImpl = OHOS::Ace::NodeModel::GetFullImpl();
361     CHECK_NULL_RETURN(fullImpl, ARKUI_ERROR_CODE_GET_INFO_FAILED);
362     auto navigationAPI = fullImpl->getNavigation();
363     CHECK_NULL_RETURN(navigationAPI, ARKUI_ERROR_CODE_GET_INFO_FAILED);
364     auto ret =
365         navigationAPI->getRouterPageName(node->uiNodeHandle, buffer, bufferSize, writeLength);
366     return static_cast<ArkUI_ErrorCode>(ret);
367 }
368 
OH_ArkUI_GetRouterPagePath(ArkUI_NodeHandle node,char * buffer,int32_t bufferSize,int32_t * writeLength)369 ArkUI_ErrorCode OH_ArkUI_GetRouterPagePath(
370     ArkUI_NodeHandle node, char* buffer, int32_t bufferSize, int32_t* writeLength)
371 {
372     CHECK_NULL_RETURN(node, ARKUI_ERROR_CODE_PARAM_INVALID);
373     CHECK_NULL_RETURN(buffer, ARKUI_ERROR_CODE_PARAM_INVALID);
374     CHECK_NULL_RETURN(writeLength, ARKUI_ERROR_CODE_PARAM_INVALID);
375     auto* fullImpl = OHOS::Ace::NodeModel::GetFullImpl();
376     CHECK_NULL_RETURN(fullImpl, ARKUI_ERROR_CODE_GET_INFO_FAILED);
377     auto navigationAPI = fullImpl->getNavigation();
378     CHECK_NULL_RETURN(navigationAPI, ARKUI_ERROR_CODE_GET_INFO_FAILED);
379     auto ret =
380         navigationAPI->getRouterPagePath(node->uiNodeHandle, buffer, bufferSize, writeLength);
381     return static_cast<ArkUI_ErrorCode>(ret);
382 }
383 
OH_ArkUI_GetRouterPageState(ArkUI_NodeHandle node,ArkUI_RouterPageState * state)384 ArkUI_ErrorCode OH_ArkUI_GetRouterPageState(ArkUI_NodeHandle node, ArkUI_RouterPageState* state)
385 {
386     CHECK_NULL_RETURN(node, ARKUI_ERROR_CODE_PARAM_INVALID);
387     CHECK_NULL_RETURN(state, ARKUI_ERROR_CODE_PARAM_INVALID);
388     auto* fullImpl = OHOS::Ace::NodeModel::GetFullImpl();
389     CHECK_NULL_RETURN(fullImpl, ARKUI_ERROR_CODE_GET_INFO_FAILED);
390     auto navigationAPI = fullImpl->getNavigation();
391     CHECK_NULL_RETURN(navigationAPI, ARKUI_ERROR_CODE_GET_INFO_FAILED);
392 
393     auto routerPageState = navigationAPI->getRouterPageState(node->uiNodeHandle);
394     if (routerPageState < 0) {
395         return ARKUI_ERROR_CODE_GET_INFO_FAILED;
396     }
397     *state = static_cast<ArkUI_RouterPageState>(routerPageState);
398     return ARKUI_ERROR_CODE_NO_ERROR;
399 }
400 
OH_ArkUI_GetRouterPageId(ArkUI_NodeHandle node,char * buffer,int32_t bufferSize,int32_t * writeLength)401 ArkUI_ErrorCode OH_ArkUI_GetRouterPageId(
402     ArkUI_NodeHandle node, char* buffer, int32_t bufferSize, int32_t* writeLength)
403 {
404     CHECK_NULL_RETURN(node, ARKUI_ERROR_CODE_PARAM_INVALID);
405     CHECK_NULL_RETURN(buffer, ARKUI_ERROR_CODE_PARAM_INVALID);
406     CHECK_NULL_RETURN(writeLength, ARKUI_ERROR_CODE_PARAM_INVALID);
407     auto* fullImpl = OHOS::Ace::NodeModel::GetFullImpl();
408     CHECK_NULL_RETURN(fullImpl, ARKUI_ERROR_CODE_GET_INFO_FAILED);
409     auto navigationAPI = fullImpl->getNavigation();
410     CHECK_NULL_RETURN(navigationAPI, ARKUI_ERROR_CODE_GET_INFO_FAILED);
411     auto ret =
412         navigationAPI->getRouterPageId(node->uiNodeHandle, buffer, bufferSize, writeLength);
413     return static_cast<ArkUI_ErrorCode>(ret);
414 }
415 
OH_ArkUI_PostFrameCallback(ArkUI_ContextHandle uiContext,void * userData,void (* callback)(uint64_t nanoTimestamp,uint32_t frameCount,void * userData))416 int32_t OH_ArkUI_PostFrameCallback(ArkUI_ContextHandle uiContext, void* userData,
417     void (*callback)(uint64_t nanoTimestamp, uint32_t frameCount, void* userData))
418 {
419     CHECK_NULL_RETURN(uiContext, ARKUI_ERROR_CODE_UI_CONTEXT_INVALID);
420     CHECK_NULL_RETURN(callback, ARKUI_ERROR_CODE_CALLBACK_INVALID);
421     auto* fullImpl = OHOS::Ace::NodeModel::GetFullImpl();
422     CHECK_NULL_RETURN(fullImpl, ARKUI_ERROR_CODE_CAPI_INIT_ERROR);
423     auto basicAPI = fullImpl->getBasicAPI();
424     CHECK_NULL_RETURN(basicAPI, ARKUI_ERROR_CODE_CAPI_INIT_ERROR);
425     auto* context = reinterpret_cast<ArkUI_Context*>(uiContext);
426     auto id = context->id;
427     auto ret = basicAPI->postFrameCallback(id, userData, callback);
428     if (ret == OHOS::Ace::ERROR_CODE_NATIVE_IMPL_NOT_MAIN_THREAD) {
429         LOGF_ABORT("OH_ArkUI_PostFrameCallback doesn't run on UI thread!");
430     }
431     return static_cast<ArkUI_ErrorCode>(ret);
432 }
433 }
434