Disk ARchive  2.4.12
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
tuyau.hpp
Go to the documentation of this file.
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 
00039 namespace libdar
00040 {
00041 
00043 
00045 
00046     class tuyau : public generic_file, public thread_cancellation, protected mem_ui
00047     {
00048     public:
00049         tuyau(user_interaction & dialog,    //< for user interaction
00050               int fd);                      //< fd is the filedescriptor of a pipe extremity already openned
00051         tuyau(user_interaction & dialog,
00052               int fd,                       //< fd is the filedescriptor of a pipe extremity already openned
00053               gf_mode mode);                //< forces the mode if possible
00054         tuyau(user_interaction & dialog,    //< for user interaction
00055               const std::string &filename,  //< named pipe to open
00056               gf_mode mode);                //< forces the mode if possible
00057         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
00058         ~tuyau();
00059 
00060             // provides the reading end of the anonymous pipe when the current object has created it (no filedesc, no path given to constructor).
00061             // it cannot be called more than once.
00062         int get_read_fd() const;
00063 
00065 
00069         void close_read_fd();
00070 
00072         void do_not_close_read_fd();
00073 
00074             // inherited from generic_file
00075         bool skip(const infinint & pos);
00076         bool skip_to_eof();
00077         bool skip_relative(signed int x);
00078         infinint get_position() { return position; };
00079 
00080         bool has_next_to_read();
00081 
00082     protected:
00083         virtual U_I inherited_read(char *a, U_I size);
00084         virtual void inherited_write(const char *a, U_I size);
00085         void inherited_sync_write() {};
00086         void inherited_terminate();
00087 
00088     private:
00089         enum
00090         {
00091             pipe_fd,        //< holds a single file descriptor for the pipe
00092             pipe_path,      //< holds a filename to be openned (named pipe)
00093             pipe_both       //< holds a pair of file descriptors
00094         }
00095         pipe_mode;          //< defines how the object's status (which possible values defined by the anonymous enum above)
00096         infinint position;  //< recorded position in the stream
00097         int filedesc;       //< file descriptors of the pipe
00098         int other_end_fd;   //< in pipe_both mode, this holds the reading side of the anonymous pipe
00099         std::string chemin; //< in pipe_path mode only, this holds the named pipe to be open
00100         bool has_one_to_read; //< if true, the next char to read is placed in "next_to_read"
00101         char next_to_read;  //< when has_one_to_read is true, contains the next to read byte
00102 
00103         void ouverture();
00104 
00106 
00109         bool read_and_drop(infinint byte);
00110 
00112         bool read_to_eof();
00113     };
00114 
00115 } // end of namespace
00116 
00117 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines