![]() |
Disk ARchive
2.5.2
Full featured and portable backup and archiving tool
|
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 00030 00031 #ifndef TUYAU_HPP 00032 #define TUYAU_HPP 00033 00034 #include "../my_config.h" 00035 #include "infinint.hpp" 00036 #include "generic_file.hpp" 00037 #include "thread_cancellation.hpp" 00038 #include "mem_ui.hpp" 00039 00040 namespace libdar 00041 { 00042 00044 00046 00047 class tuyau : public generic_file, public thread_cancellation, protected mem_ui 00048 { 00049 public: 00050 tuyau(const user_interaction & dialog, //< for user interaction 00051 int fd); //< fd is the filedescriptor of a pipe extremity already openned 00052 tuyau(const user_interaction & dialog, //< for user interaction 00053 int fd, //< fd is the filedescriptor of a pipe extremity already openned 00054 gf_mode mode); //< forces the mode if possible 00055 tuyau(const user_interaction & dialog, //< for user interaction 00056 const std::string &filename, //< named pipe to open 00057 gf_mode mode); //< forces the mode if possible 00058 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 00059 ~tuyau(); 00060 00061 // provides the reading end of the anonymous pipe when the current object has created it (no filedesc, no path given to constructor). 00062 // it cannot be called more than once. 00063 int get_read_fd() const; 00064 00066 00070 void close_read_fd(); 00071 00073 void do_not_close_read_fd(); 00074 00075 // inherited from generic_file 00076 bool skippable(skippability direction, const infinint & amount); 00077 bool skip(const infinint & pos); 00078 bool skip_to_eof(); 00079 bool skip_relative(signed int x); 00080 infinint get_position() const { return position; }; 00081 00082 bool has_next_to_read(); 00083 00084 protected: 00085 void inherited_read_ahead(const infinint & amount) {}; // relying on the operating system 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_flush_read() {}; 00090 void inherited_terminate(); 00091 00092 private: 00093 enum 00094 { 00095 pipe_fd, //< holds a single file descriptor for the pipe 00096 pipe_path, //< holds a filename to be openned (named pipe) 00097 pipe_both //< holds a pair of file descriptors 00098 } 00099 pipe_mode; //< defines how the object's status (which possible values defined by the anonymous enum above) 00100 infinint position; //< recorded position in the stream 00101 int filedesc; //< file descriptors of the pipe 00102 int other_end_fd; //< in pipe_both mode, this holds the reading side of the anonymous pipe 00103 std::string chemin; //< in pipe_path mode only, this holds the named pipe to be open 00104 bool has_one_to_read; //< if true, the next char to read is placed in "next_to_read" 00105 char next_to_read; //< when has_one_to_read is true, contains the next to read byte 00106 00107 void ouverture(); 00108 00110 00113 bool read_and_drop(infinint byte); 00114 00116 bool read_to_eof(); 00117 }; 00118 00119 } // end of namespace 00120 00121 #endif