Disk ARchive  2.5.2
Full featured and portable backup and archiving tool
messaging.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 MESSAGING_HPP
00029 #define MESSAGING_HPP
00030 
00031 #include "../my_config.h"
00032 
00033 #include <string>
00034 
00035 #include "label.hpp"
00036 #include "infinint.hpp"
00037 #include "memory_file.hpp"
00038 #include "infinint.hpp"
00039 
00040 namespace libdar
00041 {
00042 
00043     enum class msg_type
00044     {
00045     unset,                    //< no argument: message type is not set (error)
00046     order_read_ahead,         //< + infinint : messge is an info that the given amount of data is about to be read
00047     order_read_ahead_begin,   //< + infinint : message continues with the next block
00048     order_read,               //< + U_I      : message is a read order (with expected size to be read ahead)
00049     order_sync_write,         //< no argument: order to flush all pending writes
00050     answr_sync_write_done,    //< no argument: answer from the slave that all data have been sync written
00051     order_skip,               //< + infinint : message is an order to seek at given position
00052     order_skip_begin,         //< + infinint : message is an order to seek but the seek info continues in the next message
00053     order_skip_to_eof,        //< no argument: message requesting slave to skip to end of file
00054     order_skip_fwd,           //< + U_I      : order to skip foward
00055     order_skip_bkd,           //< + U_I      : order to skip backward
00056     answr_skip_done,          //< + bool     : answer for all kind of skip orders
00057     order_skippable_fwd,      //< + infinint : message from master containing a skippable forward request info
00058     order_skippable_fwd_begin,//< + infinint : message continues on the next block
00059     order_skippable_bkd,      //< + infinint : message from master containing a skippable backward request info
00060     order_skippable_bkd_begin,//< + infinint : message continues on the next block
00061     answr_skippable,          //< + bool     : answer from slace to a skippable forward/backward request
00062     order_get_position,       //< no argument: order to get the current position in file
00063     answr_position,           //< + infinint : answer with the current position
00064     answr_position_begin,     //< + infinint : message continues with the next block
00065     answr_exception,          //< no argument: last operation generated an exception for at slave side, slave has probably died after that
00066     order_end_of_xmit,        //< no argument: message is the last message and implies freedom of the slave
00067         order_stop_readahead,     //< no argument: order to stop possibly running read_ahead
00068     answr_readahead_stopped,  //< no argument: answer that the readahead has ended or no read ahead was running
00069     order_wakeup,             //< no argument: order to continue reading/writing loop (reading suspendend because of pipe full, writing because of pipe was empty)
00070     data_partial,             //< + data     : beside data in input/output data pipes
00071     data_completed            //< + data     : beside data in output data pipe when EOF has been reached
00072     };
00073 
00074     extern bool msg_equivalent(msg_type arg1, msg_type arg2);
00075     extern bool msg_continues(msg_type msg);
00076     extern char msg_type2char(msg_type x);
00077     extern msg_type char2msg_type(char x);
00078     extern msg_type msg_continuation_of(msg_type x);
00079 
00080 
00081     class messaging_decode : public on_pool
00082     {
00083     public:
00084     messaging_decode() {msgt = msg_type::unset; };
00085 
00087     void clear();
00088 
00095     bool add_block(const char *x_input, U_I x_size);
00096 
00098     msg_type get_type() const { return msgt; };
00099 
00101     infinint get_infinint() const;
00102 
00104     U_I get_U_I() const;
00105 
00107     std::string get_string() const;
00108 
00110     bool get_bool() const;
00111 
00113     label get_label() const;
00114 
00115     private:
00116     msg_type msgt;
00117     memory_file buffer;
00118 
00119     };
00120 
00121 
00122     class messaging_encode : public on_pool
00123     {
00124     public:
00126     messaging_encode() { msgt = msg_type::unset; };
00127 
00129     void clear();
00130 
00132     void set_type(msg_type val) { msgt = val; };
00133 
00135     void set_infinint(const infinint & val);
00136 
00138     void set_U_I(U_I val);
00139 
00141     void set_string(const std::string & val);
00142 
00144     void set_bool(bool val);
00145 
00147     void set_label(const label & val);
00148 
00150     void reset_get_block();
00151 
00162     bool get_block(char * ptr, unsigned int & size);
00163 
00164     private:
00165     msg_type msgt;
00166     memory_file buffer;
00167 
00168     };
00169 
00170 
00171 } // end of namespace
00172 
00173 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines