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