Disk ARchive  2.5.1
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-2052 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 
44 
46 
47  class tuyau : public generic_file, public thread_cancellation, protected mem_ui
48  {
49  public:
50  tuyau(const user_interaction & dialog, //< for user interaction
51  int fd); //< fd is the filedescriptor of a pipe extremity already openned
52  tuyau(const user_interaction & dialog, //< for user interaction
53  int fd, //< fd is the filedescriptor of a pipe extremity already openned
54  gf_mode mode); //< forces the mode if possible
55  tuyau(const user_interaction & dialog, //< for user interaction
56  const std::string &filename, //< named pipe to open
57  gf_mode mode); //< forces the mode if possible
58  tuyau(const 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
59  ~tuyau();
60 
61  // provides the reading end of the anonymous pipe when the current object has created it (no filedesc, no path given to constructor).
62  // it cannot be called more than once.
63  int get_read_fd() const;
64 
66 
70  void close_read_fd();
71 
73  void do_not_close_read_fd();
74 
75  // inherited from generic_file
76  bool skippable(skippability direction, const infinint & amount);
77  bool skip(const infinint & pos);
78  bool skip_to_eof();
79  bool skip_relative(signed int x);
80  infinint get_position() const { return position; };
81 
82  bool has_next_to_read();
83 
84  protected:
85  void inherited_read_ahead(const infinint & amount) {}; // relying on the operating system
86  virtual U_I inherited_read(char *a, U_I size);
87  virtual void inherited_write(const char *a, U_I size);
90  void inherited_terminate();
91 
92  private:
93  enum
94  {
95  pipe_fd, //< holds a single file descriptor for the pipe
96  pipe_path, //< holds a filename to be openned (named pipe)
97  pipe_both //< holds a pair of file descriptors
98  }
99  pipe_mode; //< defines how the object's status (which possible values defined by the anonymous enum above)
100  infinint position; //< recorded position in the stream
101  int filedesc; //< file descriptors of the pipe
102  int other_end_fd; //< in pipe_both mode, this holds the reading side of the anonymous pipe
103  std::string chemin; //< in pipe_path mode only, this holds the named pipe to be open
104  bool has_one_to_read; //< if true, the next char to read is placed in "next_to_read"
105  char next_to_read; //< when has_one_to_read is true, contains the next to read byte
106 
107  void ouverture();
108 
110 
113  bool read_and_drop(infinint byte);
114 
116  bool read_to_eof();
117  };
118 
119 } // end of namespace
120 
121 #endif
bool skip_to_eof()
skip to the end of file
class mem_ui definition. This class is to be used as parent class to handle user_interaction object m...
void inherited_flush_read()
Definition: tuyau.hpp:89
void inherited_read_ahead(const infinint &amount)
Definition: tuyau.hpp:85
void inherited_terminate()
destructor-like call, except that it is allowed to throw exceptions
class generic_file is defined here as well as class fichierthe generic_file interface is widely used ...
This is a pure virtual class that is used by libdar when interaction with the user is required...
infinint get_position() const
get the current read/write position
Definition: tuyau.hpp:80
void do_not_close_read_fd()
ask to not close the read descriptor upon object destruction (the fd survives the object) ...
gf_mode
generic_file openning modes
virtual U_I inherited_read(char *a, U_I size)
implementation of read() operation
bool skip(const infinint &pos)
to be able to cancel libdar operation while running in a given thread.the class thread_cancellation i...
class to be used as parent to provide checkpoints to inherited classes
switch module to limitint (32 ou 64 bits integers) or infinint
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:53
virtual void inherited_write(const char *a, U_I size)
implementation of the write() operation
bool skippable(skippability direction, const infinint &amount)
the arbitrary large positive integer class
void inherited_sync_write()
write down any pending data
Definition: tuyau.hpp:88
pipe implementation under the generic_file interface.
Definition: tuyau.hpp:47
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47
void close_read_fd()
closes the read fd of the anonymous pipe (this is to be used by a writer)