AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
DialogUXStateAggregator.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_AVS_INCLUDE_AVSCOMMON_AVS_DIALOGUXSTATEAGGREGATOR_H_
17 #define ALEXA_CLIENT_SDK_AVSCOMMON_AVS_INCLUDE_AVSCOMMON_AVS_DIALOGUXSTATEAGGREGATOR_H_
18 
19 #include <atomic>
20 #include <chrono>
21 #include <unordered_set>
22 #include <vector>
23 
35 
36 namespace alexaClientSDK {
37 namespace avsCommon {
38 namespace avs {
39 
49 public:
54  static constexpr std::chrono::milliseconds SHORT_TIMEOUT_FOR_THINKING_TO_IDLE = std::chrono::milliseconds{200};
55 
60  static constexpr std::chrono::seconds LONG_TIMEOUT_FOR_THINKING_TO_IDLE = std::chrono::seconds{8};
61 
66  static constexpr std::chrono::seconds LONG_TIMEOUT_FOR_LISTENING_TO_IDLE = std::chrono::seconds{8};
67 
78  static std::shared_ptr<DialogUXStateAggregator> createDialogUXStateAggregator(
79  const std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface>& metricRecorder,
80  const std::shared_ptr<avsCommon::sdkInterfaces::AVSConnectionManagerInterface>& connectionManager,
81  const std::shared_ptr<acsdkInteractionModelInterfaces::InteractionModelNotifierInterface>&
82  interactionModelNotifier);
83 
97  std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> metricRecorder = nullptr,
98  std::chrono::milliseconds timeoutForThinkingToIdle = LONG_TIMEOUT_FOR_THINKING_TO_IDLE,
99  std::chrono::milliseconds timeoutForListeningToIdle = LONG_TIMEOUT_FOR_LISTENING_TO_IDLE,
100  std::chrono::milliseconds shortTimeoutForThinkingToIdle = SHORT_TIMEOUT_FOR_THINKING_TO_IDLE);
101 
111  void addObserver(std::shared_ptr<sdkInterfaces::DialogUXStateObserverInterface> observer);
112 
123  void removeObserver(std::shared_ptr<sdkInterfaces::DialogUXStateObserverInterface> observer);
124 
129 
132  void onStateChanged(
136  const std::vector<avsCommon::utils::audioAnalyzer::AudioAnalyzerState>& audioAnalyzerState) override;
138 
141  void onRequestProcessingStarted() override;
142  void onRequestProcessingCompleted() override;
144 
150 
151  void onConnectionStatusChanged(const Status status, const std::vector<EngineConnectionStatus>& engineStatuses)
152  override;
154 
155 private:
159  void notifyObserversOfState();
160 
168 
172  void executeTryEnterIdleState();
173 
178  void executeTryExitThinkingState();
179 
183  void transitionFromThinkingTimedOut();
184 
188  void transitionFromListeningTimedOut();
189 
194  void tryEnterIdleStateOnTimer();
195 
199  void onActivityStarted();
200 
207 
210  std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> m_metricRecorder;
211 
213  std::unordered_set<std::shared_ptr<sdkInterfaces::DialogUXStateObserverInterface>> m_observers;
214 
217 
219  const std::chrono::milliseconds m_timeoutForThinkingToIdle;
220 
225  const std::chrono::milliseconds m_shortTimeoutForThinkingToIdle;
226 
228  avsCommon::utils::timing::Timer m_thinkingTimeoutTimer;
229 
231  avsCommon::utils::timing::Timer m_multiturnSpeakingToListeningTimer;
232 
235  const std::chrono::milliseconds m_timeoutForListeningToIdle;
236 
239  avsCommon::utils::timing::Timer m_listeningTimeoutTimer;
240 
242 
250 
252  std::atomic<alexaClientSDK::avsCommon::sdkInterfaces::SpeechSynthesizerObserverInterface::SpeechSynthesizerState>
253  m_speechSynthesizerState;
254 
256  std::atomic<alexaClientSDK::avsCommon::sdkInterfaces::AudioInputProcessorObserverInterface::State>
257  m_audioInputProcessorState;
258 };
259 
260 } // namespace avs
261 } // namespace avsCommon
262 } // namespace alexaClientSDK
263 
264 #endif // ALEXA_CLIENT_SDK_AVSCOMMON_AVS_INCLUDE_AVSCOMMON_AVS_DIALOGUXSTATEAGGREGATOR_H_
DialogUXStateAggregator(std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder=nullptr, std::chrono::milliseconds timeoutForThinkingToIdle=LONG_TIMEOUT_FOR_THINKING_TO_IDLE, std::chrono::milliseconds timeoutForListeningToIdle=LONG_TIMEOUT_FOR_LISTENING_TO_IDLE, std::chrono::milliseconds shortTimeoutForThinkingToIdle=SHORT_TIMEOUT_FOR_THINKING_TO_IDLE)
ChangedReason
Definition: ConnectionStatusObserverInterface.h:50
void addObserver(std::shared_ptr< sdkInterfaces::DialogUXStateObserverInterface > observer)
static std::shared_ptr< DialogUXStateAggregator > createDialogUXStateAggregator(const std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > &metricRecorder, const std::shared_ptr< avsCommon::sdkInterfaces::AVSConnectionManagerInterface > &connectionManager, const std::shared_ptr< acsdkInteractionModelInterfaces::InteractionModelNotifierInterface > &interactionModelNotifier)
uint64_t SourceId
A type that identifies which source is currently being operated on. This must be unique across all in...
Definition: MediaPlayerInterface.h:69
void onStateChanged(sdkInterfaces::AudioInputProcessorObserverInterface::State state) override
Single-thread executor implementation.
Definition: Executor.h:45
Definition: ConnectionStatusObserverInterface.h:31
static constexpr std::chrono::seconds LONG_TIMEOUT_FOR_LISTENING_TO_IDLE
Definition: DialogUXStateAggregator.h:66
DialogUXState
The different dialog specific AVS UX states.
Definition: DialogUXStateObserverInterface.h:32
static std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder
Metric recorder shared ptr.
Definition: BaseAPLCapabilityAgentTest.cpp:261
static constexpr std::chrono::milliseconds SHORT_TIMEOUT_FOR_THINKING_TO_IDLE
Definition: DialogUXStateAggregator.h:54
State
The different states the AudioInputProcessor can be in.
Definition: AudioInputProcessorObserverInterface.h:30
A directive observer for an InteractionModelCapabilityAgent.
Definition: InteractionModelRequestProcessingObserverInterface.h:23
Timer to schedule task for delayed and periodic execution.
Definition: Timer.h:39
static constexpr std::chrono::seconds LONG_TIMEOUT_FOR_THINKING_TO_IDLE
Definition: DialogUXStateAggregator.h:60
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
A state observer for an AudioInputProcessor.
Definition: AudioInputProcessorObserverInterface.h:27
Definition: SpeechSynthesizerObserverInterface.h:32
SpeechSynthesizerState
Definition: SpeechSynthesizerObserverInterface.h:37
Definition: DialogUXStateAggregator.h:44
void removeObserver(std::shared_ptr< sdkInterfaces::DialogUXStateObserverInterface > observer)
void onConnectionStatusChanged(const avsCommon::sdkInterfaces::ConnectionStatusObserverInterface::Status status, const avsCommon::sdkInterfaces::ConnectionStatusObserverInterface::ChangedReason reason) override
Status
Definition: ConnectionStatusObserverInterface.h:36

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