AlexaClientSDK  1.26.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
PowerMonitor.h
Go to the documentation of this file.
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0/
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 #ifndef ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_POWER_POWERMONITOR_H_
17 #define ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_POWER_POWERMONITOR_H_
18 
19 #include <memory>
20 #include <mutex>
21 #include <string>
22 #include <thread>
23 #include <unordered_map>
24 
27 
28 namespace alexaClientSDK {
29 namespace avsCommon {
30 namespace utils {
31 namespace power {
32 
41 class PowerMonitor {
42 public:
48  static std::shared_ptr<PowerMonitor> getInstance();
49 
55  void activate(std::shared_ptr<sdkInterfaces::PowerResourceManagerInterface> powerManager);
56 
62  bool isActive();
63 
70  void deactivate();
71 
77  std::shared_ptr<sdkInterfaces::PowerResourceManagerInterface> getPowerResourceManager();
78 
89  std::shared_ptr<PowerResource> getThreadPowerResourceOrCreate(
90  const std::string& identifier,
93 
99  std::shared_ptr<PowerResource> getThreadPowerResource();
100 
108  std::shared_ptr<PowerResource> assignThreadPowerResource(std::shared_ptr<PowerResource> powerResource);
109 
118  std::shared_ptr<PowerResource> createLocalPowerResource(
119  const std::string& identifier,
122 
127 
128 private:
134  bool isActiveLocked();
135 
137  static std::mutex m_mutex;
138 
140  static std::shared_ptr<PowerMonitor> m_monitor;
141 
143  std::shared_ptr<sdkInterfaces::PowerResourceManagerInterface> m_powerManager;
144 
146  std::unordered_map<std::thread::id, std::shared_ptr<PowerResource>> m_threadPowerResources;
147 };
148 
149 } // namespace power
150 } // namespace utils
151 } // namespace avsCommon
152 } // namespace alexaClientSDK
153 
154 #endif // ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_POWER_POWERMONITOR_H_
alexaClientSDK::avsCommon::utils::power::PowerMonitor::assignThreadPowerResource
std::shared_ptr< PowerResource > assignThreadPowerResource(std::shared_ptr< PowerResource > powerResource)
Definition: PowerMonitor.cpp:124
PowerResource.h
alexaClientSDK::avsCommon::utils::power::PowerMonitor::activate
void activate(std::shared_ptr< sdkInterfaces::PowerResourceManagerInterface > powerManager)
Definition: PowerMonitor.cpp:49
alexaClientSDK::avsCommon::utils::power::PowerMonitor::getPowerResourceManager
std::shared_ptr< sdkInterfaces::PowerResourceManagerInterface > getPowerResourceManager()
Definition: PowerMonitor.cpp:84
alexaClientSDK::avsCommon::utils::power::PowerMonitor::getInstance
static std::shared_ptr< PowerMonitor > getInstance()
Definition: PowerMonitor.cpp:38
alexaClientSDK::avsCommon::utils::power::PowerMonitor::createLocalPowerResource
std::shared_ptr< PowerResource > createLocalPowerResource(const std::string &identifier, sdkInterfaces::PowerResourceManagerInterface::PowerResourceLevel level=sdkInterfaces::PowerResourceManagerInterface::PowerResourceLevel::STANDBY_MED)
Definition: PowerMonitor.cpp:91
PowerResourceManagerInterface.h
alexaClientSDK::avsCommon::utils::power::PowerMonitor::getThreadPowerResource
std::shared_ptr< PowerResource > getThreadPowerResource()
Definition: PowerMonitor.cpp:104
alexaClientSDK::avsCommon::utils::power::PowerMonitor::deactivate
void deactivate()
Definition: PowerMonitor.cpp:76
alexaClientSDK::avsCommon::sdkInterfaces::PowerResourceManagerInterface::PowerResourceLevel
PowerResourceLevel
Definition: PowerResourceManagerInterface.h:49
alexaClientSDK
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
alexaClientSDK::avsCommon::utils::power::PowerMonitor::getThreadPowerResourceOrCreate
std::shared_ptr< PowerResource > getThreadPowerResourceOrCreate(const std::string &identifier, sdkInterfaces::PowerResourceManagerInterface::PowerResourceLevel level=sdkInterfaces::PowerResourceManagerInterface::PowerResourceLevel::STANDBY_MED)
Definition: PowerMonitor.cpp:153
alexaClientSDK::avsCommon::utils::power::PowerMonitor::removeThreadPowerResource
void removeThreadPowerResource()
Definition: PowerMonitor.cpp:196
alexaClientSDK::avsCommon::utils::power::PowerMonitor::isActive
bool isActive()
Definition: PowerMonitor.cpp:65
alexaClientSDK::avsCommon::sdkInterfaces::PowerResourceManagerInterface::PowerResourceLevel::STANDBY_MED
@ STANDBY_MED
STANDBY_MED usually means all the hardware components work in the medium standby power levels.
alexaClientSDK::avsCommon::utils::power::PowerMonitor
Definition: PowerMonitor.h:41

AlexaClientSDK 1.26.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0