• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_DBINDER_TEST_SERVICE_SKELETON_H
17 #define OHOS_DBINDER_TEST_SERVICE_SKELETON_H
18 
19 #include "ipc_types.h"
20 #include "iremote_broker.h"
21 #include "iremote_object.h"
22 #include "iremote_stub.h"
23 #include "iremote_proxy.h"
24 #include "hilog/log.h"
25 #include "log_tags.h"
26 #include "hitrace/trace.h"
27 
28 namespace OHOS {
29 class IDBinderTestService : public IRemoteBroker {
30 public:
31     enum {
32         REVERSEINT = 0,
33         REVERSEINTDELAY = 1,
34         PING_SERVICE = 2,
35         GET_FOO_SERVICE = 3,
36         ONLY_DELAY = 4,
37         TRANS_OBJECT = 5,
38         TRANS_OVERSIZED_PKT = 6,
39         TRANS_RAW_DATA = 7,
40         RECEIVE_RAW_DATA = 8,
41         TRANS_TRACE_ID = 9,
42         TRANS_STUB_OBJECT = 10,
43         GET_REMOTE_STUB_OBJECT = 11,
44         GET_REMOTE_DES_TIMES = 12,
45         CLEAR_REMOTE_DES_TIMES = 13,
46         TRANS_OBJECT_OVER_DEVICE_OVER_PROCESS = 14,
47         TRANS_RPC_OBJECT_TO_LOCAL = 15,
48     };
49 
50     enum {
51         NOT_SAVE = 0,
52         SAVE = 1,
53         WITHDRAW = 2,
54     };
55 
56     enum {
57         FIRST_OBJECT = 0,  // Acquired once will be released automatically
58         SECOND_OBJECT = 1, // Acquired twice will be released automatically
59     };
60 
61     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.rpc.IDBinderTestService");
62     virtual int ReverseInt(int data, int &rep) = 0;
63     virtual int ReverseIntDelay(int data, int &rep) = 0;
64     virtual int Delay(int data, int &rep) = 0;
65     virtual int PingService(std::u16string &serviceName) = 0;
66     virtual int ReverseIntDelayAsync(int data, int &rep) = 0;
67     virtual int TransProxyObject(int data, sptr<IRemoteObject> &transObject, int operation, int &rep,
68         int &withdrawRes) = 0;
69     virtual int TransProxyObjectAgain(int data, sptr<IRemoteObject> &transObject, int operation, int &rep,
70         int &withdrawRes) = 0;
71     virtual int TransStubObject(int data, sptr<IRemoteObject> &transObject, int &rep, int &stubRep) = 0;
72     virtual int TransOversizedPkt(const std::string &dataStr, std::string &repStr) = 0;
73     virtual int ProxyTransRawData(int lengths) = 0;
74     virtual int StubTransRawData(int length) = 0;
75     virtual int GetChildId(uint64_t &rep) = 0;
76     virtual int FlushAsyncCommands(int count, int length) = 0;
77     virtual sptr<IRemoteObject> GetRemoteObject(int type) = 0;
78     virtual int GetRemoteDecTimes() = 0;
79     virtual void ClearRemoteDecTimes() = 0;
80 
81 private:
82     static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_ID_RPC, "IDBinderTestService" };
83 };
84 
85 class DBinderTestServiceStub : public IRemoteStub<IDBinderTestService> {
86 public:
87     int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
88     int ReverseIntDelayAsync(int data, int &rep) override;
89     static pid_t GetLastCallingPid();
90     static uid_t GetLastCallingUid();
91 
92 private:
93     static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_ID_RPC, "DBinderTestStub" };
94     static pid_t g_lastCallingPid;
95     static pid_t g_lastCallinguid;
96     sptr<IRemoteObject> recvProxy_;
97 
98     int OnReverseInt(MessageParcel &data, MessageParcel &reply);
99     int OnReverseIntDelay(MessageParcel &data, MessageParcel &reply);
100     int OnPingService(MessageParcel &data, MessageParcel &reply);
101     int OnDelay(MessageParcel &data, MessageParcel &reply);
102     int OnReceivedObject(MessageParcel &data, MessageParcel &reply);
103     int OnReceivedObjectTransAgain(MessageParcel &data, MessageParcel &reply);
104     int OnReceivedStubObject(MessageParcel &data, MessageParcel &reply);
105     int OnReceivedOversizedPkt(MessageParcel &data, MessageParcel &reply);
106     int OnReceivedRawData(MessageParcel &data, MessageParcel &reply);
107     int OnGetChildId(MessageParcel &data, MessageParcel &reply);
108     int OnSentRawData(MessageParcel &data, MessageParcel &reply);
109     int OnReceivedGetStubObject(MessageParcel &data, MessageParcel &reply);
110     int OnReceivedGetDecTimes(MessageParcel &data, MessageParcel &reply);
111     int OnReceivedClearDecTimes(MessageParcel &data, MessageParcel &reply);
112 };
113 
114 
115 class DBinderTestServiceProxy : public IRemoteProxy<IDBinderTestService> {
116 public:
117     explicit DBinderTestServiceProxy(const sptr<IRemoteObject> &impl);
118     ~DBinderTestServiceProxy() = default;
119     int ReverseInt(int data, int &rep) override;
120     int ReverseIntNullReply(int data, int &rep);
121     int ReverseIntVoidData(int data, int &rep);
122     int ReverseIntDelay(int data, int &rep) override;
123     int Delay(int data, int &rep) override;
124     int ReverseIntDelayAsync(int data, int &rep) override;
125     int PingService(std::u16string &serviceName) override;
126     int TransProxyObject(int data, sptr<IRemoteObject> &transObject, int operation, int &rep,
127         int &withdrawRes) override;
128     int TransProxyObjectAgain(int data, sptr<IRemoteObject> &transObject, int operation, int &rep,
129         int &withdrawRes) override;
130     int TransStubObject(int data, sptr<IRemoteObject> &transObject, int &rep, int &stubRep) override;
131     int TransOversizedPkt(const std::string &dataStr, std::string &repStr) override;
132     int ProxyTransRawData(int length) override;
133     int StubTransRawData(int length) override;
134     int GetChildId(uint64_t &rep) override;
135     sptr<IRemoteObject> GetRemoteObject(int type) override;
136     int GetRemoteDecTimes() override;
137     void ClearRemoteDecTimes() override;
138     int FlushAsyncCommands(int count, int length) override;
139 
140 private:
141     static inline BrokerDelegator<DBinderTestServiceProxy> delegator_;
142     static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_ID_RPC, "DBinderTestProxy" };
143 };
144 
145 
146 class DBinderTestDeathRecipient : public IRemoteObject::DeathRecipient {
147 public:
148     virtual void OnRemoteDied(const wptr<IRemoteObject> &remote);
149     DBinderTestDeathRecipient();
150     virtual ~DBinderTestDeathRecipient();
151     static bool GotDeathRecipient();
152     static void ClearDeathRecipient();
153     static bool g_gotDeathRecipient;
154 
155 private:
156     static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_ID_RPC, "DBinderTestDeathRecipient" };
157 };
158 } // namespace OHOS
159 #endif // OHOS_DBINDER_TEST_SERVICE_SKELETON_H
160