22 #ifndef FsBroker_Lib_FileDevice_h
23 #define FsBroker_Lib_FileDevice_h
33 #include <boost/cstdint.hpp>
34 #include <boost/iostreams/categories.hpp>
35 #include <boost/iostreams/detail/ios.hpp>
36 #include <boost/shared_ptr.hpp>
58 const uint32_t READAHEAD_BUFFER_SIZE = 1024*1024;
59 const uint32_t OUTSTANDING_READS = 2;
68 struct category :
public device_tag,
public closable_tag
72 bool accurate_length =
true,
73 BOOST_IOS::openmode mode = BOOST_IOS::in);
79 bool accurate_length =
true,
80 BOOST_IOS::openmode mode = BOOST_IOS::in);
81 virtual bool is_open()
const;
84 virtual streamsize read(char_type* dst,
size_t amount);
85 virtual size_t bytes_read();
86 virtual size_t length();
89 virtual size_t write(
const char_type *src,
size_t amount);
90 virtual size_t bytes_written();
98 bool accurate_length, BOOST_IOS::openmode mode)
99 : m_client(client), m_filename(filename), m_open(false),
100 m_bytes_read(0), m_bytes_written(0), m_length(0)
103 if (mode & BOOST_IOS::in) {
104 if (!m_client->exists(filename))
106 m_length = m_client->length(filename, accurate_length);
108 READAHEAD_BUFFER_SIZE, OUTSTANDING_READS);
110 else if (mode & BOOST_IOS::out) {
122 m_client->close(m_fd);
123 m_bytes_read = m_bytes_written = 0;
128 streamsize
read(char_type *dst,
size_t amount) {
129 if (amount + m_bytes_read > m_length)
130 amount = m_length - m_bytes_read;
132 size_t bytes_read = m_client->read(m_fd, (
void *)dst, amount);
133 m_bytes_read += bytes_read;
149 size_t write(
const char_type *dst,
size_t amount) {
151 size_t bytes_written = m_client->append(m_fd, write_buffer);
152 m_bytes_written += bytes_written;
153 return bytes_written;
157 return m_bytes_written;
190 bool accurate_length =
true,
191 BOOST_IOS::openmode mode = BOOST_IOS::in) {
208 :
FileDevice(client, filename, false, BOOST_IOS::out)
213 bool accurate_length =
false,
214 BOOST_IOS::openmode mode = BOOST_IOS::out) {
223 #endif // FsBroker_Lib_FileDevice_h
A memory buffer of static size.
FileSink(ClientPtr &client, const String &filename)
std::string String
A String is simply a typedef to std::string.
streamsize read(char_type *dst, size_t amount)
virtual size_t bytes_read()
virtual size_t bytes_written()
impl(ClientPtr &client, const String &filename, bool accurate_length, BOOST_IOS::openmode mode)
std::shared_ptr< Client > ClientPtr
Smart pointer to Client.
size_t write(const char_type *dst, size_t amount)
Compatibility Macros for C/C++.
FileSource(ClientPtr &client, const String &filename)
virtual streamsize read(char_type *dst, size_t amount)
A memory buffer of static size.
virtual size_t write(const char_type *src, size_t amount)
virtual void open(ClientPtr &client, const String &filename, bool accurate_length=true, BOOST_IOS::openmode mode=BOOST_IOS::in)
virtual void open(ClientPtr &client, const String &filename, bool accurate_length=false, BOOST_IOS::openmode mode=BOOST_IOS::out)
virtual bool is_open() const
boost::shared_ptr< impl > pimpl_
virtual void open(ClientPtr &client, const String &filename, bool accurate_length=true, BOOST_IOS::openmode mode=BOOST_IOS::in)
String extensions and helpers: sets, maps, append operators etc.
Error codes, Exception handling, error logging.
#define HT_THROW(_code_, _msg_)