1# BASE DDK
2
3
4## Overview
5
6Provides APIs for creating, mapping, unmapping, and destroying an **Ashmem** object.
7
8**System capability**: SystemCapability.Driver.DDK.Extension
9
10**Since**
11
1212
13
14## Summary
15
16
17### File
18
19| Name| Description|
20| -------- | -------- |
21| [ddk_api.h](ddk_api.md) | Declares the HID DDK functions for accessing an input device from the host.<br>File to include: &lt;base/ddk_api.h&gt; <br>Library: libddk_base.z.so|
22| [ddk_types.h](ddk_types.md) | Defines the enum variables and structs used in the HID DDK.<br>File to include: <base/ddk_types.h><br>Library: libddk_base.z.so|
23
24
25### Structs
26
27| Name| Description|
28| -------- | -------- |
29| [DDK_Ashmem](_ddk_ashmem.md) | Shared memory. |
30
31
32### Enums
33
34| Name| Description|
35| -------- | -------- |
36| [DDK_RetCode](#ddk_retcode) | BASE DDK error code definitions. |
37
38
39### Functions
40
41| Name| Description|
42| -------- | -------- |
43| [OH_DDK_CreateAshmem](#oh_ddk_createashmem) (const uint8_t *name, [DDK_Ashmem](_ddk_ashmem.md) \*\*ashmem) | Creates an **Ashmem** object. |
44| [OH_DDK_MapAshmem](#oh_ddk_mapashmem) ([DDK_Ashmem](_ddk_ashmem.md) \*ashmem, const uint8_t ashmemMapType) | Maps an **Ashmem** object. |
45| [OH_DDK_UnmapAshmem](#oh_ddk_unmapashmem) ([DDK_Ashmem](_ddk_ashmem.md) \*ashmem) | Unmaps an **Ashmem** object. |
46| [OH_DDK_DestoryAshmem](#oh_ddk_destoryashmem) ([DDK_Ashmem](_ddk_ashmem.md) \*ashmem) | Destroys an **Ashmem** object. |
47
48
49## Enum Description
50
51
52### DDK_RetCode
53
54
55```
56enum DDK_RetCode
57```
58
59**Description**
60
61BASE DDK error code definitions.
62
63| Value| Description|
64| -------- | -------- |
65| DDK_SUCCESS | The operation is successful.|
66| DDK_FAILED | Operation failed.|
67| DDK_INVALID_PARAMETER | Invalid parameter.|
68| DDK_INVALID_OPERATION | Invalid operation.|
69| DDK_NULL_PTR | Null pointer.|
70
71
72## Function Description
73
74
75### OH_DDK_CreateAshmem()
76
77
78```
79DDK_RetCode OH_DDK_CreateAshmem(const uint8_t *name, uint32_t size, DDK_Ashmem **ashmem);
80```
81
82**Description**
83
84Creates an **Ashmem** object.
85
86**Parameters**
87
88| Name| Description|
89| -------- | -------- |
90| name | Name of the **Ashmem** object.|
91| size | Buffer size of the **Ashmem** object.|
92| ashmem | Pointer to the **Ashmem** object.|
93
94**Returns**
95
96- [DK_SUCCESS](#ddk_retcode) if the API call is successful.
97- [DDK_INVALID_PARAMETER](#ddk_retcode) if the input **name** or **ashmem** is a null pointer, or **size** is **0**.
98- [DDK_FAILURE](#ddk_retcode) if the attempt to create the shared memory or the **DDK_Ashmem** structure fails.
99
100
101### OH_DDK_MapAshmem()
102
103
104```
105DDK_RetCode OH_DDK_MapAshmem(DDK_Ashmem *ashmem, const uint8_t ashmemMapType);
106```
107
108**Description**
109
110Maps an **Ashmem** object.
111
112**Parameters**
113
114| Name| Description|
115| -------- | -------- |
116| ashmem | Pointer to the **Ashmem** object.|
117| ashmemMapType | Mapping type for the **Ashmem** object.|
118
119**Returns**
120
121- [DK_SUCCESS](#ddk_retcode) if the API is called successfully.
122- [DDK_NULL_PTR](#ddk_retcode) if the input **ashmem** is a null pointer.
123- [DDK_FAILURE](#ddk_retcode) if the file descriptor of the shared memory is invalid.
124- [DDK_INVALID_OPERATION](#ddk_retcode) if calling the **MapAshmem** API fails.
125
126
127### OH_DDK_UnmapAshmem()
128
129
130```
131DDK_RetCode OH_DDK_UnmapAshmem(DDK_Ashmem *ashmem);
132```
133
134**Description**
135
136Unmaps an **Ashmem** object.
137
138**Parameters**
139
140| Name| Description|
141| -------- | -------- |
142|  ashmem | Pointer to the **Ashmem** object.|
143
144**Returns**
145
146- [DK_SUCCESS](#ddk_retcode) if the API is called successfully.
147- [DDK_NULL_PTR](#ddk_retcode) if the input **ashmem** is a null pointer.
148- [DDK_FAILURE](#ddk_retcode) if the file descriptor of the shared memory is invalid.
149
150### OH_DDK_DestoryAshmem()
151
152
153```
154DDK_RetCode OH_DDK_DestroyAshmem(DDK_Ashmem *ashmem);
155```
156
157**Description**
158
159Destroys the created shared memory.
160
161**Parameters**
162
163| Name| Description|
164| -------- | -------- |
165|  ashmem | Pointer to the **Ashmem** object.|
166
167**Returns**
168
169- [DK_SUCCESS](#ddk_retcode) if the API is called successfully.
170- [DDK_NULL_PTR](#ddk_retcode) if the input **ashmem** is a null pointer.
171- [DDK_FAILURE](#ddk_retcode) if the file descriptor of the shared memory is invalid.
172