AlexaClientSDK  1.25.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
PowerResourceManagerInterface.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_SDKINTERFACES_INCLUDE_AVSCOMMON_SDKINTERFACES_POWERRESOURCEMANAGERINTERFACE_H_
17 #define ALEXA_CLIENT_SDK_AVSCOMMON_SDKINTERFACES_INCLUDE_AVSCOMMON_SDKINTERFACES_POWERRESOURCEMANAGERINTERFACE_H_
18 
19 #include <bitset>
20 #include <chrono>
21 #include <memory>
22 #include <ostream>
23 #include <string>
24 
25 namespace alexaClientSDK {
26 namespace avsCommon {
27 namespace sdkInterfaces {
28 
39 public:
49  enum class PowerResourceLevel {
53  STANDBY_LOW = 0,
61  ACTIVE_LOW,
63  ACTIVE_MED,
66  };
67 
76  TYPE_CPU = 0,
89  };
90 
94  using PartialStateBitSet = std::bitset<PowerResourceTypeIndex::NUM_OF_TYPES>;
95 
108  TYPE_CPU_FLAG = 1 << PowerResourceTypeIndex::TYPE_CPU,
110  TYPE_DDR_FLAG = 1 << PowerResourceTypeIndex::TYPE_DDR,
112  TYPE_STORAGE_FLAG = 1 << PowerResourceTypeIndex::TYPE_STORAGE,
114  TYPE_NETWORK_FLAG = 1 << PowerResourceTypeIndex::TYPE_NETWORK,
116  TYPE_RESERVED_ONE_FLAG = 1 << PowerResourceTypeIndex::TYPE_RESERVED_ONE,
118  TYPE_RESERVED_TWO_FLAG = 1 << PowerResourceTypeIndex::TYPE_RESERVED_TWO
119  };
120 
124  virtual ~PowerResourceManagerInterface() = default;
125 
131  virtual void acquirePowerResource(
132  const std::string& component,
134 
139  virtual void releasePowerResource(const std::string& component) = 0;
140 
146  virtual bool isPowerResourceAcquired(const std::string& component) = 0;
147 
152  virtual std::chrono::milliseconds getTimeSinceLastResumeMS();
153 
167  virtual std::chrono::milliseconds getTimeSinceLastPartialMS(
168  const std::string& component,
169  PartialStateBitSet partialState = PowerResourceTypeFlag::TYPE_ALL_FLAG);
170 
183  public:
186  std::string getResourceId() const {
187  return m_resourceId;
188  }
190  PowerResourceId(const std::string& resourceId) : m_resourceId(resourceId) {
191  }
192 
193  private:
195  const std::string m_resourceId;
196  };
197 
205  virtual std::shared_ptr<PowerResourceId> create(
206  const std::string& resourceId,
207  bool isRefCounted = true,
209 
216  virtual bool acquire(
217  const std::shared_ptr<PowerResourceId>& id,
218  const std::chrono::milliseconds autoReleaseTimeout = std::chrono::milliseconds::zero()) = 0;
219 
225  virtual bool release(const std::shared_ptr<PowerResourceId>& id) = 0;
226 
232  virtual bool close(const std::shared_ptr<PowerResourceId>& id) = 0;
233 };
234 
241  return std::chrono::milliseconds::zero();
242 }
243 
251  const std::string& component,
252  PartialStateBitSet partialState) {
253  return std::chrono::milliseconds::zero();
254 }
255 
263  switch (level) {
265  return "STANDBY_LOW";
267  return "STANDBY_MED";
269  return "STANDBY_HIGH";
271  return "ACTIVE_LOW";
273  return "ACTIVE_MED";
275  return "ACTIVE_HIGH";
276  }
277 
278  return "UNKNOWN";
279 }
280 
289 inline std::ostream& operator<<(std::ostream& stream, PowerResourceManagerInterface::PowerResourceLevel level) {
290  return stream << powerResourceLevelToString(level);
291 }
292 
293 } // namespace sdkInterfaces
294 } // namespace avsCommon
295 } // namespace alexaClientSDK
296 
297 #endif // ALEXA_CLIENT_SDK_AVSCOMMON_SDKINTERFACES_INCLUDE_AVSCOMMON_SDKINTERFACES_POWERRESOURCEMANAGERINTERFACE_H_
STANDBY_MED usually means all the hardware components work in the medium standby power levels...
PowerResourceLevel
Definition: PowerResourceManagerInterface.h:49
virtual void acquirePowerResource(const std::string &component, const PowerResourceLevel level=PowerResourceLevel::STANDBY_MED)=0
A reserved type that allows platforms to reserve custom PowerResourceTypeFlags.
Definition: PowerResourceManagerInterface.h:84
std::ostream & operator<<(std::ostream &stream, const AudioInputProcessorObserverInterface::State &state)
Definition: AudioInputProcessorObserverInterface.h:86
ACTIVE_LOW usually means all the hardware components work in the medium active power levels...
Flag value which represents the storage resource type.
Definition: PowerResourceManagerInterface.h:112
Flag value which represents the CPU resource type.
Definition: PowerResourceManagerInterface.h:108
virtual bool isPowerResourceAcquired(const std::string &component)=0
virtual void releasePowerResource(const std::string &component)=0
CPU capacity is limited or improved under the CPU resource type.
Definition: PowerResourceManagerInterface.h:76
STANDBY_HIGH usually means all the hardware components work in the highest standby power levels...
Flag value which represents the network resource type.
Definition: PowerResourceManagerInterface.h:114
Number of power resource types. This must always be the last enum member.
Definition: PowerResourceManagerInterface.h:88
ACTIVE_HIGH usually means all the hardware components work in the highest active power levels...
PowerResourceTypeIndex
Definition: PowerResourceManagerInterface.h:74
PowerResourceTypeFlag
Definition: PowerResourceManagerInterface.h:104
DDR latency/bandwidth are limited or improved under the DDR resource type.
Definition: PowerResourceManagerInterface.h:78
std::string powerResourceLevelToString(PowerResourceManagerInterface::PowerResourceLevel level)
Definition: PowerResourceManagerInterface.h:262
The default flag value which corresponds to all power resource types.
Definition: PowerResourceManagerInterface.h:106
A reserved type that allows platforms to reserve custom PowerResourceTypeFlags.
Definition: PowerResourceManagerInterface.h:86
virtual std::chrono::milliseconds getTimeSinceLastPartialMS(const std::string &component, PartialStateBitSet partialState=PowerResourceTypeFlag::TYPE_ALL_FLAG)
Definition: PowerResourceManagerInterface.h:250
virtual std::shared_ptr< PowerResourceId > create(const std::string &resourceId, bool isRefCounted=true, const PowerResourceLevel level=PowerResourceLevel::STANDBY_MED)=0
Flag value which represents the first reserved resource type.
Definition: PowerResourceManagerInterface.h:116
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
std::string getResourceId() const
Definition: PowerResourceManagerInterface.h:186
virtual bool release(const std::shared_ptr< PowerResourceId > &id)=0
virtual bool close(const std::shared_ptr< PowerResourceId > &id)=0
PowerResourceId(const std::string &resourceId)
Constructor.
Definition: PowerResourceManagerInterface.h:190
Disk I/O performance is limited or improved under the storage resource type.
Definition: PowerResourceManagerInterface.h:80
Network latency is limited or improved under the network resource type.
Definition: PowerResourceManagerInterface.h:82
Flag value which represents the second reserved resource type.
Definition: PowerResourceManagerInterface.h:118
std::bitset< PowerResourceTypeIndex::NUM_OF_TYPES > PartialStateBitSet
Definition: PowerResourceManagerInterface.h:94
Flag value which represents the DDR resource type.
Definition: PowerResourceManagerInterface.h:110
virtual bool acquire(const std::shared_ptr< PowerResourceId > &id, const std::chrono::milliseconds autoReleaseTimeout=std::chrono::milliseconds::zero())=0
virtual std::chrono::milliseconds getTimeSinceLastResumeMS()
Definition: PowerResourceManagerInterface.h:240

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