libfilezilla
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
writer_base Class Referenceabstract

Base class for all writers. More...

#include <writer.hpp>

Inheritance diagram for writer_base:
Inheritance graph
[legend]
Collaboration diagram for writer_base:
Collaboration graph
[legend]

Public Types

using progress_cb_t = std::function< void(writer_base const *, uint64_t written)>
 
- Public Types inherited from aio_base
using size_type = uint64_t
 

Public Member Functions

 writer_base (writer_base const &)=delete
 
writer_baseoperator= (writer_base const &)=delete
 
virtual aio_result preallocate (uint64_t)
 Instructs writer to preallocate storage. May be a noop.
 
aio_result add_buffer (buffer_lease &&b, aio_waiter &h)
 Pass a buffer to be written out. More...
 
aio_result add_buffer (buffer_lease &&b, event_handler &h)
 
aio_result finalize (aio_waiter &h)
 Finalizes the writer. More...
 
aio_result finalize (event_handler &h)
 
virtual bool set_mtime (datetime const &)
 Must be finalized already.
 
void close ()
 
- Public Member Functions inherited from aio_waitable
void remove_waiter (aio_waiter &h)
 
void remove_waiter (event_handler &h)
 

Protected Member Functions

virtual aio_result do_add_buffer (scoped_lock &l, buffer_lease &&b)=0
 
virtual aio_result do_finalize (scoped_lock &l)=0
 
 writer_base (std::wstring &&name, aio_buffer_pool &pool, progress_cb_t &&progress_cb, size_t max_buffers) noexcept
 
 writer_base (std::wstring_view name, aio_buffer_pool &pool, progress_cb_t &&progress_cb, size_t max_buffers) noexcept
 
virtual void do_close (scoped_lock &)
 
- Protected Member Functions inherited from aio_waitable
void remove_waiters ()
 Call in destructor of most-derived class.
 
void add_waiter (aio_waiter &h)
 
void add_waiter (event_handler &h)
 
void signal_availibility ()
 

Protected Attributes

mutex mtx_
 
aio_buffer_poolbuffer_pool_
 
std::wstring const name_
 
progress_cb_t progress_cb_
 
size_t const max_buffers_ {}
 
std::list< buffer_leasebuffers_
 
bool error_ {}
 
uint8_t finalizing_ {}
 

Additional Inherited Members

- Static Public Attributes inherited from aio_base
static constexpr auto nosize = static_cast<size_type>(-1)
 

Detailed Description

Base class for all writers.

All writers have a name describing them for logging purposes.

The initial state of a freshly opened writer is writable, add_buffer() can be called.

See the aio demo program for example usage.

Examples
aio.cpp.

Member Typedef Documentation

◆ progress_cb_t

using progress_cb_t = std::function<void(writer_base const*, uint64_t written)>

Progress callback is only for accounting progress. Never call into the writer from the callback.

The progress callback is invoked whenever the writer has written out some data.

Idiomatic usage of the the progress callback: Update some atomic variables and optionally send an event.

Member Function Documentation

◆ add_buffer()

aio_result add_buffer ( buffer_lease &&  b,
aio_waiter h 
)

Pass a buffer to be written out.

If aio_result::ok is returned, you can call add_buffer again.

If aio_result::wait is returned, do not call add_buffer again until after the passed waiter got on_buffer_availability() invoked.

If aio_result::error is returned, the writer has failed and can only be closed.

◆ finalize()

aio_result finalize ( aio_waiter h)

Finalizes the writer.

If aio_result::ok is returned, all pending data has been written out.

If aio_result::wait is returned, wait until the passed waiter gets on_buffer_availability() invoked, then call finalize again.

If aio_result::error is returned, the writer has failed and can only be closed.


The documentation for this class was generated from the following file: