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 <string>
17 #include "bluetooth_hfp_hf_call.h"
18 #include "bluetooth_bt_uuid.h"
19 
20 namespace OHOS {
21 namespace Bluetooth {
22 using namespace std;
23 
Marshalling(Parcel & parcel) const24 bool BluetoothHfpHfCall::Marshalling(Parcel &parcel) const
25 {
26     return WriteToParcel(parcel);
27 }
28 
Unmarshalling(Parcel & parcel)29 BluetoothHfpHfCall *BluetoothHfpHfCall::Unmarshalling(Parcel &parcel)
30 {
31     BluetoothHfpHfCall *call = new BluetoothHfpHfCall();
32     if (call != nullptr && !call->ReadFromParcel(parcel)) {
33         delete call;
34         call = nullptr;
35     }
36     return call;
37 }
38 
WriteToParcel(Parcel & parcel) const39 bool BluetoothHfpHfCall::WriteToParcel(Parcel &parcel) const
40 {
41     if (!parcel.WriteString(device_)) {
42         return false;
43     }
44     if (!parcel.WriteInt32(id_)) {
45         return false;
46     }
47     if (!parcel.WriteInt32(state_)) {
48         return false;
49     }
50     if (!parcel.WriteString(number_)) {
51         return false;
52     }
53     BluetoothUuid uuid = BluetoothUuid(uuid_);
54     if (!parcel.WriteParcelable(&uuid)) {
55         return false;
56     }
57     if (!parcel.WriteBool(multiParty_)) {
58         return false;
59     }
60     if (!parcel.WriteBool(outgoing_)) {
61         return false;
62     }
63     if (!parcel.WriteBool(inBandRing_)) {
64         return false;
65     }
66     if (!parcel.WriteInt64(creationTime_)) {
67         return false;
68     }
69     return true;
70 }
71 
ReadFromParcel(Parcel & parcel)72 bool BluetoothHfpHfCall::ReadFromParcel(Parcel &parcel)
73 {
74     if (!parcel.ReadString(device_)) {
75         return false;
76     }
77     if (!parcel.ReadInt32(id_)) {
78         return false;
79     }
80     if (!parcel.ReadInt32(state_)) {
81         return false;
82     }
83     if (!parcel.ReadString(number_)) {
84         return false;
85     }
86     std::shared_ptr<BluetoothUuid> uuid(parcel.ReadParcelable<BluetoothUuid>());
87     if (!uuid) {
88         return false;
89     }
90     uuid_ = BluetoothUuid(*uuid);
91     if (!parcel.ReadBool(multiParty_)) {
92         return false;
93     }
94     if (!parcel.ReadBool(outgoing_)) {
95         return false;
96     }
97     if (!parcel.ReadBool(inBandRing_)) {
98         return false;
99     }
100     int64_t time;
101     if (!parcel.ReadInt64(time)) {
102         return false;
103     }
104     creationTime_ = time;
105     return true;
106 }
107 
108 }  // namespace Bluetooth
109 }  // namespace OHOS