AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
MockTimerFactory.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_AVS_SHARED_PRESENTATIONORCHESTRATOR_VISUALTIMEOUTMANAGER_TEST_MOCKTIMERFACTORY_H_
17 #define ALEXA_CLIENT_SDK_AVS_SHARED_PRESENTATIONORCHESTRATOR_VISUALTIMEOUTMANAGER_TEST_MOCKTIMERFACTORY_H_
18 
19 #include <chrono>
20 #include <functional>
21 
24 
25 namespace alexaClientSDK {
26 namespace visualTimeoutManager {
27 namespace test {
28 
34 public:
37  void start(
38  std::chrono::nanoseconds delay,
39  std::chrono::nanoseconds period,
40  PeriodType periodType,
41  size_t maxCount,
42  std::function<void()> task) override {
43  m_task = task;
44  m_delay = delay;
45  }
46  void stop() override {
47  m_active = false;
48  }
49  bool activate() override {
50  assert(!m_active);
51  m_active = true;
52  return m_active;
53  }
54  bool isActive() const override {
55  return m_active;
56  }
58 
65  bool warpForward(std::chrono::nanoseconds step) {
66  bool dispatched = (step >= m_delay);
67  if (dispatched) {
68  m_task();
69  }
70 
71  return dispatched;
72  }
73 
79  std::chrono::nanoseconds getDelay() {
80  return m_delay;
81  }
82 
83 protected:
84  std::function<void()> m_task;
85  std::chrono::nanoseconds m_delay;
86  bool m_active{false};
87 };
88 
93 public:
96  bool supportsLowPowerMode() override {
97  return true;
98  }
99  std::unique_ptr<alexaClientSDK::avsCommon::sdkInterfaces::timing::TimerDelegateInterface> getTimerDelegate()
100  override {
101  if (m_timer) {
102  assert(false); // does not support multiple instances
103  }
104  m_timer = new WarpTimer();
105  std::unique_ptr<alexaClientSDK::avsCommon::sdkInterfaces::timing::TimerDelegateInterface> ptr{m_timer};
106 
107  return ptr;
108  }
110 
119  return m_timer;
120  }
121 
122 protected:
123  WarpTimer* m_timer{nullptr};
124 };
125 
126 } // namespace test
127 } // namespace visualTimeoutManager
128 } // namespace alexaClientSDK
129 
130 #endif // ALEXA_CLIENT_SDK_AVS_SHARED_PRESENTATIONORCHESTRATOR_VISUALTIMEOUTMANAGER_TEST_MOCKTIMERFACTORY_H_
bool supportsLowPowerMode() override
Definition: MockTimerFactory.h:96
std::unique_ptr< alexaClientSDK::avsCommon::sdkInterfaces::timing::TimerDelegateInterface > getTimerDelegate() override
Definition: MockTimerFactory.h:99
Definition: AmdMetricWrapperTest.cpp:24
A factory for creating TimerDelegateInterface.
Definition: TimerDelegateFactoryInterface.h:29
bool activate() override
Definition: MockTimerFactory.h:49
bool m_active
Definition: MockTimerFactory.h:86
bool warpForward(std::chrono::nanoseconds step)
Definition: MockTimerFactory.h:65
void stop() override
Definition: MockTimerFactory.h:46
std::function< void()> m_task
Definition: MockTimerFactory.h:84
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
std::chrono::nanoseconds m_delay
Definition: MockTimerFactory.h:85
bool isActive() const override
Definition: MockTimerFactory.h:54
PeriodType
Specifies different ways to apply the period of a recurring task.
Definition: TimerDelegateInterface.h:48
WarpTimer * getTimer()
Definition: MockTimerFactory.h:118
std::chrono::nanoseconds getDelay()
Definition: MockTimerFactory.h:79
void start(std::chrono::nanoseconds delay, std::chrono::nanoseconds period, PeriodType periodType, size_t maxCount, std::function< void()> task) override
Definition: MockTimerFactory.h:37

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