1 /*
2 * Copyright (c) 2023 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 "profile_change_listener_proxy.h"
17 #include "macro_utils.h"
18 #include "distributed_device_profile_errors.h"
19 #include "i_distributed_device_profile.h"
20 #include "message_parcel.h"
21
22 namespace OHOS {
23 namespace DistributedDeviceProfile {
24 namespace {
25 const std::string TAG = "ProfileListenerProxy";
26 }
OnTrustDeviceProfileAdd(const TrustDeviceProfile & profile)27 int32_t ProfileListenerProxy::OnTrustDeviceProfileAdd(const TrustDeviceProfile& profile)
28 {
29 sptr<IRemoteObject> remote = nullptr;
30 GET_REMOTE_OBJECT(remote);
31 MessageParcel data;
32 WRITE_CHANGE_LISTENER_TOKEN(data);
33 if (!profile.Marshalling(data)) {
34 HILOGE("write reply failed!");
35 return ERR_FLATTEN_OBJECT;
36 }
37 MessageParcel reply;
38 SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::ON_TRUST_DEVICE_PROFILE_ADD), data, reply);
39 return DP_SUCCESS;
40 }
41
OnTrustDeviceProfileDelete(const TrustDeviceProfile & profile)42 int32_t ProfileListenerProxy::OnTrustDeviceProfileDelete(const TrustDeviceProfile& profile)
43 {
44 sptr<IRemoteObject> remote = nullptr;
45 GET_REMOTE_OBJECT(remote);
46 MessageParcel data;
47 WRITE_CHANGE_LISTENER_TOKEN(data);
48 if (!profile.Marshalling(data)) {
49 HILOGE("write reply failed!");
50 return ERR_FLATTEN_OBJECT;
51 }
52 MessageParcel reply;
53 SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::ON_TRUST_DEVICE_PROFILE_DELETE), data, reply);
54 return DP_SUCCESS;
55 }
56
OnTrustDeviceProfileUpdate(const TrustDeviceProfile & oldProfile,const TrustDeviceProfile & newProfile)57 int32_t ProfileListenerProxy::OnTrustDeviceProfileUpdate(const TrustDeviceProfile& oldProfile,
58 const TrustDeviceProfile& newProfile)
59 {
60 sptr<IRemoteObject> remote = nullptr;
61 GET_REMOTE_OBJECT(remote);
62 MessageParcel data;
63 WRITE_CHANGE_LISTENER_TOKEN(data);
64 if (!oldProfile.Marshalling(data)) {
65 HILOGE("write reply failed!");
66 return ERR_FLATTEN_OBJECT;
67 }
68 if (!newProfile.Marshalling(data)) {
69 HILOGE("write reply failed!");
70 return ERR_FLATTEN_OBJECT;
71 }
72 MessageParcel reply;
73 SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::ON_TRUST_DEVICE_PROFILE_UPDATE), data, reply);
74 return DP_SUCCESS;
75 }
76
OnDeviceProfileAdd(const DeviceProfile & profile)77 int32_t ProfileListenerProxy::OnDeviceProfileAdd(const DeviceProfile& profile)
78 {
79 sptr<IRemoteObject> remote = nullptr;
80 GET_REMOTE_OBJECT(remote);
81 MessageParcel data;
82 WRITE_CHANGE_LISTENER_TOKEN(data);
83 if (!profile.Marshalling(data)) {
84 HILOGE("write reply failed!");
85 return ERR_FLATTEN_OBJECT;
86 }
87 MessageParcel reply;
88 SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::ON_DEVICE_PROFILE_ADD), data, reply);
89 return DP_SUCCESS;
90 }
91
OnDeviceProfileDelete(const DeviceProfile & profile)92 int32_t ProfileListenerProxy::OnDeviceProfileDelete(const DeviceProfile& profile)
93 {
94 sptr<IRemoteObject> remote = nullptr;
95 GET_REMOTE_OBJECT(remote);
96 MessageParcel data;
97 WRITE_CHANGE_LISTENER_TOKEN(data);
98 if (!profile.Marshalling(data)) {
99 HILOGE("write reply failed!");
100 return ERR_FLATTEN_OBJECT;
101 }
102 MessageParcel reply;
103 SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::ON_DEVICE_PROFILE_DELETE), data, reply);
104 return DP_SUCCESS;
105 }
106
OnDeviceProfileUpdate(const DeviceProfile & oldProfile,const DeviceProfile & newProfile)107 int32_t ProfileListenerProxy::OnDeviceProfileUpdate(const DeviceProfile& oldProfile, const DeviceProfile& newProfile)
108 {
109 sptr<IRemoteObject> remote = nullptr;
110 GET_REMOTE_OBJECT(remote);
111 MessageParcel data;
112 WRITE_CHANGE_LISTENER_TOKEN(data);
113 if (!oldProfile.Marshalling(data)) {
114 HILOGE("write reply failed!");
115 return ERR_FLATTEN_OBJECT;
116 }
117 if (!newProfile.Marshalling(data)) {
118 HILOGE("write reply failed!");
119 return ERR_FLATTEN_OBJECT;
120 }
121 MessageParcel reply;
122 SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::ON_DEVICE_PROFILE_UPDATE), data, reply);
123 return DP_SUCCESS;
124 }
125
OnServiceProfileAdd(const ServiceProfile & profile)126 int32_t ProfileListenerProxy::OnServiceProfileAdd(const ServiceProfile& profile)
127 {
128 sptr<IRemoteObject> remote = nullptr;
129 GET_REMOTE_OBJECT(remote);
130 MessageParcel data;
131 WRITE_CHANGE_LISTENER_TOKEN(data);
132 if (!profile.Marshalling(data)) {
133 HILOGE("write reply failed!");
134 return ERR_FLATTEN_OBJECT;
135 }
136 MessageParcel reply;
137 SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::ON_SERVICE_PROFILE_ADD), data, reply);
138 return DP_SUCCESS;
139 }
140
OnServiceProfileDelete(const ServiceProfile & profile)141 int32_t ProfileListenerProxy::OnServiceProfileDelete(const ServiceProfile& profile)
142 {
143 sptr<IRemoteObject> remote = nullptr;
144 GET_REMOTE_OBJECT(remote);
145 MessageParcel data;
146 WRITE_CHANGE_LISTENER_TOKEN(data);
147 if (!profile.Marshalling(data)) {
148 HILOGE("write reply failed!");
149 return ERR_FLATTEN_OBJECT;
150 }
151 MessageParcel reply;
152 SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::ON_SERVICE_PROFILE_DELETE), data, reply);
153 return DP_SUCCESS;
154 }
155
OnServiceProfileUpdate(const ServiceProfile & oldProfile,const ServiceProfile & newProfile)156 int32_t ProfileListenerProxy::OnServiceProfileUpdate(const ServiceProfile& oldProfile, const ServiceProfile& newProfile)
157 {
158 sptr<IRemoteObject> remote = nullptr;
159 GET_REMOTE_OBJECT(remote);
160 MessageParcel data;
161 WRITE_CHANGE_LISTENER_TOKEN(data);
162 if (!oldProfile.Marshalling(data)) {
163 HILOGE("write reply failed!");
164 return ERR_FLATTEN_OBJECT;
165 }
166 if (!newProfile.Marshalling(data)) {
167 HILOGE("write reply failed!");
168 return ERR_FLATTEN_OBJECT;
169 }
170 MessageParcel reply;
171 SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::ON_SERVICE_PROFILE_UPDATE), data, reply);
172 return DP_SUCCESS;
173 }
174
OnCharacteristicProfileAdd(const CharacteristicProfile & profile)175 int32_t ProfileListenerProxy::OnCharacteristicProfileAdd(const CharacteristicProfile& profile)
176 {
177 sptr<IRemoteObject> remote = nullptr;
178 GET_REMOTE_OBJECT(remote);
179 MessageParcel data;
180 WRITE_CHANGE_LISTENER_TOKEN(data);
181 if (!profile.Marshalling(data)) {
182 HILOGE("write reply failed!");
183 return ERR_FLATTEN_OBJECT;
184 }
185 MessageParcel reply;
186 SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::ON_CHAR_PROFILE_ADD), data, reply);
187 return DP_SUCCESS;
188 }
189
OnCharacteristicProfileDelete(const CharacteristicProfile & profile)190 int32_t ProfileListenerProxy::OnCharacteristicProfileDelete(const CharacteristicProfile& profile)
191 {
192 sptr<IRemoteObject> remote = nullptr;
193 GET_REMOTE_OBJECT(remote);
194 MessageParcel data;
195 WRITE_CHANGE_LISTENER_TOKEN(data);
196 if (!profile.Marshalling(data)) {
197 HILOGE("write reply failed!");
198 return ERR_FLATTEN_OBJECT;
199 }
200 MessageParcel reply;
201 SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::ON_CHAR_PROFILE_DELETE), data, reply);
202 return DP_SUCCESS;
203 }
204
OnCharacteristicProfileUpdate(const CharacteristicProfile & oldProfile,const CharacteristicProfile & newProfile)205 int32_t ProfileListenerProxy::OnCharacteristicProfileUpdate(const CharacteristicProfile& oldProfile,
206 const CharacteristicProfile& newProfile)
207 {
208 sptr<IRemoteObject> remote = nullptr;
209 GET_REMOTE_OBJECT(remote);
210 MessageParcel data;
211 WRITE_CHANGE_LISTENER_TOKEN(data);
212 if (!oldProfile.Marshalling(data)) {
213 HILOGE("write reply failed!");
214 return ERR_FLATTEN_OBJECT;
215 }
216 if (!newProfile.Marshalling(data)) {
217 HILOGE("write reply failed!");
218 return ERR_FLATTEN_OBJECT;
219 }
220 MessageParcel reply;
221 SEND_REQUEST(remote, static_cast<uint32_t>(DPInterfaceCode::ON_CHAR_PROFILE_UPDATE), data, reply);
222 return DP_SUCCESS;
223 }
224 } // namespace DistributedDeviceProfile
225 } // namespace OHOS
226
227