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  * @syscap SystemCapability.Communication.IPC.Core
38  * @since 12
39  */
40 
41 #include <stdint.h>
42 
43 #include "ipc_cparcel.h"
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 /**
50  * @brief Joints this thread to the IPC worker thread pool.
51  *
52  * @syscap SystemCapability.Communication.IPC.Core
53  * @since 12
54  */
55 void OH_IPCSkeleton_JoinWorkThread(void);
56 
57 /**
58  * @brief Stops this thread.
59  *
60  * @syscap SystemCapability.Communication.IPC.Core
61  * @since 12
62  */
63 void OH_IPCSkeleton_StopWorkThread(void);
64 
65 /**
66  * @brief Obtains the token ID of the caller. This function must be called in the IPC context.
67  * Otherwise, the local token ID is returned.
68  *
69  * @syscap SystemCapability.Communication.IPC.Core
70  * @return Returns the token ID of the caller.
71  * @since 12
72  */
73 uint64_t OH_IPCSkeleton_GetCallingTokenId(void);
74 
75 /**
76  * @brief Obtains the token ID of the first caller.
77  *
78  * @syscap SystemCapability.Communication.IPC.Core
79  * @return Returns the token ID obtained.
80  * @since 12
81  */
82 uint64_t OH_IPCSkeleton_GetFirstTokenId(void);
83 
84 /**
85  * @brief Obtains the local token ID.
86  *
87  * @syscap SystemCapability.Communication.IPC.Core
88  * @return Returns the token ID obtained.
89  * @since 12
90  */
91 uint64_t OH_IPCSkeleton_GetSelfTokenId(void);
92 
93 /**
94  * @brief Obtains the process ID of the caller. This function must be called in the IPC context.
95  * Otherwise, the current process ID is returned.
96  *
97  * @syscap SystemCapability.Communication.IPC.Core
98  * @return Returns the process ID of the caller.
99  * @since 12
100  */
101 uint64_t OH_IPCSkeleton_GetCallingPid(void);
102 
103 /**
104  * @brief Obtains the UID of the caller. This function must be called in the IPC context.
105  * Otherwise, the current UID is returned.
106  *
107  * @syscap SystemCapability.Communication.IPC.Core
108  * @return Returns the UID of the caller.
109  * @since 12
110  */
111 uint64_t OH_IPCSkeleton_GetCallingUid(void);
112 
113 /**
114  * @brief Checks whether a local calling is being made.
115  *
116  * @syscap SystemCapability.Communication.IPC.Core
117  * @return Returns <b>1</b> if a local calling is in progress; returns <b>0</b> otherwise.
118  * @since 12
119  */
120 int OH_IPCSkeleton_IsLocalCalling(void);
121 
122 /**
123  * @brief Sets the maximum number of worker threads.
124  *
125  * @syscap SystemCapability.Communication.IPC.Core
126  * @param maxThreadNum Maximum number of worker threads to set. The default value is <b>16</b>.
127  * The value range is [1, 32].
128  * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
129  * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if incorrect parameters are found. \n
130  * Returns {@link OH_IPC_ErrorCode#OH_IPC_INNER_ERROR} in other cases.
131  * @since 12
132  */
133 int OH_IPCSkeleton_SetMaxWorkThreadNum(const int maxThreadNum);
134 
135 /**
136  * @brief Resets the caller identity credential (including the token ID, UID, and PID) to that of this process and
137  * returns the caller credential information.
138  * The identity information is used in <b>OH_IPCSkeleton_SetCallingIdentity</b>.
139  *
140  * @syscap SystemCapability.Communication.IPC.Core
141  * @param identity Pointer to the address of the memory for holding the caller identity information.
142  * The memory is allocated by the allocator provided by the user and needs to be released. This pointer cannot be NULL.
143  * @param len Pointer to the length of the identity information. It cannot be NULL.
144  * @param allocator Memory allocator specified by the user for allocating memory for <b>identity</b>. It cannot be NULL.
145  * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
146  * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if incorrect parameters are found. \n
147  * Returns {@link OH_IPC_ErrorCode#OH_IPC_MEM_ALLOCATOR_ERROR} if memory allocation fails. \n
148  * Returns {@link OH_IPC_ErrorCode#OH_IPC_INNER_ERROR} in other cases.
149  * @since 12
150  */
151 int OH_IPCSkeleton_ResetCallingIdentity(char **identity, int32_t *len, OH_IPC_MemAllocator allocator);
152 
153 /**
154  * @brief Sets the caller credential information to the IPC context.
155  *
156  * @syscap SystemCapability.Communication.IPC.Core
157  * @param identity Pointer to the caller identity, which cannot be NULL.
158  * The value is returned by <b>OH_IPCSkeleton_ResetCallingIdentity</b>.
159  * @return Returns {@link OH_IPC_ErrorCode#OH_IPC_SUCCESS} if the operation is successful. \n
160  * Returns {@link OH_IPC_ErrorCode#OH_IPC_CHECK_PARAM_ERROR} if incorrect parameters are found. \n
161  * Returns {@link OH_IPC_ErrorCode#OH_IPC_INNER_ERROR} in other cases.
162  * @since 12
163  */
164 int OH_IPCSkeleton_SetCallingIdentity(const char *identity);
165 
166 /**
167  * @brief Checks whether an IPC request is being handled.
168  *
169  * @syscap SystemCapability.Communication.IPC.Core
170  * @return Returns <b>1</b> if an IPC request is being handled; returns <b>0</b> otherwise.
171  * @since 12
172  */
173 int OH_IPCSkeleton_IsHandlingTransaction(void);
174 
175 #ifdef __cplusplus
176 }
177 #endif
178 
179 /** @} */
180 #endif
181