| 1 |
/* |
| 2 |
* Copyright (C) 2024 Linux Studio Plugins Project <https://lsp-plug.in/> |
| 3 |
* (C) 2024 Vladimir Sadovnikov <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of lsp-runtime-lib |
| 6 |
* Created on: 14 нояб. 2017 г. |
| 7 |
* |
| 8 |
* lsp-runtime-lib is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU Lesser General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* lsp-runtime-lib is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU Lesser General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public License |
| 19 |
* along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifndef LSP_PLUG_IN_IO_IINSTREAM_H_ |
| 23 |
#define LSP_PLUG_IN_IO_IINSTREAM_H_ |
| 24 |
|
| 25 |
#include <lsp-plug.in/runtime/version.h> |
| 26 |
#include <lsp-plug.in/common/types.h> |
| 27 |
#include <lsp-plug.in/common/status.h> |
| 28 |
|
| 29 |
namespace lsp |
| 30 |
{ |
| 31 |
namespace io |
| 32 |
{ |
| 33 |
class IOutStream; |
| 34 |
|
| 35 |
/** This is data stream available to be read from clipboard |
| 36 |
* |
| 37 |
*/ |
| 38 |
class IInStream |
| 39 |
{ |
| 40 |
protected: |
| 41 |
status_t nErrorCode; |
| 42 |
|
| 43 |
protected: |
| 44 |
inline status_t set_error(status_t error) { return nErrorCode = error; } |
| 45 |
|
| 46 |
public: |
| 47 |
explicit IInStream(); |
| 48 |
IInStream(const IInStream &) = delete; |
| 49 |
IInStream(IInStream &&) = delete; |
| 50 |
virtual ~IInStream(); |
| 51 |
|
| 52 |
IInStream & operator = (const IInStream &) = delete; |
| 53 |
IInStream & operator = (IInStream &&) = delete; |
| 54 |
|
| 55 |
public: |
| 56 |
/** Get last I/O error code |
| 57 |
* |
| 58 |
* @return last I/O error code |
| 59 |
*/ |
| 60 |
inline status_t last_error() const { return nErrorCode; }; |
| 61 |
|
| 62 |
/** The number of bytes available |
| 63 |
* |
| 64 |
* @return number of bytes available or negative error code |
| 65 |
* @note some implementations can return STATUS_NOT_IMPLEMENTED error code |
| 66 |
*/ |
| 67 |
virtual wssize_t avail(); |
| 68 |
|
| 69 |
/** The current read position |
| 70 |
* |
| 71 |
* @return current read position or negative error code |
| 72 |
*/ |
| 73 |
virtual wssize_t position(); |
| 74 |
|
| 75 |
/** Read single byte from stream |
| 76 |
* |
| 77 |
* @return byte value or negative error code |
| 78 |
*/ |
| 79 |
virtual ssize_t read_byte(); |
| 80 |
|
| 81 |
/** Read amount of data |
| 82 |
* |
| 83 |
* @param dst target buffer to read data |
| 84 |
* @param count number of bytes to read |
| 85 |
* @return number of bytes actually read or negative error code, |
| 86 |
* for end of file, -STATUS_EOF should be returned |
| 87 |
*/ |
| 88 |
virtual ssize_t read(void *dst, size_t count); |
| 89 |
|
| 90 |
/** Read maximum possible amount of data |
| 91 |
* |
| 92 |
* @param dst target buffer to read data |
| 93 |
* @param count number of bytes to read |
| 94 |
* @return number of bytes actually read |
| 95 |
*/ |
| 96 |
virtual ssize_t read_fully(void *dst, size_t count); |
| 97 |
|
| 98 |
/** |
| 99 |
* Read entire block of specified size |
| 100 |
* @param dst target buffer to read block |
| 101 |
* @param count number of bytes in block |
| 102 |
* @return status of operation |
| 103 |
*/ |
| 104 |
virtual status_t read_block(void *dst, size_t count); |
| 105 |
|
| 106 |
/** Seek the stream to the specified position from the beginning |
| 107 |
* |
| 108 |
* @param position the specified position |
| 109 |
* @return real position or negative value on error |
| 110 |
* @note some implementations can return STATUS_NOT_IMPLEMENTED error code |
| 111 |
*/ |
| 112 |
virtual wssize_t seek(wsize_t position); |
| 113 |
|
| 114 |
/** |
| 115 |
* Skip amount of data |
| 116 |
* @param amount amount of bytes to skip |
| 117 |
* @return actual number of bytes skipped or error |
| 118 |
*/ |
| 119 |
virtual wssize_t skip(wsize_t amount); |
| 120 |
|
| 121 |
/** |
| 122 |
* Sink all data to the output stream |
| 123 |
* @param os pointer to the output stream |
| 124 |
* @return number of bytes written or negative error code |
| 125 |
*/ |
| 126 |
virtual wssize_t sink(IOutStream *os, size_t buf_size = 0x1000); |
| 127 |
|
| 128 |
/** Close the clip data stream |
| 129 |
* |
| 130 |
* @return status of operation |
| 131 |
*/ |
| 132 |
virtual status_t close(); |
| 133 |
}; |
| 134 |
|
| 135 |
/** |
| 136 |
* Finalize input stream according to wrapping flags |
| 137 |
* @param is input stream to finalize |
| 138 |
* @param wrap_flags wrap fiags |
| 139 |
* @return status of operation |
| 140 |
*/ |
| 141 |
status_t finalize(io::IInStream *is, size_t wrap_flags); |
| 142 |
|
| 143 |
} /* namespace io */ |
| 144 |
} /* namespace lsp */ |
| 145 |
|
| 146 |
#endif /* LSP_PLUG_IN_IO_IINSTREAM_H_ */ |