AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
ModeControllerCapabilityAgent.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_CAPABILITYAGENTS_MODECONTROLLER_INCLUDE_MODECONTROLLER_MODECONTROLLERCAPABILITYAGENT_H_
17 #define ALEXA_CLIENT_SDK_CAPABILITYAGENTS_MODECONTROLLER_INCLUDE_MODECONTROLLER_MODECONTROLLERCAPABILITYAGENT_H_
18 
31 
32 namespace alexaClientSDK {
33 namespace capabilityAgents {
34 namespace modeController {
35 
46  , public std::enable_shared_from_this<ModeControllerCapabilityAgent> {
47 public:
51 
70  static std::shared_ptr<ModeControllerCapabilityAgent> create(
71  const EndpointIdentifier& endpointId,
72  const std::string& instance,
74  std::shared_ptr<avsCommon::sdkInterfaces::modeController::ModeControllerInterface> modeController,
75  std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface> contextManager,
76  std::shared_ptr<avsCommon::sdkInterfaces::AlexaInterfaceMessageSenderInterface> responseSender,
77  std::shared_ptr<avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface> exceptionSender,
78  bool isProactivelyReported,
79  bool isRetrievable,
80  bool isNonControllable = false);
81 
84  void handleDirectiveImmediately(std::shared_ptr<avsCommon::avs::AVSDirective> directive) override;
85  void preHandleDirective(std::shared_ptr<DirectiveInfo> info) override;
86  void handleDirective(std::shared_ptr<DirectiveInfo> info) override;
87  void cancelDirective(std::shared_ptr<DirectiveInfo> info) override;
90 
93  void provideState(
94  const avsCommon::avs::CapabilityTag& stateProviderName,
95  const avsCommon::sdkInterfaces::ContextRequestToken contextRequestToken) override;
96  bool canStateBeRetrieved() override;
97  bool hasReportableStateProperties() override;
99 
106 
111 
112 private:
131  const EndpointIdentifier& endpointId,
132  const std::string& instance,
134  std::shared_ptr<avsCommon::sdkInterfaces::modeController::ModeControllerInterface> modeController,
135  std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface> contextManager,
136  std::shared_ptr<avsCommon::sdkInterfaces::AlexaInterfaceMessageSenderInterface> responseSender,
137  std::shared_ptr<avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface> exceptionSender,
138  bool isProactivelyReported,
139  bool isRetrievable,
140  bool isNonControllable);
141 
142  // @name RequiresShutdown Functions
144  void doShutdown() override;
146 
152  bool initialize();
153 
159  void removeDirective(std::shared_ptr<DirectiveInfo> info);
160 
166  void executeSetHandlingCompleted(std::shared_ptr<DirectiveInfo> info);
167 
173  std::string buildModeConfigurationJson();
174 
181  void executeSetModeDirective(std::shared_ptr<DirectiveInfo> info, rapidjson::Document& payload);
182 
189  void executeAdjustModeDirective(std::shared_ptr<DirectiveInfo> info, rapidjson::Document& payload);
190 
197  void executeUnknownDirective(std::shared_ptr<DirectiveInfo> info, avsCommon::avs::ExceptionErrorType type);
198 
206  bool validateMode(const std::string& mode);
207 
214  void executeSetMode(
215  const std::shared_ptr<avsCommon::avs::CapabilityAgent::DirectiveInfo> info,
216  rapidjson::Document& payload);
217 
224  void executeAdjustMode(
225  const std::shared_ptr<avsCommon::avs::CapabilityAgent::DirectiveInfo> info,
226  rapidjson::Document& payload);
227 
234  void executeProvideState(
235  const avsCommon::avs::CapabilityTag& stateProviderName,
236  const avsCommon::sdkInterfaces::ContextRequestToken contextRequestToken);
237 
245  void executeSendResponseEvent(
246  const std::shared_ptr<avsCommon::avs::CapabilityAgent::DirectiveInfo> info,
247  std::pair<avsCommon::avs::AlexaResponseType, std::string> result);
248 
254  avsCommon::avs::CapabilityState buildCapabilityState(const ModeState& modeState);
255 
257  EndpointIdentifier m_endpointId;
258 
260  std::string m_instance;
261 
263  bool m_isProactivelyReported;
264 
266  bool m_isRetrievable;
267 
269  bool m_isNonControllable;
270 
273 
276  m_modeControllerConfiguration;
277 
279  std::shared_ptr<avsCommon::sdkInterfaces::modeController::ModeControllerInterface> m_modeController;
280 
282  std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface> m_contextManager;
283 
285  std::shared_ptr<avsCommon::sdkInterfaces::AlexaInterfaceMessageSenderInterface> m_responseSender;
286 
287  // The pair to hold the @c ModeState and @c AlexaStateChangeCauseType
288  using ModeAndCauseTypePair = std::pair<ModeState, avsCommon::sdkInterfaces::AlexaStateChangeCauseType>;
289 
290  // Map of context request token and @c ModeAndCauseTypePair for handling the ChangeReport.
291  std::map<avsCommon::sdkInterfaces::ContextRequestToken, ModeAndCauseTypePair> m_pendingChangeReports;
292 
295 };
296 
297 } // namespace modeController
298 } // namespace capabilityAgents
299 } // namespace alexaClientSDK
300 
301 #endif // ALEXA_CLIENT_SDK_CAPABILITYAGENTS_MODECONTROLLER_INCLUDE_MODECONTROLLER_MODECONTROLLERCAPABILITYAGENT_H_
Definition: CapabilityAgent.h:47
void cancelDirective(std::shared_ptr< DirectiveInfo > info) override
Definition: CapabilityTag.h:32
::std::string string
Definition: gtest-port.h:1097
Single-thread executor implementation.
Definition: Executor.h:45
unsigned int ContextRequestToken
Alias for the token used to identify a context request.
Definition: ContextRequestToken.h:23
avsCommon::avs::DirectiveHandlerConfiguration getConfiguration() const override
ExceptionErrorType
Definition: ExceptionErrorType.h:28
AlexaStateChangeCauseType
Definition: AlexaStateChangeCauseType.h:28
std::vector< std::string > ModeControllerConfiguration
Definition: ModeControllerInterface.h:51
void provideState(const avsCommon::avs::CapabilityTag &stateProviderName, const avsCommon::sdkInterfaces::ContextRequestToken contextRequestToken) override
void handleDirective(std::shared_ptr< DirectiveInfo > info) override
void preHandleDirective(std::shared_ptr< DirectiveInfo > info) override
std::unordered_map< directiveRoutingRule::DirectiveRoutingRule, BlockingPolicy > DirectiveHandlerConfiguration
Definition: DirectiveHandlerConfiguration.h:32
avsCommon::sdkInterfaces::modeController::ModeControllerObserverInterface::ModeState ModeState
Alias to improve readability.
Definition: ModeControllerInterface.h:40
Definition: CapabilityState.h:31
void onModeChanged(const ModeState &mode, avsCommon::sdkInterfaces::AlexaStateChangeCauseType cause) override
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
type
Definition: upload.py:443
static std::shared_ptr< ModeControllerCapabilityAgent > create(const EndpointIdentifier &endpointId, const std::string &instance, const avsCommon::sdkInterfaces::modeController::ModeControllerAttributes &modeControllerAttributes, std::shared_ptr< avsCommon::sdkInterfaces::modeController::ModeControllerInterface > modeController, std::shared_ptr< avsCommon::sdkInterfaces::ContextManagerInterface > contextManager, std::shared_ptr< avsCommon::sdkInterfaces::AlexaInterfaceMessageSenderInterface > responseSender, std::shared_ptr< avsCommon::sdkInterfaces::ExceptionEncounteredSenderInterface > exceptionSender, bool isProactivelyReported, bool isRetrievable, bool isNonControllable=false)
avsCommon::sdkInterfaces::endpoints::EndpointIdentifier EndpointIdentifier
Alias to improve readability.
Definition: ModeControllerCapabilityAgent.h:49
std::string EndpointIdentifier
Definition: EndpointIdentifier.h:38
Definition: CapabilityConfiguration.h:42
void handleDirectiveImmediately(std::shared_ptr< avsCommon::avs::AVSDirective > directive) override

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