Loading...
Searching...
No Matches
tuyau.hpp
Go to the documentation of this file.
/*********************************************************************/
// dar - disk archive - a backup/restoration program
// Copyright (C) 2002-2025 Denis Corbin
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// to contact the author, see the AUTHOR file
/*********************************************************************/
#ifndef TUYAU_HPP
#define TUYAU_HPP
#include "../my_config.h"
#include "infinint.hpp"
#include "generic_file.hpp"
#include "thread_cancellation.hpp"
#include "mem_ui.hpp"
namespace libdar
{
class tuyau : public generic_file, public thread_cancellation, protected mem_ui
{
public:
tuyau(const std::shared_ptr<user_interaction> & dialog,
int fd
);
tuyau(const std::shared_ptr<user_interaction> & dialog,
int fd,
gf_mode mode
);
tuyau(const std::shared_ptr<user_interaction> & dialog,
const std::string &filename,
gf_mode mode
);
tuyau(const std::shared_ptr<user_interaction> & dialog);
tuyau(const tuyau & ref) = default;
tuyau(tuyau && ref) noexcept = default;
tuyau & operator = (const tuyau & ref) = default;
tuyau & operator = (tuyau && ref) noexcept = default;
~tuyau();
int get_read_fd() const;
void close_read_fd();
void do_not_close_read_fd();
// inherited from generic_file
virtual bool skippable(skippability direction, const infinint & amount) override;
virtual bool skip(const infinint & pos) override;
virtual bool skip_to_eof() override;
virtual bool skip_relative(signed int x) override;
virtual bool truncatable(const infinint & pos) const override { return pos >= position; };
virtual infinint get_position() const override { return position; };
bool has_next_to_read();
protected:
virtual void inherited_read_ahead(const infinint & amount) override {}; // relying on the operating system
virtual U_I inherited_read(char *a, U_I size) override;
virtual void inherited_write(const char *a, U_I size) override;
virtual void inherited_truncate(const infinint & pos) override { if(pos < position) throw SRC_BUG; };
virtual void inherited_sync_write() override {};
virtual void inherited_flush_read() override {};
virtual void inherited_terminate() override;
private:
enum
{
pipe_fd,
pipe_path,
pipe_both
} pipe_mode;
infinint position;
int filedesc;
int other_end_fd;
std::string chemin;
bool has_one_to_read;
char next_to_read;
void ouverture();
bool read_and_drop(infinint byte);
bool read_to_eof();
};
} // end of namespace
#endif
libdar::generic_file::generic_file
generic_file(gf_mode m)
main constructor
Definition generic_file.hpp:80
libdar::infinint
the arbitrary large positive integer class
Definition real_infinint.hpp:62
libdar::mem_ui::mem_ui
mem_ui(const std::shared_ptr< user_interaction > &dialog)
constructor
libdar::thread_cancellation::thread_cancellation
thread_cancellation()
the constructor
libdar::tuyau::read_to_eof
bool read_to_eof()
skip to eof by reading data
libdar::tuyau::chemin
std::string chemin
in pipe_path mode only, this holds the named pipe to be open
Definition tuyau.hpp:113
libdar::tuyau::inherited_terminate
virtual void inherited_terminate() override
destructor-like call, except that it is allowed to throw exceptions
libdar::tuyau::other_end_fd
int other_end_fd
in pipe_both mode, this holds the reading side of the anonymous pipe
Definition tuyau.hpp:112
libdar::tuyau::tuyau
tuyau(const std::shared_ptr< user_interaction > &dialog, int fd)
libdar::tuyau::read_and_drop
bool read_and_drop(infinint byte)
skip forward by reading data
libdar::tuyau::skippable
virtual bool skippable(skippability direction, const infinint &amount) override
whether the implementation is able to skip
libdar::tuyau::get_position
virtual infinint get_position() const override
get the current read/write position
Definition tuyau.hpp:90
libdar::tuyau::inherited_read_ahead
virtual void inherited_read_ahead(const infinint &amount) override
tells the object that several calls to read() will follow to probably obtain at least the given amoun...
Definition tuyau.hpp:95
libdar::tuyau::skip_to_eof
virtual bool skip_to_eof() override
skip to the end of file
libdar::tuyau::do_not_close_read_fd
void do_not_close_read_fd()
ask to not close the read descriptor upon object destruction (the fd survives the object)
libdar::tuyau::inherited_read
virtual U_I inherited_read(char *a, U_I size) override
implementation of read() operation
libdar::tuyau::skip
virtual bool skip(const infinint &pos) override
skip at the absolute position
libdar::tuyau::inherited_write
virtual void inherited_write(const char *a, U_I size) override
implementation of the write() operation
libdar::tuyau::close_read_fd
void close_read_fd()
closes the read fd of the anonymous pipe (this is to be used by a writer)
libdar::tuyau::get_read_fd
int get_read_fd() const
libdar::tuyau::tuyau
tuyau(const std::shared_ptr< user_interaction > &dialog)
creates a anonymous pipe and bind itself to the writing end. The reading end can be obtained by get_r...
libdar::tuyau::position
infinint position
recorded position in the stream
Definition tuyau.hpp:110
libdar::tuyau::pipe_mode
enum libdar::tuyau::@017250332164054312220245041076224013116127130034 pipe_mode
defines how the object's status (which possible values defined by the anonymous enum above)
libdar::tuyau::tuyau
tuyau(const std::shared_ptr< user_interaction > &dialog, const std::string &filename, gf_mode mode)
libdar::tuyau::inherited_flush_read
virtual void inherited_flush_read() override
reset internal engine, flush caches in order to read the data at current position
Definition tuyau.hpp:100
libdar::tuyau::truncatable
virtual bool truncatable(const infinint &pos) const override
whether the implementation is able to truncate to the given position
Definition tuyau.hpp:89
libdar::tuyau::filedesc
int filedesc
file descriptors of the pipe
Definition tuyau.hpp:111
libdar::tuyau::next_to_read
char next_to_read
when has_one_to_read is true, contains the next to read byte
Definition tuyau.hpp:115
libdar::tuyau::has_one_to_read
bool has_one_to_read
if true, the next char to read is placed in "next_to_read"
Definition tuyau.hpp:114
libdar::tuyau::tuyau
tuyau(const std::shared_ptr< user_interaction > &dialog, int fd, gf_mode mode)
libdar::tuyau::inherited_sync_write
virtual void inherited_sync_write() override
write down any pending data
Definition tuyau.hpp:99
libdar::tuyau::inherited_truncate
virtual void inherited_truncate(const infinint &pos) override
truncate file at the give offset
Definition tuyau.hpp:98
libdar::tuyau::pipe_path
@ pipe_path
holds a filename to be openned (named pipe)
Definition tuyau.hpp:107
libdar::tuyau::pipe_fd
@ pipe_fd
holds a single file descriptor for the pipe
Definition tuyau.hpp:106
libdar::tuyau::pipe_both
@ pipe_both
holds a pair of file descriptors
Definition tuyau.hpp:108
generic_file.hpp
class generic_file is defined here as well as class fichier
libdar::gf_mode
gf_mode
generic_file openning modes
Definition gf_mode.hpp:44
infinint.hpp
switch module to limitint (32 ou 64 bits integers) or infinint
mem_ui.hpp
class mem_ui definition. This class is to be used as parent class to handle user_interaction object m...
my_config.h
include macro defined by the configure script and some specific additional ones
libdar
libdar namespace encapsulate all libdar symbols
Definition archive.hpp:47
thread_cancellation.hpp
to be able to cancel libdar operation while running in a given thread.