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 OHOS_RPC_FOO_TEST_H
17 #define OHOS_RPC_FOO_TEST_H
18 
19 #include "iremote_broker.h"
20 #include "iremote_object.h"
21 #include "iremote_proxy.h"
22 #include "iremote_stub.h"
23 #include "message_parcel.h"
24 
25 namespace OHOS {
26 #define RPC_ACCESS_TOKEN_FLAG 0x1
27 #define INVAL_TOKEN_ID 0x0
28 class IRpcFooTest : public IRemoteBroker {
29 public:
30     enum FooInterFaceId {
31         GET_FOO_NAME = 0,
32         SEND_ASYNC_REPLY = 1,
33         SEND_WRONG_REPLY = 2,
34         GET_TOKENID = 3,
35         TEST_REMOTE_OBJECT = 4,
36         TEST_ADD = 5,
37     };
38     std::string GetFooName(void);
39     virtual std::string TestGetFooName(void) = 0;
40     virtual int32_t TestAccessToken(MessageParcel &data, MessageParcel &reply) = 0;
41     virtual int32_t TestRemoteObject(MessageParcel &data, MessageParcel &reply) = 0;
42     virtual int32_t TestAdd(MessageParcel &data, MessageParcel &reply) = 0;
43 public:
44     DECLARE_INTERFACE_DESCRIPTOR(u"test.rpc.IRpcFooTest");
45 private:
46     std::string fooName_ = "IRpcFooTest";
47 };
48 
49 class RpcFooStub : public IRemoteStub<IRpcFooTest> {
50 public:
51     int OnRemoteRequest(uint32_t code,
52         MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
53     std::string TestGetFooName(void) override;
54     int32_t TestAccessToken(MessageParcel &data, MessageParcel &reply) override;
55     int32_t TestRemoteObject(MessageParcel &data, MessageParcel &reply) override;
56     int32_t TestAdd(MessageParcel &data, MessageParcel &reply) override;
57 };
58 
59 class RpcFooProxy : public IRemoteProxy<IRpcFooTest> {
60 public:
61     explicit RpcFooProxy(const sptr<IRemoteObject> &impl);
62     ~RpcFooProxy() = default;
63     std::string TestGetFooName(void) override;
64     int32_t TestAccessToken(MessageParcel &data, MessageParcel &reply) override;
65     int32_t TestRemoteObject(MessageParcel &data, MessageParcel &reply) override;
66     int32_t TestAdd(MessageParcel &data, MessageParcel &reply) override;
67 private:
68     static inline BrokerDelegator<RpcFooProxy> delegator_;
69 };
70 
71 class RpcDeathRecipient : public IRemoteObject::DeathRecipient {
72 public:
73     virtual void OnRemoteDied(const wptr<IRemoteObject> &remote);
74     RpcDeathRecipient();
75     virtual ~RpcDeathRecipient();
76 };
77 } // namespace OHOS
78 #endif // OHOS_RPC_FOO_TEST_H
79 
80