AlexaClientSDK  1.25.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 
56  std::string name;
57 
59  std::shared_ptr<avsCommon::avs::attachment::AttachmentReader> reader;
60  };
61 
70  std::function<bool(const std::shared_ptr<EditableMessageRequest>& req, const std::string& resolveKey)>;
71 
84  const std::string& jsonContent,
85  const std::string& uriPathExtension = "",
86  const unsigned int threshold = 0,
87  const std::string& streamMetricName = "");
88 
96  MessageRequest(const std::string& jsonContent, const unsigned int threshold, const std::string& streamMetricName);
97 
117  const std::string& jsonContent,
118  bool isSerialized,
119  const std::string& uriPathExtension = "",
120  std::vector<std::pair<std::string, std::string>> headers = {},
121  MessageRequestResolveFunction resolver = nullptr,
122  const unsigned int threshold = 0,
123  const std::string& streamMetricName = "");
124 
130  MessageRequest(const MessageRequest& messageRequest);
131 
135  virtual ~MessageRequest();
136 
146  void addAttachmentReader(const std::string& name, std::shared_ptr<attachment::AttachmentReader> attachmentReader);
147 
153  std::string getJsonContent() const;
154 
160  bool getIsSerialized() const;
161 
167  std::string getUriPathExtension() const;
168 
174  int attachmentReadersCount() const;
175 
183  std::shared_ptr<NamedReader> getAttachmentReader(size_t index) const;
184 
191 
197 
203  virtual void exceptionReceived(const std::string& exceptionMessage);
204 
210  void addObserver(std::shared_ptr<avsCommon::sdkInterfaces::MessageRequestObserverInterface> observer);
211 
217  void removeObserver(std::shared_ptr<avsCommon::sdkInterfaces::MessageRequestObserverInterface> observer);
218 
224  const std::vector<std::pair<std::string, std::string>>& getHeaders() const;
225 
230  bool isResolved() const;
231 
237  std::shared_ptr<MessageRequest> resolveRequest(const std::string& resolveKey) const;
238 
243  unsigned int getStreamBytesThreshold() const;
244 
249  std::string getStreamMetricName() const;
250 
251 protected:
253  std::mutex m_observerMutex;
254 
256  std::unordered_set<std::shared_ptr<avsCommon::sdkInterfaces::MessageRequestObserverInterface>> m_observers;
257 
259  std::string m_jsonContent;
260 
263 
265  std::string m_uriPathExtension;
266 
268  std::vector<std::shared_ptr<NamedReader>> m_readers;
269 
271  std::vector<std::pair<std::string, std::string>> m_headers;
272 
275 
277  std::string m_streamMetricName;
278 
281 };
282 
283 } // namespace avs
284 } // namespace avsCommon
285 } // namespace alexaClientSDK
286 
287 #endif // ALEXA_CLIENT_SDK_AVSCOMMON_AVS_INCLUDE_AVSCOMMON_AVS_MESSAGEREQUEST_H_
virtual void sendCompleted(avsCommon::sdkInterfaces::MessageRequestObserverInterface::Status status)
Definition: MessageRequest.cpp:141
A struct to hold an AttachmentReader alongside its name.
Definition: MessageRequest.h:43
int attachmentReadersCount() const
Definition: MessageRequest.cpp:112
MessageRequestResolveFunction m_resolver
Resolver function to resolve current message request to a valid state. Null if message is already res...
Definition: MessageRequest.h:274
bool m_isSerialized
True if sending this message must be serialized with sending other serialized messages.
Definition: MessageRequest.h:262
Definition: MessageRequest.h:40
virtual ~MessageRequest()
Definition: MessageRequest.cpp:85
bool getIsSerialized() const
Definition: MessageRequest.cpp:104
std::vector< std::shared_ptr< NamedReader > > m_readers
The AttachmentReaders of the Attachments data to be sent to AVS.
Definition: MessageRequest.h:268
void addAttachmentReader(const std::string &name, std::shared_ptr< attachment::AttachmentReader > attachmentReader)
Definition: MessageRequest.cpp:88
unsigned int getStreamBytesThreshold() const
Definition: MessageRequest.cpp:118
const std::vector< std::pair< std::string, std::string > > & getHeaders() const
Definition: MessageRequest.cpp:183
std::shared_ptr< MessageRequest > resolveRequest(const std::string &resolveKey) const
Definition: MessageRequest.cpp:191
MessageRequest(const std::string &jsonContent, const std::string &uriPathExtension="", const unsigned int threshold=0, const std::string &streamMetricName="")
Definition: MessageRequest.cpp:36
std::shared_ptr< NamedReader > getAttachmentReader(size_t index) const
Definition: MessageRequest.cpp:122
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:271
void addObserver(std::shared_ptr< avsCommon::sdkInterfaces::MessageRequestObserverInterface > observer)
Definition: MessageRequest.cpp:162
unsigned int m_streamBytesThreshold
The threshold for the number of bytes for when we should record the stream metric.
Definition: MessageRequest.h:280
virtual void exceptionReceived(const std::string &exceptionMessage)
Definition: MessageRequest.cpp:150
std::unordered_set< std::shared_ptr< avsCommon::sdkInterfaces::MessageRequestObserverInterface > > m_observers
Set of observers of MessageRequestObserverInterface.
Definition: MessageRequest.h:256
virtual void responseStatusReceived(avsCommon::sdkInterfaces::MessageRequestObserverInterface::Status status)
Definition: MessageRequest.cpp:131
std::mutex m_observerMutex
Mutex to guard access of m_observers.
Definition: MessageRequest.h:253
std::string m_uriPathExtension
The path extension to be appended to the base URL when sending.
Definition: MessageRequest.h:265
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
std::string getUriPathExtension() const
Definition: MessageRequest.cpp:108
std::function< bool(const std::shared_ptr< EditableMessageRequest > &req, const std::string &resolveKey)> MessageRequestResolveFunction
Definition: MessageRequest.h:70
NamedReader(const std::string &name, std::shared_ptr< avsCommon::avs::attachment::AttachmentReader > reader)
Definition: MessageRequest.h:50
std::string getJsonContent() const
Definition: MessageRequest.cpp:100
Status
Definition: MessageRequestObserverInterface.h:33
std::string m_streamMetricName
The name for the stream byte metric.
Definition: MessageRequest.h:277
void removeObserver(std::shared_ptr< avsCommon::sdkInterfaces::MessageRequestObserverInterface > observer)
Definition: MessageRequest.cpp:172
std::string getStreamMetricName() const
Definition: MessageRequest.cpp:115
bool isResolved() const
Definition: MessageRequest.cpp:187
std::string m_jsonContent
The JSON content to be sent to AVS.
Definition: MessageRequest.h:259

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