AlexaClientSDK  1.22.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
MessageRouter.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_ACL_INCLUDE_ACL_TRANSPORT_MESSAGEROUTER_H_
17 #define ALEXA_CLIENT_SDK_ACL_INCLUDE_ACL_TRANSPORT_MESSAGEROUTER_H_
18 
19 #include <memory>
20 #include <mutex>
21 #include <string>
22 #include <vector>
23 
30 
38 
39 namespace alexaClientSDK {
40 namespace acl {
41 
48  : public MessageRouterInterface
51  , public std::enable_shared_from_this<MessageRouter> {
52 public:
54  static const std::chrono::milliseconds DEFAULT_SERVER_SIDE_DISCONNECT_GRACE_PERIOD;
55 
65  static std::shared_ptr<MessageRouterInterface> createMessageRouterInterface(
66  const std::shared_ptr<acsdkShutdownManagerInterfaces::ShutdownNotifierInterface>& shutdownNotifier,
67  const std::shared_ptr<avsCommon::sdkInterfaces::AuthDelegateInterface>& authDelegate,
68  const std::shared_ptr<avsCommon::avs::attachment::AttachmentManagerInterface>& attachmentManager,
69  const std::shared_ptr<TransportFactoryInterface>& transportFactory);
70 
88  std::shared_ptr<avsCommon::sdkInterfaces::AuthDelegateInterface> authDelegate,
89  std::shared_ptr<avsCommon::avs::attachment::AttachmentManagerInterface> attachmentManager,
90  std::shared_ptr<TransportFactoryInterface> transportFactory,
91  const std::string& avsGateway = "",
93  std::chrono::milliseconds serverSideDisconnectGracePeriod = DEFAULT_SERVER_SIDE_DISCONNECT_GRACE_PERIOD);
94 
97  void enable() override;
98  void disable() override;
100  void sendMessage(std::shared_ptr<avsCommon::avs::MessageRequest> request) override;
101  void setAVSGateway(const std::string& avsGateway) override;
102  std::string getAVSGateway() override;
103  void onWakeConnectionRetry() override;
104  void onWakeVerifyConnectivity() override;
105  void setObserver(std::shared_ptr<MessageRouterObserverInterface> observer) override;
107 
108  void onConnected(std::shared_ptr<TransportInterface> transport) override;
109 
110  void onDisconnected(
111  std::shared_ptr<TransportInterface> transport,
113 
114  void onServerSideDisconnect(std::shared_ptr<TransportInterface> transport) override;
115 
116  void consumeMessage(const std::string& contextId, const std::string& message) override;
117 
118  void doShutdown() override;
119 
120 private:
128  void setConnectionStatusLocked(
131 
142  void notifyObserverOnConnectionStatusChanged(
145 
152  void handleNotifyObserverOnConnectionStatusChanged(
155 
166  void notifyObserverOnReceive(const std::string& contextId, const std::string& message);
167 
172  void createActiveTransportLocked();
173 
181  void disconnectAllTransportsLocked(
182  std::unique_lock<std::mutex>& lock,
184 
190  std::shared_ptr<MessageRouterObserverInterface> getObserver();
191 
197  void safelyResetActiveTransportLocked();
198 
204  void safelyReleaseTransport(std::shared_ptr<TransportInterface> transport);
205 
207  std::shared_ptr<MessageRouterObserverInterface> m_observer;
208 
210  std::string m_avsGateway;
211 
213  std::shared_ptr<avsCommon::sdkInterfaces::AuthDelegateInterface> m_authDelegate;
214 
216  std::mutex m_connectionMutex;
217 
220 
223 
225  int m_engineType;
226 
231  bool m_isEnabled;
232 
234  std::vector<std::shared_ptr<TransportInterface>> m_transports;
235 
237  std::shared_ptr<TransportInterface> m_activeTransport;
238 
240  std::shared_ptr<avsCommon::avs::attachment::AttachmentManagerInterface> m_attachmentManager;
241 
243  std::shared_ptr<TransportFactoryInterface> m_transportFactory;
244 
246  std::shared_ptr<SynchronizedMessageRequestQueue> m_requestQueue;
247 
249  avsCommon::utils::timing::Timer m_serverSideDisconnectTimer;
250 
252  bool m_serverSideDisconnectNotificationPending;
253 
256 
258  const std::chrono::milliseconds m_serverSideReconnectGracePeriod;
259 
260 protected:
267 };
268 
269 } // namespace acl
270 } // namespace alexaClientSDK
271 
272 #endif // ALEXA_CLIENT_SDK_ACL_INCLUDE_ACL_TRANSPORT_MESSAGEROUTER_H_
Timer.h
alexaClientSDK::acl::MessageRouter::MessageRouter
MessageRouter(std::shared_ptr< avsCommon::sdkInterfaces::AuthDelegateInterface > authDelegate, std::shared_ptr< avsCommon::avs::attachment::AttachmentManagerInterface > attachmentManager, std::shared_ptr< TransportFactoryInterface > transportFactory, const std::string &avsGateway="", int engineType=avsCommon::sdkInterfaces::ENGINE_TYPE_ALEXA_VOICE_SERVICES, std::chrono::milliseconds serverSideDisconnectGracePeriod=DEFAULT_SERVER_SIDE_DISCONNECT_GRACE_PERIOD)
Definition: MessageRouter.cpp:74
alexaClientSDK::acl::MessageRouter::consumeMessage
void consumeMessage(const std::string &contextId, const std::string &message) override
Definition: MessageRouter.cpp:281
alexaClientSDK::acl::MessageRouter::onWakeVerifyConnectivity
void onWakeVerifyConnectivity() override
Definition: MessageRouter.cpp:193
TransportObserverInterface.h
alexaClientSDK::acl::MessageRouter
Definition: MessageRouter.h:47
alexaClientSDK::acl::MessageRouterInterface
Definition: MessageRouterInterface.h:40
TransportFactoryInterface.h
alexaClientSDK::acl::MessageRouter::setObserver
void setObserver(std::shared_ptr< MessageRouterObserverInterface > observer) override
Definition: MessageRouter.cpp:285
MessageConsumerInterface.h
alexaClientSDK::avsCommon::utils::timing::Timer
Definition: Timer.h:39
MessageRequest.h
alexaClientSDK::avsCommon::sdkInterfaces::ConnectionStatusObserverInterface::ChangedReason
ChangedReason
Definition: ConnectionStatusObserverInterface.h:50
alexaClientSDK::avsCommon::utils::threading::Executor
Definition: Executor.h:40
alexaClientSDK::acl::MessageRouter::enable
void enable() override
Definition: MessageRouter.cpp:101
ShutdownNotifierInterface.h
alexaClientSDK::acl::MessageRouter::doShutdown
void doShutdown() override
Definition: MessageRouter.cpp:122
alexaClientSDK::acl::MessageRouter::createMessageRouterInterface
static std::shared_ptr< MessageRouterInterface > createMessageRouterInterface(const std::shared_ptr< acsdkShutdownManagerInterfaces::ShutdownNotifierInterface > &shutdownNotifier, const std::shared_ptr< avsCommon::sdkInterfaces::AuthDelegateInterface > &authDelegate, const std::shared_ptr< avsCommon::avs::attachment::AttachmentManagerInterface > &attachmentManager, const std::shared_ptr< TransportFactoryInterface > &transportFactory)
Definition: MessageRouter.cpp:48
alexaClientSDK::acl::MessageRouter::onDisconnected
void onDisconnected(std::shared_ptr< TransportInterface > transport, avsCommon::sdkInterfaces::ConnectionStatusObserverInterface::ChangedReason reason) override
Definition: MessageRouter.cpp:225
Executor.h
alexaClientSDK
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
AuthDelegateInterface.h
alexaClientSDK::acl::MessageConsumerInterface
Definition: MessageConsumerInterface.h:27
alexaClientSDK::acl::MessageRouter::sendMessage
void sendMessage(std::shared_ptr< avsCommon::avs::MessageRequest > request) override
Definition: MessageRouter.cpp:148
alexaClientSDK::acl::MessageRouter::DEFAULT_SERVER_SIDE_DISCONNECT_GRACE_PERIOD
static const std::chrono::milliseconds DEFAULT_SERVER_SIDE_DISCONNECT_GRACE_PERIOD
Amount of time to allow for an automatic reconnect before notifying of a server side disconnect.
Definition: MessageRouter.h:54
alexaClientSDK::avsCommon::sdkInterfaces::ENGINE_TYPE_ALEXA_VOICE_SERVICES
static const int ENGINE_TYPE_ALEXA_VOICE_SERVICES
Definition: ConnectionStatusObserverInterface.h:26
alexaClientSDK::acl::MessageRouter::getConnectionStatus
ConnectionStatus getConnectionStatus() override
Definition: MessageRouter.cpp:96
alexaClientSDK::avsCommon::sdkInterfaces::ConnectionStatusObserverInterface::Status
Status
Definition: ConnectionStatusObserverInterface.h:36
SynchronizedMessageRequestQueue.h
alexaClientSDK::acl::MessageRouter::m_executor
avsCommon::utils::threading::Executor m_executor
Definition: MessageRouter.h:266
MessageRouterInterface.h
alexaClientSDK::acl::MessageRouter::disable
void disable() override
Definition: MessageRouter.cpp:141
alexaClientSDK::acl::TransportObserverInterface
Definition: TransportObserverInterface.h:30
alexaClientSDK::acl::MessageRouterInterface::ConnectionStatus
std::pair< avsCommon::sdkInterfaces::ConnectionStatusObserverInterface::Status, avsCommon::sdkInterfaces::ConnectionStatusObserverInterface::ChangedReason > ConnectionStatus
Alias to a connection status and changed reason pair.
Definition: MessageRouterInterface.h:47
alexaClientSDK::acl::MessageRouter::onWakeConnectionRetry
void onWakeConnectionRetry() override
Definition: MessageRouter.cpp:184
alexaClientSDK::acl::MessageRouter::onServerSideDisconnect
void onServerSideDisconnect(std::shared_ptr< TransportInterface > transport) override
Definition: MessageRouter.cpp:265
alexaClientSDK::acl::MessageRouter::setAVSGateway
void setAVSGateway(const std::string &avsGateway) override
Definition: MessageRouter.cpp:163
alexaClientSDK::acl::MessageRouter::getAVSGateway
std::string getAVSGateway() override
Definition: MessageRouter.cpp:179
alexaClientSDK::acl::MessageRouter::onConnected
void onConnected(std::shared_ptr< TransportInterface > transport) override
Definition: MessageRouter.cpp:202
AttachmentManagerInterface.h
MessageRouterObserverInterface.h
TransportInterface.h

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