16 #ifndef ALEXA_CLIENT_SDK_AVSCOMMON_AVS_INCLUDE_AVSCOMMON_AVS_ATTACHMENT_DEFAULTATTACHMENTREADER_H_ 17 #define ALEXA_CLIENT_SDK_AVSCOMMON_AVS_INCLUDE_AVSCOMMON_AVS_ATTACHMENT_DEFAULTATTACHMENTREADER_H_ 26 namespace attachment {
33 template <
typename SDSType>
49 static std::unique_ptr<AttachmentReader>
create(
50 typename SDSType::Reader::Policy policy,
51 std::shared_ptr<SDSType> sds,
54 bool resetOnOverrun =
false);
67 std::chrono::milliseconds timeoutMs = std::chrono::milliseconds(0))
override;
71 bool seek(uint64_t offset)
override;
85 DefaultAttachmentReader(
typename SDSType::Reader::Policy policy, std::shared_ptr<SDSType> sds,
bool resetOnOverrun);
91 std::shared_ptr<typename SDSType::Reader> m_reader;
94 bool m_resetOnOverrun;
97 template <
typename SDSType>
100 template <
typename SDSType>
102 typename SDSType::Reader::Policy policy,
103 std::shared_ptr<SDSType> sds,
106 bool resetOnOverrun) {
109 if (!reader->m_reader) {
114 if (!reader->m_reader->seek(offset, reference)) {
119 return std::unique_ptr<AttachmentReader>(reader.release());
122 template <
typename SDSType>
127 template <
typename SDSType>
130 std::size_t numBytes,
132 std::chrono::milliseconds timeoutMs) {
150 if (timeoutMs.count() < 0) {
162 const auto wordSize = m_reader->getWordSize();
163 if (numBytes < wordSize) {
170 std::size_t bytesRead = 0;
171 const auto numWords = numBytes / wordSize;
173 const auto readResult = m_reader->read(buf, numWords, timeoutMs);
183 if (readResult < 0) {
184 switch (readResult) {
186 case SDSType::Reader::Error::OVERRUN:
187 if (m_resetOnOverrun) {
192 m_reader->seek(0, SDSType::Reader::Reference::BEFORE_WRITER);
202 case SDSType::Reader::Error::WOULDBLOCK:
207 case SDSType::Reader::Error::TIMEDOUT:
219 }
else if (0 == readResult) {
223 bytesRead =
static_cast<size_t>(readResult) * wordSize;
229 template <
typename SDSType>
232 switch (closePoint) {
237 m_reader->close(0, SDSType::Reader::Reference::BEFORE_WRITER);
243 template <
typename SDSType>
246 return m_reader->seek(offset);
251 template <
typename SDSType>
254 return m_reader->tell(SDSType::Reader::Reference::BEFORE_WRITER);
261 template <
typename SDSType>
263 typename SDSType::Reader::Policy policy,
264 std::shared_ptr<SDSType> sds,
265 bool resetOnOverrun) :
266 m_resetOnOverrun{resetOnOverrun} {
272 m_reader = sds->createReader(policy);
285 #endif // ALEXA_CLIENT_SDK_AVSCOMMON_AVS_INCLUDE_AVSCOMMON_AVS_ATTACHMENT_DEFAULTATTACHMENTREADER_H_ bool seek(uint64_t offset) override
Definition: DefaultAttachmentReader.h:244
Reference
Specifies a reference to measure seek()/tell()/close() offsets against.
Definition: Reader.h:51
Stop returning data immediately after the close() call.
On a request for n bytes, less than n bytes were available on a blocking read.
::std::string string
Definition: gtest-port.h:1097
Definition: AttachmentReader.h:33
#define ACSDK_DEBUG5(entry)
Definition: Logger.h:400
uint64_t getNumUnreadBytes() override
Definition: DefaultAttachmentReader.h:252
static std::unique_ptr< AttachmentReader > create(typename SDSType::Reader::Policy policy, std::shared_ptr< SDSType > sds, typename SDSType::Index offset=0, typename SDSType::Reader::Reference reference=SDSType::Reader::Reference::ABSOLUTE, bool resetOnOverrun=false)
Definition: DefaultAttachmentReader.h:101
~DefaultAttachmentReader()
Definition: DefaultAttachmentReader.h:123
Stop returning data when all of the data in the buffer at the time close() was called has been read...
ReadStatus
Definition: AttachmentReader.h:38
#define ACSDK_ERROR(entry)
Definition: Logger.h:481
Index
Index used for setting access.
Definition: StateReportGeneratorTest.cpp:41
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::size_t read(void *buf, std::size_t numBytes, ReadStatus *readStatus, std::chrono::milliseconds timeoutMs=std::chrono::milliseconds(0)) override
Definition: DefaultAttachmentReader.h:128
The underlying data representation is no longer readable.
#define ACSDK_INFO(entry)
Definition: Logger.h:463
The number of bytes in the request is smaller than the word-size of the underlying data representatio...
A non-specified error occurred.
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
void close(ClosePoint closePoint=ClosePoint::AFTER_DRAINING_CURRENT_BUFFER) override
Definition: DefaultAttachmentReader.h:230
#define ACSDK_DEBUG0(entry)
Definition: Logger.h:445
Definition: DefaultAttachmentReader.h:34
LogEntry is used to compile the log entry text to log via Logger.
Definition: LogEntry.h:33