• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "dscreen_sink_proxy.h"
17 
18 #include "parcel.h"
19 
20 #include "dscreen_errcode.h"
21 #include "dscreen_log.h"
22 
23 namespace OHOS {
24 namespace DistributedHardware {
InitSink(const std::string & params)25 int32_t DScreenSinkProxy::InitSink(const std::string &params)
26 {
27     DHLOGD("InitSink");
28     MessageParcel data;
29     MessageParcel reply;
30     MessageOption option;
31     if (!data.WriteInterfaceToken(GetDescriptor())) {
32         DHLOGE("WriteInterfaceToken failed");
33         return ERR_DH_SCREEN_SA_WRITEINTERFACETOKEN_FAILED;
34     }
35 
36     if (!data.WriteString(params)) {
37         DHLOGE("Write param failed.");
38         return ERR_DH_SCREEN_SA_WRITEPARAM_FAILED;
39     }
40 
41     Remote()->SendRequest(INIT_SINK, data, reply, option);
42     int32_t ret = reply.ReadInt32();
43     return ret;
44 }
45 
ReleaseSink()46 int32_t DScreenSinkProxy::ReleaseSink()
47 {
48     DHLOGD("ReleaseSink");
49     MessageParcel data;
50     MessageParcel reply;
51     MessageOption option;
52     if (!data.WriteInterfaceToken(GetDescriptor())) {
53         DHLOGE("WriteInterfaceToken failed");
54         return ERR_DH_SCREEN_SA_WRITEINTERFACETOKEN_FAILED;
55     }
56 
57     Remote()->SendRequest(RELEASE_SINK, data, reply, option);
58     int32_t ret = reply.ReadInt32();
59     return ret;
60 }
61 
SubscribeLocalHardware(const std::string & dhId,const std::string & param)62 int32_t DScreenSinkProxy::SubscribeLocalHardware(const std::string &dhId, const std::string &param)
63 {
64     DHLOGD("SubscribeLocalHardware");
65     MessageParcel data;
66     MessageParcel reply;
67     MessageOption option;
68     if (!data.WriteInterfaceToken(GetDescriptor())) {
69         DHLOGE("WriteInterfaceToken failed");
70         return ERR_DH_SCREEN_SA_WRITEINTERFACETOKEN_FAILED;
71     }
72 
73     if (!data.WriteString(dhId) || !data.WriteString(param)) {
74         DHLOGE("Write param failed.");
75         return ERR_DH_SCREEN_SA_WRITEPARAM_FAILED;
76     }
77 
78     Remote()->SendRequest(SUBSCRIBE_DISTRIBUTED_HARDWARE, data, reply, option);
79     int32_t ret = reply.ReadInt32();
80     return ret;
81 }
82 
UnsubscribeLocalHardware(const std::string & dhId)83 int32_t DScreenSinkProxy::UnsubscribeLocalHardware(const std::string &dhId)
84 {
85     DHLOGD("UnsubscribeLocalHardware");
86     MessageParcel data;
87     MessageParcel reply;
88     MessageOption option;
89     if (!data.WriteInterfaceToken(GetDescriptor())) {
90         DHLOGE("WriteInterfaceToken failed");
91         return ERR_DH_SCREEN_SA_WRITEINTERFACETOKEN_FAILED;
92     }
93 
94     if (!data.WriteString(dhId)) {
95         DHLOGE("Write param failed.");
96         return ERR_DH_SCREEN_SA_WRITEPARAM_FAILED;
97     }
98 
99     Remote()->SendRequest(UNSUBSCRIBE_DISTRIBUTED_HARDWARE, data, reply, option);
100     int32_t ret = reply.ReadInt32();
101     return ret;
102 }
103 
DScreenNotify(const std::string & devId,int32_t eventCode,const std::string & eventContent)104 void DScreenSinkProxy::DScreenNotify(const std::string &devId, int32_t eventCode, const std::string &eventContent)
105 {
106     DHLOGD("DScreenNotify");
107     MessageParcel data;
108     MessageParcel reply;
109     MessageOption option = { MessageOption::TF_ASYNC };
110     if (!data.WriteInterfaceToken(GetDescriptor())) {
111         DHLOGE("WriteInterfaceToken failed");
112         return;
113     }
114 
115     if (!data.WriteString(devId) || !data.WriteInt32(eventCode) || !data.WriteString(eventContent)) {
116         DHLOGE("Write param failed.");
117         return;
118     }
119 
120     Remote()->SendRequest(DSCREEN_NOTIFY, data, reply, option);
121 }
122 } // namespace DistributedHardware
123 } // namespace OHOS