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_DEVICE_H
17 #define A2DP_SERVICE_DEVICE_H
18 
19 #include <cstdint>
20 #include <map>
21 
22 #include "a2dp_service_state_machine.h"
23 #include "bt_def.h"
24 #include "btstack.h"
25 #include "interface_profile_a2dp_src.h"
26 #include "raw_address.h"
27 
28 namespace OHOS {
29 namespace bluetooth {
30 /**
31  * @brief Single device information management,including device address,playing state,
32  *        connection state,state machine,etc.
33  *
34  * @since 6.0
35  */
36 class A2dpDeviceInfo {
37 public:
38     /**
39      * @brief A constructor used to create an <b>A2dpDeviceInfo</b> instance.
40      *
41      * @since 6.0
42      */
43     explicit A2dpDeviceInfo(const RawAddress &device);
44 
45     /**
46      * @brief A destructor used to delete the <b>A2dpDeviceInfo</b> instance.
47      *
48      * @since 6.0
49      */
50     ~A2dpDeviceInfo();
51 
52     /**
53      * @brief Save codec status in Device information.
54      *
55      * @param codecStatusInfo The codec information.
56      * @since 6.0
57      */
58     void SetCodecStatus(A2dpSrcCodecStatus codecStatusInfo);
59 
60     /**
61      * @brief Save playing state in Device information.
62      *
63      * @param state The playing state of device.
64      * @since 6.0
65      */
66     void SetPlayingState(bool state);
67 
68     /**
69      * @brief Save connection state in Device information..
70      *
71      * @param state The connection state of device.
72      * @since 6.0
73      */
74     void SetConnectState(int state);
75 
76     /**
77      * @brief Save device handle in Device information.
78      *
79      * @param handleInfo The handle of device.
80      * @since 6.0
81      */
82     void SetHandle(uint16_t handleInfo);
83 
84     /**
85      * @brief Get device from Device information.
86      *
87      * @return Return the device address
88      * @since 6.0
89      */
90     BtAddr GetDevice() const;
91 
92     /**
93      * @brief Get state machine from Device information.
94      *
95      * @return Returns the device statemachine
96      * @since 6.0
97      */
98     A2dpStateManager *GetStateMachine();
99 
100     /**
101      * @brief Get codec status from Device information.
102      *
103      * @return Returns the device code information
104      * @since 6.0
105      */
106     A2dpSrcCodecStatus GetCodecStatus() const;
107 
108     /**
109      * @brief Get playing state from Device information.
110      *
111      * @return Returns <b>true</b> if device is on playing;
112      *         Returns <b>false</b> if device is not on playing.
113      * @since 6.0
114      */
115     bool GetPlayingState() const;
116 
117     /**
118      * @brief Get connect state from Device information.
119      *
120      * @return Returns <b>DISCONNECTED</b> if device connect state is disconnected;
121      *         Returns <b>DISCONNECTING</b> if device connect state is disconnecting;
122      *         Returns <b>CONNECTED</b> if device connect state is connected;
123      *         Returns <b>CONNECTING</b> if device connect state is connecting;
124      * @since 6.0
125      */
126     int GetConnectState() const;
127 
128     /**
129      * @brief Get device handle from Device information.
130      *
131      * @return Returns device handle value
132      * @since 6.0
133      */
134     uint16_t GetHandle() const;
135 
136 private:
137     A2dpDeviceInfo() = delete;
138     // The handle of device.
139     uint16_t handle_ = 0;
140     // The address of the bluetooth device.
141     BtAddr peerAddress_ {};
142     // The codec status information.
143     A2dpSrcCodecStatus codecStatus_ {};
144     // The playing state of device.
145     bool isPlaying_ = false;
146     // The connection state of device.
147     int currentConnectState_ = static_cast<int>(BTConnectState::DISCONNECTED);
148     // The pointer of device's state machine.
149     A2dpStateManager state_ {};
150 };
151 }  // namespace bluetooth
152 }  // namespace OHOS
153 #endif  // A2DP_SERVICE_DEVICE_H