AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
HTTP2RequestConfig.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_UTILS_INCLUDE_AVSCOMMON_UTILS_HTTP2_HTTP2REQUESTCONFIG_H_
17 #define ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_HTTP2_HTTP2REQUESTCONFIG_H_
18 
19 #include <atomic>
20 #include <chrono>
21 #include <cstdint>
22 #include <memory>
23 #include <string>
24 
25 #include "HTTP2RequestType.h"
28 #include "HTTP2RequestType.h"
29 
30 #ifdef ACSDK_EMIT_SENSITIVE_LOGS
31 #define ACSDK_EMIT_CURL_LOGS
32 #endif
33 
34 namespace alexaClientSDK {
35 namespace avsCommon {
36 namespace utils {
37 namespace http2 {
38 
43 public:
51  HTTP2RequestConfig(HTTP2RequestType type, const std::string& url, const std::string& idPrefix);
52 
58  void setConnectionTimeout(std::chrono::milliseconds timeout);
59 
65  void setTransferTimeout(std::chrono::milliseconds timeout);
66 
72  void setActivityTimeout(std::chrono::milliseconds timeout);
73 
81  void setPriority(uint8_t priority);
82 
88  void setRequestSource(std::shared_ptr<HTTP2RequestSourceInterface> source);
89 
95  void setResponseSink(std::shared_ptr<HTTP2ResponseSinkInterface> sink);
96 
101 
107  void setLogicalStreamIdPrefix(std::string logicalStreamIdPrefix);
108 
115 
121  std::string getUrl() const;
122 
128  std::chrono::milliseconds getConnectionTimeout() const;
129 
135  std::chrono::milliseconds getTransferTimeout() const;
136 
142  std::chrono::milliseconds getActivityTimeout() const;
143 
151  uint8_t getPriority() const;
152 
158  std::shared_ptr<HTTP2RequestSourceInterface> getSource() const;
159 
165  std::shared_ptr<HTTP2ResponseSinkInterface> getSink() const;
166 
171  bool isIntermittentTransferExpected() const;
172 
178  std::string getId() const;
179 
180 private:
182  const HTTP2RequestType m_type;
183 
185  const std::string m_url;
186 
188  static const uint8_t DEFAULT_PRIORITY = 16;
189 
192  std::chrono::milliseconds m_connectionTimeout;
193 
196  std::chrono::milliseconds m_transferTimeout;
197 
200  std::chrono::milliseconds m_activityTimeout;
201 
205  uint8_t m_priority;
206 
208  std::shared_ptr<HTTP2RequestSourceInterface> m_source;
209 
211  std::shared_ptr<HTTP2ResponseSinkInterface> m_sink;
212 
215  bool m_isIntermittentTransferExpected;
216 
218 
219  std::string m_id;
220 };
221 
224  const std::string& url,
225  const std::string& idPrefix) :
226  m_type(type),
227  m_url(url),
228  m_connectionTimeout{std::chrono::milliseconds::zero()},
229  m_transferTimeout{std::chrono::milliseconds::zero()},
230  m_activityTimeout{std::chrono::milliseconds::zero()},
231  m_priority{DEFAULT_PRIORITY},
232  m_isIntermittentTransferExpected{false} {
233  static std::atomic<uint64_t> nextId{1};
234  m_id = idPrefix + std::to_string(std::atomic_fetch_add(&nextId, uint64_t{2}));
235 };
236 
237 inline void HTTP2RequestConfig::setConnectionTimeout(std::chrono::milliseconds timeout) {
238  m_connectionTimeout = timeout;
239 }
240 
241 inline void HTTP2RequestConfig::setTransferTimeout(std::chrono::milliseconds timeout) {
242  m_transferTimeout = timeout;
243 }
244 
245 inline void HTTP2RequestConfig::setActivityTimeout(std::chrono::milliseconds timeout) {
246  m_activityTimeout = timeout;
247 }
248 
249 inline void HTTP2RequestConfig::setPriority(uint8_t priority) {
250  m_priority = priority;
251 }
252 
253 inline void HTTP2RequestConfig::setRequestSource(std::shared_ptr<HTTP2RequestSourceInterface> source) {
254  m_source = std::move(source);
255 }
256 
257 inline void HTTP2RequestConfig::setResponseSink(std::shared_ptr<HTTP2ResponseSinkInterface> sink) {
258  m_sink = std::move(sink);
259 }
260 
262  m_isIntermittentTransferExpected = true;
263 }
264 
266  return m_id;
267 }
268 
270  return m_type;
271 }
272 
274  return m_url;
275 };
276 
277 inline std::chrono::milliseconds HTTP2RequestConfig::getConnectionTimeout() const {
278  return m_connectionTimeout;
279 }
280 
281 inline std::chrono::milliseconds HTTP2RequestConfig::getTransferTimeout() const {
282  return m_transferTimeout;
283 }
284 
285 inline std::chrono::milliseconds HTTP2RequestConfig::getActivityTimeout() const {
286  return m_activityTimeout;
287 }
288 
289 inline uint8_t HTTP2RequestConfig::getPriority() const {
290  return m_priority;
291 }
292 
293 inline std::shared_ptr<HTTP2RequestSourceInterface> HTTP2RequestConfig::getSource() const {
294  return m_source;
295 }
296 
297 inline std::shared_ptr<HTTP2ResponseSinkInterface> HTTP2RequestConfig::getSink() const {
298  return m_sink;
299 }
300 
302  return m_isIntermittentTransferExpected;
303 }
304 
305 } // namespace http2
306 } // namespace utils
307 } // namespace avsCommon
308 } // namespace alexaClientSDK
309 
310 #endif // ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_HTTP2_HTTP2REQUESTCONFIG_H_
void setResponseSink(std::shared_ptr< HTTP2ResponseSinkInterface > sink)
Definition: HTTP2RequestConfig.h:257
::std::string string
Definition: gtest-port.h:1097
std::chrono::milliseconds getConnectionTimeout() const
Definition: HTTP2RequestConfig.h:277
void setLogicalStreamIdPrefix(std::string logicalStreamIdPrefix)
HTTP2RequestType getRequestType() const
Definition: HTTP2RequestConfig.h:269
std::string getId() const
Definition: HTTP2RequestConfig.h:265
void setActivityTimeout(std::chrono::milliseconds timeout)
Definition: HTTP2RequestConfig.h:245
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
std::chrono::milliseconds getActivityTimeout() const
Definition: HTTP2RequestConfig.h:285
void setIntermittentTransferExpected()
Definition: HTTP2RequestConfig.h:261
std::string getUrl() const
Definition: HTTP2RequestConfig.h:273
void setTransferTimeout(std::chrono::milliseconds timeout)
Definition: HTTP2RequestConfig.h:241
HTTP2RequestConfig(HTTP2RequestType type, const std::string &url, const std::string &idPrefix)
Definition: HTTP2RequestConfig.h:222
type
Definition: upload.py:443
void setConnectionTimeout(std::chrono::milliseconds timeout)
Definition: HTTP2RequestConfig.h:237
std::chrono::milliseconds getTransferTimeout() const
Definition: HTTP2RequestConfig.h:281
std::shared_ptr< HTTP2ResponseSinkInterface > getSink() const
Definition: HTTP2RequestConfig.h:297
void setPriority(uint8_t priority)
Definition: HTTP2RequestConfig.h:249
uint8_t getPriority() const
Definition: HTTP2RequestConfig.h:289
void setRequestSource(std::shared_ptr< HTTP2RequestSourceInterface > source)
Definition: HTTP2RequestConfig.h:253
std::shared_ptr< HTTP2RequestSourceInterface > getSource() const
Definition: HTTP2RequestConfig.h:293
const T & move(const T &t)
Definition: gtest-port.h:1317
bool isIntermittentTransferExpected() const
Definition: HTTP2RequestConfig.h:301
HTTP2RequestType
Definition: HTTP2RequestType.h:29

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