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