1 /*
2  * Copyright (c) 2022-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 #include "input_node_listener_proxy.h"
17 
18 #include "ipc_types.h"
19 #include "parcel.h"
20 
21 #include "dinput_log.h"
22 
23 namespace OHOS {
24 namespace DistributedHardware {
25 namespace DistributedInput {
InputNodeListenerProxy(const sptr<IRemoteObject> & object)26 InputNodeListenerProxy::InputNodeListenerProxy(const sptr<IRemoteObject> &object)
27     : IRemoteProxy<InputNodeListener>(object)
28 {
29 }
30 
~InputNodeListenerProxy()31 InputNodeListenerProxy::~InputNodeListenerProxy() {}
32 
OnNodeOnLine(const std::string & srcDevId,const std::string & sinkDevId,const std::string & sinkNodeId,const std::string & sinkNodeDesc)33 void InputNodeListenerProxy::OnNodeOnLine(const std::string &srcDevId, const std::string &sinkDevId,
34     const std::string &sinkNodeId, const std::string &sinkNodeDesc)
35 {
36     sptr<IRemoteObject> remote = Remote();
37     if (remote == nullptr) {
38         return;
39     }
40 
41     MessageParcel data;
42     MessageParcel reply;
43     MessageOption option;
44     if (!data.WriteInterfaceToken(GetDescriptor())) {
45         DHLOGE("InputNodeListenerProxy write token valid failed");
46         return;
47     }
48     if (!data.WriteString(srcDevId)) {
49         DHLOGE("InputNodeListenerProxy write srcDevId failed");
50         return;
51     }
52     if (!data.WriteString(sinkDevId)) {
53         DHLOGE("InputNodeListenerProxy write sinkDevId failed");
54         return;
55     }
56     if (!data.WriteString(sinkNodeId)) {
57         DHLOGE("InputNodeListenerProxy write sinkNodeId failed");
58         return;
59     }
60     if (!data.WriteString(sinkNodeDesc)) {
61         DHLOGE("InputNodeListenerProxy write sinkNodeDesc failed");
62         return;
63     }
64     int32_t ret = remote->SendRequest(static_cast<uint32_t>(InputNodeListener::Message::RESULT_ON), data, reply,
65         option);
66     if (ret != 0) {
67         return;
68     }
69 }
70 
OnNodeOffLine(const std::string & srcDevId,const std::string & sinkDevId,const std::string & sinkNodeId)71 void InputNodeListenerProxy::OnNodeOffLine(const std::string &srcDevId, const std::string &sinkDevId,
72     const std::string &sinkNodeId)
73 {
74     sptr<IRemoteObject> remote = Remote();
75     if (remote == nullptr) {
76         return;
77     }
78 
79     MessageParcel data;
80     MessageParcel reply;
81     MessageOption option;
82     if (!data.WriteInterfaceToken(GetDescriptor())) {
83         DHLOGE("InputNodeListenerProxy write token valid failed");
84         return;
85     }
86     if (!data.WriteString(srcDevId)) {
87         DHLOGE("InputNodeListenerProxy write srcDevId failed");
88         return;
89     }
90     if (!data.WriteString(sinkDevId)) {
91         DHLOGE("InputNodeListenerProxy write sinkDevId failed");
92         return;
93     }
94     if (!data.WriteString(sinkNodeId)) {
95         DHLOGE("InputNodeListenerProxy write sinkNodeId failed");
96         return;
97     }
98     int32_t ret = remote->SendRequest(static_cast<uint32_t>(InputNodeListener::Message::RESULT_OFF), data, reply,
99         option);
100     if (ret != 0) {
101         return;
102     }
103 }
104 } // namespace DistributedInput
105 } // namespace DistributedHardware
106 } // namespace OHOS
107