AlexaClientSDK  1.26.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 
170  virtual std::chrono::milliseconds getTimeSinceLastPartialMS(
171  const std::string& component,
172  PartialStateBitSet& resourceFlags,
173  PartialStateBitSet partialState = PowerResourceTypeFlag::TYPE_ALL_FLAG);
174 
187  public:
190  std::string getResourceId() const {
191  return m_resourceId;
192  }
194  PowerResourceId(const std::string& resourceId) : m_resourceId(resourceId) {
195  }
196 
197  private:
199  const std::string m_resourceId;
200  };
201 
209  virtual std::shared_ptr<PowerResourceId> create(
210  const std::string& resourceId,
211  bool isRefCounted = true,
213 
220  virtual bool acquire(
221  const std::shared_ptr<PowerResourceId>& id,
222  const std::chrono::milliseconds autoReleaseTimeout = std::chrono::milliseconds::zero()) = 0;
223 
229  virtual bool release(const std::shared_ptr<PowerResourceId>& id) = 0;
230 
236  virtual bool close(const std::shared_ptr<PowerResourceId>& id) = 0;
237 };
238 
245  return std::chrono::milliseconds::zero();
246 }
247 
256  const std::string& component,
257  PartialStateBitSet& resourceFlags,
258  PartialStateBitSet partialState) {
259  return std::chrono::milliseconds::zero();
260 }
261 
269  switch (level) {
271  return "STANDBY_LOW";
273  return "STANDBY_MED";
275  return "STANDBY_HIGH";
277  return "ACTIVE_LOW";
279  return "ACTIVE_MED";
281  return "ACTIVE_HIGH";
282  }
283 
284  return "UNKNOWN";
285 }
286 
295 inline std::ostream& operator<<(std::ostream& stream, PowerResourceManagerInterface::PowerResourceLevel level) {
296  return stream << powerResourceLevelToString(level);
297 }
298 
299 } // namespace sdkInterfaces
300 } // namespace avsCommon
301 } // namespace alexaClientSDK
302 
303 #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:268
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::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:190
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:194
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:244
virtual std::chrono::milliseconds getTimeSinceLastPartialMS(const std::string &component, PartialStateBitSet &resourceFlags, PartialStateBitSet partialState=PowerResourceTypeFlag::TYPE_ALL_FLAG)
Definition: PowerResourceManagerInterface.h:255

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