AlexaClientSDK  1.23.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Classes | Public Types | Public Member Functions | Protected Attributes | List of all members
alexaClientSDK::avsCommon::avs::MessageRequest Class Reference

#include <MessageRequest.h>

Inheritance diagram for alexaClientSDK::avsCommon::avs::MessageRequest:
Inheritance graph
[legend]

Classes

struct  NamedReader
 A struct to hold an AttachmentReader alongside its name. More...
 

Public Types

using MessageRequestResolveFunction = std::function< bool(const std::shared_ptr< EditableMessageRequest > &req, const std::string &resolveKey)>
 

Public Member Functions

 MessageRequest (const std::string &jsonContent, const std::string &uriPathExtension="")
 
 MessageRequest (const std::string &jsonContent, bool isSerialized, const std::string &uriPathExtension="", std::vector< std::pair< std::string, std::string >> headers={}, MessageRequestResolveFunction resolver=nullptr)
 
 MessageRequest (const MessageRequest &messageRequest)
 
virtual ~MessageRequest ()
 
void addAttachmentReader (const std::string &name, std::shared_ptr< attachment::AttachmentReader > attachmentReader)
 
std::string getJsonContent () const
 
bool getIsSerialized () const
 
std::string getUriPathExtension () const
 
int attachmentReadersCount () const
 
std::shared_ptr< NamedReadergetAttachmentReader (size_t index) const
 
virtual void responseStatusReceived (avsCommon::sdkInterfaces::MessageRequestObserverInterface::Status status)
 
virtual void sendCompleted (avsCommon::sdkInterfaces::MessageRequestObserverInterface::Status status)
 
virtual void exceptionReceived (const std::string &exceptionMessage)
 
void addObserver (std::shared_ptr< avsCommon::sdkInterfaces::MessageRequestObserverInterface > observer)
 
void removeObserver (std::shared_ptr< avsCommon::sdkInterfaces::MessageRequestObserverInterface > observer)
 
const std::vector< std::pair< std::string, std::string > > & getHeaders () const
 
bool isResolved () const
 
std::shared_ptr< MessageRequestresolveRequest (const std::string &resolveKey) const
 

Protected Attributes

std::mutex m_observerMutex
 Mutex to guard access of m_observers. More...
 
std::unordered_set< std::shared_ptr< avsCommon::sdkInterfaces::MessageRequestObserverInterface > > m_observers
 Set of observers of MessageRequestObserverInterface. More...
 
std::string m_jsonContent
 The JSON content to be sent to AVS. More...
 
bool m_isSerialized
 True if sending this message must be serialized with sending other serialized messages. More...
 
std::string m_uriPathExtension
 The path extension to be appended to the base URL when sending. More...
 
std::vector< std::shared_ptr< NamedReader > > m_readers
 The AttachmentReaders of the Attachments data to be sent to AVS. More...
 
std::vector< std::pair< std::string, std::string > > m_headers
 Optional headers to send with this request to AVS. More...
 
MessageRequestResolveFunction m_resolver
 Resolver function to resolve current message request to a valid state. Null if message is already resolved. More...
 

Detailed Description

This is a wrapper class which allows a client to send a Message to AVS, and be notified when the attempt to send the Message was completed.

Member Typedef Documentation

◆ MessageRequestResolveFunction

using alexaClientSDK::avsCommon::avs::MessageRequest::MessageRequestResolveFunction = std::function<bool(const std::shared_ptr<EditableMessageRequest>& req, const std::string& resolveKey)>

Function to resolve an editable message request based on the provided resolveKey by updating the MessageRequest.

Parameters
[in,out]reqTarget editable request message that will be modified in place.
resolveKeyKey used to resolve the message request
Returns
true if resolving successfully, else @ false
Note
This function need to be thread-safe, and is allowed to block.

Constructor & Destructor Documentation

◆ MessageRequest() [1/3]

alexaClientSDK::avsCommon::avs::MessageRequest::MessageRequest ( const std::string &  jsonContent,
const std::string &  uriPathExtension = "" 
)

