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_ble_scan_settings.h"
17 
18 namespace OHOS {
19 namespace Bluetooth {
Marshalling(Parcel & parcel) const20 bool BluetoothBleScanSettings::Marshalling(Parcel &parcel) const
21 {
22     if (!parcel.WriteInt64(reportDelayMillis_)) {
23         return false;
24     }
25     if (!parcel.WriteInt32(scanMode_)) {
26         return false;
27     }
28     if (!parcel.WriteBool(legacy_)) {
29         return false;
30     }
31     if (!parcel.WriteInt32(phy_)) {
32         return false;
33     }
34     if (!parcel.WriteUint8(callbackType_)) {
35         return false;
36     }
37     if (!parcel.WriteUint8(matchTrackAdvType_)) {
38         return false;
39     }
40     return true;
41 }
42 
Unmarshalling(Parcel & parcel)43 BluetoothBleScanSettings *BluetoothBleScanSettings::Unmarshalling(Parcel &parcel)
44 {
45     BluetoothBleScanSettings *settings = new BluetoothBleScanSettings();
46     if (settings != nullptr && !settings->ReadFromParcel(parcel)) {
47         delete settings;
48         settings = nullptr;
49     }
50     return settings;
51 }
52 
WriteToParcel(Parcel & parcel)53 bool BluetoothBleScanSettings::WriteToParcel(Parcel &parcel)
54 {
55     return Marshalling(parcel);
56 }
57 
ReadFromParcel(Parcel & parcel)58 bool BluetoothBleScanSettings::ReadFromParcel(Parcel &parcel)
59 {
60     int64_t reportDelayMillis = 0;
61     if (parcel.ReadInt64(reportDelayMillis)) {
62         BluetoothBleScanSettings::SetReportDelay(reportDelayMillis);
63     } else {
64         return false;
65     }
66     if (!parcel.ReadInt32(scanMode_)) {
67         return false;
68     }
69     if (!parcel.ReadBool(legacy_)) {
70         return false;
71     }
72     if (!parcel.ReadInt32(phy_)) {
73         return false;
74     }
75     if (!parcel.ReadUint8(callbackType_)) {
76         return false;
77     }
78     if (!parcel.ReadUint8(matchTrackAdvType_)) {
79         return false;
80     }
81     return true;
82 }
83 }  // namespace Bluetooth
84 }  // namespace OHOS
85