AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
DownloadStream.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_DOWNLOADSTREAM_H_
17 #define ACSDKASSETSCOMMON_DOWNLOADSTREAM_H_
18 
19 #include <fstream>
20 #include <memory>
21 #include <mutex>
22 #include <string>
23 
24 namespace alexaClientSDK {
25 namespace acsdkAssets {
26 namespace common {
27 
28 /*
29  * Consumer Producer queue with blocking wait and pop operation to store downloaded data chunks.
30  * It comes with downloaded file size validation.
31  */
33 public:
40  static std::shared_ptr<DownloadStream> create(const std::string& path, size_t expectedSize);
41 
42  virtual ~DownloadStream();
43 
50  bool write(const char* data, size_t size);
51 
52  bool downloadSucceeded() const;
53 
54 private:
60  explicit DownloadStream(const std::string& path, size_t expectedSize);
61 
66  bool good() const;
67 
69  mutable std::mutex m_mutex;
70 
72  std::ofstream m_ostream;
73 
75  size_t m_expectedSize;
76 
78  size_t m_downloadedSize;
79 };
80 
81 } // namespace common
82 } // namespace acsdkAssets
83 } // namespace alexaClientSDK
84 
85 #endif // ACSDKASSETSCOMMON_DOWNLOADSTREAM_H_
bool write(const char *data, size_t size)
::std::string string
Definition: gtest-port.h:1097
static std::shared_ptr< DownloadStream > create(const std::string &path, size_t expectedSize)
Definition: common.py:1
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36

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