AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
DownloadChunkQueue.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 ACSDKASSETSCOMMON_DOWNLOADCHUNKQUEUE_H_
17 #define ACSDKASSETSCOMMON_DOWNLOADCHUNKQUEUE_H_
18 
19 #include <condition_variable>
20 #include <memory>
21 #include <mutex>
22 #include <queue>
23 
24 #include "DataChunk.h"
25 
26 namespace alexaClientSDK {
27 namespace acsdkAssets {
28 namespace common {
29 
34 
35 /*
36  * Consumer Producer queue with blocking wait and pop operation to store downloaded data chunks.
37  * It comes with downloaded file size validation.
38  */
40 public:
46  explicit DownloadChunkQueue(size_t expectedSize);
47 
48  virtual ~DownloadChunkQueue();
49 
54  size_t size();
55 
62  bool push(char* data, size_t size);
63 
69  bool pushComplete(bool succeeded);
70 
76  std::shared_ptr<DataChunk> waitAndPop();
77 
84  bool popComplete(bool succeeded);
85 
86 private:
90  inline bool isSizeCheckingEnabled() const {
91  return m_expectedSize > 0;
92  }
93 
94 private:
96  std::condition_variable m_cond;
97 
99  std::mutex m_mutex;
100 
102  std::queue<std::shared_ptr<DataChunk>> m_queue;
103 
105  size_t m_expectedSize;
106 
108  size_t m_downloadedSize;
109 
111  StreamingStatus m_downloadStatus;
112 
114  StreamingStatus m_unpackStatus;
115 
118  std::shared_ptr<DataChunk> m_activeChunk;
119 
121  size_t m_maxQueueSizeReached;
122 
124  size_t m_bytesToReport;
125 
127  size_t m_reportIncrement;
128 };
129 
130 } // namespace common
131 } // namespace acsdkAssets
132 } // namespace alexaClientSDK
133 
134 #endif // ACSDKASSETSCOMMON_DOWNLOADCHUNKQUEUE_H_
Definition: common.py:1
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
StreamingStatus
Definition: DownloadChunkQueue.h:33

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