• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# ipc_cskeleton.h
2<!--Kit: IPC Kit-->
3<!--Subsystem: Communication-->
4<!--Owner: @xdx19211@luodonghui0157-->
5<!--SE: @zhaopeng_gitee-->
6<!--TSE: @maxiaorong2-->
7
8## Overview
9
10Provides C APIs for managing the token IDs, credentials, process IDs (PIDs), user IDs (UIDs), and thread pool in the IPC framework.
11
12**Library**: libipc_capi.so
13
14**System capability**: SystemCapability.Communication.IPC.Core
15
16**Since**: 12
17
18**Related module**: [OHIPCSkeleton](capi-ohipcskeleton.md)
19
20## Summary
21
22### Function
23
24| Name| Description|
25| ---- | ---- |
26| [void OH_IPCSkeleton_JoinWorkThread(void)](#oh_ipcskeleton_joinworkthread) | Joints this thread to the IPC worker thread pool.|
27| [void OH_IPCSkeleton_StopWorkThread(void)](#oh_ipcskeleton_stopworkthread) | Stops this thread.|
28| [uint64_t OH_IPCSkeleton_GetCallingTokenId(void)](#oh_ipcskeleton_getcallingtokenid) | Obtains the token ID of the caller. This function must be called in the IPC context. Otherwise, the local token ID is returned.|
29| [uint64_t OH_IPCSkeleton_GetFirstTokenId(void)](#oh_ipcskeleton_getfirsttokenid) | Obtains the token ID of the first caller.|
30| [uint64_t OH_IPCSkeleton_GetSelfTokenId(void)](#oh_ipcskeleton_getselftokenid) | Obtains the local token ID.|
31| [uint64_t OH_IPCSkeleton_GetCallingPid(void)](#oh_ipcskeleton_getcallingpid) | Obtains the PID of the caller. This function must be called in the IPC context. Otherwise, the local PID is returned.|
32| [uint64_t OH_IPCSkeleton_GetCallingUid(void)](#oh_ipcskeleton_getcallinguid) | Obtains the UID of the caller. This function must be called in the IPC context. Otherwise, the local UID is returned.|
33| [int OH_IPCSkeleton_IsLocalCalling(void)](#oh_ipcskeleton_islocalcalling) | Checks whether a local calling is being made.|
34| [int OH_IPCSkeleton_SetMaxWorkThreadNum(const int maxThreadNum)](#oh_ipcskeleton_setmaxworkthreadnum) | Sets the maximum number of worker threads.|
35| [int OH_IPCSkeleton_ResetCallingIdentity(char **identity, int32_t *len, OH_IPC_MemAllocator allocator)](#oh_ipcskeleton_resetcallingidentity) | Resets the caller identity credential (including the token ID, UID, and PID) to that of this process and returns the caller credential information. The credential information is used in **OH_IPCSkeleton_SetCallingIdentity**.|
36| [int OH_IPCSkeleton_SetCallingIdentity(const char *identity)](#oh_ipcskeleton_setcallingidentity) | Sets the caller credential information to the IPC context.|
37| [int OH_IPCSkeleton_IsHandlingTransaction(void)](#oh_ipcskeleton_ishandlingtransaction) | Checks whether an IPC request is being handled.|
38
39## Function Description
40
41### OH_IPCSkeleton_JoinWorkThread()
42
43```C
44void OH_IPCSkeleton_JoinWorkThread(void)
45```
46
47**Description**
48
49Joints this thread to the IPC worker thread pool.
50
51**System capability**: SystemCapability.Communication.IPC.Core
52
53**Since**: 12
54
55### OH_IPCSkeleton_StopWorkThread()
56
57```C
58void OH_IPCSkeleton_StopWorkThread(void)
59```
60
61**Description**
62
63Stops this thread.
64
65**System capability**: SystemCapability.Communication.IPC.Core
66
67**Since**: 12
68
69### OH_IPCSkeleton_GetCallingTokenId()
70
71```C
72uint64_t OH_IPCSkeleton_GetCallingTokenId(void)
73```
74
75**Description**
76
77Obtains the token ID of the caller. This function must be called in the IPC context. Otherwise, the local token ID is returned.
78
79**System capability**: SystemCapability.Communication.IPC.Core
80
81**Since**: 12
82
83**Returns**
84
85| Type| Description|
86| ---- | ---- |
87| uint64_t | Returns the caller token ID.|
88
89### OH_IPCSkeleton_GetFirstTokenId()
90
91```C
92uint64_t OH_IPCSkeleton_GetFirstTokenId(void)
93```
94
95**Description**
96
97Obtains the token ID of the first caller.
98
99**System capability**: SystemCapability.Communication.IPC.Core
100
101**Since**: 12
102
103**Returns**
104
105| Type| Description|
106| ---- | ---- |
107| uint64_t | Returns the token ID of the first caller.|
108
109### OH_IPCSkeleton_GetSelfTokenId()
110
111```C
112uint64_t OH_IPCSkeleton_GetSelfTokenId(void)
113```
114
115**Description**
116
117Obtains the local token ID.
118
119**System capability**: SystemCapability.Communication.IPC.Core
120
121**Since**: 12
122
123**Returns**
124
125| Type| Description|
126| ---- | ---- |
127| uint64_t | Returns the local token ID.|
128
129### OH_IPCSkeleton_GetCallingPid()
130
131```C
132uint64_t OH_IPCSkeleton_GetCallingPid(void)
133```
134
135**Description**
136
137Obtains the PID of the caller. This function must be called in the IPC context. Otherwise, the local PID is returned.
138
139**System capability**: SystemCapability.Communication.IPC.Core
140
141**Since**: 12
142
143**Returns**
144
145| Type| Description|
146| ---- | ---- |
147| uint64_t | Returns the caller PID.|
148
149### OH_IPCSkeleton_GetCallingUid()
150
151```C
152uint64_t OH_IPCSkeleton_GetCallingUid(void)
153```
154
155**Description**
156
157Obtains the UID of the caller. This function must be called in the IPC context. Otherwise, the local UID is returned.
158
159**System capability**: SystemCapability.Communication.IPC.Core
160
161**Since**: 12
162
163**Returns**
164
165| Type| Description|
166| ---- | ---- |
167| uint64_t | Returns the caller UID.|
168
169### OH_IPCSkeleton_IsLocalCalling()
170
171```C
172int OH_IPCSkeleton_IsLocalCalling(void)
173```
174
175**Description**
176
177Checks whether a local calling is being made.
178
179**System capability**: SystemCapability.Communication.IPC.Core
180
181**Since**: 12
182
183**Returns**
184
185| Type| Description|
186| ---- | ---- |
187| int | Returns **1** if a local calling is in progress; returns **0** otherwise.|
188
189### OH_IPCSkeleton_SetMaxWorkThreadNum()
190
191```C
192int OH_IPCSkeleton_SetMaxWorkThreadNum(const int maxThreadNum)
193```
194
195**Description**
196
197Sets the maximum number of worker threads.
198
199**System capability**: SystemCapability.Communication.IPC.Core
200
201**Since**: 12
202
203**Parameters**
204
205| Name| Description|
206| ------ | ---- |
207| const int maxThreadNum | Maximum number of worker threads.<br>Value range: [1, 32]<br>Default value: **16**|
208
209**Returns**
210
211| Type| Description|
212| ---- | ---- |
213| int | Returns [OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md) if the operation is successful;<br> returns [OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md) if the parameter is incorrect;<br> returns [OH_IPC_ErrorCode#OH_IPC_INNER_ERROR](capi-ipc-error-code-h.md) in other cases.|
214
215### OH_IPCSkeleton_ResetCallingIdentity()
216
217```C
218int OH_IPCSkeleton_ResetCallingIdentity(char **identity, int32_t *len, OH_IPC_MemAllocator allocator)
219```
220
221**Description**
222
223Resets the caller identity credential (including the token ID, UID, and PID) to that of this process and returns the caller credential information. The credential information is used in **OH_IPCSkeleton_SetCallingIdentity**.
224
225**System capability**: SystemCapability.Communication.IPC.Core
226
227**Since**: 12
228
229**Parameters**
230
231| Name| Description|
232| ------ | ---- |
233| char **identity | Double pointer to the address of the memory for holding the caller identity information. The memory is allocated by the allocator provided by the user and needs to be released. This pointer cannot be NULL.|
234| int32_t *len | Pointer to the length of the data written to the identity. The value cannot be empty.|
235| [OH_IPC_MemAllocator](capi-ipc-cparcel-h.md#oh_ipc_memallocator) allocator | Memory allocator specified by the user for allocating memory for **identity**. It cannot be NULL.|
236
237**Returns**
238
239| Type| Description|
240| ---- | ---- |
241| int | Returns [OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md) if the operation is successful;<br> returns [OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md) if the parameter is incorrect;<br> returns [OH_IPC_ErrorCode#OH_IPC_MEM_ALLOCATOR_ERROR](capi-ipc-error-code-h.md) if memory allocation fails;<br> returns [OH_IPC_ErrorCode#OH_IPC_INNER_ERROR](capi-ipc-error-code-h.md) in other cases.|
242
243### OH_IPCSkeleton_SetCallingIdentity()
244
245```C
246int OH_IPCSkeleton_SetCallingIdentity(const char *identity)
247```
248
249**Description**
250
251Sets the caller credential information to the IPC context.
252
253**System capability**: SystemCapability.Communication.IPC.Core
254
255**Since**: 12
256
257**Parameters**
258
259| Name| Description|
260| ------ | ---- |
261| const char *identity | Pointer to the caller credential, which cannot be empty. The value is returned by **OH_IPCSkeleton_ResetCallingIdentity**.|
262
263**Returns**
264
265| Type| Description|
266| ---- | ---- |
267| int | Returns [OH_IPC_ErrorCode#OH_IPC_SUCCESS](capi-ipc-error-code-h.md) if the operation is successful;<br> returns [OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR](capi-ipc-error-code-h.md) if the parameter is incorrect;<br> returns [OH_IPC_ErrorCode#OH_IPC_INNER_ERROR](capi-ipc-error-code-h.md) in other cases.|
268
269### OH_IPCSkeleton_IsHandlingTransaction()
270
271```C
272int OH_IPCSkeleton_IsHandlingTransaction(void)
273```
274
275**Description**
276
277Checks whether an IPC request is being handled.
278
279**System capability**: SystemCapability.Communication.IPC.Core
280
281**Since**: 12
282
283**Returns**
284
285| Type| Description|
286| ---- | ---- |
287| int | Returns **1** if an IPC request is being handled; returns **0** otherwise.|
288