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_SKELETON_H 17 #define OHOS_IPC_RPC_SKELETON_H 18 19 #include <stdbool.h> 20 #include <stdint.h> 21 #include <sys/types.h> 22 #include <unistd.h> 23 24 #include "serializer.h" 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif /* __cplusplus */ 29 30 enum { 31 TF_OP_SYNC = 0x00, 32 TF_OP_ASYNC = 0x01, 33 TF_OP_STATUS_CODE = 0x08, 34 TF_OP_ACCEPT_FDS = 0x10, 35 }; 36 37 typedef struct { 38 uint32_t flags; 39 uint32_t waitTime; 40 void *args; 41 } MessageOption; 42 43 typedef int32_t (*OnRemoteRequest)(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option); 44 typedef void (*OnRemoteDead)(void *args); 45 46 typedef struct { 47 OnRemoteRequest func; 48 void *args; 49 bool isRemote; 50 } IpcObjectStub; 51 52 // default is 4 53 int32_t SetMaxWorkThreadNum(int32_t maxThreadNum); 54 55 // join current thread into work loop. 56 void JoinWorkThread(void); 57 58 pid_t GetCallingPid(void); 59 60 pid_t GetCallingUid(void); 61 62 const SvcIdentity *GetContextObject(void); 63 64 int32_t SetContextObject(SvcIdentity target); 65 66 int32_t SendRequest(SvcIdentity target, uint32_t code, IpcIo *data, IpcIo *reply, 67 MessageOption option, uintptr_t *buffer); 68 69 int32_t FreeBuffer(void *ptr); 70 71 int32_t AddDeathRecipient(SvcIdentity target, OnRemoteDead deathFunc, void *args, uint32_t *cbId); 72 73 int32_t RemoveDeathRecipient(SvcIdentity target, uint32_t cbId); 74 75 int32_t MessageOptionInit(MessageOption *option); 76 77 int32_t ReleaseSvc(SvcIdentity target); 78 #ifdef __cplusplus 79 } 80 #endif /* __cplusplus */ 81 #endif /* OHOS_IPC_RPC_SKELETON_H */ 82