From b813fd3f2f140b4e448700322dec2c8cccaf30ca Mon Sep 17 00:00:00 2001 From: zhuhan Date: Tue, 17 Dec 2024 10:45:42 +0800 Subject: [PATCH] cwant Signed-off-by: zhuhan Change-Id: I9a4f52097d5d76fd51339b621c030aa149fed5f4 --- AbilityKit/ability_base/BUILD.gn | 34 ++++ AbilityKit/ability_base/ability_base_common.h | 61 +++++++ .../ability_base/libability_base_want.json | 34 ++++ AbilityKit/ability_base/want.h | 169 ++++++++++++++++++ ndk_targets.gni | 2 + 5 files changed, 300 insertions(+) create mode 100644 AbilityKit/ability_base/BUILD.gn create mode 100644 AbilityKit/ability_base/ability_base_common.h create mode 100644 AbilityKit/ability_base/libability_base_want.json create mode 100644 AbilityKit/ability_base/want.h diff --git a/AbilityKit/ability_base/BUILD.gn b/AbilityKit/ability_base/BUILD.gn new file mode 100644 index 00000000000..35e4257765b --- /dev/null +++ b/AbilityKit/ability_base/BUILD.gn @@ -0,0 +1,34 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/ohos/ndk/ndk.gni") +ohos_ndk_headers("ability_base_want_ndk_header") { + dest_dir = "$ndk_headers_out_dir/AbilityKit/ability_base" + sources = [ + "./ability_base_common.h", + "./want.h", + ] +} + +ohos_ndk_library("libability_base_want") { + output_name = "ability_base_want" + output_extension = "so" + system_capability = "SystemCapability.Ability.AbilityBase" + ndk_description_file = "./libability_base_want.json" + min_compact_version = "14" + system_capability_headers = [ + "AbilityKit/ability_base/ability_base_common.h", + "AbilityKit/ability_base/want.h", + ] +} diff --git a/AbilityKit/ability_base/ability_base_common.h b/AbilityKit/ability_base/ability_base_common.h new file mode 100644 index 00000000000..81a5d7be6e0 --- /dev/null +++ b/AbilityKit/ability_base/ability_base_common.h @@ -0,0 +1,61 @@ +/* +* Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup AbilityBase + * @{ + * + * @brief Provide the definition of the C interface for the native AbilityBase + * + * @syscap SystemCapability.Ability.AbilityBase + * @since 14 + */ + +/** + * @file ability_base_common.h + * + * @brief Declare the common types for the native AbilityBase. + * + * @library libability_base_want.so + * @kit AbilityKit + * @syscap SystemCapability.Ability.AbilityBase + * @since 14 + */ + +#ifndef ABILITY_BASE_COMMON_H +#define ABILITY_BASE_COMMON_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Enumerates the error codes. + * + * @since 14 + */ +typedef enum { + /** @error No error. */ + ABILITY_BASE_ERROR_CODE_NO_ERROR = 0, + /** @error Invalid parameters. */ + ABILITY_BASE_ERROR_CODE_PARAM_INVALID = 401, +} AbilityBase_ErrorCode; + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif // ABILITY_BASE_COMMON_H diff --git a/AbilityKit/ability_base/libability_base_want.json b/AbilityKit/ability_base/libability_base_want.json new file mode 100644 index 00000000000..e20c47126bf --- /dev/null +++ b/AbilityKit/ability_base/libability_base_want.json @@ -0,0 +1,34 @@ +[ + { + "first_introduced": "14", + "name": "OH_AbilityBase_NewWant" + }, + { + "first_introduced": "14", + "name": "OH_AbilityBase_DeleteWant" + }, + { + "first_introduced": "14", + "name": "OH_AbilityBase_SetWantElement" + }, + { + "first_introduced": "14", + "name": "OH_AbilityBase_GetWantElement" + }, + { + "first_introduced": "14", + "name": "OH_AbilityBase_SetWantCharParam" + }, + { + "first_introduced": "14", + "name": "OH_AbilityBase_GetWantCharParam" + }, + { + "first_introduced": "14", + "name": "OH_AbilityBase_AddWantFd" + }, + { + "first_introduced": "14", + "name": "OH_AbilityBase_GetWantFd" + } +] \ No newline at end of file diff --git a/AbilityKit/ability_base/want.h b/AbilityKit/ability_base/want.h new file mode 100644 index 00000000000..bd6fb757f1c --- /dev/null +++ b/AbilityKit/ability_base/want.h @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup AbilityBase + * @{ + * + * @brief Describe the functions of want. + * + * @syscap SystemCapability.Ability.AbilityBase + * @since 14 + */ + +/** + * @file want.h + * + * @brief Defines the want APIs. + * + * @library libability_base_want.so + * @kit AbilityKit + * @syscap SystemCapability.Ability.AbilityBase + * @since 14 + */ + +#ifndef ABILITY_BASE_WANT_H +#define ABILITY_BASE_WANT_H + +#include +#include +#include "ability_base_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Indicates information of element. + * + * @since 14 + */ +typedef struct AbilityBase_Element { + /** Indicates the name of application. */ + char* bundleName; + /** Indicates the name of module. */ + char* moduleName; + /** Indicates the name of ability. */ + char* abilityName; +} AbilityBase_Element; + +struct AbilityBase_Want; +typedef struct AbilityBase_Want AbilityBase_Want; + +/** + * @brief Creat want. + * + * @param element Information of element. + * @return Returns the newly created AbilityBase_Want object. + * + * @since 14 + */ +AbilityBase_Want* OH_AbilityBase_NewWant(AbilityBase_Element element); + +/** + * @brief Delete input want. + * + * @param want The want to be deleted. + * @return The error code. + * {@link ABILITY_BASE_ERROR_CODE_NO_ERROR} if the operation is successful. + * {@link ABILITY_BASE_ERROR_CODE_PARAM_INVALID} if the want is invalid. + * @since 14 + */ +AbilityBase_ErrorCode OH_AbilityBase_DeleteWant(AbilityBase_Want* want); + +/** + * @brief Set want element. + * + * @param want The want that needs to be set element. + * @param element Information of element. + * @return The error code. + * {@link ABILITY_BASE_ERROR_CODE_NO_ERROR} if the operation is successful. + * {@link ABILITY_BASE_ERROR_CODE_PARAM_INVALID} if the want is invalid. + * @since 14 + */ +AbilityBase_ErrorCode OH_AbilityBase_SetWantElement(AbilityBase_Want* want, AbilityBase_Element element); + +/** + * @brief Get want element. + * + * @param want The want for the element that has been obtained. + * @param element The element obtained from want. + * @return The error code. + * {@link ABILITY_BASE_ERROR_CODE_NO_ERROR} if the operation is successful. + * {@link ABILITY_BASE_ERROR_CODE_PARAM_INVALID} if the want or element is invalid. + * @since 14 + */ +AbilityBase_ErrorCode OH_AbilityBase_GetWantElement(AbilityBase_Want* want, AbilityBase_Element* element); + +/** + * @brief Set want char param. + * + * @param want The want needs to be set char param. + * @param key The key of char param. + * @param value The value of char param. + * @return The error code. + * {@link ABILITY_BASE_ERROR_CODE_NO_ERROR} if the operation is successful. + * {@link ABILITY_BASE_ERROR_CODE_PARAM_INVALID} if the input parameters are invalid. + * @since 14 + */ +AbilityBase_ErrorCode OH_AbilityBase_SetWantCharParam(AbilityBase_Want* want, const char* key, const char* value); + +/** + * @brief Get want char param. + * + * @param want The want for the char param that has been obtained. + * @param key The key of char param. + * @param value The value of char param. + * @param valueSize Size of the value. + * @return The error code. + * {@link ABILITY_BASE_ERROR_CODE_NO_ERROR} if the operation is successful. + * {@link ABILITY_BASE_ERROR_CODE_PARAM_INVALID} if the input parameters are invalid. + * @since 14 + */ +AbilityBase_ErrorCode OH_AbilityBase_GetWantCharParam(AbilityBase_Want* want, const char* key, + char* value, size_t valueSize); + +/** + * @brief Add fd to want. + * + * @param want The want needs to be add fd. + * @param key The key of the fd. + * @param fd File Descriptor. + * @return The error code. + * {@link ABILITY_BASE_ERROR_CODE_NO_ERROR} if the operation is successful. + * {@link ABILITY_BASE_ERROR_CODE_PARAM_INVALID} if the input parameters are invalid. + * @since 14 + */ +AbilityBase_ErrorCode OH_AbilityBase_AddWantFd(AbilityBase_Want* want, const char* key, int32_t fd); + +/** + * @brief Get fd from want. + * + * @param want The want that includes fd. + * @param key The key of the fd. + * @param fd File Descriptor. + * @return The error code. + * {@link ABILITY_BASE_ERROR_CODE_NO_ERROR} if the operation is successful. + * {@link ABILITY_BASE_ERROR_CODE_PARAM_INVALID} if the input parameters are invalid. + * @since 14 + */ +AbilityBase_ErrorCode OH_AbilityBase_GetWantFd(AbilityBase_Want* want, const char* key, int32_t* fd); + +#ifdef __cplusplus +} // extern "C" +#endif + +/** @} */ +#endif // ABILITY_BASE_WANT_H diff --git a/ndk_targets.gni b/ndk_targets.gni index a97312222ec..494c60c035a 100644 --- a/ndk_targets.gni +++ b/ndk_targets.gni @@ -55,6 +55,8 @@ _ndk_library_targets = [ "//interface/sdk_c/ability/ability_runtime/child_process:libchild_process", "//interface/sdk_c/AbilityKit/ability_runtime:ability_runtime_ndk_header", "//interface/sdk_c/AbilityKit/ability_runtime:libability_runtime", + "//interface/sdk_c/AbilityKit/want:ability_base_want_ndk_header", + "//interface/sdk_c/AbilityKit/want:libability_base_want", "//interface/sdk_c/arkui/ace_engine/native:ace_header", "//interface/sdk_c/arkui/ace_engine/native:arkui_header", "//interface/sdk_c/arkui/ace_engine/native:libace_ndk", -- Gitee