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 #ifndef A2DP_SERVICE_CONNECTION_H
17 #define A2DP_SERVICE_CONNECTION_H
18 
19 #include <cstdint>
20 
21 #include "a2dp_service_device.h"
22 #include "raw_address.h"
23 
24 namespace OHOS {
25 namespace bluetooth {
26 class A2dpConnectManager {
27 public:
28     /**
29      * @brief A constructor used to create an <b>A2dpConnectManager</b> instance.
30      *
31      * @param role The a2dp profile role of local device.
32      * @since 6.0
33      */
34     explicit A2dpConnectManager(uint8_t role);
35 
36     /**
37      * @brief A constructor used to create an <b>A2dpConnectManager</b> instance.
38      *
39      * @since 6.0
40      */
41     A2dpConnectManager() = default;
42 
43     /**
44      * @brief A destructor used to delete the <b>A2dpConnectManager</b> instance.
45      *
46      * @since 6.0
47      */
48     ~A2dpConnectManager(void) = default;
49 
50     /**
51      * @brief Connect to the peer bluetooth device.
52      *
53      * @param device The address of the peer bluetooth device.
54      * @return Returns <b>true</b> if the operation is successful.
55      *         Returns <b>false</b> if the operation fails.
56      * @since 6.0
57      */
58     bool A2dpConnect(const RawAddress &device);
59 
60     /**
61      * @brief Disconnect with the peer bluetooth service.
62      *
63      * @param device The address of the peer bluetooth device.
64      * @return Returns <b>true</b> if the operation is successful.
65      *         Returns <b>false</b> if the operation fails.
66      * @since 6.0
67      */
68     bool A2dpDisconnect(const RawAddress &device);
69 
70     /**
71      * @brief Add the peer bluetooth service to local device management list.
72      *
73      * @param device The address of the peer bluetooth device.
74      * @param state The connection state of the peer bluetooth device.
75      * @return The device pointer of peer device
76      * @since 6.0
77      */
78     A2dpDeviceInfo *AddDevice(const RawAddress &device, int state);
79 
80     /**
81      * @brief Delete the peer bluetooth service from local device management list.
82      *
83      * @param device The address of the peer bluetooth device.
84      * @return void
85      * @since 6.0
86      */
87     void DeleteDevice(const RawAddress &device);
88     /**
89      * @brief Get local device's a2dp profile role.
90      *
91      * @return Returns <b>A2DP_ROLE_SOURCE</b> if local device is a2dp source role.
92      *         Returns <b>A2DP_ROLE_SINK</b> if local device is a2dp sink role.
93      * @since 6.0
94      */
GetRole()95     uint8_t GetRole() const
96     {
97         return role_;
98     }
99 
100     /**
101      * @brief Judge whether the number of connections is the maximum.
102      *
103      * @return Returns <b>true</b> if the number of connections is less than the maximum.
104      *         Returns <b>false</b> if the number of connections is greater than or equal to the maximum.
105      * @since 6.0
106      */
107     bool JudgeConnectedNum() const;
108 
109     /**
110      * @brief Judge whether the current device have connected peer as another role.
111      *
112      * @param device The address of the peer bluetooth device.
113      * @param role The local device's profile role.
114      * @return Returns <b>true</b> if the current device have connected peer as another role.
115      *         Returns <b>false</b> if the current device have not connected peer as another role.
116      * @since 6.0
117      */
118     static bool JudgeConnectExit(const RawAddress &device, uint8_t role);
119 
120 private:
121     // The a2dp profile role of local device.
122     uint8_t role_ {};
123 };
124 }  // namespace bluetooth
125 }  // namespace OHOS
126 #endif  // A2DP_SERVICE_CONNECTION_H