• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-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 "bluetooth_gatt_server_callback_proxy.h"
17 #include "bluetooth_log.h"
18 
19 namespace OHOS {
20 namespace Bluetooth {
OnCharacteristicReadRequest(const BluetoothGattDevice & device,const BluetoothGattCharacteristic & characteristic)21 void BluetoothGattServerCallbackProxy::OnCharacteristicReadRequest(
22     const BluetoothGattDevice &device, const BluetoothGattCharacteristic &characteristic)
23 {
24     MessageParcel data;
25     if (!data.WriteInterfaceToken(BluetoothGattServerCallbackProxy::GetDescriptor())) {
26         HILOGE("BluetoothGattServerCallbackProxy::OnCharacteristicReadRequest WriteInterfaceToken error");
27         return;
28     }
29     if (!data.WriteParcelable(&device)) {
30         HILOGE("BluetoothGattServerCallbackProxy::OnCharacteristicReadRequest error");
31         return;
32     }
33     if (!data.WriteParcelable(&characteristic)) {
34         HILOGE("BluetoothGattServerCallbackProxy::OnCharacteristicReadRequest error");
35         return;
36     }
37     MessageParcel reply;
38     MessageOption option {
39         MessageOption::TF_ASYNC
40     };
41     int error = Remote()->SendRequest(
42         BluetoothGattServerCallbackInterfaceCode::GATT_SERVER_CALLBACK_CHARACTERISTIC_READREQUEST, data, reply, option);
43     if (error != NO_ERROR) {
44         HILOGE("BluetoothGattServerCallbackProxy::OnCharacteristicReadRequest done fail, error: %d", error);
45         return;
46     }
47     return;
48 }
OnConnectionStateChanged(const BluetoothGattDevice & device,int32_t ret,int32_t state,int32_t disconnectReason)49 void BluetoothGattServerCallbackProxy::OnConnectionStateChanged(
50     const BluetoothGattDevice &device, int32_t ret, int32_t state, int32_t disconnectReason)
51 {
52     HILOGI("BluetoothGattServerCallbackProxy::OnConnectionStateChanged Triggered!");
53     MessageParcel data;
54     if (!data.WriteInterfaceToken(BluetoothGattServerCallbackProxy::GetDescriptor())) {
55         HILOGE("BluetoothGattServerCallbackProxy::OnConnectionStateChanged WriteInterfaceToken error");
56         return;
57     }
58     if (!data.WriteParcelable(&device)) {
59         HILOGE("BluetoothGattServerCallbackProxy::OnConnectionStateChanged error");
60         return;
61     }
62     if (!data.WriteInt32(ret)) {
63         HILOGE("BluetoothGattServerCallbackProxy::OnConnectionStateChanged error");
64         return;
65     }
66     if (!data.WriteInt32(state)) {
67         HILOGE("BluetoothGattServerCallbackProxy::OnConnectionStateChanged error");
68         return;
69     }
70     if (!data.WriteInt32(disconnectReason)) {
71         HILOGE("BluetoothGattServerCallbackProxy::OnConnectionStateChanged error");
72         return;
73     }
74     MessageParcel reply;
75     MessageOption option {
76         MessageOption::TF_ASYNC
77     };
78     int error = Remote()->SendRequest(
79         BluetoothGattServerCallbackInterfaceCode::GATT_SERVER_CALLBACK_CONNECTIONSTATE_CHANGED, data, reply, option);
80     if (error != NO_ERROR) {
81         HILOGE("BluetoothGattServerCallbackProxy::OnConnectionStateChanged done fail, error: %d", error);
82         return;
83     }
84     return;
85 }
OnAddService(int32_t ret,const BluetoothGattService & service)86 void BluetoothGattServerCallbackProxy::OnAddService(int32_t ret, const BluetoothGattService &service)
87 {
88     MessageParcel data;
89     if (!data.WriteInterfaceToken(BluetoothGattServerCallbackProxy::GetDescriptor())) {
90         HILOGE("BluetoothGattServerCallbackProxy::OnAddService WriteInterfaceToken error");
91         return;
92     }
93     if (!data.WriteInt32(ret)) {
94         HILOGE("BluetoothGattServerCallbackProxy::OnAddService error");
95         return;
96     }
97     if (!data.WriteParcelable(&service)) {
98         HILOGE("BluetoothGattServerCallbackProxy::OnAddService error");
99         return;
100     }
101     MessageParcel reply;
102     MessageOption option {
103         MessageOption::TF_ASYNC
104     };
105     int error = Remote()->SendRequest(
106         BluetoothGattServerCallbackInterfaceCode::GATT_SERVER_CALLBACK_ADD_SERVICE, data, reply, option);
107     if (error != NO_ERROR) {
108         HILOGE("BluetoothGattServerCallbackProxy::OnAddService done fail, error: %d", error);
109         return;
110     }
111     return;
112 }
OnCharacteristicWriteRequest(const BluetoothGattDevice & device,const BluetoothGattCharacteristic & characteristic,bool needRespones)113 void BluetoothGattServerCallbackProxy::OnCharacteristicWriteRequest(
114     const BluetoothGattDevice &device, const BluetoothGattCharacteristic &characteristic, bool needRespones)
115 {
116     MessageParcel data;
117     if (!data.WriteInterfaceToken(BluetoothGattServerCallbackProxy::GetDescriptor())) {
118         HILOGE("BluetoothGattServerCallbackProxy::OnCharacteristicWriteRequest WriteInterfaceToken error");
119         return;
120     }
121     if (!data.WriteParcelable(&device)) {
122         HILOGE("BluetoothGattServerCallbackProxy::OnCharacteristicWriteRequest error");
123         return;
124     }
125     if (!data.WriteParcelable(&characteristic)) {
126         HILOGE("BluetoothGattServerCallbackProxy::OnCharacteristicWriteRequest error");
127         return;
128     }
129     if (!data.WriteBool(needRespones)) {
130         HILOGE("BluetoothGattServerProxy::OnCharacteristicWriteRequest error");
131         return;
132     }
133     MessageParcel reply;
134     MessageOption option {
135         MessageOption::TF_ASYNC
136     };
137     int error = Remote()->SendRequest(
138         BluetoothGattServerCallbackInterfaceCode::GATT_SERVER_CALLBACK_CHARACTERISTIC_WRITE_REQUEST,
139         data, reply, option);
140     if (error != NO_ERROR) {
141         HILOGE("BluetoothGattServerCallbackProxy::OnCharacteristicWriteRequest done fail, error: %d", error);
142         return;
143     }
144     return;
145 }
OnDescriptorReadRequest(const BluetoothGattDevice & device,const BluetoothGattDescriptor & descriptor)146 void BluetoothGattServerCallbackProxy::OnDescriptorReadRequest(
147     const BluetoothGattDevice &device, const BluetoothGattDescriptor &descriptor)
148 {
149     MessageParcel data;
150     if (!data.WriteInterfaceToken(BluetoothGattServerCallbackProxy::GetDescriptor())) {
151         HILOGE("BluetoothGattServerCallbackProxy::OnDescriptorReadRequest WriteInterfaceToken error");
152         return;
153     }
154     if (!data.WriteParcelable(&device)) {
155         HILOGE("BluetoothGattServerCallbackProxy::OnDescriptorReadRequest error");
156         return;
157     }
158     if (!data.WriteParcelable(&descriptor)) {
159         HILOGE("BluetoothGattServerCallbackProxy::OnDescriptorReadRequest error");
160         return;
161     }
162     MessageParcel reply;
163     MessageOption option {
164         MessageOption::TF_ASYNC
165     };
166     int error = Remote()->SendRequest(
167         BluetoothGattServerCallbackInterfaceCode::GATT_SERVER_CALLBACK_DESCRIPTOR_READ_REQUEST, data, reply, option);
168     if (error != NO_ERROR) {
169         HILOGE("BluetoothGattServerCallbackProxy::OnDescriptorReadRequest done fail, error: %d", error);
170         return;
171     }
172     return;
173 }
OnDescriptorWriteRequest(const BluetoothGattDevice & device,const BluetoothGattDescriptor & descriptor)174 void BluetoothGattServerCallbackProxy::OnDescriptorWriteRequest(
175     const BluetoothGattDevice &device, const BluetoothGattDescriptor &descriptor)
176 {
177     MessageParcel data;
178     if (!data.WriteInterfaceToken(BluetoothGattServerCallbackProxy::GetDescriptor())) {
179         HILOGE("BluetoothGattServerCallbackProxy::OnDescriptorWriteRequest WriteInterfaceToken error");
180         return;
181     }
182     if (!data.WriteParcelable(&device)) {
183         HILOGE("BluetoothGattServerCallbackProxy::OnDescriptorWriteRequest error");
184         return;
185     }
186     if (!data.WriteParcelable(&descriptor)) {
187         HILOGE("BluetoothGattServerCallbackProxy::OnDescriptorWriteRequest error");
188         return;
189     }
190     MessageParcel reply;
191     MessageOption option {
192         MessageOption::TF_ASYNC
193     };
194     int error = Remote()->SendRequest(
195         BluetoothGattServerCallbackInterfaceCode::GATT_SERVER_CALLBACK_DESCRIPTOR_WRITE_REQUEST, data, reply, option);
196     if (error != NO_ERROR) {
197         HILOGE("BluetoothGattServerCallbackProxy::OnDescriptorWriteRequest done fail, error: %d", error);
198         return;
199     }
200     return;
201 }
OnMtuChanged(const BluetoothGattDevice & device,int32_t mtu)202 void BluetoothGattServerCallbackProxy::OnMtuChanged(const BluetoothGattDevice &device, int32_t mtu)
203 {
204     MessageParcel data;
205     if (!data.WriteInterfaceToken(BluetoothGattServerCallbackProxy::GetDescriptor())) {
206         HILOGE("BluetoothGattServerCallbackProxy::OnMtuUpdateOnMtuChanged WriteInterfaceToken error");
207         return;
208     }
209     if (!data.WriteParcelable(&device)) {
210         HILOGE("BluetoothGattServerCallbackProxy::OnMtuUpdateOnMtuChanged error");
211         return;
212     }
213     if (!data.WriteInt32(mtu)) {
214         HILOGE("BluetoothGattServerCallbackProxy::OnMtuUpdateOnMtuChanged error");
215         return;
216     }
217     MessageParcel reply;
218     MessageOption option {
219         MessageOption::TF_ASYNC
220     };
221     int error = Remote()->SendRequest(
222         BluetoothGattServerCallbackInterfaceCode::GATT_SERVER_CALLBACK_MTU_CHANGED, data, reply, option);
223     if (error != NO_ERROR) {
224         HILOGE("BluetoothGattServerCallbackProxy::OnMtuUpdateOnMtuChanged done fail, error: %d", error);
225         return;
226     }
227     return;
228 }
OnNotifyConfirm(const BluetoothGattDevice & device,const BluetoothGattCharacteristic & characteristic,int result)229 void BluetoothGattServerCallbackProxy::OnNotifyConfirm(
230     const BluetoothGattDevice &device, const BluetoothGattCharacteristic &characteristic, int result)
231 {
232     MessageParcel data;
233     if (!data.WriteInterfaceToken(BluetoothGattServerCallbackProxy::GetDescriptor())) {
234         HILOGE("BluetoothGattServerCallbackProxy::OnNotifyConfirm WriteInterfaceToken error");
235         return;
236     }
237     if (!data.WriteParcelable(&device)) {
238         HILOGE("BluetoothGattServerCallbackProxy::OnNotifyConfirm error");
239         return;
240     }
241     if (!data.WriteParcelable(&characteristic)) {
242         HILOGE("BluetoothGattServerCallbackProxy::OnNotifyConfirm error");
243         return;
244     }
245     if (!data.WriteInt32(result)) {
246         HILOGE("BluetoothGattServerCallbackProxy::OnNotifyConfirm error");
247         return;
248     }
249     MessageParcel reply;
250     MessageOption option {
251         MessageOption::TF_ASYNC
252     };
253     int error = Remote()->SendRequest(
254         BluetoothGattServerCallbackInterfaceCode::GATT_SERVER_CALLBACK_NOTIFY_CONFIRM, data, reply, option);
255     if (error != NO_ERROR) {
256         HILOGE("BluetoothGattServerCallbackProxy::OnNotifyConfirm done fail, error: %d", error);
257         return;
258     }
259     return;
260 }
OnConnectionParameterChanged(const BluetoothGattDevice & device,int32_t interval,int32_t latency,int32_t timeout,int32_t status)261 void BluetoothGattServerCallbackProxy::OnConnectionParameterChanged(
262     const BluetoothGattDevice &device, int32_t interval, int32_t latency, int32_t timeout, int32_t status)
263 {
264     MessageParcel data;
265     if (!data.WriteInterfaceToken(BluetoothGattServerCallbackProxy::GetDescriptor())) {
266         HILOGE("BluetoothGattServerCallbackProxy::OnConnectionParameterChanged WriteInterfaceToken error");
267         return;
268     }
269     if (!data.WriteParcelable(&device)) {
270         HILOGE("BluetoothGattServerCallbackProxy::OnConnectionParameterChanged error");
271         return;
272     }
273     if (!data.WriteInt32(interval)) {
274         HILOGE("BluetoothGattServerCallbackProxy::OnConnectionParameterChanged error");
275         return;
276     }
277     if (!data.WriteInt32(latency)) {
278         HILOGE("BluetoothGattServerCallbackProxy::OnConnectionParameterChanged error");
279         return;
280     }
281     if (!data.WriteInt32(timeout)) {
282         HILOGE("BluetoothGattServerCallbackProxy::OnConnectionParameterChanged error");
283         return;
284     }
285     if (!data.WriteInt32(status)) {
286         HILOGE("BluetoothGattServerCallbackProxy::OnConnectionParameterChanged error");
287         return;
288     }
289     MessageParcel reply;
290     MessageOption option {
291         MessageOption::TF_ASYNC
292     };
293     int error = Remote()->SendRequest(
294         BluetoothGattServerCallbackInterfaceCode::GATT_SERVER_CALLBACK_CONNECTION_PARAMETER_CHANGED,
295         data, reply, option);
296     if (error != NO_ERROR) {
297         HILOGE("BluetoothGattServerCallbackProxy::OnConnectionParameterChanged done fail, error: %d", error);
298         return;
299     }
300     return;
301 }
302 }  // namespace Bluetooth
303 }  // namespace OHOS