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 #include "a2dp_service_device.h"
17
18 #include "context.h"
19 #include "log.h"
20 #include "memory.h"
21
22 namespace bluetooth {
23 std::recursive_mutex g_deviceMutex {};
24
A2dpDeviceInfo(const RawAddress & device)25 A2dpDeviceInfo::A2dpDeviceInfo(const RawAddress &device)
26 {
27 LOG_INFO("[A2dpDeviceInfo] %{public}s\n", __func__);
28 currentConnectState_ = static_cast<int>(BTConnectState::DISCONNECTED);
29 device.ConvertToUint8(peerAddress_.addr);
30 }
31
~A2dpDeviceInfo()32 A2dpDeviceInfo::~A2dpDeviceInfo()
33 {
34 LOG_INFO("[A2dpDeviceInfo] %{public}s\n", __func__);
35 }
36
GetDevice() const37 BtAddr A2dpDeviceInfo::GetDevice() const
38 {
39 LOG_INFO("[A2dpDeviceInfo] %{public}s\n", __func__);
40
41 return peerAddress_;
42 }
43
GetStateMachine()44 A2dpStateManager *A2dpDeviceInfo::GetStateMachine()
45 {
46 LOG_INFO("[A2dpDeviceInfo] %{public}s\n", __func__);
47
48 return &state_;
49 }
50
SetCodecStatus(A2dpSrcCodecStatus codecStatusInfo)51 void A2dpDeviceInfo::SetCodecStatus(A2dpSrcCodecStatus codecStatusInfo)
52 {
53 LOG_INFO("[A2dpDeviceInfo] %{public}s\n", __func__);
54 std::lock_guard<std::recursive_mutex> lock(g_deviceMutex);
55
56 codecStatus_ = codecStatusInfo;
57 }
58
GetCodecStatus() const59 A2dpSrcCodecStatus A2dpDeviceInfo::GetCodecStatus() const
60 {
61 LOG_INFO("[A2dpDeviceInfo] %{public}s\n", __func__);
62 std::lock_guard<std::recursive_mutex> lock(g_deviceMutex);
63
64 return codecStatus_;
65 }
66
SetPlayingState(bool state)67 void A2dpDeviceInfo::SetPlayingState(bool state)
68 {
69 LOG_INFO("[A2dpDeviceInfo] %{public}s playState(%{public}d)\n", __func__, state);
70 std::lock_guard<std::recursive_mutex> lock(g_deviceMutex);
71
72 isPlaying_ = state;
73 }
74
GetPlayingState() const75 bool A2dpDeviceInfo::GetPlayingState() const
76 {
77 LOG_INFO("[A2dpDeviceInfo] %{public}s\n", __func__);
78 std::lock_guard<std::recursive_mutex> lock(g_deviceMutex);
79
80 return isPlaying_;
81 }
82
SetConnectState(int state)83 void A2dpDeviceInfo::SetConnectState(int state)
84 {
85 std::lock_guard<std::recursive_mutex> lock(g_deviceMutex);
86 LOG_INFO("[SettState state] = %{public}d\n", state);
87 LOG_INFO("[currentConnectState_] = %{public}d\n", currentConnectState_);
88
89 currentConnectState_ = state;
90 }
91
GetConnectState() const92 int A2dpDeviceInfo::GetConnectState() const
93 {
94 std::lock_guard<std::recursive_mutex> lock(g_deviceMutex);
95
96 LOG_INFO("[currentConnectState_] = %{public}d\n", currentConnectState_);
97 return currentConnectState_;
98 }
99
SetHandle(uint16_t handleInfo)100 void A2dpDeviceInfo::SetHandle(uint16_t handleInfo)
101 {
102 std::lock_guard<std::recursive_mutex> lock(g_deviceMutex);
103 LOG_INFO("[A2dpDeviceInfo] %{public}s handle_[%u]\n", __func__, handleInfo);
104
105 handle_ = handleInfo;
106 }
107
GetHandle() const108 uint16_t A2dpDeviceInfo::GetHandle() const
109 {
110 std::lock_guard<std::recursive_mutex> lock(g_deviceMutex);
111 LOG_INFO("[A2dpDeviceInfo] %{public}s handle_[%u]\n", __func__, handle_);
112
113 return handle_;
114 }
115 } // namespace bluetooth