1 /* 2 * Copyright (C) 2021 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 OHOS_IPC_RPC_PROCESS_SKELETON_H 17 #define OHOS_IPC_RPC_PROCESS_SKELETON_H 18 19 #include <stdbool.h> 20 21 #include "ipc_skeleton.h" 22 #include "ipc_thread_pool.h" 23 #include "rpc_types.h" 24 #include "utils_list.h" 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif /* __cplusplus */ 29 30 typedef struct { 31 bool usedFlag; 32 OnRemoteDead func; 33 void *args; 34 } DeathHandler; 35 36 typedef struct { 37 UTILS_DL_LIST list; 38 pthread_mutex_t lock; 39 DeathHandler handler[MAX_DEATH_CALLBACK_NUM]; 40 int32_t handle; 41 int32_t deathNum; 42 bool isRemoteDead; 43 bool isNewHandler; 44 } DeathCallback; 45 46 typedef struct { 47 UTILS_DL_LIST objects; 48 pthread_mutex_t lock; 49 ThreadPool *threadPool; 50 } IpcSkeleton; 51 52 IpcSkeleton *GetCurrentSkeleton(void); 53 int32_t SetMaxWorkThread(int32_t maxThreadNum); 54 void JoinMainWorkThread(void); 55 pid_t ProcessGetCallingPid(void); 56 pid_t ProcessGetCallingUid(void); 57 int32_t SpawnThread(int32_t policy, int32_t proto); 58 int32_t SetRegistryObject(SvcIdentity target); 59 const SvcIdentity *GetRegistryObject(void); 60 int32_t ProcessSendRequest(SvcIdentity target, uint32_t code, IpcIo *data, IpcIo *reply, 61 MessageOption option, uintptr_t *buffer); 62 int32_t ProcessFreeBuffer(void *ptr); 63 void OnFirstStrongRef(int32_t handle); 64 int32_t ProcessAddDeathRecipient(int32_t handle, OnRemoteDead deathFunc, void *args, uint32_t *cbId); 65 int32_t ProcessRemoveDeathRecipient(int32_t handle, uint32_t cbId); 66 int32_t OnRemoteRequestInner(uint32_t code, IpcIo *data, IpcIo *reply, 67 MessageOption option, IpcObjectStub *objectStub); 68 bool OnThreadTerminated(pthread_t threadId); 69 void SendObituary(DeathCallback *deathCallback); 70 void DeleteDeathCallback(DeathCallback *deathCallback); 71 void WaitForProxyInit(SvcIdentity *svc); 72 int32_t DeleteHandle(int32_t handle); 73 #ifdef __cplusplus 74 } 75 #endif /* __cplusplus */ 76 #endif /* OHOS_IPC_RPC_PROCESS_SKELETON_H */