| 1 |
/* |
| 2 |
* Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/> |
| 3 |
* (C) 2020 Vladimir Sadovnikov <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of lsp-runtime-lib |
| 6 |
* Created on: 14 янв. 2018 г. |
| 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_FMT_LSPC_CHUNKWRITER_H_ |
| 23 |
#define LSP_PLUG_IN_FMT_LSPC_CHUNKWRITER_H_ |
| 24 |
|
| 25 |
#include <lsp-plug.in/runtime/version.h> |
| 26 |
#include <lsp-plug.in/fmt/lspc/ChunkAccessor.h> |
| 27 |
#include <lsp-plug.in/fmt/lspc/ChunkWriterStream.h> |
| 28 |
#include <lsp-plug.in/fmt/lspc/lspc.h> |
| 29 |
|
| 30 |
namespace lsp |
| 31 |
{ |
| 32 |
namespace lspc |
| 33 |
{ |
| 34 |
class ChunkWriter: public ChunkAccessor |
| 35 |
{ |
| 36 |
private: |
| 37 |
ChunkWriter & operator = (const ChunkWriter &); |
| 38 |
|
| 39 |
protected: |
| 40 |
friend class File; |
| 41 |
|
| 42 |
enum flush_t |
| 43 |
{ |
| 44 |
F_FORCE = 1 << 0, |
| 45 |
F_LAST = 1 << 1 |
| 46 |
}; |
| 47 |
|
| 48 |
protected: |
| 49 |
size_t nChunksOut; |
| 50 |
wssize_t nPosition; |
| 51 |
ChunkWriterStream sStream; |
| 52 |
|
| 53 |
protected: |
| 54 |
status_t do_flush(size_t flags); |
| 55 |
|
| 56 |
protected: |
| 57 |
explicit ChunkWriter(Resource *fd, uint32_t magic); |
| 58 |
|
| 59 |
public: |
| 60 |
virtual ~ChunkWriter(); |
| 61 |
|
| 62 |
public: |
| 63 |
/** |
| 64 |
* Obtain access to chunk writer as a stream. |
| 65 |
* @return pointer to the stream |
| 66 |
*/ |
| 67 |
inline io::IOutStream *stream() { return &sStream; } |
| 68 |
|
| 69 |
/** |
| 70 |
* Get current write position in bytes |
| 71 |
* @return actual position from the beginning of the chunk including header |
| 72 |
*/ |
| 73 |
inline wssize_t position() const { return nPosition; } |
| 74 |
|
| 75 |
public: |
| 76 |
/** |
| 77 |
* Write chunk data header to LSPC chunk. |
| 78 |
* @param buf buffer containing header |
| 79 |
* @return status of operation |
| 80 |
*/ |
| 81 |
virtual status_t write_header(const void *buf); |
| 82 |
|
| 83 |
/** |
| 84 |
* Write data to LSPC chunk |
| 85 |
* @param buf buffer to write |
| 86 |
* @param count number of bytes to write |
| 87 |
* @return status of operation |
| 88 |
*/ |
| 89 |
virtual status_t write(const void *buf, size_t count); |
| 90 |
|
| 91 |
/** |
| 92 |
* Flush all buffers to file |
| 93 |
* @return status of operation |
| 94 |
*/ |
| 95 |
virtual status_t flush(); |
| 96 |
|
| 97 |
/** |
| 98 |
* Close chunk writer |
| 99 |
* @return status of operation |
| 100 |
*/ |
| 101 |
virtual status_t close(); |
| 102 |
}; |
| 103 |
} |
| 104 |
|
| 105 |
} /* namespace lsp */ |
| 106 |
|
| 107 |
#endif /* LSP_PLUG_IN_FMT_LSPC_CHUNKWRITER_H_ */ |