AlexaClientSDK  1.26.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
AlexaInterfaceMessageSender.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_ALEXA_INCLUDE_ALEXA_ALEXAINTERFACEMESSAGESENDER_H_
17 #define ALEXA_CLIENT_SDK_CAPABILITYAGENTS_ALEXA_INCLUDE_ALEXA_ALEXAINTERFACEMESSAGESENDER_H_
18 
19 #include <memory>
20 #include <string>
21 #include <unordered_map>
22 
31 
32 namespace alexaClientSDK {
33 namespace capabilityAgents {
34 namespace alexa {
35 
46  , public std::enable_shared_from_this<AlexaInterfaceMessageSender> {
47 public:
52 
61  static std::shared_ptr<AlexaInterfaceMessageSender> createAlexaInterfaceMessageSender(
62  const std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface>& contextManager,
63  const std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface>& messageSender,
64  const std::shared_ptr<acsdkShutdownManagerInterfaces::ShutdownNotifierInterface>& shutdownNotifier);
65 
73  static std::shared_ptr<AlexaInterfaceMessageSenderInternalInterface>
75  const std::shared_ptr<AlexaInterfaceMessageSender>& messageSender);
76 
85  static std::shared_ptr<AlexaInterfaceMessageSender> create(
86  std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface> contextManager,
87  std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> messageSender);
88 
91  void onStateChanged(
92  const avsCommon::avs::CapabilityTag& identifier,
96 
99  void onContextAvailable(
100  const std::string& endpointId,
101  const avsCommon::avs::AVSContext& endpointContext,
103  void onContextFailure(
107 
111  void onExceptionReceived(const std::string& exceptionMessage) override;
113 
116  virtual bool sendStateReportEvent(
117  const std::string& instance,
118  const std::string& correlationToken,
119  const avsCommon::avs::AVSMessageEndpoint& endpoint) override;
120  virtual bool sendResponseEvent(
121  const std::string& instance,
122  const std::string& correlationToken,
123  const avsCommon::avs::AVSMessageEndpoint& endpoint,
124  const std::string& jsonPayload = "{}") override;
125  virtual bool sendResponseEvent(
126  const std::string& instance,
127  const std::string& correlationToken,
128  const avsCommon::avs::AVSMessageEndpoint& endpoint,
129  const std::string& responseNamespace,
130  const std::string& responseName,
131  const std::string& jsonPayload = "{}") override;
132  virtual bool sendErrorResponseEvent(
133  const std::string& instance,
134  const std::string& correlationToken,
135  const avsCommon::avs::AVSMessageEndpoint& endpoint,
136  const ErrorResponseType errorType,
137  const std::string& errorMessage = "") override;
139  const std::string& instance,
140  const std::string& correlationToken,
141  const avsCommon::avs::AVSMessageEndpoint& endpoint,
142  const std::string& responseNamespace,
143  const std::string& jsonPayload = "{}") override;
144  virtual bool sendDeferredResponseEvent(
145  const std::string& instance,
146  const std::string& correlationToken,
147  const int estimatedDeferralInSeconds = 0) override;
149 
150 private:
151  // Hold Alexa.Response event details until we have context.
152  struct ResponseData {
162  ResponseData(
163  const std::string& type,
164  const std::string& instance,
165  const std::string& correlationToken,
166  const avsCommon::avs::AVSMessageEndpoint& endpoint,
167  const std::string& jsonPayload,
168  const std::string& responseNamespace);
169 
171  const std::string type;
172 
174  const std::string instance;
175 
177  const std::string correlationToken;
178 
180  const avsCommon::avs::AVSMessageEndpoint endpoint;
181 
183  const std::string jsonPayload;
184 
186  const std::string responseNamespace;
187  };
188 
189  // Hold Alexa.ChangeReport event details until we have context.
190  struct ChangeReportData {
198  ChangeReportData(
200  const avsCommon::avs::CapabilityState& state,
202 
205 
208 
211  };
212 
220  std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface> contextManager,
221  std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> messageSender);
222 
228  bool initialize();
229 
230  // @name RequiresShutdown method
232  void doShutdown() override;
234 
245  bool sendCommonResponseEvent(
246  const std::string& type,
247  const std::string& instance,
248  const std::string& correlationToken,
249  const avsCommon::avs::AVSMessageEndpoint& endpoint,
250  const std::string& jsonPayload = "{}",
251  const std::string& responseNamespace = "");
252 
260  void completeResponseEvent(
261  const std::shared_ptr<ResponseData>& event,
264 
272  void completeChangeReportEvent(
273  const std::shared_ptr<ChangeReportData>& event,
274  const avsCommon::avs::AVSContext& context);
275 
281  void sendEvent(const std::string& eventJson);
282 
284  std::shared_ptr<avsCommon::sdkInterfaces::ContextManagerInterface> m_contextManager;
285 
287  std::shared_ptr<avsCommon::sdkInterfaces::MessageSenderInterface> m_messageSender;
288 
290  std::map<avsCommon::sdkInterfaces::ContextRequestToken, std::shared_ptr<ResponseData>> m_pendingResponses;
291 
293  std::map<avsCommon::sdkInterfaces::ContextRequestToken, std::shared_ptr<ChangeReportData>> m_pendingChangeReports;
294 
297 };
298 
299 } // namespace alexa
300 } // namespace capabilityAgents
301 } // namespace alexaClientSDK
302 
303 #endif // ALEXA_CLIENT_SDK_CAPABILITYAGENTS_ALEXA_INCLUDE_ALEXA_ALEXAINTERFACEMESSAGESENDER_H_
void onContextFailure(const avsCommon::sdkInterfaces::ContextRequestError error, avsCommon::sdkInterfaces::ContextRequestToken token) override
Definition: AlexaInterfaceMessageSender.cpp:438
virtual bool sendStateReportEvent(const std::string &instance, const std::string &correlationToken, const avsCommon::avs::AVSMessageEndpoint &endpoint) override
Definition: AlexaInterfaceMessageSender.cpp:201
ErrorResponseType
The type of error when calling sendErrorResponseEvent().
Definition: AlexaInterfaceMessageSenderInterface.h:34
Definition: AlexaInterfaceMessageSenderInternalInterface.h:28
Definition: CapabilityTag.h:32
static std::shared_ptr< AlexaInterfaceMessageSender > create(std::shared_ptr< avsCommon::sdkInterfaces::ContextManagerInterface > contextManager, std::shared_ptr< avsCommon::sdkInterfaces::MessageSenderInterface > messageSender)
Definition: AlexaInterfaceMessageSender.cpp:147
ContextRequestError
Definition: ContextRequesterInterface.h:40
unsigned int ContextRequestToken
Alias for the token used to identify a context request.
Definition: ContextRequestToken.h:23
~AlexaInterfaceMessageSender()
Definition: AlexaInterfaceMessageSender.cpp:184
AlexaStateChangeCauseType
Definition: AlexaStateChangeCauseType.h:28
void onSendCompleted(avsCommon::sdkInterfaces::MessageRequestObserverInterface::Status status) override
Definition: AlexaInterfaceMessageSender.cpp:458
void onStateChanged(const avsCommon::avs::CapabilityTag &identifier, const avsCommon::avs::CapabilityState &state, const avsCommon::sdkInterfaces::AlexaStateChangeCauseType cause) override
Definition: AlexaInterfaceMessageSender.cpp:406
Definition: CapabilityState.h:31
Definition: AVSMessageEndpoint.h:32
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
static std::shared_ptr< AlexaInterfaceMessageSenderInternalInterface > createAlexaInterfaceMessageSenderInternalInterface(const std::shared_ptr< AlexaInterfaceMessageSender > &messageSender)
Definition: AlexaInterfaceMessageSender.cpp:142
virtual bool sendResponseEvent(const std::string &instance, const std::string &correlationToken, const avsCommon::avs::AVSMessageEndpoint &endpoint, const std::string &jsonPayload="{}") override
Definition: AlexaInterfaceMessageSender.cpp:208
void onExceptionReceived(const std::string &exceptionMessage) override
Definition: AlexaInterfaceMessageSender.cpp:468
static std::shared_ptr< AlexaInterfaceMessageSender > createAlexaInterfaceMessageSender(const std::shared_ptr< avsCommon::sdkInterfaces::ContextManagerInterface > &contextManager, const std::shared_ptr< avsCommon::sdkInterfaces::MessageSenderInterface > &messageSender, const std::shared_ptr< acsdkShutdownManagerInterfaces::ShutdownNotifierInterface > &shutdownNotifier)
Definition: AlexaInterfaceMessageSender.cpp:121
void onContextAvailable(const std::string &endpointId, const avsCommon::avs::AVSContext &endpointContext, avsCommon::sdkInterfaces::ContextRequestToken token) override
Definition: AlexaInterfaceMessageSender.cpp:418
Status
Definition: MessageRequestObserverInterface.h:33
virtual bool sendErrorResponseEvent(const std::string &instance, const std::string &correlationToken, const avsCommon::avs::AVSMessageEndpoint &endpoint, const ErrorResponseType errorType, const std::string &errorMessage="") override
Definition: AlexaInterfaceMessageSender.cpp:226
virtual bool sendDeferredResponseEvent(const std::string &instance, const std::string &correlationToken, const int estimatedDeferralInSeconds=0) override
Definition: AlexaInterfaceMessageSender.cpp:271

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