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