AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
AggregatedPowerResourceManager.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_AGGREGATEDPOWERRESOURCEMANAGER_H_
17 #define ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_POWER_AGGREGATEDPOWERRESOURCEMANAGER_H_
18 
19 #include <memory>
20 #include <mutex>
21 #include <string>
22 #include <unordered_map>
23 
28 
29 namespace alexaClientSDK {
30 namespace avsCommon {
31 namespace utils {
32 namespace power {
33 
49 public:
56  static std::shared_ptr<AggregatedPowerResourceManager> create(
57  std::shared_ptr<avsCommon::sdkInterfaces::PowerResourceManagerInterface> powerResourceManager);
58 
61 
64  /**********************************Deprecated Legacy APIs**********************************************/
66  const std::string& component,
68  void releasePowerResource(const std::string& component) override;
69  bool isPowerResourceAcquired(const std::string& component) override;
70  /******************************************************************************************************/
71  std::shared_ptr<avsCommon::sdkInterfaces::PowerResourceManagerInterface::PowerResourceId> create(
72  const std::string& resourceId,
73  bool isRefCounted = true,
75  bool acquire(
76  const std::shared_ptr<avsCommon::sdkInterfaces::PowerResourceManagerInterface::PowerResourceId>& id,
77  const std::chrono::milliseconds autoReleaseTimeout = std::chrono::milliseconds::zero()) override;
78  bool release(
79  const std::shared_ptr<avsCommon::sdkInterfaces::PowerResourceManagerInterface::PowerResourceId>& id) override;
80  bool close(
81  const std::shared_ptr<avsCommon::sdkInterfaces::PowerResourceManagerInterface::PowerResourceId>& id) override;
83 
84 private:
86  using AggregatedPowerResourceMap = std::unordered_map<
88  std::shared_ptr<avsCommon::sdkInterfaces::PowerResourceManagerInterface::PowerResourceId>,
90 
95  struct PowerResourceInfo {
102  PowerResourceInfo(
103  bool isRefCounted,
104  avsCommon::sdkInterfaces::PowerResourceManagerInterface::PowerResourceLevel level);
105 
109  void updateLastAcquiredTimepoint();
110 
112  const bool isRefCounted;
113 
115  const avsCommon::sdkInterfaces::PowerResourceManagerInterface::PowerResourceLevel level;
116 
118  uint64_t refCount;
119 
121  std::chrono::system_clock::time_point lastAcquired;
122  };
123 
130  std::shared_ptr<avsCommon::sdkInterfaces::PowerResourceManagerInterface> powerResourceManager);
131 
135  void logActivePowerResources();
136 
143  std::shared_ptr<PowerResourceId> getAggregatedPowerResourceIdLocked(
145 
147  std::mutex m_mutex;
148 
150  std::shared_ptr<avsCommon::sdkInterfaces::PowerResourceManagerInterface> m_appPowerResourceManager;
151 
154  std::unordered_map<std::string, PowerResourceInfo> m_ids;
155 
157  AggregatedPowerResourceMap m_aggregatedPowerResources;
158 
161 
164 };
165 
166 } // namespace power
167 } // namespace utils
168 } // namespace avsCommon
169 } // namespace alexaClientSDK
170 
171 #endif // ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_POWER_AGGREGATEDPOWERRESOURCEMANAGER_H_
STANDBY_MED usually means all the hardware components work in the medium standby power levels...
PowerResourceLevel
Definition: PowerResourceManagerInterface.h:49
::std::string string
Definition: gtest-port.h:1097
bool acquire(const std::shared_ptr< avsCommon::sdkInterfaces::PowerResourceManagerInterface::PowerResourceId > &id, const std::chrono::milliseconds autoReleaseTimeout=std::chrono::milliseconds::zero()) override
void releasePowerResource(const std::string &component) override
void acquirePowerResource(const std::string &component, const PowerResourceLevel level=PowerResourceLevel::STANDBY_MED) override
static std::shared_ptr< AggregatedPowerResourceManager > create(std::shared_ptr< avsCommon::sdkInterfaces::PowerResourceManagerInterface > powerResourceManager)
Timer to schedule task for delayed and periodic execution.
Definition: Timer.h:39
bool close(const std::shared_ptr< avsCommon::sdkInterfaces::PowerResourceManagerInterface::PowerResourceId > &id) override
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
bool isPowerResourceAcquired(const std::string &component) override
bool release(const std::shared_ptr< avsCommon::sdkInterfaces::PowerResourceManagerInterface::PowerResourceId > &id) override

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