AlexaClientSDK  1.26.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_
Timer.h
alexaClientSDK::acsdkInteractionModelInterfaces::InteractionModelRequestProcessingObserverInterface
A directive observer for an InteractionModelCapabilityAgent.
Definition: InteractionModelRequestProcessingObserverInterface.h:23
alexaClientSDK::avsCommon::avs::DialogUXStateAggregator::onStateChanged
void onStateChanged(sdkInterfaces::AudioInputProcessorObserverInterface::State state) override
Definition: DialogUXStateAggregator.cpp:131
alexaClientSDK::avsCommon::avs::DialogUXStateAggregator
Definition: DialogUXStateAggregator.h:44
alexaClientSDK::avsCommon::utils::mediaPlayer::MediaPlayerInterface::SourceId
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
alexaClientSDK::avsCommon::sdkInterfaces::ConnectionStatusObserverInterface
Definition: ConnectionStatusObserverInterface.h:31
alexaClientSDK::avsCommon::avs::DialogUXStateAggregator::onConnectionStatusChanged
void onConnectionStatusChanged(const avsCommon::sdkInterfaces::ConnectionStatusObserverInterface::Status status, const avsCommon::sdkInterfaces::ConnectionStatusObserverInterface::ChangedReason reason) override
Definition: DialogUXStateAggregator.cpp:209
alexaClientSDK::avsCommon::avs::DialogUXStateAggregator::addObserver
void addObserver(std::shared_ptr< sdkInterfaces::DialogUXStateObserverInterface > observer)
Definition: DialogUXStateAggregator.cpp:112
alexaClientSDK::avsCommon::utils::timing::Timer
Definition: Timer.h:39
InteractionModelRequestProcessingObserverInterface.h
alexaClientSDK::avsCommon::avs::DialogUXStateAggregator::createDialogUXStateAggregator
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)
Definition: DialogUXStateAggregator.cpp:73
alexaClientSDK::avsCommon::avs::DialogUXStateAggregator::LONG_TIMEOUT_FOR_LISTENING_TO_IDLE
static constexpr std::chrono::seconds LONG_TIMEOUT_FOR_LISTENING_TO_IDLE
Definition: DialogUXStateAggregator.h:66
alexaClientSDK::avsCommon::sdkInterfaces::ConnectionStatusObserverInterface::ChangedReason
ChangedReason
Definition: ConnectionStatusObserverInterface.h:50
alexaClientSDK::avsCommon::avs::DialogUXStateAggregator::onRequestProcessingCompleted
void onRequestProcessingCompleted() override
Definition: DialogUXStateAggregator.cpp:275
alexaClientSDK::avsCommon::utils::threading::Executor
Definition: Executor.h:40
alexaClientSDK::avsCommon::sdkInterfaces::SpeechSynthesizerObserverInterface::SpeechSynthesizerState
SpeechSynthesizerState
Definition: SpeechSynthesizerObserverInterface.h:37
MetricRecorderInterface.h
alexaClientSDK::avsCommon::sdkInterfaces::SpeechSynthesizerObserverInterface
Definition: SpeechSynthesizerObserverInterface.h:32
AVSConnectionManagerInterface.h
Executor.h
AudioInputProcessorObserverInterface.h
alexaClientSDK
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
alexaClientSDK::avsCommon::avs::DialogUXStateAggregator::SHORT_TIMEOUT_FOR_THINKING_TO_IDLE
static constexpr std::chrono::milliseconds SHORT_TIMEOUT_FOR_THINKING_TO_IDLE
Definition: DialogUXStateAggregator.h:54
SpeechSynthesizerObserverInterface.h
MessageObserverInterface.h
alexaClientSDK::avsCommon::sdkInterfaces::AudioInputProcessorObserverInterface::State
State
The different states the AudioInputProcessor can be in.
Definition: AudioInputProcessorObserverInterface.h:30
alexaClientSDK::avsCommon::avs::DialogUXStateAggregator::LONG_TIMEOUT_FOR_THINKING_TO_IDLE
static constexpr std::chrono::seconds LONG_TIMEOUT_FOR_THINKING_TO_IDLE
Definition: DialogUXStateAggregator.h:60
alexaClientSDK::avsCommon::avs::DialogUXStateAggregator::onRequestProcessingStarted
void onRequestProcessingStarted() override
Definition: DialogUXStateAggregator.cpp:245
alexaClientSDK::avsCommon::sdkInterfaces::ConnectionStatusObserverInterface::Status
Status
Definition: ConnectionStatusObserverInterface.h:36
ConnectionStatusObserverInterface.h
DialogUXStateObserverInterface.h
alexaClientSDK::avsCommon::avs::DialogUXStateAggregator::removeObserver
void removeObserver(std::shared_ptr< sdkInterfaces::DialogUXStateObserverInterface > observer)
Definition: DialogUXStateAggregator.cpp:123
InteractionModelNotifierInterface.h
alexaClientSDK::avsCommon::avs::DialogUXStateAggregator::DialogUXStateAggregator
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)
Definition: DialogUXStateAggregator.cpp:94
alexaClientSDK::avsCommon::utils::Optional
Definition: Optional.h:32
alexaClientSDK::avsCommon::sdkInterfaces::AudioInputProcessorObserverInterface
A state observer for an AudioInputProcessor.
Definition: AudioInputProcessorObserverInterface.h:27
alexaClientSDK::avsCommon::sdkInterfaces::DialogUXStateObserverInterface::DialogUXState
DialogUXState
The different dialog specific AVS UX states.
Definition: DialogUXStateObserverInterface.h:32

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