AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
DirectiveRouter.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_DIRECTIVEROUTER_H_
17 #define ALEXA_CLIENT_SDK_ADSL_INCLUDE_ADSL_DIRECTIVEROUTER_H_
18 
19 #include <map>
20 #include <set>
21 #include <unordered_map>
22 
29 
30 namespace alexaClientSDK {
31 namespace adsl {
37 public:
40  DirectiveRouter(std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> metricRecorder = nullptr);
41 
50  bool addDirectiveHandler(std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerInterface> handler);
51 
60  bool removeDirectiveHandler(std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerInterface> handler);
61 
68  bool handleDirectiveImmediately(std::shared_ptr<avsCommon::avs::AVSDirective> directive);
69 
78  bool preHandleDirective(
79  std::shared_ptr<avsCommon::avs::AVSDirective> directive,
80  std::unique_ptr<avsCommon::sdkInterfaces::DirectiveHandlerResultInterface> result);
81 
89  bool handleDirective(const std::shared_ptr<avsCommon::avs::AVSDirective>& directive);
90 
97  bool cancelDirective(std::shared_ptr<avsCommon::avs::AVSDirective> directive);
98 
105  avsCommon::avs::BlockingPolicy getPolicy(const std::shared_ptr<avsCommon::avs::AVSDirective>& directive);
106 
107 private:
108  void doShutdown() override;
109 
117  class HandlerCallScope {
118  public:
128  HandlerCallScope(
129  std::unique_lock<std::mutex>& lock,
130  DirectiveRouter* router,
131  std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerInterface> handler);
132 
138  ~HandlerCallScope();
139 
140  private:
142  std::unique_lock<std::mutex>& m_lock;
143 
145  DirectiveRouter* m_router;
146 
148  std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerInterface> m_handler;
149  };
150 
158  avsCommon::avs::HandlerAndPolicy getHandlerAndPolicyLocked(
159  const std::shared_ptr<avsCommon::avs::AVSDirective>& directive);
160 
168  std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerInterface> getHandlerLocked(
169  std::shared_ptr<avsCommon::avs::AVSDirective> directive);
170 
176  void incrementHandlerReferenceCountLocked(
177  std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerInterface> handler);
178 
186  void decrementHandlerReferenceCountLocked(
187  std::unique_lock<std::mutex>& lock,
188  std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerInterface> handler);
189 
198  bool removeDirectiveHandlerLocked(std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerInterface> handler);
199 
201  std::shared_ptr<avsCommon::utils::metrics::MetricRecorderInterface> m_metricRecorder;
202 
204  std::mutex m_mutex;
205 
207  std::unordered_map<avsCommon::avs::CapabilityTag, avsCommon::avs::HandlerAndPolicy> m_configuration;
208 
218  std::unordered_map<std::shared_ptr<avsCommon::sdkInterfaces::DirectiveHandlerInterface>, int>
219  m_handlerReferenceCounts;
220 
227  void submitMetric(
229  const std::shared_ptr<avsCommon::avs::AVSDirective>& directive);
230 };
231 
232 } // namespace adsl
233 } // namespace alexaClientSDK
234 
235 #endif // ALEXA_CLIENT_SDK_ADSL_INCLUDE_ADSL_DIRECTIVEROUTER_H_
bool handleDirectiveImmediately(std::shared_ptr< avsCommon::avs::AVSDirective > directive)
bool handleDirective(const std::shared_ptr< avsCommon::avs::AVSDirective > &directive)
DirectiveRouter(std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder=nullptr)
avsCommon::avs::BlockingPolicy getPolicy(const std::shared_ptr< avsCommon::avs::AVSDirective > &directive)
static std::shared_ptr< avsCommon::utils::metrics::MetricRecorderInterface > metricRecorder
Metric recorder shared ptr.
Definition: BaseAPLCapabilityAgentTest.cpp:261
bool cancelDirective(std::shared_ptr< avsCommon::avs::AVSDirective > directive)
Definition: DirectiveRouter.h:36
bool preHandleDirective(std::shared_ptr< avsCommon::avs::AVSDirective > directive, std::unique_ptr< avsCommon::sdkInterfaces::DirectiveHandlerResultInterface > result)
bool removeDirectiveHandler(std::shared_ptr< avsCommon::sdkInterfaces::DirectiveHandlerInterface > handler)
bool addDirectiveHandler(std::shared_ptr< avsCommon::sdkInterfaces::DirectiveHandlerInterface > handler)
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
Definition: BlockingPolicy.h:31
Definition: HandlerAndPolicy.h:30

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