1 /*
2  * Copyright (C) 2021 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 /**
17  * @addtogroup Bluetooth
18  * @{
19  *
20  * @brief Defines a bluetooth system that provides basic blurtooth connection and profile functions,
21  *        including A2DP, AVRCP, BLE, GATT, HFP, MAP, PBAP, and SPP, etc.
22  *
23  * @since 6
24  */
25 
26 /**
27  * @file bluetooth_hf_call.h
28  *
29  * @brief Declares HFP HandsFree Unit call data class.
30  *
31  * @since 6
32  */
33 
34 #ifndef BLUETOOTH_HF_CALL_H
35 #define BLUETOOTH_HF_CALL_H
36 
37 #include <ctime>
38 #include "bluetooth_host.h"
39 #include "bluetooth_types.h"
40 
41 namespace OHOS {
42 namespace Bluetooth {
43 /**
44  * @brief Phone call state enum.
45  *
46  * @since 6
47  */
48 enum CallState {
49     HF_CALL_STATE_ACTIVE = 0,
50     HF_CALL_STATE_HELD,
51     HF_CALL_STATE_DIALING,
52     HF_CALL_STATE_ALERTING,
53     HF_CALL_STATE_INCOMING,
54     HF_CALL_STATE_WAITING,
55     HF_CALL_STATE_RESPONSE_HELD,
56     HF_CALL_STATE_FINISHED
57 };
58 
59 /**
60  * @brief Class for HandsFree Unit call.
61  *
62  * @since 6
63  */
64 class HandsFreeUnitCall {
65 public:
66     /**
67      * @brief Construct a new HandsFreeUnitCall object.
68      *
69      * @param device Remote device address.
70      * @param id Call index.
71      * @param state Call state @see HfpCallState.
72      * @param number Call number.
73      * @param multiParty Is multiparty flag.
74      * @param outgoing Incoming/outing flag.
75      * @param inBandRing Is inband-ring flag.
76      * @since 6
77      */
HandsFreeUnitCall(std::string device,int id,int state,std::string number,bool multiParty,bool outgoing,bool inBandRing)78     HandsFreeUnitCall(
79         std::string device, int id, int state, std::string number, bool multiParty, bool outgoing, bool inBandRing)
80         : device_(device),
81           id_(id),
82           state_(state),
83           number_(number),
84           multiParty_(multiParty),
85           outgoing_(outgoing),
86           inBandRing_(inBandRing)
87     {
88         uuid_ = UUID::RandomUUID();
89         creationTime_ = clock();
90     }
91 
92     /**
93      * @brief Construct a new HandsFreeUnitCall object.
94      *
95      * @param device Remote device address.
96      * @param id Call index.
97      * @param state Call state @see HfpCallState.
98      * @param number Call number.
99      * @param uuid Call uuid.
100      * @param multiParty Is multiparty flag.
101      * @param outgoing Incoming/outing flag.
102      * @param inBandRing Is inband-ring flag.
103      * @param creationTime Call's creation time.
104      * @since 6
105      */
HandsFreeUnitCall(std::string device,int id,int state,std::string number,UUID uuid,bool multiParty,bool outgoing,bool inBandRing,long creationTime)106     HandsFreeUnitCall(std::string device, int id, int state, std::string number, UUID uuid, bool multiParty,
107         bool outgoing, bool inBandRing, long creationTime)
108         : device_(device),
109           id_(id),
110           state_(state),
111           number_(number),
112           uuid_(uuid),
113           multiParty_(multiParty),
114           outgoing_(outgoing),
115           inBandRing_(inBandRing),
116           creationTime_(creationTime)
117     {}
118 
119     /**
120      * @brief Construct a new HandsFreeUnitCall object as default.
121      *
122      * @since 6
123      */
124     HandsFreeUnitCall() = default;
125 
126     /**
127      * @brief Destroy the HandsFreeUnitCall object.
128      *
129      * @since 6
130      */
131     ~HandsFreeUnitCall() = default;
132 
133     /**
134      * @brief Get the remote device address.
135      *
136      * @return Returns remote device address.
137      * @since 6
138      */
GetRemoteDevice()139     std::string GetRemoteDevice() const
140     {
141         return device_;
142     }
143 
144     /**
145      * @brief Get the call index.
146      *
147      * @return Returns the call index.
148      * @since 6
149      */
GetId()150     int GetId() const
151     {
152         return id_;
153     }
154 
155     /**
156      * @brief Get the uuid object.
157      *
158      * @return Returns the call uuid.
159      * @since 6
160      */
GetUuid()161     UUID GetUuid() const
162     {
163         return uuid_;
164     }
165 
166     /**
167      * @brief Get the call state.
168      *
169      * @return Returns the call state.
170      * @since 6
171      */
GetState()172     int GetState() const
173     {
174         return state_;
175     }
176 
177     /**
178      * @brief Get the call number.
179      *
180      * @return Returns the call number.
181      * @since 6
182      */
GetNumber()183     std::string GetNumber() const
184     {
185         return number_;
186     }
187 
188     /**
189      * @brief Get the call's creation time.
190      *
191      * @return Returns the call's creation time.
192      * @since 6
193      */
GetCreationTime()194     long GetCreationTime() const
195     {
196         return creationTime_;
197     }
198 
199     /**
200      * @brief Get the IsMultiParty flag.
201      *
202      * @return Returns the IsMultiParty flag.
203      * @since 6
204      */
IsMultiParty()205     bool IsMultiParty() const
206     {
207         return multiParty_;
208     }
209 
210     /**
211      * @brief Get the IsOutgoing flag.
212      *
213      * @return Returns the IsOutgoing flag.
214      * @since 6
215      */
IsOutgoing()216     bool IsOutgoing() const
217     {
218         return outgoing_;
219     }
220 
221     /**
222      * @brief Get the IsInBandRing flag.
223      *
224      * @return Returns the IsInBandRing flag.
225      * @since 6
226      */
IsInBandRing()227     bool IsInBandRing() const
228     {
229         return inBandRing_;
230     }
231 
232     /**
233      * @brief Set the call state.
234      *
235      * @param state Call state.
236      * @since 6
237      */
SetState(int state)238     void SetState(int state)
239     {
240         state_ = state;
241     }
242 
243     /**
244      * @brief Set the call number.
245      *
246      * @param number Call number.
247      * @since 6
248      */
SetNumber(std::string number)249     void SetNumber(std::string number)
250     {
251         number_ = number;
252     }
253 
254     /**
255      * @brief Set the multiParty flag.
256      *
257      * @param multiParty The multiParty flag
258      * @since 6
259      */
SetMultiParty(bool multiParty)260     void SetMultiParty(bool multiParty)
261     {
262         multiParty_ = multiParty;
263     }
264 
265 protected:
266     std::string device_ {""};
267     int id_ {0};
268     int state_ {-1};
269     std::string number_ {""};
270     UUID uuid_;
271     bool multiParty_ {false};
272     bool outgoing_ {false};
273     bool inBandRing_ {false};
274     long creationTime_ {0};
275 };
276 }  // namespace Bluetooth
277 }  // namespace OHOS
278 #endif  // BLUETOOTH_HF_CALL_H