Constructor.

Parameters
jsonContentThe message to be sent to AVS.
uriPathExtensionAn optional uri path extension which will be appended to the base url of the AVS. endpoint. If not specified, the default AVS path extension should be used by the sender implementation.

◆ MessageRequest() [2/3]

alexaClientSDK::avsCommon::avs::MessageRequest::MessageRequest ( const std::string &  jsonContent,
bool  isSerialized,
const std::string &  uriPathExtension = "",
std::vector< std::pair< std::string, std::string >>  headers = {},
MessageRequestResolveFunction  resolver = nullptr 
)

Constructor.

Parameters
jsonContentThe message to be sent to AVS.
isSerializedTrue if sending this message must be serialized with sending other serialized messages.
uriPathExtensionAn optional uri path extension which will be appended to the base url of the AVS.
headerskey/value pairs of extra HTTP headers to use with this request. endpoint. If not specified, the default AVS path extension should be used by the sender implementation.
resolverFunction to resolve message. Null if message doesn't need resolving. Resolving function aims to support the use case that one message request will be sent to multiple places with some fields having different values for different destinations. In such use cases, MessageRequest works as a container with all required info to build different versions of requests. The resolving function contains the logic to build the target message request based on the info in the original request, and provided resolveKey.

◆ MessageRequest() [3/3]

alexaClientSDK::avsCommon::avs::MessageRequest::MessageRequest ( const MessageRequest messageRequest)

Constructor to construct a MessageRequest which contains a copy of the data in MessageRequest.

Parameters
messageRequestMessageRequest to copy from
Note
Observers are not considered data and don't get copied by this constructor.

◆ ~MessageRequest()

alexaClientSDK::avsCommon::avs::MessageRequest::~MessageRequest ( )
virtual

Destructor.

Member Function Documentation

◆ addAttachmentReader()

void alexaClientSDK::avsCommon::avs::MessageRequest::addAttachmentReader ( const std::string &  name,
std::shared_ptr< attachment::AttachmentReader attachmentReader 
)

Adds an attachment reader to the message. The attachment data will be the next part in the message to be sent to AVS.

Note
: The order by which the message attachments sent to AVS is the one by which they have been added to it.
Parameters
nameThe name of the message part containing the attachment data.
attachmentReaderThe attachment data to be sent to AVS along with the message.

◆ addObserver()

void alexaClientSDK::avsCommon::avs::MessageRequest::addObserver ( std::shared_ptr< avsCommon::sdkInterfaces::MessageRequestObserverInterface observer)

Add observer of MessageRequestObserverInterface.

Parameters
observerThe observer to be added to the set.

◆ attachmentReadersCount()

int alexaClientSDK::avsCommon::avs::MessageRequest::attachmentReadersCount ( ) const

Gets the number of AttachmentReaders in this message.

Returns
The number of readers in this message.

◆ exceptionReceived()

void alexaClientSDK::avsCommon::avs::MessageRequest::exceptionReceived ( const std::string &  exceptionMessage)
virtual

This function will be called if AVS responds with an exception message to this message request being sent.

Parameters
exceptionMessageThe exception message.

Reimplemented in alexaClientSDK::integration::ObservableMessageRequest.

◆ getAttachmentReader()

std::shared_ptr< MessageRequest::NamedReader > alexaClientSDK::avsCommon::avs::MessageRequest::getAttachmentReader ( size_t  index) const

Retrieves the ith AttachmentReader in the message.

Parameters
indexThe index of the AttachmentReader to retrieve.
Returns
NamedReader of the ith attachment in the message. A null pointer is returned when index is out of bound.

◆ getHeaders()

const std::vector< std::pair< std::string, std::string > > & alexaClientSDK::avsCommon::avs::MessageRequest::getHeaders ( ) const

Get additional HTTP headers for this request

Returns
key/value pairs of extra HTTP headers to use with this request.

◆ getIsSerialized()

bool alexaClientSDK::avsCommon::avs::MessageRequest::getIsSerialized ( ) const

