AlexaClientSDK  1.25.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
TestDirectiveHandler.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_INTEGRATION_INCLUDE_INTEGRATION_TESTDIRECTIVEHANDLER_H_
17 #define ALEXA_CLIENT_SDK_INTEGRATION_INCLUDE_INTEGRATION_TESTDIRECTIVEHANDLER_H_
18 
19 #include <condition_variable>
20 #include <string>
21 #include <future>
22 #include <fstream>
23 #include <chrono>
24 #include <deque>
25 #include <mutex>
26 #include <unordered_map>
27 
31 
32 using namespace alexaClientSDK::avsCommon;
33 
34 namespace alexaClientSDK {
35 namespace integration {
36 namespace test {
37 
43 public:
51 
52  void handleDirectiveImmediately(std::shared_ptr<avsCommon::avs::AVSDirective> directive) override;
53 
54  void preHandleDirective(
55  std::shared_ptr<avsCommon::avs::AVSDirective> directive,
56  std::unique_ptr<avsCommon::sdkInterfaces::DirectiveHandlerResultInterface> result) override;
57 
58  bool handleDirective(const std::string& messageId) override;
59 
60  void cancelDirective(const std::string& messageId) override;
61 
62  avsCommon::avs::DirectiveHandlerConfiguration getConfiguration() const override;
63 
64  void onDeregistered() override;
65 
70  public:
75 
81  bool isUnset() const {
82  return Type::UNSET == type;
83  }
84 
90  bool isHandleImmediately() const {
91  return Type::HANDLE_IMMEDIATELY == type;
92  }
93 
99  bool isPreHandle() const {
100  return Type::PREHANDLE == type;
101  }
102 
108  bool isHandle() const {
109  return Type::HANDLE == type;
110  }
111 
117  bool isCancel() const {
118  return Type::CANCEL == type;
119  }
120 
126  bool isTimeout() const {
127  return Type::TIMEOUT == type;
128  }
129 
130  // Enum for the way the directive was passed to DirectiveHandler.
131  enum class Type {
132  // Not yet set.
133  UNSET,
134  // Set when handleDirectiveImmediately is called.
135  HANDLE_IMMEDIATELY,
136  // Set when preHandleDirective is called.
137  PREHANDLE,
138  // Set when handleDirective is called.
139  HANDLE,
140  // Set when cancelDirective is called.
141  CANCEL,
142  // Set when waitForNext times out waiting for a directive.
143  TIMEOUT
144  };
145 
146  // Type of how the directive was passed to DirectiveHandler.
148  // AVSDirective passed from the Directive Sequencer to the DirectiveHandler.
149  std::shared_ptr<avsCommon::avs::AVSDirective> directive;
150  // DirectiveHandlerResult to inform the Directive Sequencer a directive has either successfully or
151  // unsuccessfully handled.
152  std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerResultInterface> result;
153  };
154 
159  DirectiveParams waitForNext(const std::chrono::seconds duration);
160 
161 private:
163  std::mutex m_mutex;
165  std::condition_variable m_wakeTrigger;
167  std::deque<DirectiveParams> m_queue;
169  std::unordered_map<std::string, std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerResultInterface>>
170  m_results;
172  std::unordered_map<std::string, std::shared_ptr<avsCommon::avs::AVSDirective>> m_directives;
175 };
176 } // namespace test
177 } // namespace integration
178 } // namespace alexaClientSDK
179 
180 #endif // ALEXA_CLIENT_SDK_INTEGRATION_INCLUDE_INTEGRATION_TESTDIRECTIVEHANDLER_H_
Definition: MockHTTP2Connection.cpp:19
static constexpr std::chrono::milliseconds TIMEOUT
Reader timeout.
Definition: AndroidSLESMicrophoneTest.cpp:40
Definition: TestDirectiveHandler.h:42
bool isCancel() const
Definition: TestDirectiveHandler.h:117
bool isTimeout() const
Definition: TestDirectiveHandler.h:126
std::shared_ptr< avsCommon::sdkInterfaces::DirectiveHandlerResultInterface > result
Definition: TestDirectiveHandler.h:152
std::unordered_map< directiveRoutingRule::DirectiveRoutingRule, BlockingPolicy > DirectiveHandlerConfiguration
Definition: DirectiveHandlerConfiguration.h:32
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
bool isHandleImmediately() const
Definition: TestDirectiveHandler.h:90
bool isPreHandle() const
Definition: TestDirectiveHandler.h:99
bool isHandle() const
Definition: TestDirectiveHandler.h:108
std::shared_ptr< avsCommon::avs::AVSDirective > directive
Definition: TestDirectiveHandler.h:149
bool isUnset() const
Definition: TestDirectiveHandler.h:81

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