1 /* 2 * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/> 3 * (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com> 4 * 5 * This file is part of lsp-plugins 6 * Created on: 14 нояб. 2017 г. 7 * 8 * lsp-plugins 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-plugins 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-plugins. If not, see <https://www.gnu.org/licenses/>. 20 */ 21 22 #ifndef CORE_IO_IINSTREAM_H_ 23 #define CORE_IO_IINSTREAM_H_ 24 25 #include <core/types.h> 26 #include <core/status.h> 27 28 namespace lsp 29 { 30 namespace io 31 { 32 class IOutStream; 33 34 /** This is data stream available to be read from clipboard 35 * 36 */ 37 class IInStream 38 { 39 private: 40 IInStream & operator = (const IInStream &); 41 42 protected: 43 status_t nErrorCode; 44 45 protected: set_error(status_t error)46 inline status_t set_error(status_t error) { return nErrorCode = error; } 47 48 public: 49 explicit IInStream(); 50 virtual ~IInStream(); 51 52 public: 53 /** Get last I/O error code 54 * 55 * @return last I/O error code 56 */ last_error()57 inline status_t last_error() const { return nErrorCode; }; 58 59 /** The number of bytes available 60 * 61 * @return number of bytes available or negative error code 62 */ 63 virtual wssize_t avail(); 64 65 /** The current read position 66 * 67 * @return current read position or negative error code 68 */ 69 virtual wssize_t position(); 70 71 /** Read single byte from stream 72 * 73 * @return byte value or negative error code 74 */ 75 virtual ssize_t read_byte(); 76 77 /** Read amount of data 78 * 79 * @param dst target buffer to read data 80 * @param count number of bytes to read 81 * @return number of bytes actually read or negative error code, 82 * for end of file, -STATUS_EOF should be returned 83 */ 84 virtual ssize_t read(void *dst, size_t count); 85 86 /** Read maximum possible amount of data 87 * 88 * @param dst target buffer to read data 89 * @param count number of bytes to read 90 * @return number of bytes actually read 91 */ 92 virtual ssize_t read_fully(void *dst, size_t count); 93 94 /** 95 * Read entire block of specified size 96 * @param dst target buffer to read block 97 * @param count number of bytes in block 98 * @return status of operation 99 */ 100 virtual status_t read_block(void *dst, size_t count); 101 102 /** Seek the stream to the specified position from the beginning 103 * 104 * @param position the specified position 105 * @return real position or negative value on error 106 */ 107 virtual wssize_t seek(wsize_t position); 108 109 /** 110 * Skip amount of data 111 * @param amount amount of bytes to skip 112 * @return actual number of bytes skipped or error 113 */ 114 virtual wssize_t skip(wsize_t amount); 115 116 /** 117 * Sink all data to the output stream 118 * @param os pointer to the output stream 119 * @return number of bytes written or negative error code 120 */ 121 virtual wssize_t sink(IOutStream *os, size_t buf_size = 0x1000); 122 123 /** Close the clip data stream 124 * 125 * @return status of operation 126 */ 127 virtual status_t close(); 128 }; 129 130 } /* namespace ws */ 131 } /* namespace lsp */ 132 133 #endif /* CORE_IO_IINSTREAM_H_ */ 134