Return true if sending this message must be serialized with sending other serialized messages.

Returns
True if sending this message must be serialized with sending other serialized messages.

◆ getJsonContent()

std::string alexaClientSDK::avsCommon::avs::MessageRequest::getJsonContent ( ) const

Retrieves the JSON content to be sent to AVS.

Returns
The JSON content to be sent to AVS.

◆ getUriPathExtension()

std::string alexaClientSDK::avsCommon::avs::MessageRequest::getUriPathExtension ( ) const

Retrieves the path extension to be appended to the base URL when sending.

Returns
The path extension to be appended to the base URL when sending.

◆ isResolved()

bool alexaClientSDK::avsCommon::avs::MessageRequest::isResolved ( ) const

Check whether message is resolved and ready to send.

Returns
true if message is already resolved, else false

◆ removeObserver()

void alexaClientSDK::avsCommon::avs::MessageRequest::removeObserver ( std::shared_ptr< avsCommon::sdkInterfaces::MessageRequestObserverInterface observer)

Remove observer of MessageRequestObserverInterface.

Parameters
observerThe observer to be removed from the set.

◆ resolveRequest()

std::shared_ptr< MessageRequest > alexaClientSDK::avsCommon::avs::MessageRequest::resolveRequest ( const std::string &  resolveKey) const

Resolve message to a valid message by updating the content of the message based on provided resolveKey

Parameters
resolveKeyKey used to resolve message
Returns
New resolved MessageRequest

◆ responseStatusReceived()

void alexaClientSDK::avsCommon::avs::MessageRequest::responseStatusReceived ( avsCommon::sdkInterfaces::MessageRequestObserverInterface::Status  status)
virtual

Called when the Response code is received.

Parameters
statusThe status of the response that was received.

◆ sendCompleted()

void alexaClientSDK::avsCommon::avs::MessageRequest::sendCompleted ( avsCommon::sdkInterfaces::MessageRequestObserverInterface::Status  status)
virtual

This is called once the send request has completed. The status parameter indicates success or failure.

Parameters
statusWhether the send request succeeded or failed.

Reimplemented in alexaClientSDK::capabilityAgents::playbackController::PlaybackMessageRequest, alexaClientSDK::capabilityAgents::doNotDisturb::DNDMessageRequest, alexaClientSDK::avsCommon::avs::WaitableMessageRequest, and alexaClientSDK::integration::ObservableMessageRequest.

Member Data Documentation

◆ m_headers

std::vector<std::pair<std::string, std::string> > alexaClientSDK::avsCommon::avs::MessageRequest::m_headers
protected

Optional headers to send with this request to AVS.

◆ m_isSerialized

bool alexaClientSDK::avsCommon::avs::MessageRequest::m_isSerialized
protected

True if sending this message must be serialized with sending other serialized messages.

◆ m_jsonContent

std::string alexaClientSDK::avsCommon::avs::MessageRequest::m_jsonContent
protected

The JSON content to be sent to AVS.

◆ m_observerMutex

std::mutex alexaClientSDK::avsCommon::avs::MessageRequest::m_observerMutex
protected

Mutex to guard access of m_observers.

◆ m_observers

std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::MessageRequestObserverInterface> > alexaClientSDK::avsCommon::avs::MessageRequest::m_observers
protected

Set of observers of MessageRequestObserverInterface.

◆ m_readers

std::vector<std::shared_ptr<NamedReader> > alexaClientSDK::avsCommon::avs::MessageRequest::m_readers
protected

The AttachmentReaders of the Attachments data to be sent to AVS.

◆ m_resolver

MessageRequestResolveFunction alexaClientSDK::avsCommon::avs::MessageRequest::m_resolver
protected

Resolver function to resolve current message request to a valid state. Null if message is already resolved.

◆ m_uriPathExtension

std::string alexaClientSDK::avsCommon::avs::MessageRequest::m_uriPathExtension
protected

The path extension to be appended to the base URL when sending.


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

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