AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
alexaClientSDK::acl::MessageRouter Class Reference

#include <MessageRouter.h>

Inheritance diagram for alexaClientSDK::acl::MessageRouter:
Inheritance graph
[legend]
Collaboration diagram for alexaClientSDK::acl::MessageRouter:
Collaboration graph
[legend]

Public Member Functions

 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)
 
void onConnected (std::shared_ptr< TransportInterface > transport) override
 
void onDisconnected (std::shared_ptr< TransportInterface > transport, avsCommon::sdkInterfaces::ConnectionStatusObserverInterface::ChangedReason reason) override
 
void onServerSideDisconnect (std::shared_ptr< TransportInterface > transport) override
 
void consumeMessage (const std::string &contextId, const std::string &message) override
 
void doShutdown () override
 
MessageRouterInterface methods.
void enable () override
 
void disable () override
 
ConnectionStatus getConnectionStatus () override
 
void sendMessage (std::shared_ptr< avsCommon::avs::MessageRequest > request) override
 
void setAVSGateway (const std::string &avsGateway) override
 
std::string getAVSGateway () override
 
void onWakeConnectionRetry () override
 
void onWakeVerifyConnectivity () override
 
void setObserver (std::shared_ptr< MessageRouterObserverInterface > observer) override
 
- Public Member Functions inherited from alexaClientSDK::acl::MessageRouterInterface
 MessageRouterInterface (const std::string &name)
 
virtual ~MessageRouterInterface ()=default
 
- Public Member Functions inherited from alexaClientSDK::avsCommon::sdkInterfaces::MessageSenderInterface
virtual ~MessageSenderInterface ()=default
 Destructor. More...
 
virtual void sendMessage (std::shared_ptr< avs::MessageRequest > request)=0
 
- Public Member Functions inherited from alexaClientSDK::avsCommon::utils::RequiresShutdown
 RequiresShutdown (const std::string &name)
 
virtual ~RequiresShutdown ()
 Destructor. More...
 
const std::string & name () const
 
void shutdown ()
 
bool isShutdown () const
 
- Public Member Functions inherited from alexaClientSDK::acl::TransportObserverInterface
virtual ~TransportObserverInterface ()=default
 
- Public Member Functions inherited from alexaClientSDK::acl::MessageConsumerInterface
virtual ~MessageConsumerInterface ()=default
 

Static Public Member Functions

static std::shared_ptr< MessageRouterInterfacecreateMessageRouterInterface (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)
 

Static Public Attributes

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. More...
 

Protected Attributes

avsCommon::utils::threading::Executor m_executor
 

Additional Inherited Members

- Public Types inherited from alexaClientSDK::acl::MessageRouterInterface
using ConnectionStatus = std::pair< avsCommon::sdkInterfaces::ConnectionStatusObserverInterface::Status, avsCommon::sdkInterfaces::ConnectionStatusObserverInterface::ChangedReason >
 Alias to a connection status and changed reason pair. More...
 

Detailed Description

This an abstract base class which specifies the interface to manage an actual connection over some medium to AVS.

Implementations of this class are required to be thread-safe.

Constructor & Destructor Documentation

◆ MessageRouter()

alexaClientSDK::acl::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 
)

Constructor.

Deprecated:
Parameters
authDelegateAn implementation of an AuthDelegate, which will provide valid access tokens with which the MessageRouter can authorize the client to AVS.
attachmentManagerThe AttachmentManager, which allows ACL to write attachments received from AVS.
transportFactoryFactory used to create new transport objects.
avsGatewayThe gateway to connect to AVS. The value will be set by the AVSGatewayManager based on either the previously verified gateway or a value from the config file. If both are not present, a default value is used.
engineTypeoptional parameter of engine type associated with this MessageRouter. Default to be ENGINE_TYPE_ALEXA_VOICE_SERVICES.
serverSideDisconnectGracePeriodHow long to allow for an automatic reconnection before reporting a server side disconnect to our observer.

Member Function Documentation

◆ consumeMessage()

void alexaClientSDK::acl::MessageRouter::consumeMessage ( const std::string &  contextId,
const std::string &  message 
)
overridevirtual

Called when a message has been received from AVS.

Parameters
contextIdThe context id for the current message.
messageThe AVS message in string representation.

Implements alexaClientSDK::acl::MessageConsumerInterface.

◆ createMessageRouterInterface()

static std::shared_ptr<MessageRouterInterface> alexaClientSDK::acl::MessageRouter::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 
)
static

Factory function for creating an instance of MessageRouterInterface.

Parameters
shutdownNotifierThe object with which to register to be told when to shut down.
authDelegateAn implementation of an AuthDelegate, which will provide valid access tokens with which the MessageRouter can authorize the client to AVS.
attachmentManagerThe AttachmentManager, which allows ACL to write attachments received from AVS.
transportFactoryFactory used to create new transport objects.

◆ disable()

void alexaClientSDK::acl::MessageRouter::disable ( )
overridevirtual

Close the AVS connection. If the underlying implementation is not connected, or is in the process of changing its connection state, this function should do nothing.

Implements alexaClientSDK::acl::MessageRouterInterface.

◆ doShutdown()

void alexaClientSDK::acl::MessageRouter::doShutdown ( )
overridevirtual

Prepares/enables this object to be deleted. This should be the last function called on this object prior to deleting (or resetting) its shared_ptr.

Warning
  • Attempting to call functions on this object after calling shutdown() can result in undefined behavior.
  • Neglecting to call shutdown() on this object can result in resource leaks or other undefined behavior.

Implements alexaClientSDK::avsCommon::utils::RequiresShutdown.

◆ enable()

void alexaClientSDK::acl::MessageRouter::enable ( )
overridevirtual

Begin the process of establishing an AVS connection. If the underlying implementation is already connected, or is in the process of changing its connection state, this function should do nothing.

Implements alexaClientSDK::acl::MessageRouterInterface.

◆ getAVSGateway()

std::string alexaClientSDK::acl::MessageRouter::getAVSGateway ( )
overridevirtual

Get the gateway URL for the AVS connection.

Returns
The URL for the current AVS gateway.

Implements alexaClientSDK::acl::MessageRouterInterface.

◆ getConnectionStatus()

ConnectionStatus alexaClientSDK::acl::MessageRouter::getConnectionStatus ( )
overridevirtual

Queries the status of the connection.

Returns
Returns the connection status and changed reason pair of the underlying implementation.

Implements alexaClientSDK::acl::MessageRouterInterface.

◆ onConnected()

void alexaClientSDK::acl::MessageRouter::onConnected ( std::shared_ptr< TransportInterface transport)
overridevirtual

Called when a connection to AVS is established.

Parameters
transportThe transport that has connected.

Implements alexaClientSDK::acl::TransportObserverInterface.

◆ onDisconnected()

void alexaClientSDK::acl::MessageRouter::onDisconnected ( std::shared_ptr< TransportInterface transport,
avsCommon::sdkInterfaces::ConnectionStatusObserverInterface::ChangedReason  reason 
)
overridevirtual

Called when we disconnect from AVS.

Parameters
transportThe transport that is no longer connected (or attempting to connect).
reasonThe reason that we disconnected.

Implements alexaClientSDK::acl::TransportObserverInterface.

◆ onServerSideDisconnect()

void alexaClientSDK::acl::MessageRouter::onServerSideDisconnect ( std::shared_ptr< TransportInterface transport)
overridevirtual

Called when the server asks the client to reconnect

Parameters
transportThe transport that has received the disconnect request.

Implements alexaClientSDK::acl::TransportObserverInterface.

◆ onWakeConnectionRetry()

void alexaClientSDK::acl::MessageRouter::onWakeConnectionRetry ( )
overridevirtual

This method is a hint to retry connecting (if not connected).

Implements alexaClientSDK::acl::MessageRouterInterface.

◆ onWakeVerifyConnectivity()

void alexaClientSDK::acl::MessageRouter::onWakeVerifyConnectivity ( )
overridevirtual

This method is a hint to verify that there is a valid connection to AVS.

Implements alexaClientSDK::acl::MessageRouterInterface.

◆ sendMessage()

void alexaClientSDK::acl::MessageRouter::sendMessage ( std::shared_ptr< avsCommon::avs::MessageRequest request)
override

◆ setAVSGateway()

void alexaClientSDK::acl::MessageRouter::setAVSGateway ( const std::string &  avsGateway)
overridevirtual

Set the gateway URL for the AVS connection. Calling this function with a new value will cause the current active connection to be closed, and a new one opened to the new gateway.

Parameters
avsGatewayThe URL for the new AVS gateway.

Implements alexaClientSDK::acl::MessageRouterInterface.

◆ setObserver()

void alexaClientSDK::acl::MessageRouter::setObserver ( std::shared_ptr< MessageRouterObserverInterface observer)
overridevirtual

Set the observer to this object.

Parameters
observerAn observer to this class, which will be notified when the connection status changes, and when messages arrive from AVS.

Implements alexaClientSDK::acl::MessageRouterInterface.

Member Data Documentation

◆ DEFAULT_SERVER_SIDE_DISCONNECT_GRACE_PERIOD

const std::chrono::milliseconds alexaClientSDK::acl::MessageRouter::DEFAULT_SERVER_SIDE_DISCONNECT_GRACE_PERIOD
static

Amount of time to allow for an automatic reconnect before notifying of a server side disconnect.

◆ m_executor

avsCommon::utils::threading::Executor alexaClientSDK::acl::MessageRouter::m_executor
protected

Executor to perform asynchronous operations:

  • Delivery of connection status notifications.
  • completion of send operations delayed by a pending connection state.

The documentation for this class was generated from the following file:

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