1# AbilityBase 2 3## Overview 4 5As the basic definition module of Ability Kit, AbilityBase provides definitions and APIs for [Want](want__8h.md), which can be used to transfer information between application components. 6 7**System capability**: SystemCapability.Ability.AbilityBase 8 9**Since**: 15 10 11## Summary 12 13 14### Files 15 16| Name| Description| 17| -------- | -------- | 18| [ability_base_common.h](ability__base__common_8h.md) | Declares the error codes related to AbilityBase.<br>**File to include**: <AbilityKit/ability_base/ability_base_common.h><br>**Library**: libability_base_want.so| 19| [want.h](want__8h.md) | Declares the capabilities related to [Want](want__8h.md).<br>**File to include**: <AbilityKit/ability_base/want.h><br>**Library**: libability_base_want.so| 20 21### Enums 22 23| Name | Description | 24| ------------------------------------------------------------ | ---------------------- | 25| [AbilityBase_ErrorCode](#abilitybase_errorcode) {<br> ABILITY_RUNTIME_ERROR_CODE_NO_ERROR = 0,<br> ABILITY_RUNTIME_ERROR_CODE_PARAM_INVALID = 401,<br/>} | Enumerates the AbilityBase error codes.| 26 27### Structs 28 29| Name | Description | 30| ------------------------------------------------------------ | ---------------------------- | 31| [AbilityBase_Element](_ability_base_element.md#abilitybase_element) {<br> char* bundleName;<br> char* moduleName;<br> char* abilityName;<br>} | Element struct.| 32| [AbilityBase_Want](#abilitybase_want) | Element struct.| 33 34### Functions 35 36| Name | Description | 37| ------------------------------------------------------------ | ---------------------------- | 38| [AbilityBase_Want](#abilitybase_want)* [OH_AbilityBase_CreateWant](#oh_abilitybase_createwant)([AbilityBase_Element](_ability_base_element.md#abilitybase_element) element) | Creates Want.| 39| [AbilityBase_ErrorCode](#abilitybase_errorcode) [OH_AbilityBase_DestroyWant](#oh_abilitybase_destroywant)([AbilityBase_Want](#abilitybase_want)* want) | Destroys Want. Want cannot be used after being destroyed. Otherwise, undefined behavior may occur.| 40| [AbilityBase_ErrorCode](#abilitybase_errorcode) [OH_AbilityBase_SetWantElement](#oh_abilitybase_setwantelement)([AbilityBase_Want](#abilitybase_want)* want, [AbilityBase_Element](_ability_base_element.md#abilitybase_element) element) | Sets the Element struct, which consists of **bundleName**, **moduleName**, and **abilityName** in Want.| 41| [AbilityBase_ErrorCode](#abilitybase_errorcode) [OH_AbilityBase_GetWantElement](#oh_abilitybase_getwantelement)([AbilityBase_Want](#abilitybase_want)* want, [AbilityBase_Element](_ability_base_element.md#abilitybase_element)* element) | Obtains the Element struct, which consists of **bundleName**, **moduleName**, and **abilityName** in Want.| 42| [AbilityBase_ErrorCode](#abilitybase_errorcode) [OH_AbilityBase_SetWantCharParam](#oh_abilitybase_setwantcharparam)([AbilityBase_Want](#abilitybase_want)* want, const char* key, const char* value) | Sets **Param** in Want. For details about **Param**, see [parameters in Want](js-apis-inner-ability-want.md).| 43| [AbilityBase_ErrorCode](#abilitybase_errorcode) [OH_AbilityBase_GetWantCharParam](#oh_abilitybase_getwantcharparam)([AbilityBase_Want](#abilitybase_want)* want, const char* key, char* value, size_t valueSize) | Obtains **Param** set by [OH_AbilityBase_SetWantCharParam](#oh_abilitybase_setwantcharparam) in Want.| 44| [AbilityBase_ErrorCode](#abilitybase_errorcode) [OH_AbilityBase_AddWantFd](#oh_abilitybase_addwantfd)([AbilityBase_Want](#abilitybase_want)* want, const char* key, int32_t fd) | Adds a Want file descriptor. The file descriptor can be obtained through [fs.open](../apis-core-file-kit/js-apis-file-fs.md#fsopen).| 45| [AbilityBase_ErrorCode](#abilitybase_errorcode) [OH_AbilityBase_GetWantFd](#oh_abilitybase_getwantfd)([AbilityBase_Want](#abilitybase_want)* want, const char* key, int32_t* fd) | Obtains a Want file descriptor.| 46 47 48## Enum Description 49 50### AbilityBase_ErrorCode 51 52``` 53enum AbilityBase_ErrorCode 54``` 55 56**Description** 57 58Enumerates the AbilityBase error codes. 59 60**Since**: 15 61 62| Value | Description | 63| --------------------------------------------- | -------------- | 64| ABILITY_BASE_ERROR_CODE_NO_ERROR | Operation successful. | 65| ABILITY_BASE_ERROR_CODE_PARAM_INVALID | Invalid parameter. | 66 67 68## Struct Description 69 70### AbilityBase_Want 71 72``` 73AbilityBase_Want 74``` 75 76**Description** 77 78Want struct. 79 80**Since**: 15 81 82 83## Function Description 84 85 86### OH_AbilityBase_CreateWant 87 88``` 89AbilityBase_Want* OH_AbilityBase_CreateWant(AbilityBase_Element element) 90``` 91**Description** 92 93Creates Want. 94 95**Since**: 15 96 97**Parameters** 98 99| Name| Description| 100| -------- | -------- | 101| element | Element struct.| 102 103**Returns** 104 105Returns **AbilityBase_Want**, which is a Want struct. 106 107 108### OH_AbilityBase_DestroyWant 109 110``` 111AbilityBase_ErrorCode OH_AbilityBase_DestroyWant(AbilityBase_Want* want) 112``` 113**Description** 114 115Destroys Want. Want cannot be used after being destroyed. Otherwise, undefined behavior may occur. 116 117**Since**: 15 118 119**Parameters** 120 121| Name| Description| 122| -------- | -------- | 123| want | Pointer to Want.| 124 125**Returns** 126 127Returns **ABILITY_BASE_ERROR_CODE_NO_ERROR** if Want is destroyed. 128 129Returns **ABILITY_BASE_ERROR_CODE_PARAM_INVALID** if **element** is invalid. 130 131### OH_AbilityBase_SetWantElement 132 133``` 134AbilityBase_ErrorCode OH_AbilityBase_SetWantElement(AbilityBase_Want* want, AbilityBase_Element element) 135``` 136**Description** 137 138Sets the Element struct, which consists of **bundleName**, **moduleName**, and **abilityName** in Want. 139 140**Since**: 15 141 142**Parameters** 143 144| Name| Description| 145| -------- | -------- | 146| want | Pointer to Want.| 147| element | Element struct.| 148 149**Returns** 150 151Returns **ABILITY_BASE_ERROR_CODE_NO_ERROR** if the setting is successful. 152 153Returns **ABILITY_BASE_ERROR_CODE_PARAM_INVALID** if **want** is set to a null pointer or **element** is invalid. 154 155### OH_AbilityBase_GetWantElement 156 157``` 158AbilityBase_ErrorCode OH_AbilityBase_GetWantElement(AbilityBase_Want* want, AbilityBase_Element* element) 159``` 160**Description** 161 162Obtains the Element struct, which consists of **bundleName**, **moduleName**, and **abilityName** in Want. 163 164**Since**: 15 165 166**Parameters** 167 168| Name| Description| 169| -------- | -------- | 170| want | Pointer to Want.| 171| element | Pointer to the Element struct.| 172 173**Returns** 174 175Returns **ABILITY_BASE_ERROR_CODE_NO_ERROR** if the element struct is obtained. 176 177Returns **ABILITY_BASE_ERROR_CODE_PARAM_INVALID** if **want** is set to a null pointer or **element** is invalid. 178 179### OH_AbilityBase_SetWantCharParam 180 181``` 182AbilityBase_ErrorCode OH_AbilityBase_SetWantCharParam(AbilityBase_Want* want, const char* key, const char* value) 183``` 184**Description** 185 186Sets **Param** in Want. For details about **Param**, see [parameters in Want](js-apis-inner-ability-want.md). 187 188**Since**: 15 189 190**Parameters** 191 192| Name| Description| 193| -------- | -------- | 194| want | Pointer to Want.| 195| key | Pointer to a key in Want.| 196| value | Pointer to the value of the key in Want.| 197 198**Returns** 199 200Returns **ABILITY_BASE_ERROR_CODE_NO_ERROR** if the setting is successful. 201 202Returns **ABILITY_BASE_ERROR_CODE_PARAM_INVALID** if **want** is a null pointer or invalid. 203 204### OH_AbilityBase_GetWantCharParam 205 206``` 207AbilityBase_ErrorCode OH_AbilityBase_GetWantCharParam(AbilityBase_Want* want, const char* key, char* value, size_t valueSize) 208``` 209**Description** 210 211Obtains **Param** set by [OH_AbilityBase_SetWantCharParam](#oh_abilitybase_setwantcharparam) in Want. 212 213**Since**: 15 214 215**Parameters** 216 217| Name| Description| 218| -------- | -------- | 219| want | Pointer to Want.| 220| key | Pointer to a key in Want.| 221| value | Pointer to the value of the key in Want.| 222| valueSize | Length of the value string. If **valueSize** is less than the actual value length, the **ABILITY_BASE_ERROR_CODE_PARAM_INVALID** error is reported.| 223 224**Returns** 225 226Returns **ABILITY_BASE_ERROR_CODE_NO_ERROR** if the param struct is obtained. 227 228Returns **ABILITY_BASE_ERROR_CODE_PARAM_INVALID** if **want** is a null pointer or invalid. 229 230### OH_AbilityBase_AddWantFd 231 232``` 233AbilityBase_ErrorCode OH_AbilityBase_AddWantFd(AbilityBase_Want* want, const char* key, int32_t fd) 234``` 235**Description** 236 237Adds a Want file descriptor. The file descriptor can be obtained through [fs.open](../apis-core-file-kit/js-apis-file-fs.md#fsopen). 238 239**Since**: 15 240 241**Parameters** 242 243| Name| Description| 244| -------- | -------- | 245| want | Pointer to Want.| 246| key | Pointer to a key in Want.| 247| fd | File descriptor, which is obtained by calling [fs.open](../apis-core-file-kit/js-apis-file-fs.md#fsopen).| 248 249**Returns** 250 251Returns **ABILITY_BASE_ERROR_CODE_NO_ERROR** if the Want file descriptor is added. 252 253Returns **ABILITY_BASE_ERROR_CODE_PARAM_INVALID** if **want** is a null pointer or invalid. 254 255### OH_AbilityBase_GetWantFd 256 257``` 258AbilityBase_ErrorCode OH_AbilityBase_GetWantFd(AbilityBase_Want* want, const char* key, int32_t* fd) 259``` 260**Description** 261 262Obtains a Want file descriptor. 263 264**Since**: 15 265 266**Parameters** 267 268| Name| Description| 269| -------- | -------- | 270| want | Pointer to Want.| 271| key | Pointer to a key in Want.| 272| fd | Pointer to the file descriptor.| 273 274**Returns** 275 276Returns **ABILITY_BASE_ERROR_CODE_NO_ERROR** if the Want file descriptor is obtained. 277 278Returns **ABILITY_BASE_ERROR_CODE_PARAM_INVALID** if **want** is a null pointer or invalid. 279