Disk ARchive  2.6.0
Full featured and portable backup and archiving tool
tuyau.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2018 Denis Corbin
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 // to contact the author : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21 
30 
31 #ifndef TUYAU_HPP
32 #define TUYAU_HPP
33 
34 #include "../my_config.h"
35 #include "infinint.hpp"
36 #include "generic_file.hpp"
37 #include "thread_cancellation.hpp"
38 #include "mem_ui.hpp"
39 
40 namespace libdar
41 {
42 
45 
47 
48  class tuyau : public generic_file, public thread_cancellation, protected mem_ui
49  {
50  public:
51  tuyau(const std::shared_ptr<user_interaction> & dialog, //< for user interaction
52  int fd); //< fd is the filedescriptor of a pipe extremity already openned
53  tuyau(const std::shared_ptr<user_interaction> & dialog, //< for user interaction
54  int fd, //< fd is the filedescriptor of a pipe extremity already openned
55  gf_mode mode); //< forces the mode if possible
56  tuyau(const std::shared_ptr<user_interaction> & dialog, //< for user interaction
57  const std::string &filename, //< named pipe to open
58  gf_mode mode); //< forces the mode if possible
59  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_read_side() method
60  tuyau(const tuyau & ref) = default;
61  tuyau(tuyau && ref) noexcept = default;
62  tuyau & operator = (const tuyau & ref) = default;
63  tuyau & operator = (tuyau && ref) noexcept = default;
64  ~tuyau();
65 
68  int get_read_fd() const;
69 
71 
75  void close_read_fd();
76 
78  void do_not_close_read_fd();
79 
80  // inherited from generic_file
81  virtual bool skippable(skippability direction, const infinint & amount) override;
82  virtual bool skip(const infinint & pos) override;
83  virtual bool skip_to_eof() override;
84  virtual bool skip_relative(signed int x) override;
85  virtual infinint get_position() const override { return position; };
86 
87  bool has_next_to_read();
88 
89  protected:
90  virtual void inherited_read_ahead(const infinint & amount) override {}; // relying on the operating system
91  virtual U_I inherited_read(char *a, U_I size) override;
92  virtual void inherited_write(const char *a, U_I size) override;
93  virtual void inherited_sync_write() override {};
94  virtual void inherited_flush_read() override {};
95  virtual void inherited_terminate() override;
96 
97  private:
98  enum
99  {
103  } pipe_mode;
105  int filedesc;
107  std::string chemin;
110 
111  void ouverture();
112 
114 
117  bool read_and_drop(infinint byte);
118 
120  bool read_to_eof();
121  };
122 
124 
125 } // end of namespace
126 
127 #endif
virtual bool skippable(skippability direction, const infinint &amount) override
whether the implementation is able to skip
enum libdar::tuyau::@6 pipe_mode
defines how the object&#39;s status (which possible values defined by the anonymous enum above) ...
class mem_ui definition. This class is to be used as parent class to handle user_interaction object m...
infinint position
recorded position in the stream
Definition: tuyau.hpp:104
virtual bool skip_to_eof() override
skip to the end of file
int get_read_fd() const
class generic_file is defined here as well as class fichierthe generic_file interface is widely used ...
holds a pair of file descriptors
Definition: tuyau.hpp:102
std::string chemin
in pipe_path mode only, this holds the named pipe to be open
Definition: tuyau.hpp:107
virtual void inherited_write(const char *a, U_I size) override
implementation of the write() operation
bool has_one_to_read
if true, the next char to read is placed in "next_to_read"
Definition: tuyau.hpp:108
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:90
void do_not_close_read_fd()
ask to not close the read descriptor upon object destruction (the fd survives the object) ...
virtual void inherited_terminate() override
destructor-like call, except that it is allowed to throw exceptions
gf_mode
generic_file openning modes
Definition: gf_mode.hpp:43
int filedesc
file descriptors of the pipe
Definition: tuyau.hpp:105
holds a filename to be openned (named pipe)
Definition: tuyau.hpp:101
bool read_to_eof()
skip to eof by reading data
virtual U_I inherited_read(char *a, U_I size) override
implementation of read() operation
to be able to cancel libdar operation while running in a given thread.
class to be used as parent to provide checkpoints to inherited classes
holds a single file descriptor for the pipe
Definition: tuyau.hpp:100
switch module to limitint (32 ou 64 bits integers) or infinint
char next_to_read
when has_one_to_read is true, contains the next to read byte
Definition: tuyau.hpp:109
int other_end_fd
in pipe_both mode, this holds the reading side of the anonymous pipe
Definition: tuyau.hpp:106
this is the interface class from which all other data transfer classes inherit
class mem_ui to keep a copy of a user_interaction object
Definition: mem_ui.hpp:54
virtual void inherited_flush_read() override
reset internal engine, flush caches in order to read the data at current position ...
Definition: tuyau.hpp:94
the arbitrary large positive integer class
virtual bool skip(const infinint &pos) override
skip at the absolute position
pipe implementation under the generic_file interface.
Definition: tuyau.hpp:48
bool read_and_drop(infinint byte)
skip forward by reading data
virtual infinint get_position() const override
get the current read/write position
Definition: tuyau.hpp:85
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:46
void close_read_fd()
closes the read fd of the anonymous pipe (this is to be used by a writer)
virtual void inherited_sync_write() override
write down any pending data
Definition: tuyau.hpp:93