1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef CAPI_INCLUDE_IPC_CSKELETON_H
17 #define CAPI_INCLUDE_IPC_CSKELETON_H
18 
19 /**
20  * @addtogroup OHIPCSkeleton
21  * @{
22  *
23  * @brief Provides C interfaces for managing the token IDs, credentials, process IDs (PIDs),
24  * user IDs (UIDs), and thread pool in the IPC framework.
25  *
26  * @syscap SystemCapability.Communication.IPC.Core
27  * @since 12
28  */
29 
30 /**
31  * @file ipc_cskeleton.h
32  *
33  * @brief Defines C interfaces for managing the token IDs, credentials, PIDs, UIDs, and thread
34  * pool in the IPC framework.
35  *
36  * @library libipc_capi.so
37  * @kit IPCKit
38  * @syscap SystemCapability.Communication.IPC.Core
39  * @since 12
40  */
41 
42 #include <stdint.h>
43 
44 #include "ipc_cparcel.h"
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 /**
51  * @brief Joints this thread to the IPC worker thread pool.
52  *
53  * @syscap SystemCapability.Communication.IPC.Core
54  * @since 12
55  */
56 void OH_IPCSkeleton_JoinWorkThread(void);
57 
58 /**
59  * @brief Stops this thread.
60  *
61  * @syscap SystemCapability.Communication.IPC.Core
62  * @since 12
63  */
64 void OH_IPCSkeleton_StopWorkThread(void);
65 
66 /**
67  * @brief Obtains the token ID of the caller. This function must be called in the IPC context.
68  * Otherwise, the local token ID is returned.
69  *
70  * @syscap SystemCapability.Communication.IPC.Core
71  * @return Returns the token ID of the caller.
72  * @since 12
73  */
74 uint64_t OH_IPCSkeleton_GetCallingTokenId(void);
75 
76 /**
77  * @brief Obtains the token ID of the first caller.
78  *
79  * @syscap SystemCapability.Communication.IPC.Core
80  * @return Returns the token ID obtained.
81  * @since 12
82  */
83 uint64_t OH_IPCSkeleton_GetFirstTokenId(void);
84 
85 /**
86  * @brief Obtains the local token ID.
87  *
88  * @syscap SystemCapability.Communication.IPC.Core
89  * @return Returns the token ID obtained.
90  * @since 12
91  */
92 uint64_t OH_IPCSkeleton_GetSelfTokenId(void);
93 
94 /**
95  * @brief Obtains the process ID of the caller. This function must be called in the IPC context.
96  * Otherwise, the current process ID is returned.
97  *
98  * @syscap SystemCapability.Communication.IPC.Core
99  * @return Returns the process ID of the caller.
100  * @since 12
101  */
102 uint64_t OH_IPCSkeleton_GetCallingPid(void);
103 
104 /**
105  * @brief Obtains the UID of the caller. This function must be called in the IPC context.
106  * Otherwise, the current UID is returned.
107  *
108  * @syscap SystemCapability.Communication.IPC.Core
109  * @return Returns the UID of the caller.
110  * @since 12
111  */
112 uint64_t OH_IPCSkeleton_GetCallingUid(void);
113 
114 /**
115  * @brief Checks whether a local calling is being made.
116  *
117  * @syscap SystemCapability.Communication.IPC.Core
118  * @return Returns <b>1</b> if a local calling is in progress; returns <b>0</b> otherwise.
119  * @since 12
120  */
121 int OH_IPCSkeleton_IsLocalCalling(void);
122 
123 /**
124  * @brief Sets the maximum number of worker threads.
125  *
126  * @syscap SystemCapability.Communication.IPC.Core
127  * @param maxThreadNum Maximum number of worker threads to set. The default value is <b>16</b>.
128  * The value range is [1, 32].
129  * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
130  * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if incorrect parameters are found. \n
131  * Returns {@link OH_IPC_ErrorCode#OH_IPC_INNER_ERROR} in other cases.
132  * @since 12
133  */
134 int OH_IPCSkeleton_SetMaxWorkThreadNum(const int maxThreadNum);
135 
136 /**
137  * @brief Resets the caller identity credential (including the token ID, UID, and PID) to that of this process and
138  * returns the caller credential information.
139  * The identity information is used in <b>OH_IPCSkeleton_SetCallingIdentity</b>.
140  *
141  * @syscap SystemCapability.Communication.IPC.Core
142  * @param identity Pointer to the address of the memory for holding the caller identity information.
143  * The memory is allocated by the allocator provided by the user and needs to be released. This pointer cannot be NULL.
144  * @param len Pointer to the length of the identity information. It cannot be NULL.
145  * @param allocator Memory allocator specified by the user for allocating memory for <b>identity</b>. It cannot be NULL.
146  * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
147  * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if incorrect parameters are found. \n
148  * Returns {@link OH_IPC_ErrorCode#OH_IPC_MEM_ALLOCATOR_ERROR} if memory allocation fails. \n
149  * Returns {@link OH_IPC_ErrorCode#OH_IPC_INNER_ERROR} in other cases.
150  * @since 12
151  */
152 int OH_IPCSkeleton_ResetCallingIdentity(char **identity, int32_t *len, OH_IPC_MemAllocator allocator);
153 
154 /**
155  * @brief Sets the caller credential information to the IPC context.
156  *
157  * @syscap SystemCapability.Communication.IPC.Core
158  * @param identity Pointer to the caller identity, which cannot be NULL.
159  * The value is returned by <b>OH_IPCSkeleton_ResetCallingIdentity</b>.
160  * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
161  * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if incorrect parameters are found. \n
162  * Returns {@link OH_IPC_ErrorCode#OH_IPC_INNER_ERROR} in other cases.
163  * @since 12
164  */
165 int OH_IPCSkeleton_SetCallingIdentity(const char *identity);
166 
167 /**
168  * @brief Checks whether an IPC request is being handled.
169  *
170  * @syscap SystemCapability.Communication.IPC.Core
171  * @return Returns <b>1</b> if an IPC request is being handled; returns <b>0</b> otherwise.
172  * @since 12
173  */
174 int OH_IPCSkeleton_IsHandlingTransaction(void);
175 
176 #ifdef __cplusplus
177 }
178 #endif
179 
180 /** @} */
181 #endif
182