AlexaClientSDK  1.25.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
DirectiveSequencer.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_ADSL_INCLUDE_ADSL_DIRECTIVESEQUENCER_H_
17 #define ALEXA_CLIENT_SDK_ADSL_INCLUDE_ADSL_DIRECTIVESEQUENCER_H_
18 
19 #include <condition_variable>
20 #include <deque>
21 #include <memory>
22 #include <mutex>
23 #include <thread>
24 
30 
32 #include "ADSL/DirectiveRouter.h"
33 
34 namespace alexaClientSDK {
35 namespace adsl {
36 
41 public:
51  static std::shared_ptr<DirectiveSequencerInterface> createDirectiveSequencerInterface(
52  std::shared_ptr<avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface> exceptionSender,
53  std::shared_ptr<acsdkShutdownManagerInterfaces::ShutdownNotifierInterface> shutdownNotifier,
54  std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> metricRecorder);
55 
65  static std::unique_ptr<DirectiveSequencerInterface> create(
66  std::shared_ptr<avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface> exceptionSender,
67  std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> metricRecorder = nullptr);
68 
69  bool addDirectiveHandler(std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerInterface> handler) override;
70 
71  bool removeDirectiveHandler(std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerInterface> handler) override;
72 
73  void setDialogRequestId(const std::string& dialogRequestId) override;
74 
75  std::string getDialogRequestId() override;
76 
77  bool onDirective(std::shared_ptr<avsCommon::avs::AVSDirective> directive) override;
78 
79  void disable() override;
80 
81  void enable() override;
82 
83 private:
91  std::shared_ptr<avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface> exceptionSender,
92  std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> metricRecorder);
93 
94  void doShutdown() override;
95 
99  void receivingLoop();
100 
108  void receiveDirectiveLocked(std::unique_lock<std::mutex>& lock);
109 
111  std::mutex m_mutex;
112 
114  std::shared_ptr<avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface> m_exceptionSender;
115 
117  bool m_isShuttingDown;
118 
120  bool m_isEnabled;
121 
123  DirectiveRouter m_directiveRouter;
124 
126  std::shared_ptr<DirectiveProcessor> m_directiveProcessor;
127 
129  std::deque<std::shared_ptr<avsCommon::avs::AVSDirective>> m_receivingQueue;
130 
133 
135  std::shared_ptr<avsCommon::utils::power::PowerResource> m_powerResource;
136 
138  std::thread m_receivingThread;
139 };
140 
141 } // namespace adsl
142 } // namespace alexaClientSDK
143 
144 #endif // ALEXA_CLIENT_SDK_ADSL_INCLUDE_ADSL_DIRECTIVESEQUENCER_H_
static std::unique_ptr< DirectiveSequencerInterface > create(std::shared_ptr< avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface > exceptionSender, std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder=nullptr)
Definition: DirectiveSequencer.cpp:65
static std::shared_ptr< DirectiveSequencerInterface > createDirectiveSequencerInterface(std::shared_ptr< avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface > exceptionSender, std::shared_ptr< acsdkShutdownManagerInterfaces::ShutdownNotifierInterface > shutdownNotifier, std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder)
Definition: DirectiveSequencer.cpp:46
bool addDirectiveHandler(std::shared_ptr< avsCommon::sdkInterfaces::DirectiveHandlerInterface > handler) override
Definition: DirectiveSequencer.cpp:75
Definition: DirectiveSequencer.h:40
void enable() override
Definition: DirectiveSequencer.cpp:154
bool removeDirectiveHandler(std::shared_ptr< avsCommon::sdkInterfaces::DirectiveHandlerInterface > handler) override
Definition: DirectiveSequencer.cpp:79
Definition: DirectiveRouter.h:36
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
void setDialogRequestId(const std::string &dialogRequestId) override
Definition: DirectiveSequencer.cpp:83
bool onDirective(std::shared_ptr< avsCommon::avs::AVSDirective > directive) override
Definition: DirectiveSequencer.cpp:91
void disable() override
Definition: DirectiveSequencer.cpp:145
std::string getDialogRequestId() override
Definition: DirectiveSequencer.cpp:87

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