From 3f44a104cfb427eea8c99547c66362f6944ed80d Mon Sep 17 00:00:00 2001 From: Jonathan Schwender Date: Thu, 9 Jan 2025 18:52:54 +0100 Subject: [PATCH] arkui: Add native node napi Signed-off-by: Jonathan Schwender --- components/arkui/src/lib.rs | 4 + components/arkui/src/native_node_napi.rs | 2 + .../native_node_napi/native_node_napi_ffi.rs | 504 ++++++++++++++++++ scripts/generator/src/main.rs | 6 + 4 files changed, 516 insertions(+) create mode 100644 components/arkui/src/native_node_napi.rs create mode 100644 components/arkui/src/native_node_napi/native_node_napi_ffi.rs diff --git a/components/arkui/src/lib.rs b/components/arkui/src/lib.rs index d04e32a..1077257 100644 --- a/components/arkui/src/lib.rs +++ b/components/arkui/src/lib.rs @@ -50,6 +50,10 @@ pub mod native_interface; #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] pub mod native_node; +#[cfg(feature = "api-12")] +#[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] +pub mod native_node_napi; + #[cfg(feature = "api-12")] #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] pub mod native_type; diff --git a/components/arkui/src/native_node_napi.rs b/components/arkui/src/native_node_napi.rs new file mode 100644 index 0000000..118de65 --- /dev/null +++ b/components/arkui/src/native_node_napi.rs @@ -0,0 +1,2 @@ +mod native_node_napi_ffi; +pub use native_node_napi_ffi::*; diff --git a/components/arkui/src/native_node_napi/native_node_napi_ffi.rs b/components/arkui/src/native_node_napi/native_node_napi_ffi.rs new file mode 100644 index 0000000..19b6926 --- /dev/null +++ b/components/arkui/src/native_node_napi/native_node_napi_ffi.rs @@ -0,0 +1,504 @@ +// automatically generated by rust-bindgen 0.71.1 + +#![allow(non_upper_case_globals)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +use crate::drawable_descriptor::ArkUI_DrawableDescriptor; +use crate::native_type::*; +use ohos_sys_opaque_types::{napi_env, napi_value}; + +extern "C" { + /// Obtains a FrameNode object on the ArkTS side and maps it to an ArkUI_NodeHandle object on the + /// native side. + /// + /// # Arguments + /// + /// `env` - Indicates the NAPI environment pointer. + /// + /// `frameNode` - Indicates the FrameNode object created on the ArkTS side. + /// + /// `handle` - Indicates the pointer to the ArkUI_NodeHandle object. + /// + /// # Returns + /// + /// Returns the error code. + /// Returns [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful. + /// Returns [`ARKUI_ERROR_CODE_PARAM_INVALID`] if a parameter error occurs. + /// + /// Available since API-level: 12 + #[cfg(feature = "api-12")] + #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] + pub fn OH_ArkUI_GetNodeHandleFromNapiValue( + env: napi_env, + frameNode: napi_value, + handle: *mut ArkUI_NodeHandle, + ) -> i32; + /// Obtains a UIContext object on the ArkTS side and maps it to an ArkUI_ContextHandle object on the + /// native side. + /// + /// # Arguments + /// + /// `env` - ndicates the NAPI environment pointer. + /// + /// `value` - Indicates the UIContext object created on the ArkTS side. + /// + /// `context` - Indicates the pointer to the ArkUI_ContextHandle object. + /// + /// # Returns + /// + /// Returns the error code. + /// Returns [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful. + /// Returns [`ARKUI_ERROR_CODE_PARAM_INVALID`] if a parameter error occurs. + /// + /// Available since API-level: 12 + #[cfg(feature = "api-12")] + #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] + pub fn OH_ArkUI_GetContextFromNapiValue( + env: napi_env, + value: napi_value, + context: *mut ArkUI_ContextHandle, + ) -> i32; + /// Obtains a NodeContent object on the ArkTS side and maps it to an ArkUI_NodeContentHandle + /// object on the native side. + /// + /// # Arguments + /// + /// `env` - ndicates the NAPI environment pointer. + /// + /// `value` - Indicates the NodeContent object created on the ArkTS side. + /// + /// `content` - Indicates the pointer to the ArkUI_NodeContentHandle object. + /// + /// # Returns + /// + /// Returns the error code. + /// Returns [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful. + /// Returns [`ARKUI_ERROR_CODE_PARAM_INVALID`] if a parameter error occurs. + /// + /// Available since API-level: 12 + #[cfg(feature = "api-12")] + #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] + pub fn OH_ArkUI_GetNodeContentFromNapiValue( + env: napi_env, + value: napi_value, + content: *mut ArkUI_NodeContentHandle, + ) -> i32; + /// Obtains a DrawableDescriptor object on the ArkTS side and maps it to an + /// ArkUI_DrawableDescriptro object on the native side. + /// + /// # Arguments + /// + /// `env` - Indicates the NAPI environment pointer. + /// + /// `value` - Indicates the DrawableDescriptor object created on the ArkTS side. + /// + /// `drawableDescriptor` - Indicates the pointer to the ArkUI_DrawableDescriptro object. + /// + /// # Returns + /// + /// Returns the error code. + /// Returns [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful. + /// Returns [`ARKUI_ERROR_CODE_PARAM_INVALID`] if a parameter error occurs. + /// + /// Available since API-level: 12 + #[cfg(feature = "api-12")] + #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] + pub fn OH_ArkUI_GetDrawableDescriptorFromNapiValue( + env: napi_env, + value: napi_value, + drawableDescriptor: *mut *mut ArkUI_DrawableDescriptor, + ) -> i32; + /// Obtains a Resource object on the ArkTS side and maps it to an + /// ArkUI_DrawableDescriptro object on the native side. + /// + /// # Arguments + /// + /// `env` - Indicates the NAPI environment pointer. + /// + /// `value` - Indicates the Resource object created on the ArkTS side. + /// + /// `drawableDescriptor` - Indicates the pointer to the ArkUI_DrawableDescriptro object. + /// + /// # Returns + /// + /// Returns the error code. + /// Returns [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful. + /// Returns [`ARKUI_ERROR_CODE_PARAM_INVALID`] if a parameter error occurs. + /// + /// Available since API-level: 12 + #[cfg(feature = "api-12")] + #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] + pub fn OH_ArkUI_GetDrawableDescriptorFromResourceNapiValue( + env: napi_env, + value: napi_value, + drawableDescriptor: *mut *mut ArkUI_DrawableDescriptor, + ) -> i32; + /// Obtain the ID of the Navigation component where the node is located. + /// + /// # Arguments + /// + /// `node` - The node. + /// + /// `buffer` - The buffer to which NavigationID writes to the memory, + /// memory space needs to be allocated by the developer. + /// + /// `bufferSize` - The buffer size + /// + /// `writeLength` - Indicates the string length actually written to the buffer + /// when returning [`ARKUI_ERROR_CODE_NO_ERROR`]. + /// Indicates the minimum buffer size that can accommodate the target + /// when [`ARKUI_ERROR_CODE_BUFFER_SIZE_ERROR`] is returned. + /// + /// # Returns + /// + /// The error code. + /// [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful. + /// [`ARKUI_ERROR_CODE_PARAM_INVALID`] if the node, buffer or writeLength is null. + /// [`ARKUI_ERROR_CODE_GET_INFO_FAILED`] if query information failed, + /// this may be because the node is not in Navigation. + /// [`ARKUI_ERROR_CODE_BUFFER_SIZE_ERROR`] If the buffer size is less than the minimum buffer size. + /// + /// Available since API-level: 12 + #[cfg(feature = "api-12")] + #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] + pub fn OH_ArkUI_GetNavigationId( + node: ArkUI_NodeHandle, + buffer: *mut ::core::ffi::c_char, + bufferSize: i32, + writeLength: *mut i32, + ) -> ArkUI_ErrorCode; + /// Obtain the name of the NavDestination component where the node is located. + /// + /// # Arguments + /// + /// `node` - The node. + /// + /// `buffer` - The buffer to which NavDestination name writes to the memory, + /// memory space needs to be allocated by the developer. + /// + /// `bufferSize` - The buffer size + /// + /// `writeLength` - Indicates the string length actually written to the buffer + /// when returning [`ARKUI_ERROR_CODE_NO_ERROR`]. + /// Indicates the minimum buffer size that can accommodate the target + /// when [`ARKUI_ERROR_CODE_BUFFER_SIZE_ERROR`] is returned. + /// + /// # Returns + /// + /// The error code. + /// [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful. + /// [`ARKUI_ERROR_CODE_PARAM_INVALID`] if the node, buffer or writeLength is null. + /// [`ARKUI_ERROR_CODE_GET_INFO_FAILED`] if query information failed, + /// this may be because the node is not in Navigation. + /// [`ARKUI_ERROR_CODE_BUFFER_SIZE_ERROR`] If the buffer size is less than the minimum buffer size. + /// + /// Available since API-level: 12 + #[cfg(feature = "api-12")] + #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] + pub fn OH_ArkUI_GetNavDestinationName( + node: ArkUI_NodeHandle, + buffer: *mut ::core::ffi::c_char, + bufferSize: i32, + writeLength: *mut i32, + ) -> ArkUI_ErrorCode; + /// Based on the given index value, obtain the length of the Navigation stack where the node is located. + /// + /// # Arguments + /// + /// `node` - The node. + /// + /// `length` - The length of the stack. After the operation succeeds, the result is written back to this parameter. + /// + /// # Returns + /// + /// The error code. + /// [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful. + /// [`ARKUI_ERROR_CODE_PARAM_INVALID`] if the node or length is null. + /// [`ARKUI_ERROR_CODE_GET_INFO_FAILED`] if query information failed, + /// this may be because the node is not in Navigation. + /// + /// Available since API-level: 12 + #[cfg(feature = "api-12")] + #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] + pub fn OH_ArkUI_GetNavStackLength(node: ArkUI_NodeHandle, length: *mut i32) -> ArkUI_ErrorCode; + /// Based on the given index value, obtain the page name of the corresponding position + /// in the navigation stack where the node is located. + /// Index values are counted from 0, with 0 being the bottom of the stack. + /// + /// # Arguments + /// + /// `node` - The node. + /// + /// `index` - The index of the NavDestination in the stack is queried. + /// + /// `buffer` - The buffer to which NavDestination index writes to the memory, + /// memory space needs to be allocated by the developer. + /// + /// `bufferSize` - The buffer size + /// + /// `writeLength` - Indicates the string length actually written to the buffer + /// when returning [`ARKUI_ERROR_CODE_NO_ERROR`]. + /// Indicates the minimum buffer size that can accommodate the target + /// when [`ARKUI_ERROR_CODE_BUFFER_SIZE_ERROR`] is returned. + /// + /// # Returns + /// + /// The error code. + /// [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful. + /// [`ARKUI_ERROR_CODE_PARAM_INVALID`] if the node, buffer or writeLength is null. + /// [`ARKUI_ERROR_CODE_NODE_INDEX_INVALID`] if index is an invalid value. + /// [`ARKUI_ERROR_CODE_GET_INFO_FAILED`] if query information failed, + /// this may be because the node is not in Navigation. + /// [`ARKUI_ERROR_CODE_BUFFER_SIZE_ERROR`] If the buffer size is less than the minimum buffer size. + /// + /// Available since API-level: 12 + #[cfg(feature = "api-12")] + #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] + pub fn OH_ArkUI_GetNavDestinationNameByIndex( + node: ArkUI_NodeHandle, + index: i32, + buffer: *mut ::core::ffi::c_char, + bufferSize: i32, + writeLength: *mut i32, + ) -> ArkUI_ErrorCode; + /// Obtain the ID of the NavDestination component where the node is located. + /// + /// # Arguments + /// + /// `node` - The node. + /// + /// `buffer` - The buffer to which NavDestination ID writes to the memory, + /// memory space needs to be allocated by the developer. + /// + /// `bufferSize` - The buffer size + /// + /// `writeLength` - Indicates the string length actually written to the buffer + /// when returning [`ARKUI_ERROR_CODE_NO_ERROR`]. + /// Indicates the minimum buffer size that can accommodate the target + /// when [`ARKUI_ERROR_CODE_BUFFER_SIZE_ERROR`] is returned. + /// + /// # Returns + /// + /// The error code. + /// [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful. + /// [`ARKUI_ERROR_CODE_PARAM_INVALID`] if the node, buffer or writeLength is null. + /// [`ARKUI_ERROR_CODE_GET_INFO_FAILED`] if query information failed, + /// this may be because the node is not in Navigation. + /// [`ARKUI_ERROR_CODE_BUFFER_SIZE_ERROR`] If the buffer size is less than the minimum buffer size. + /// + /// Available since API-level: 12 + #[cfg(feature = "api-12")] + #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] + pub fn OH_ArkUI_GetNavDestinationId( + node: ArkUI_NodeHandle, + buffer: *mut ::core::ffi::c_char, + bufferSize: i32, + writeLength: *mut i32, + ) -> ArkUI_ErrorCode; + /// Obtain the state of the NavDestination component where the node is located. + /// + /// # Arguments + /// + /// `node` - The node. + /// + /// `state` - The state value of NavDestination is written back into this parameter. + /// + /// # Returns + /// + /// The error code. + /// [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful. + /// [`ARKUI_ERROR_CODE_PARAM_INVALID`] if the node or state is null. + /// [`ARKUI_ERROR_CODE_GET_INFO_FAILED`] if query information failed, + /// this may be because the node is not in Navigation. + /// + /// Available since API-level: 12 + #[cfg(feature = "api-12")] + #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] + pub fn OH_ArkUI_GetNavDestinationState( + node: ArkUI_NodeHandle, + state: *mut ArkUI_NavDestinationState, + ) -> ArkUI_ErrorCode; + /// Obtain the index of the NavDestination component on the Navigation stack where the node is located. + /// + /// # Arguments + /// + /// `node` - The node. + /// + /// `index` - Index value, counted from 0. + /// + /// # Returns + /// + /// The error code. + /// [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful. + /// [`ARKUI_ERROR_CODE_PARAM_INVALID`] if the node or index is null. + /// [`ARKUI_ERROR_CODE_GET_INFO_FAILED`] if query information failed, + /// this may be because the node is not in Navigation. + /// + /// Available since API-level: 12 + #[cfg(feature = "api-12")] + #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] + pub fn OH_ArkUI_GetNavDestinationIndex( + node: ArkUI_NodeHandle, + index: *mut i32, + ) -> ArkUI_ErrorCode; + /// Obtain the parameters of the NavDestination component where the node is located. + /// + /// # Arguments + /// + /// `node` - The node. + /// + /// # Returns + /// + /// The parameters. + /// If a null pointer is returned, it may be because the node is empty or the parameters does not exist. + /// + /// Available since API-level: 12 + #[cfg(feature = "api-12")] + #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] + pub fn OH_ArkUI_GetNavDestinationParam(node: ArkUI_NodeHandle) -> napi_value; + /// Obtain the index of the page where the node resides in the Router page stack. + /// + /// # Arguments + /// + /// `node` - The node. + /// + /// `index` - Index value, counted from 1. + /// + /// # Returns + /// + /// The error code. + /// [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful. + /// [`ARKUI_ERROR_CODE_PARAM_INVALID`] if the node or index is null. + /// [`ARKUI_ERROR_CODE_GET_INFO_FAILED`] if query information failed, + /// this may be because the node is not in RouterPage. + /// + /// Available since API-level: 12 + #[cfg(feature = "api-12")] + #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] + pub fn OH_ArkUI_GetRouterPageIndex(node: ArkUI_NodeHandle, index: *mut i32) -> ArkUI_ErrorCode; + /// Obtain the name of the page where the node is located. + /// + /// # Arguments + /// + /// `node` - The node. + /// + /// `buffer` - The buffer to which page name writes to the memory, + /// memory space needs to be allocated by the developer. + /// + /// `bufferSize` - The buffer size + /// + /// `writeLength` - Indicates the string length actually written to the buffer + /// when returning [`ARKUI_ERROR_CODE_NO_ERROR`]. + /// Indicates the minimum buffer size that can accommodate the target + /// when [`ARKUI_ERROR_CODE_BUFFER_SIZE_ERROR`] is returned. + /// + /// # Returns + /// + /// The error code. + /// [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful. + /// [`ARKUI_ERROR_CODE_PARAM_INVALID`] if the node, buffer or writeLength is null. + /// [`ARKUI_ERROR_CODE_GET_INFO_FAILED`] if query information failed, + /// this may be because the node is not in RouterPage. + /// [`ARKUI_ERROR_CODE_BUFFER_SIZE_ERROR`] If the buffer size is less than the minimum buffer size. + /// + /// Available since API-level: 12 + #[cfg(feature = "api-12")] + #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] + pub fn OH_ArkUI_GetRouterPageName( + node: ArkUI_NodeHandle, + buffer: *mut ::core::ffi::c_char, + bufferSize: i32, + writeLength: *mut i32, + ) -> ArkUI_ErrorCode; + /// Obtain the path of the page where the node is located. + /// + /// # Arguments + /// + /// `node` - The node. + /// + /// `buffer` - The buffer to which page path writes to the memory, + /// memory space needs to be allocated by the developer. + /// + /// `bufferSize` - The buffer size + /// + /// `writeLength` - Indicates the string length actually written to the buffer + /// when returning [`ARKUI_ERROR_CODE_NO_ERROR`]. + /// Indicates the minimum buffer size that can accommodate the target + /// when [`ARKUI_ERROR_CODE_BUFFER_SIZE_ERROR`] is returned. + /// + /// # Returns + /// + /// The error code. + /// [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful. + /// [`ARKUI_ERROR_CODE_PARAM_INVALID`] if the node, buffer or writeLength is null. + /// [`ARKUI_ERROR_CODE_GET_INFO_FAILED`] if query information failed, + /// this may be because the node is not in RouterPage. + /// [`ARKUI_ERROR_CODE_BUFFER_SIZE_ERROR`] If the buffer size is less than the minimum buffer size. + /// + /// Available since API-level: 12 + #[cfg(feature = "api-12")] + #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] + pub fn OH_ArkUI_GetRouterPagePath( + node: ArkUI_NodeHandle, + buffer: *mut ::core::ffi::c_char, + bufferSize: i32, + writeLength: *mut i32, + ) -> ArkUI_ErrorCode; + /// Obtain the state of the page where the node is located. + /// + /// # Arguments + /// + /// `node` - The node. + /// + /// `state` - The state value of the page is written back to this parameter. + /// + /// # Returns + /// + /// The error code. + /// [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful. + /// [`ARKUI_ERROR_CODE_PARAM_INVALID`] if the node or state is null. + /// [`ARKUI_ERROR_CODE_GET_INFO_FAILED`] if query information failed, + /// this may be because the node is not in RouterPage. + /// + /// Available since API-level: 12 + #[cfg(feature = "api-12")] + #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] + pub fn OH_ArkUI_GetRouterPageState( + node: ArkUI_NodeHandle, + state: *mut ArkUI_RouterPageState, + ) -> ArkUI_ErrorCode; + /// Obtain the ID of the page where the node is located. + /// + /// # Arguments + /// + /// `node` - The node. + /// + /// `buffer` - The buffer to which page ID writes to the memory, + /// memory space needs to be allocated by the developer. + /// + /// `bufferSize` - The buffer size + /// + /// `writeLength` - Indicates the string length actually written to the buffer + /// when returning [`ARKUI_ERROR_CODE_NO_ERROR`]. + /// Indicates the minimum buffer size that can accommodate the target + /// when [`ARKUI_ERROR_CODE_BUFFER_SIZE_ERROR`] is returned. + /// + /// # Returns + /// + /// The error code. + /// [`ARKUI_ERROR_CODE_NO_ERROR`] if the operation is successful. + /// [`ARKUI_ERROR_CODE_PARAM_INVALID`] if the node, buffer or writeLength is null. + /// [`ARKUI_ERROR_CODE_GET_INFO_FAILED`] if query information failed, + /// this may be because the node is not in RouterPage. + /// [`ARKUI_ERROR_CODE_BUFFER_SIZE_ERROR`] If the buffer size is less than the minimum buffer size. + /// + /// Available since API-level: 12 + #[cfg(feature = "api-12")] + #[cfg_attr(docsrs, doc(cfg(feature = "api-12")))] + pub fn OH_ArkUI_GetRouterPageId( + node: ArkUI_NodeHandle, + buffer: *mut ::core::ffi::c_char, + bufferSize: i32, + writeLength: *mut i32, + ) -> ArkUI_ErrorCode; +} diff --git a/scripts/generator/src/main.rs b/scripts/generator/src/main.rs index 422e2be..2258d2c 100644 --- a/scripts/generator/src/main.rs +++ b/scripts/generator/src/main.rs @@ -731,6 +731,12 @@ fn get_module_bindings_config(api_version: u32) -> Vec { .blocklist_var("MAX_COMPONENT_EVENT_ARG_NUM") .raw_line("use crate::ui_input_event::ArkUI_UIInputEvent;") }, + "native_node_napi" => { + builder + .raw_line("use ohos_sys_opaque_types::{napi_env, napi_value};") + .raw_line("use crate::drawable_descriptor::ArkUI_DrawableDescriptor;") + + }, "native_type" => { builder .raw_line("use crate::drawable_descriptor::ArkUI_DrawableDescriptor;")