AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
MessageRequest.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_AVSCOMMON_AVS_INCLUDE_AVSCOMMON_AVS_MESSAGEREQUEST_H_
17 #define ALEXA_CLIENT_SDK_AVSCOMMON_AVS_INCLUDE_AVSCOMMON_AVS_MESSAGEREQUEST_H_
18 
19 #include <cstdlib>
20 #include <functional>
21 #include <memory>
22 #include <mutex>
23 #include <string>
24 #include <unordered_set>
25 #include <vector>
26 
29 
30 namespace alexaClientSDK {
31 namespace avsCommon {
32 namespace avs {
33 
34 class EditableMessageRequest;
35 
41 public:
43  struct NamedReader {
50  NamedReader(const std::string& name, std::shared_ptr<avsCommon::avs::attachment::AttachmentReader> reader) :
51  name{name},
52  reader{reader} {
53  }
54 
57 
59  std::shared_ptr<avsCommon::avs::attachment::AttachmentReader> reader;
60  };
61 
63  struct EventHeaders {
70  EventHeaders(const std::string& eventNamespace, const std::string& eventName) :
71  eventNamespace{eventNamespace},
72  eventName{eventName} {
73  }
74 
75  EventHeaders() = default;
76 
79 
82  };
83 
92  std::function<bool(const std::shared_ptr<EditableMessageRequest>& req, const std::string& resolveKey)>;
93 
106  const std::string& jsonContent,
107  const std::string& uriPathExtension = "",
108  const unsigned int threshold = 0,
109  const std::string& streamMetricName = "");
110 
118  MessageRequest(const std::string& jsonContent, const unsigned int threshold, const std::string& streamMetricName);
119 
139  const std::string& jsonContent,
140  bool isSerialized,
141  const std::string& uriPathExtension = "",
142  std::vector<std::pair<std::string, std::string>> headers = {},
143  MessageRequestResolveFunction resolver = nullptr,
144  const unsigned int threshold = 0,
145  const std::string& streamMetricName = "");
146 
152  MessageRequest(const MessageRequest& messageRequest);
153 
157  virtual ~MessageRequest();
158 
168  void addAttachmentReader(const std::string& name, std::shared_ptr<attachment::AttachmentReader> attachmentReader);
169 
175  std::string getJsonContent() const;
176 
182  bool getIsSerialized() const;
183 
190 
196  int attachmentReadersCount() const;
197 
205  std::shared_ptr<NamedReader> getAttachmentReader(size_t index) const;
206 
213 
219 
225  virtual void exceptionReceived(const std::string& exceptionMessage);
226 
232  void addObserver(std::shared_ptr<avsCommon::sdkInterfaces::MessageRequestObserverInterface> observer);
233 
239  void removeObserver(std::shared_ptr<avsCommon::sdkInterfaces::MessageRequestObserverInterface> observer);
240 
247 
253  const std::vector<std::pair<std::string, std::string>>& getHeaders() const;
254 
259  bool isResolved() const;
260 
266  std::shared_ptr<MessageRequest> resolveRequest(const std::string& resolveKey) const;
267 
272  unsigned int getStreamBytesThreshold() const;
273 
279 
280 protected:
282  std::mutex m_observerMutex;
283 
285  std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::MessageRequestObserverInterface>> m_observers;
286 
289 
292 
295 
297  std::vector<std::shared_ptr<NamedReader>> m_readers;
298 
300  std::vector<std::pair<std::string, std::string>> m_headers;
301 
304 
307 
310 };
311 
312 } // namespace avs
313 } // namespace avsCommon
314 } // namespace alexaClientSDK
315 
316 #endif // ALEXA_CLIENT_SDK_AVSCOMMON_AVS_INCLUDE_AVSCOMMON_AVS_MESSAGEREQUEST_H_
A struct to hold an AttachmentReader alongside its name.
Definition: MessageRequest.h:43
MessageRequestResolveFunction m_resolver
Resolver function to resolve current message request to a valid state. Null if message is already res...
Definition: MessageRequest.h:303
bool m_isSerialized
True if sending this message must be serialized with sending other serialized messages.
Definition: MessageRequest.h:291
Definition: MessageRequest.h:40
::std::string string
Definition: gtest-port.h:1097
std::vector< std::shared_ptr< NamedReader > > m_readers
The AttachmentReaders of the Attachments data to be sent to AVS.
Definition: MessageRequest.h:297
EventHeaders(const std::string &eventNamespace, const std::string &eventName)
Definition: MessageRequest.h:70
const std::vector< std::pair< std::string, std::string > > & getHeaders() const
void addAttachmentReader(const std::string &name, std::shared_ptr< attachment::AttachmentReader > attachmentReader)
MessageRequest(const std::string &jsonContent, const std::string &uriPathExtension="", const unsigned int threshold=0, const std::string &streamMetricName="")
static int index
Mock buffer index.
Definition: AndroidSLESMediaQueueTest.cpp:70
std::vector< std::pair< std::string, std::string > > m_headers
Optional headers to send with this request to AVS.
Definition: MessageRequest.h:300
std::string eventNamespace
The event namespace.
Definition: MessageRequest.h:78
void addObserver(std::shared_ptr< avsCommon::sdkInterfaces::MessageRequestObserverInterface > observer)
unsigned int m_streamBytesThreshold
The threshold for the number of bytes for when we should record the stream metric.
Definition: MessageRequest.h:309
std::unordered_set< std::shared_ptr< avsCommon::sdkInterfaces::MessageRequestObserverInterface > > m_observers
Set of observers of MessageRequestObserverInterface.
Definition: MessageRequest.h:285
std::mutex m_observerMutex
Mutex to guard access of m_observers.
Definition: MessageRequest.h:282
std::string m_uriPathExtension
The path extension to be appended to the base URL when sending.
Definition: MessageRequest.h:294
std::string name
The name of this message part.
Definition: MessageRequest.h:56
std::shared_ptr< avsCommon::avs::attachment::AttachmentReader > reader
The AttachmentReader contains the data of this message part.
Definition: MessageRequest.h:59
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
virtual void sendCompleted(avsCommon::sdkInterfaces::MessageRequestObserverInterface::Status status)
virtual void exceptionReceived(const std::string &exceptionMessage)
std::function< bool(const std::shared_ptr< EditableMessageRequest > &req, const std::string &resolveKey)> MessageRequestResolveFunction
Definition: MessageRequest.h:92
NamedReader(const std::string &name, std::shared_ptr< avsCommon::avs::attachment::AttachmentReader > reader)
Definition: MessageRequest.h:50
Status
Definition: MessageRequestObserverInterface.h:33
virtual void responseStatusReceived(avsCommon::sdkInterfaces::MessageRequestObserverInterface::Status status)
std::string m_streamMetricName
The name for the stream byte metric.
Definition: MessageRequest.h:306
void removeObserver(std::shared_ptr< avsCommon::sdkInterfaces::MessageRequestObserverInterface > observer)
std::shared_ptr< MessageRequest > resolveRequest(const std::string &resolveKey) const
std::string m_jsonContent
The JSON content to be sent to AVS.
Definition: MessageRequest.h:288
A struct to hold event namespace and name.
Definition: MessageRequest.h:63
std::string eventName
The event name.
Definition: MessageRequest.h:81
std::shared_ptr< NamedReader > getAttachmentReader(size_t index) const

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