Disk ARchive  2.5.2
Full featured and portable backup and archiving tool
generic_thread.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 
00026 
00027 
00028 #ifndef GENERIC_THREAD_HPP
00029 #define GENERIC_THREAD_HPP
00030 
00031 #include "../my_config.h"
00032 
00033 #include "generic_file.hpp"
00034 #include "messaging.hpp"
00035 #include "slave_thread.hpp"
00036 #include "erreurs.hpp"
00037 
00038 namespace libdar
00039 {
00040 
00041 
00042     class generic_thread : public generic_file
00043     {
00044     public:
00045         // default values for constuctor
00046     static const unsigned int tampon_block_size = 102401;
00047     static const unsigned int tampon_num_block = 1000;
00048     static const unsigned int tampon_block_size_ctrl = 1024;
00049     static const unsigned int tampon_num_block_ctrl = 10;
00050 
00058     generic_thread(generic_file *ptr,
00059                U_I data_block_size = tampon_block_size,
00060                U_I data_num_block = tampon_num_block,
00061                U_I ctrl_block_size = tampon_block_size_ctrl,
00062                U_I ctrl_num_block = tampon_num_block_ctrl);
00063     generic_thread(const generic_thread & ref); //< copy constructor is disabled (throws exception)
00064     const generic_thread & operator = (const generic_thread & ref) { throw SRC_BUG; };
00065     virtual ~generic_thread();
00066 
00067         // inherited methods from generic_file
00068 
00069     virtual bool skippable(skippability direction, const infinint & amount);
00070     virtual bool skip(const infinint & pos);
00071     virtual bool skip_to_eof();
00072     virtual bool skip_relative(S_I x);
00073     virtual infinint get_position() const;
00074 
00075     protected:
00076         // inherited from generic_file
00077     virtual void inherited_read_ahead(const infinint & amount);
00078     virtual U_I inherited_read(char *a, U_I size);
00079     virtual void inherited_write(const char *a, U_I size);
00080 
00085     virtual void inherited_sync_write();
00086     virtual void inherited_flush_read();
00087     virtual void inherited_terminate();
00088 
00089 
00090     private:
00091     libthreadar::fast_tampon<char> toslave_data;
00092     libthreadar::fast_tampon<char> tomaster_data;
00093     libthreadar::fast_tampon<char> toslave_ctrl;
00094     libthreadar::fast_tampon<char> tomaster_ctrl;
00095     slave_thread *remote;
00096     bool reached_eof;     //< whether we reached end of file
00097     char data_header;     //< contains 1 byte header for data
00098     char data_header_eof; //< contains 1 byte header for data + eof
00099     bool running;         //< whether a remote is expected to run, tid is then set
00100     pthread_t tid;        //< thread id of remote
00101 
00102         // the following variables are locally used in quite all methods
00103         // they do not contain valuable information outside each method call
00104     messaging_encode order;
00105     messaging_decode answer;
00106     unsigned int num;
00107     char *ptr;
00108     label dataname;
00109 
00110     void send_order();
00111     void read_answer();   //< \note ptr must be released/recycled after this call
00112     void check_answer(msg_type expected);
00113     void wake_up_slave_if_asked(); //< check whether an order to wakeup the slave has been received, and send wake up the slave
00114     void release_block_answer() { tomaster_ctrl.fetch_recycle(ptr); ptr = nullptr; };
00115     void release_data_ptr();
00116     void purge_data_pipe(); //< drops all data in the toslave_data pipe
00117     void my_run();
00118     void my_join();
00119     };
00120 
00121 } // end of namespace
00122 
00123 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines