Disk ARchive  2.5.2
Full featured and portable backup and archiving tool
slave_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 SLAVE_THREAD_HPP
00029 #define SLAVE_THREAD_HPP
00030 
00031 #include "../my_config.h"
00032 
00033 #if HAVE_LIBTHREADAR_LIBTHREADAR_HPP
00034 #include <libthreadar/libthreadar.hpp>
00035 #endif
00036 
00037 #include "generic_file.hpp"
00038 #include "messaging.hpp"
00039 #include "erreurs.hpp"
00040 
00041 namespace libdar
00042 {
00043 
00044 
00045     class slave_thread : public libthreadar::thread, public on_pool
00046     {
00047     public:
00053     slave_thread(generic_file *x_data,
00054              libthreadar::fast_tampon<char> *x_input_data,
00055              libthreadar::fast_tampon<char> *x_output_data,
00056              libthreadar::fast_tampon<char> *x_input_ctrl,
00057              libthreadar::fast_tampon<char> *x_output_ctrl);
00058     slave_thread(const slave_thread & ref) { throw SRC_BUG; };
00059     const slave_thread & operator = (const slave_thread & ref) { throw SRC_BUG; };
00060 
00062     bool wake_me_up() const { if(wake_me) { const_cast<slave_thread *>(this)->wake_me = false; return true; } else return false; };
00063 
00064     protected:
00065     virtual void inherited_run();
00066 
00067     private:
00068     generic_file *data;
00069     libthreadar::fast_tampon<char> *input_data;
00070     libthreadar::fast_tampon<char> *output_data;
00071     libthreadar::fast_tampon<char> *input_ctrl;
00072     libthreadar::fast_tampon<char> *output_ctrl;
00073 
00074     messaging_encode answer;    //< used to communicate with master thread
00075     messaging_decode order;     //< used to communicate with master thread
00076     unsigned int num;           //< size of the read block or to be written block
00077     char *ptr;                  //< address of the block to be written or to be read
00078     char data_header;           //< the one byte message to prepend data with, when more data block follow to answer a given order
00079     char data_header_completed; //< the one byte message to prepend data with, when end of order is reached
00080     infinint read_ahead;        //< amount of data sent for reading and not yet asked for reading
00081     bool endless_read_ahead;    //< whether an endeless read ahead request has been asked
00082     infinint to_send_ahead;     //< remaining amount of data to send for the requested read_ahead
00083     U_I immediate_read;         //< next action is to read this amount of data
00084     bool stop;                  //< whether thread end has been asked
00085     bool wake_me;               //< whether we ask the master awake us
00086 
00087     void init();
00088     void set_header_vars(); //< set the value of data_header and data_header_completed fields
00089     void read_order();      //< \note ptr must be released/recycled after this call
00090     void send_answer();     //< send the answer to the last order received
00091     bool pending_order() { return input_ctrl->is_not_empty(); };
00092     bool pending_input_data() { return input_data->is_not_empty(); };
00093     void treat_input_data(); //< empty input_data and write down the data
00094     void ask_to_wake_me_up(); //< ask the master to wake the slave upon possible action
00095 
00103     U_I send_data_block(U_I size, bool & eof);
00104 
00105     bool treat_order(); //< \return true if answer is prepared and must be sent back to the master thread
00106 
00108     void go_read();
00109     };
00110 
00111 } // end of namespace
00112 
00113 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines