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 "classic_battery_observer.h"
17
18 #include "interface_adapter_classic.h"
19 #include "interface_adapter_manager.h"
20 #include "log.h"
21 #include "log_util.h"
22
23 namespace bluetooth {
ClassicBatteryObserverHf(utility::Dispatcher & dispatcher)24 ClassicBatteryObserverHf::ClassicBatteryObserverHf(utility::Dispatcher &dispatcher) : dispatcher_(&dispatcher)
25 {
26 LOG_DEBUG("[ClassicBatteryObserverHf]::%{public}s", __func__);
27 }
28
~ClassicBatteryObserverHf()29 ClassicBatteryObserverHf::~ClassicBatteryObserverHf()
30 {
31 LOG_DEBUG("[ClassicBatteryObserverHf]::%{public}s", __func__);
32 }
33
OnBatteryLevelChanged(const RawAddress & device,int batteryLevel)34 void ClassicBatteryObserverHf::OnBatteryLevelChanged(const RawAddress &device, int batteryLevel)
35 {
36 LOG_DEBUG("[ClassicBatteryObserverHf]::%{public}s, address: %{public}s, batteryLevel: %{public}d",
37 __func__,
38 GetEncryptAddr(device.GetAddress()).c_str(),
39 batteryLevel);
40 dispatcher_->PostTask(std::bind(&ClassicBatteryObserverHf::SetBatteryLevel, this, device, batteryLevel));
41 }
42
SetBatteryLevel(const RawAddress & device,int batteryLevel) const43 void ClassicBatteryObserverHf::SetBatteryLevel(const RawAddress &device, int batteryLevel) const
44 {
45 LOG_DEBUG("[ClassicBatteryObserverAg]::%{public}s", __func__);
46 IAdapterClassic *classicAdapter = (IAdapterClassic *)IAdapterManager::GetInstance()->GetAdapter(ADAPTER_BREDR);
47 classicAdapter->SetDeviceBatteryLevel(device, batteryLevel);
48 }
49
ClassicBatteryObserverAg(utility::Dispatcher & dispatcher)50 ClassicBatteryObserverAg::ClassicBatteryObserverAg(utility::Dispatcher &dispatcher) : dispatcher_(&dispatcher)
51 {
52 LOG_DEBUG("[ClassicBatteryObserverAg]::%{public}s", __func__);
53 }
54
~ClassicBatteryObserverAg()55 ClassicBatteryObserverAg::~ClassicBatteryObserverAg()
56 {
57 LOG_DEBUG("[ClassicBatteryObserverAg]::%{public}s", __func__);
58 }
59
OnHfBatteryLevelChanged(const RawAddress & device,int indValue)60 void ClassicBatteryObserverAg::OnHfBatteryLevelChanged(const RawAddress &device, int indValue)
61 {
62 LOG_DEBUG("[ClassicBatteryObserverAg]::%{public}s, address: %{public}s, batteryLevel: %{public}d",
63 __func__,
64 GetEncryptAddr(device.GetAddress()).c_str(),
65 indValue);
66 dispatcher_->PostTask(std::bind(&ClassicBatteryObserverAg::SetBatteryLevel, this, device, indValue));
67 }
68
SetBatteryLevel(const RawAddress & device,int batteryLevel) const69 void ClassicBatteryObserverAg::SetBatteryLevel(const RawAddress &device, int batteryLevel) const
70 {
71 LOG_DEBUG("[ClassicBatteryObserverAg]::%{public}s", __func__);
72 IAdapterClassic *classicAdapter = (IAdapterClassic *)IAdapterManager::GetInstance()->GetAdapter(ADAPTER_BREDR);
73 classicAdapter->SetDeviceBatteryLevel(device, batteryLevel);
74 }
75 } // namespace bluetooth