Disk ARchive  2.5.16
Full featured and portable backup and archiving tool
messaging.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2052 Denis Corbin
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 // to contact the author : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21 
26 
27 
28 #ifndef MESSAGING_HPP
29 #define MESSAGING_HPP
30 
31 #include "../my_config.h"
32 
33 #include <string>
34 
35 #include "label.hpp"
36 #include "infinint.hpp"
37 #include "memory_file.hpp"
38 #include "infinint.hpp"
39 
40 namespace libdar
41 {
42 
43  enum class msg_type
44  {
45  unset, //< no argument: message type is not set (error)
46  order_read_ahead, //< + infinint : messge is an info that the given amount of data is about to be read
47  order_read_ahead_begin, //< + infinint : message continues with the next block
48  order_read, //< + U_I : message is a read order (with expected size to be read ahead)
49  order_sync_write, //< no argument: order to flush all pending writes
50  answr_sync_write_done, //< no argument: answer from the slave that all data have been sync written
51  order_skip, //< + infinint : message is an order to seek at given position
52  order_skip_begin, //< + infinint : message is an order to seek but the seek info continues in the next message
53  order_skip_to_eof, //< no argument: message requesting slave to skip to end of file
54  order_skip_fwd, //< + U_I : order to skip foward
55  order_skip_bkd, //< + U_I : order to skip backward
56  answr_skip_done, //< + bool : answer for all kind of skip orders
57  order_skippable_fwd, //< + infinint : message from master containing a skippable forward request info
58  order_skippable_fwd_begin,//< + infinint : message continues on the next block
59  order_skippable_bkd, //< + infinint : message from master containing a skippable backward request info
60  order_skippable_bkd_begin,//< + infinint : message continues on the next block
61  answr_skippable, //< + bool : answer from slace to a skippable forward/backward request
62  order_get_position, //< no argument: order to get the current position in file
63  answr_position, //< + infinint : answer with the current position
64  answr_position_begin, //< + infinint : message continues with the next block
65  answr_exception, //< no argument: last operation generated an exception for at slave side, slave has probably died after that
66  order_end_of_xmit, //< no argument: message is the last message and implies freedom of the slave
67  order_stop_readahead, //< no argument: order to stop possibly running read_ahead
68  answr_readahead_stopped, //< no argument: answer that the readahead has ended or no read ahead was running
69  order_wakeup, //< no argument: order to continue reading/writing loop (reading suspendend because of pipe full, writing because of pipe was empty)
70  data_partial, //< + data : beside data in input/output data pipes
71  data_completed //< + data : beside data in output data pipe when EOF has been reached
72  };
73 
74  extern bool msg_equivalent(msg_type arg1, msg_type arg2);
75  extern bool msg_continues(msg_type msg);
76  extern char msg_type2char(msg_type x);
77  extern msg_type char2msg_type(char x);
78  extern msg_type msg_continuation_of(msg_type x);
79 
80 
81  class messaging_decode : public on_pool
82  {
83  public:
84  messaging_decode() {msgt = msg_type::unset; };
85 
87  void clear();
88 
95  bool add_block(const char *x_input, U_I x_size);
96 
98  msg_type get_type() const { return msgt; };
99 
101  infinint get_infinint() const;
102 
104  U_I get_U_I() const;
105 
107  std::string get_string() const;
108 
110  bool get_bool() const;
111 
113  label get_label() const;
114 
115  private:
116  msg_type msgt;
117  memory_file buffer;
118 
119  };
120 
121 
122  class messaging_encode : public on_pool
123  {
124  public:
126  messaging_encode() { msgt = msg_type::unset; };
127 
129  void clear();
130 
132  void set_type(msg_type val) { msgt = val; };
133 
135  void set_infinint(const infinint & val);
136 
138  void set_U_I(U_I val);
139 
141  void set_string(const std::string & val);
142 
144  void set_bool(bool val);
145 
147  void set_label(const label & val);
148 
150  void reset_get_block();
151 
162  bool get_block(char * ptr, unsigned int & size);
163 
164  private:
165  msg_type msgt;
166  memory_file buffer;
167 
168  };
169 
170 
171 } // end of namespace
172 
173 #endif
define the datastructure "label" used to identify slice membership to an archive
Memory_file is a generic_file class that only uses virtual memory.
switch module to limitint (32 ou 64 bits integers) or infinint
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47