Disk ARchive
2.4.2
|
00001 /*********************************************************************/ 00002 // dar - disk archive - a backup/restoration program 00003 // Copyright (C) 2002-2052 Denis Corbin 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License 00007 // as published by the Free Software Foundation; either version 2 00008 // of the License, or (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 // 00019 // to contact the author : http://dar.linux.free.fr/email.html 00020 /*********************************************************************/ 00021 // $Id: tuyau.hpp,v 1.27 2011/04/19 14:57:24 edrusb Rel $ 00022 // 00023 /*********************************************************************/ 00024 00033 00034 #ifndef TUYAU_HPP 00035 #define TUYAU_HPP 00036 00037 #include "../my_config.h" 00038 #include "infinint.hpp" 00039 #include "generic_file.hpp" 00040 #include "thread_cancellation.hpp" 00041 00042 namespace libdar 00043 { 00044 00046 00048 00049 class tuyau : public generic_file, public thread_cancellation, protected mem_ui 00050 { 00051 public: 00052 tuyau(user_interaction & dialog, //< for user interaction 00053 int fd); //< fd is the filedescriptor of a pipe extremity already openned 00054 tuyau(user_interaction & dialog, 00055 int fd, //< fd is the filedescriptor of a pipe extremity already openned 00056 gf_mode mode); //< forces the mode if possible 00057 tuyau(user_interaction & dialog, //< for user interaction 00058 const std::string &filename, //< named pipe to open 00059 gf_mode mode); //< forces the mode if possible 00060 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 00061 ~tuyau(); 00062 00063 // provides the reading end of the anonymous pipe when the current object has created it (no filedesc, no path given to constructor). 00064 // it cannot be called more than once. 00065 int get_read_fd() const; 00066 00068 00072 void close_read_fd(); 00073 00075 void do_not_close_read_fd(); 00076 00077 // inherited from generic_file 00078 bool skip(const infinint & pos); 00079 bool skip_to_eof(); 00080 bool skip_relative(signed int x); 00081 infinint get_position() { return position; }; 00082 00083 bool has_next_to_read(); 00084 00085 protected: 00086 virtual U_I inherited_read(char *a, U_I size); 00087 virtual void inherited_write(const char *a, U_I size); 00088 void inherited_sync_write() {}; 00089 void inherited_terminate(); 00090 00091 private: 00092 enum 00093 { 00094 pipe_fd, //< holds a single file descriptor for the pipe 00095 pipe_path, //< holds a filename to be openned (named pipe) 00096 pipe_both //< holds a pair of file descriptors 00097 } 00098 pipe_mode; //< defines how the object's status (which possible values defined by the anonymous enum above) 00099 infinint position; //< recorded position in the stream 00100 int filedesc; //< file descriptors of the pipe 00101 int other_end_fd; //< in pipe_both mode, this holds the reading side of the anonymous pipe 00102 std::string chemin; //< in pipe_path mode only, this holds the named pipe to be open 00103 bool has_one_to_read; //< if true, the next char to read is placed in "next_to_read" 00104 char next_to_read; //< when has_one_to_read is true, contains the next to read byte 00105 00106 void ouverture(); 00107 00109 00112 bool read_and_drop(infinint byte); 00113 00115 bool read_to_eof(); 00116 }; 00117 00118 } // end of namespace 00119 00120 #endif