AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
AttachmentReader.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_ATTACHMENT_ATTACHMENTREADER_H_
17 #define ALEXA_CLIENT_SDK_AVSCOMMON_AVS_INCLUDE_AVSCOMMON_AVS_ATTACHMENT_ATTACHMENTREADER_H_
18 
19 #include <chrono>
20 #include <cstddef>
21 #include <ostream>
22 
24 
25 namespace alexaClientSDK {
26 namespace avsCommon {
27 namespace avs {
28 namespace attachment {
29 
34 public:
38  enum class ReadStatus {
40  OK,
49  CLOSED,
56  };
57 
59  enum class ClosePoint {
61  IMMEDIATELY,
63  AFTER_DRAINING_CURRENT_BUFFER
64  };
65 
66  /*
67  * Destructor.
68  */
69  virtual ~AttachmentReader() = default;
70 
81  virtual std::size_t read(
82  void* buf,
83  std::size_t numBytes,
84  ReadStatus* readStatus,
85  std::chrono::milliseconds timeoutMs = std::chrono::milliseconds(0)) = 0;
86 
94  virtual bool seek(uint64_t offset) = 0;
95 
101  virtual uint64_t getNumUnreadBytes() = 0;
102 
109  virtual void close(ClosePoint closePoint = ClosePoint::AFTER_DRAINING_CURRENT_BUFFER) = 0;
110 };
111 
119 inline std::ostream& operator<<(std::ostream& stream, const AttachmentReader::ReadStatus& status) {
120  switch (status) {
122  stream << "OK";
123  break;
125  stream << "OK_WOULDBLOCK";
126  break;
128  stream << "OK_TIMEDOUT";
129  break;
131  stream << "OK_OVERRUN_RESET";
132  break;
134  stream << "CLOSED";
135  break;
137  stream << "ERROR_BYTES_LESS_THAN_WORD_SIZE";
138  break;
140  stream << "ERROR_OVERRUN";
141  break;
143  stream << "ERROR_INTERNAL";
144  break;
145  }
146  return stream;
147 }
148 
149 } // namespace attachment
150 } // namespace avs
151 } // namespace avsCommon
152 } // namespace alexaClientSDK
153 
154 #endif // ALEXA_CLIENT_SDK_AVSCOMMON_AVS_INCLUDE_AVSCOMMON_AVS_ATTACHMENT_ATTACHMENTREADER_H_
On a request for n bytes, less than n bytes were available on a blocking read.
Stop returning data when all of the data in the buffer at the time close() was called has been read...
virtual void close(ClosePoint closePoint=ClosePoint::AFTER_DRAINING_CURRENT_BUFFER)=0
virtual std::size_t read(void *buf, std::size_t numBytes, ReadStatus *readStatus, std::chrono::milliseconds timeoutMs=std::chrono::milliseconds(0))=0
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
On a request for n bytes, less than n bytes were available on a non-blocking read.
std::ostream & operator<<(std::ostream &stream, const AttachmentReader::ReadStatus &status)
Definition: AttachmentReader.h:119
The underlying data representation is no longer readable.
The number of bytes in the request is smaller than the word-size of the underlying data representatio...
The writer has corrupted the reader data. The attachment is no longer valid.
ClosePoint
An enum class to indicate when the read() function should stop returning data after a call to close()...
Definition: AttachmentReader.h:59

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