AlexaClientSDK
3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
|
#include <MessageRequest.h>
Classes | |
struct | EventHeaders |
A struct to hold event namespace and name. More... | |
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="", const unsigned int threshold=0, const std::string &streamMetricName="") | |
MessageRequest (const std::string &jsonContent, const unsigned int threshold, const std::string &streamMetricName) | |
MessageRequest (const std::string &jsonContent, bool isSerialized, const std::string &uriPathExtension="", std::vector< std::pair< std::string, std::string >> headers={}, MessageRequestResolveFunction resolver=nullptr, const unsigned int threshold=0, const std::string &streamMetricName="") | |
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< NamedReader > | getAttachmentReader (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) |
EventHeaders | retrieveEventHeaders () const |
const std::vector< std::pair< std::string, std::string > > & | getHeaders () const |
bool | isResolved () const |
std::shared_ptr< MessageRequest > | resolveRequest (const std::string &resolveKey) const |
unsigned int | getStreamBytesThreshold () const |
std::string | getStreamMetricName () 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... | |
std::string | m_streamMetricName |
The name for the stream byte metric. More... | |
unsigned int | m_streamBytesThreshold |
The threshold for the number of bytes for when we should record the stream metric. More... | |
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.
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.
[in,out] | req | Target editable request message that will be modified in place. |
resolveKey | Key used to resolve the message request |
true
if resolving successfully, else @ false alexaClientSDK::avsCommon::avs::MessageRequest::MessageRequest | ( | const std::string & | jsonContent, |
const std::string & | uriPathExtension = "" , |
||
const unsigned int | threshold = 0 , |
||
const std::string & | streamMetricName = "" |
||
) |
Constructor.
jsonContent | The message to be sent to AVS. |
uriPathExtension | An 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. |
threshold. | An optional threshold to ACL to send the metric specified by streamMetricName. If this isn't specified no metric will be recorded. |
streamMetricName. | An optional metric name for ACL to submit when the threshold is met. If this isn't specified no metric will be recorded. |
alexaClientSDK::avsCommon::avs::MessageRequest::MessageRequest | ( | const std::string & | jsonContent, |
const unsigned int | threshold, | ||
const std::string & | streamMetricName | ||
) |
Constructor.
jsonContent | The message to be sent to AVS. |
threshold. | A required threshold to ACL to send the metric specified by streamMetricName. |
streamMetricName. | A required metric name for ACL to submit when the threshold is met. |
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 , |
||
const unsigned int | threshold = 0 , |
||
const std::string & | streamMetricName = "" |
||
) |
Constructor.
jsonContent | The message to be sent to AVS. |
isSerialized | True if sending this message must be serialized with sending other serialized messages. |
uriPathExtension | An optional uri path extension which will be appended to the base url of the AVS. |
headers | key/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. |
resolver | Function 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. |
threshold. | An optional threshold to ACL to send the metric specified by streamMetricName. If this isn't specified no metric will be recorded. |
streamMetricName. | An optional metric name for ACL to submit when the threshold is met. If this isn't specified no metric will be recorded. |
alexaClientSDK::avsCommon::avs::MessageRequest::MessageRequest | ( | const MessageRequest & | messageRequest | ) |
Constructor to construct a MessageRequest which contains a copy of the data in MessageRequest
.
messageRequest | MessageRequest to copy from |
|
virtual |
Destructor.
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.
name | The name of the message part containing the attachment data. |
attachmentReader | The attachment data to be sent to AVS along with the message. |
void alexaClientSDK::avsCommon::avs::MessageRequest::addObserver | ( | std::shared_ptr< avsCommon::sdkInterfaces::MessageRequestObserverInterface > | observer | ) |
Add observer of MessageRequestObserverInterface.
observer | The observer to be added to the set. |
int alexaClientSDK::avsCommon::avs::MessageRequest::attachmentReadersCount | ( | ) | const |
Gets the number of AttachmentReaders
in this message.
|
virtual |
This function will be called if AVS responds with an exception message to this message request being sent.
exceptionMessage | The exception message. |
std::shared_ptr<NamedReader> alexaClientSDK::avsCommon::avs::MessageRequest::getAttachmentReader | ( | size_t | index | ) | const |
Retrieves the ith AttachmentReader in the message.
index | The index of the AttachmentReader to retrieve. |
NamedReader
of the ith attachment in the message. A null pointer is returned when index
is out of bound. const std::vector<std::pair<std::string, std::string> >& alexaClientSDK::avsCommon::avs::MessageRequest::getHeaders | ( | ) | const |
Get additional HTTP headers for this request
bool alexaClientSDK::avsCommon::avs::MessageRequest::getIsSerialized | ( | ) | const |
Return true if sending this message must be serialized with sending other serialized messages.
std::string alexaClientSDK::avsCommon::avs::MessageRequest::getJsonContent | ( | ) | const |
Retrieves the JSON content to be sent to AVS.
unsigned int alexaClientSDK::avsCommon::avs::MessageRequest::getStreamBytesThreshold | ( | ) | const |
Get the stream bytes threshold, to determine when we should record the stream metric.
std::string alexaClientSDK::avsCommon::avs::MessageRequest::getStreamMetricName | ( | ) | const |
Get the name for the bytes stream metric.
std::string alexaClientSDK::avsCommon::avs::MessageRequest::getUriPathExtension | ( | ) | const |
Retrieves the path extension to be appended to the base URL when sending.
bool alexaClientSDK::avsCommon::avs::MessageRequest::isResolved | ( | ) | const |
Check whether message is resolved and ready to send.
true
if message is already resolved, else false
void alexaClientSDK::avsCommon::avs::MessageRequest::removeObserver | ( | std::shared_ptr< avsCommon::sdkInterfaces::MessageRequestObserverInterface > | observer | ) |
Remove observer of MessageRequestObserverInterface.
observer | The observer to be removed from the set. |
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
resolveKey | Key used to resolve message |
|
virtual |
Called when the Response code is received.
status | The status of the response that was received. |
EventHeaders alexaClientSDK::avsCommon::avs::MessageRequest::retrieveEventHeaders | ( | ) | const |
Retrieve MessageRequest event headers (namespace and name).
|
virtual |
This is called once the send request has completed. The status parameter indicates success or failure.
status | Whether the send request succeeded or failed. |
Reimplemented in alexaClientSDK::capabilityAgents::playbackController::PlaybackMessageRequest, alexaClientSDK::capabilityAgents::doNotDisturb::DNDMessageRequest, and alexaClientSDK::avsCommon::avs::WaitableMessageRequest.
|
protected |
Optional headers to send with this request to AVS.
|
protected |
True if sending this message must be serialized with sending other serialized messages.
|
protected |
The JSON content to be sent to AVS.
|
protected |
Mutex to guard access of m_observers.
|
protected |
Set of observers of MessageRequestObserverInterface.
|
protected |
The AttachmentReaders of the Attachments data to be sent to AVS.
|
protected |
Resolver function to resolve current message request to a valid state. Null if message is already resolved.
|
protected |
The threshold for the number of bytes for when we should record the stream metric.
|
protected |
The name for the stream byte metric.
|
protected |
The path extension to be appended to the base URL when sending.
AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0