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_source_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 {
InitSource(const std::string & params,const sptr<IDScreenSourceCallback> & callback)25 int32_t DScreenSourceProxy::InitSource(const std::string ¶ms, const sptr<IDScreenSourceCallback> &callback)
26 {
27 MessageParcel data;
28 MessageParcel reply;
29 MessageOption option;
30 if (!data.WriteInterfaceToken(GetDescriptor())) {
31 DHLOGE("WriteInterfaceToken failed");
32 return ERR_DH_SCREEN_SA_WRITEINTERFACETOKEN_FAILED;
33 }
34
35 if (!data.WriteString(params)
36 || !data.WriteRemoteObject(callback->AsObject())) {
37 DHLOGE("Write param failed.");
38 return ERR_DH_SCREEN_SA_WRITEPARAM_FAILED;
39 }
40
41 Remote()->SendRequest(INIT_SOURCE, data, reply, option);
42 int32_t ret = reply.ReadInt32();
43 return ret;
44 }
45
ReleaseSource()46 int32_t DScreenSourceProxy::ReleaseSource()
47 {
48 MessageParcel data;
49 MessageParcel reply;
50 MessageOption option;
51 if (!data.WriteInterfaceToken(GetDescriptor())) {
52 DHLOGE("WriteInterfaceToken failed");
53 return ERR_DH_SCREEN_SA_WRITEINTERFACETOKEN_FAILED;
54 }
55
56 Remote()->SendRequest(RELEASE_SOURCE, data, reply, option);
57 int32_t ret = reply.ReadInt32();
58 return ret;
59 }
60
RegisterDistributedHardware(const std::string & devId,const std::string & dhId,const EnableParam & param,const std::string & reqId)61 int32_t DScreenSourceProxy::RegisterDistributedHardware(const std::string &devId,
62 const std::string &dhId, const EnableParam ¶m, const std::string &reqId)
63 {
64 MessageParcel data;
65 MessageParcel reply;
66 MessageOption option;
67 if (!data.WriteInterfaceToken(GetDescriptor())) {
68 DHLOGE("WriteInterfaceToken failed");
69 return ERR_DH_SCREEN_SA_WRITEINTERFACETOKEN_FAILED;
70 }
71
72 if (!data.WriteString(devId) || !data.WriteString(dhId)
73 || !data.WriteString(param.version) || !data.WriteString(param.attrs)
74 || !data.WriteString(reqId)) {
75 DHLOGE("Write param failed.");
76 return ERR_DH_SCREEN_SA_WRITEPARAM_FAILED;
77 }
78 Remote()->SendRequest(REGISTER_DISTRIBUTED_HARDWARE, data, reply, option);
79 int32_t ret = reply.ReadInt32();
80 return ret;
81 }
82
UnregisterDistributedHardware(const std::string & devId,const std::string & dhId,const std::string & reqId)83 int32_t DScreenSourceProxy::UnregisterDistributedHardware(const std::string &devId,
84 const std::string &dhId, const std::string &reqId)
85 {
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(devId) || !data.WriteString(dhId)
95 || !data.WriteString(reqId)) {
96 DHLOGE("Write param failed.");
97 return ERR_DH_SCREEN_SA_WRITEPARAM_FAILED;
98 }
99 Remote()->SendRequest(UNREGISTER_DISTRIBUTED_HARDWARE, data, reply, option);
100 int32_t ret = reply.ReadInt32();
101 return ret;
102 }
103
ConfigDistributedHardware(const std::string & devId,const std::string & dhId,const std::string & key,const std::string & value)104 int32_t DScreenSourceProxy::ConfigDistributedHardware(const std::string &devId,
105 const std::string &dhId, const std::string &key, const std::string &value)
106 {
107 MessageParcel data;
108 MessageParcel reply;
109 MessageOption option;
110 if (!data.WriteInterfaceToken(GetDescriptor())) {
111 DHLOGE("WriteInterfaceToken failed");
112 return ERR_DH_SCREEN_SA_WRITEINTERFACETOKEN_FAILED;
113 }
114
115 if (!data.WriteString(devId) || !data.WriteString(dhId)
116 || !data.WriteString(key) || !data.WriteString(value)) {
117 DHLOGE("Write param failed.");
118 return ERR_DH_SCREEN_SA_WRITEPARAM_FAILED;
119 }
120 Remote()->SendRequest(CONFIG_DISTRIBUTED_HARDWARE, data, reply, option);
121 int32_t ret = reply.ReadInt32();
122 return ret;
123 }
124
DScreenNotify(const std::string & devId,int32_t eventCode,const std::string & eventContent)125 void DScreenSourceProxy::DScreenNotify(const std::string &devId,
126 int32_t eventCode, const std::string &eventContent)
127 {
128 DHLOGD("DScreenNotify");
129 MessageParcel data;
130 MessageParcel reply;
131 MessageOption option = { MessageOption::TF_ASYNC };
132 if (!data.WriteInterfaceToken(GetDescriptor())) {
133 DHLOGE("WriteInterfaceToken failed");
134 return;
135 }
136
137 if (!data.WriteString(devId) || !data.WriteInt32(eventCode) || !data.WriteString(eventContent)) {
138 DHLOGE("Write param failed.");
139 return;
140 }
141
142 Remote()->SendRequest(DSCREEN_NOTIFY, data, reply, option);
143 }
144 }
145 }
146