1 /*
2  * Copyright (c) 2021-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 SOFTBUS_CLIENT_STUB_H_
17 #define SOFTBUS_CLIENT_STUB_H_
18 
19 #include <map>
20 #include "if_softbus_client.h"
21 #include "iremote_object.h"
22 #include "iremote_stub.h"
23 
24 namespace OHOS {
25 #define READ_PARCEL_WITH_RET(parcel, type, data, retVal)        \
26     do {                                                        \
27         if (!(parcel).Read##type(data)) {                       \
28             COMM_LOGE(COMM_SDK, "read data failed.");           \
29             return (retVal);                                    \
30         }                                                       \
31     } while (false)                                             \
32 
33 class SoftBusClientStub : public IRemoteStub<ISoftBusClient> {
34 public:
35     SoftBusClientStub();
36     virtual ~SoftBusClientStub() = default;
37     int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
38     int32_t OnChannelOpened(const char *sessionName, const ChannelInfo *info) override;
39     int32_t OnChannelOpenFailed(int32_t channelId, int32_t channelType, int32_t errCode) override;
40     int32_t OnChannelLinkDown(const char *networkId, int32_t routeType) override;
41     int32_t OnChannelClosed(int32_t channelId, int32_t channelType, int32_t messageType) override;
42     int32_t OnChannelMsgReceived(int32_t channelId, int32_t channelType, const void *data,
43         uint32_t len, int32_t type) override;
44     int32_t OnChannelQosEvent(int32_t channelId, int32_t channelType, int32_t eventId, int32_t tvCount,
45         const QosTv *tvList) override;
46     int32_t SetChannelInfo(const char *sessionName, int32_t sessionId, int32_t channelId, int32_t channelType) override;
47     int32_t OnJoinLNNResult(void *addr, uint32_t addrTypeLen, const char *networkId, int retCode) override;
48     int32_t OnLeaveLNNResult(const char *networkId, int retCode) override;
49     int32_t OnNodeOnlineStateChanged(const char *pkgName, bool isOnline, void *info, uint32_t infoTypeLen) override;
50     int32_t OnNodeBasicInfoChanged(const char *pkgName, void *info, uint32_t infoTypeLen, int32_t type) override;
51     int32_t OnNodeStatusChanged(const char *pkgName, void *info, uint32_t infoTypeLen, int32_t type) override;
52     int32_t OnLocalNetworkIdChanged(const char *pkgName) override;
53     int32_t OnNodeDeviceNotTrusted(const char *pkgName, const char *msg) override;
54     int32_t OnHichainProofException(const char *pkgName, const char *proofInfo, uint32_t proofLen,
55         uint16_t deviceTypeId, int32_t errCode) override;
56     int32_t OnTimeSyncResult(const void *info, uint32_t infoTypeLen, int32_t retCode) override;
57     void OnPublishLNNResult(int32_t publishId, int32_t reason) override;
58     void OnRefreshLNNResult(int32_t refreshId, int32_t reason) override;
59     void OnRefreshDeviceFound(const void *device, uint32_t deviceLen) override;
60     void OnDataLevelChanged(const char *networkId, const DataLevelInfo *dataLevelInfo) override;
61     int32_t OnClientTransLimitChange(int32_t channelId, uint8_t tos) override;
62     int32_t OnChannelBind(int32_t channelId, int32_t channelType) override;
63     int32_t OnClientChannelOnQos(
64         int32_t channelId, int32_t channelType, QoSEvent event, const QosTV *qos, uint32_t count) override;
65 
66 private:
67     int32_t OnChannelOpenedInner(MessageParcel &data, MessageParcel &reply);
68     int32_t OnChannelOpenFailedInner(MessageParcel &data, MessageParcel &reply);
69     int32_t OnChannelLinkDownInner(MessageParcel &data, MessageParcel &reply);
70     int32_t OnChannelClosedInner(MessageParcel &data, MessageParcel &reply);
71     int32_t OnChannelMsgReceivedInner(MessageParcel &data, MessageParcel &reply);
72     int32_t OnChannelQosEventInner(MessageParcel &data, MessageParcel &reply);
73     int32_t SetChannelInfoInner(MessageParcel &data, MessageParcel &reply);
74     int32_t OnJoinLNNResultInner(MessageParcel &data, MessageParcel &reply);
75     int32_t OnLeaveLNNResultInner(MessageParcel &data, MessageParcel &reply);
76     int32_t OnNodeOnlineStateChangedInner(MessageParcel &data, MessageParcel &reply);
77     int32_t OnNodeBasicInfoChangedInner(MessageParcel &data, MessageParcel &reply);
78     int32_t OnNodeStatusChangedInner(MessageParcel &data, MessageParcel &reply);
79     int32_t OnLocalNetworkIdChangedInner(MessageParcel &data, MessageParcel &reply);
80     int32_t OnNodeDeviceNotTrustedInner(MessageParcel &data, MessageParcel &reply);
81     int32_t OnHichainProofExceptionInner(MessageParcel &data, MessageParcel &reply);
82     int32_t OnTimeSyncResultInner(MessageParcel &data, MessageParcel &reply);
83     int32_t OnPublishLNNResultInner(MessageParcel &data, MessageParcel &reply);
84     int32_t OnRefreshLNNResultInner(MessageParcel &data, MessageParcel &reply);
85     int32_t OnRefreshDeviceFoundInner(MessageParcel &data, MessageParcel &reply);
86     int32_t OnClientPermissonChangeInner(MessageParcel &data, MessageParcel &reply);
87     int32_t OnDataLevelChangedInner(MessageParcel &data, MessageParcel &reply);
88     int32_t OnClientTransLimitChangeInner(MessageParcel &data, MessageParcel &reply);
89     int32_t OnChannelBindInner(MessageParcel &data, MessageParcel &reply);
90     int32_t OnChannelOnQosInner(MessageParcel &data, MessageParcel &reply);
91     using SoftBusClientStubFunc =
92         int32_t (SoftBusClientStub::*)(MessageParcel &data, MessageParcel &reply);
93     std::map<uint32_t, SoftBusClientStubFunc> memberFuncMap_;
94 };
95 } // namespace OHOS
96 
97 #endif // SOFTBUS_CLIENT_STUB_H_
98