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 IPC_REMOTE_OBJECT_INTERNAL_H
17 #define IPC_REMOTE_OBJECT_INTERNAL_H
18
19 #include "ipc_cremote_object.h"
20 #include "iremote_object.h"
21 #include "ipc_object_stub.h"
22 #include "ipc_error_code.h"
23
IsUserDefinedError(int error)24 static inline bool IsUserDefinedError(int error)
25 {
26 return (error >= OH_IPC_USER_ERROR_CODE_MIN) && (error <= OH_IPC_USER_ERROR_CODE_MAX);
27 }
28
IsIpcErrorCode(int error)29 static inline bool IsIpcErrorCode(int error)
30 {
31 return (error >= OH_IPC_ERROR_CODE_BASE) && (error <= OH_IPC_INNER_ERROR);
32 }
33
34 struct IPCDeathRecipient : public OHOS::IRemoteObject::DeathRecipient {
35 public:
36 IPCDeathRecipient(OH_OnDeathRecipientCallback deathRecipientCallback,
37 OH_OnDeathRecipientDestroyCallback destroyCallback, void *userData);
38 ~IPCDeathRecipient();
39
40 virtual void OnRemoteDied(const OHOS::wptr<OHOS::IRemoteObject> &object) override;
41
42 private:
43 OH_OnDeathRecipientCallback deathRecipientCallback_;
44 OH_OnDeathRecipientDestroyCallback destroyCallback_;
45 void *userData_;
46 };
47
48 struct OHIPCDeathRecipient {
49 OHOS::sptr<IPCDeathRecipient> recipient;
50 };
51
52 class OHIPCRemoteServiceStub : public OHOS::IPCObjectStub {
53 public:
54 OHIPCRemoteServiceStub(std::u16string &desc, OH_OnRemoteRequestCallback requestCallback,
55 OH_OnRemoteDestroyCallback destroyCallback, void *userData);
56 ~OHIPCRemoteServiceStub();
57
58 int OnRemoteRequest(uint32_t code, OHOS::MessageParcel &data,
59 OHOS::MessageParcel &reply, OHOS::MessageOption &option) override;
60
61 private:
62 OH_OnRemoteRequestCallback requestCallback_;
63 OH_OnRemoteDestroyCallback destroyCallback_;
64 void *userData_;
65 };
66
67 #endif
68