Disk ARchive  2.4.15
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 
39 namespace libdar
40 {
41 
43 
45 
46  class tuyau : public generic_file, public thread_cancellation, protected mem_ui
47  {
48  public:
49  tuyau(user_interaction & dialog, //< for user interaction
50  int fd); //< fd is the filedescriptor of a pipe extremity already openned
51  tuyau(user_interaction & dialog,
52  int fd, //< fd is the filedescriptor of a pipe extremity already openned
53  gf_mode mode); //< forces the mode if possible
54  tuyau(user_interaction & dialog, //< for user interaction
55  const std::string &filename, //< named pipe to open
56  gf_mode mode); //< forces the mode if possible
57  tuyau(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
58  ~tuyau();
59 
60  // provides the reading end of the anonymous pipe when the current object has created it (no filedesc, no path given to constructor).
61  // it cannot be called more than once.
62  int get_read_fd() const;
63 
65 
69  void close_read_fd();
70 
72  void do_not_close_read_fd();
73 
74  // inherited from generic_file
75  bool skip(const infinint & pos);
76  bool skip_to_eof();
77  bool skip_relative(signed int x);
78  infinint get_position() { return position; };
79 
80  bool has_next_to_read();
81 
82  protected:
83  virtual U_I inherited_read(char *a, U_I size);
84  virtual void inherited_write(const char *a, U_I size);
86  void inherited_terminate();
87 
88  private:
89  enum
90  {
91  pipe_fd, //< holds a single file descriptor for the pipe
92  pipe_path, //< holds a filename to be openned (named pipe)
93  pipe_both //< holds a pair of file descriptors
94  }
95  pipe_mode; //< defines how the object's status (which possible values defined by the anonymous enum above)
96  infinint position; //< recorded position in the stream
97  int filedesc; //< file descriptors of the pipe
98  int other_end_fd; //< in pipe_both mode, this holds the reading side of the anonymous pipe
99  std::string chemin; //< in pipe_path mode only, this holds the named pipe to be open
100  bool has_one_to_read; //< if true, the next char to read is placed in "next_to_read"
101  char next_to_read; //< when has_one_to_read is true, contains the next to read byte
102 
103  void ouverture();
104 
106 
109  bool read_and_drop(infinint byte);
110 
112  bool read_to_eof();
113  };
114 
115 } // end of namespace
116 
117 #endif
bool skip_to_eof()
skip to the end of file
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...
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)
skip at the absolute position
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
infinint get_position()
get the current read/write position
Definition: tuyau.hpp:78
virtual void inherited_write(const char *a, U_I size)
implementation of the write() operation
the arbitrary large positive integer class
void inherited_sync_write()
write down any pending data
Definition: tuyau.hpp:85
pipe implementation under the generic_file interface.
Definition: tuyau.hpp:46
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:43
void close_read_fd()
closes the read fd of the anonymous pipe (this is to be used by a writer)