• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 IPC_C_REMOTE_OBJECT_H
17 #define IPC_C_REMOTE_OBJECT_H
18 
19 #include <stdint.h>
20 #include "c_parcel.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 struct CRemoteObjectHolder;
27 typedef struct CRemoteObjectHolder CRemoteObject;
28 
29 struct CDeathRecipient;
30 typedef struct CDeathRecipient CDeathRecipient;
31 
32 // Callback as remote stub
33 typedef int (*OnRemoteRequestCb)(const void *userData, int code,
34     const CParcel *data, CParcel *reply);
35 typedef int (*OnRemoteDumpCb)(const void *userData, const CParcel *data);
36 typedef void (*OnRemoteObjectDestroyCb)(const void *userData);
37 // Callback as death recipient
38 typedef void (*OnDeathRecipientCb)(const void *userData);
39 typedef void (*OnDeathRecipientDestroyCb)(const void *userData);
40 
41 typedef bool (*On16BytesAllocator)(void *stringData, uint16_t **buffer, int32_t len);
42 
43 CRemoteObject *CreateRemoteStub(const char *desc, OnRemoteRequestCb callback,
44     OnRemoteObjectDestroyCb destroy, const void *userData, OnRemoteDumpCb dumpCallback);
45 
46 void RemoteObjectIncStrongRef(CRemoteObject *object);
47 void RemoteObjectDecStrongRef(CRemoteObject *object);
48 
49 bool RemoteObjectLessThan(const CRemoteObject *lhs, const CRemoteObject *rhs);
50 int RemoteObjectSendRequest(const CRemoteObject *object, uint32_t code,
51     const CParcel *data, CParcel *reply, bool isAsync);
52 
53 // Death Recipient
54 CDeathRecipient *CreateDeathRecipient(OnDeathRecipientCb onDeathRecipient,
55     OnDeathRecipientDestroyCb onDestroy, const void *userData);
56 void DeathRecipientIncStrongRef(CDeathRecipient *recipient);
57 void DeathRecipientDecStrongRef(CDeathRecipient *recipient);
58 bool AddDeathRecipient(CRemoteObject *object, CDeathRecipient *recipient);
59 bool RemoveDeathRecipient(CRemoteObject *object, CDeathRecipient *recipient);
60 
61 bool IsProxyObject(CRemoteObject *object);
62 int Dump(CRemoteObject *object, int fd, CParcel *parcel);
63 
64 bool IsObjectDead(CRemoteObject *object);
65 bool GetInterfaceDescriptor(CRemoteObject *object, void *value, On16BytesAllocator allocator);
66 #ifdef __cplusplus
67 }
68 #endif
69 #endif /* IPC_C_REMOTE_OBJECT_H */
70