| Disk ARchive 2.6.11 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-2020 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // to contact the author : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21
25
26
27 #ifndef MESSAGING_HPP
28 #define MESSAGING_HPP
29
30 #include "../my_config.h"
31
32 #include <string>
33
34 #include "label.hpp"
35 #include "infinint.hpp"
36 #include "memory_file.hpp"
37
38 namespace libdar
39 {
40
43
45
46 enum class msg_type
47 {
48 unset, //< no argument: message type is not set (error)
49 order_read_ahead, //< + infinint : messge is an info that the given amount of data is about to be read
50 order_read_ahead_begin, //< + infinint : message continues with the next block
51 order_read, //< + U_I : message is a read order (with expected size to be read ahead)
52 order_sync_write, //< no argument: order to flush all pending writes
53 answr_sync_write_done, //< no argument: answer from the slave that all data have been sync written
54 order_skip, //< + infinint : message is an order to seek at given position
55 order_skip_begin, //< + infinint : message is an order to seek but the seek info continues in the next message
56 order_skip_to_eof, //< no argument: message requesting slave to skip to end of file
57 order_skip_fwd, //< + U_I : order to skip foward
58 order_skip_bkd, //< + U_I : order to skip backward
59 answr_skip_done, //< + bool : answer for all kind of skip orders
60 order_skippable_fwd, //< + infinint : message from master containing a skippable forward request info
61 order_skippable_fwd_begin,//< + infinint : message continues on the next block
62 order_skippable_bkd, //< + infinint : message from master containing a skippable backward request info
63 order_skippable_bkd_begin,//< + infinint : message continues on the next block
64 answr_skippable, //< + bool : answer from slace to a skippable forward/backward request
65 order_get_position, //< no argument: order to get the current position in file
66 answr_position, //< + infinint : answer with the current position
67 answr_position_begin, //< + infinint : message continues with the next block
68 answr_exception, //< no argument: last operation generated an exception for at slave side, slave has probably died after that
69 order_end_of_xmit, //< no argument: message is the last message and implies freedom of the slave
70 order_stop_readahead, //< no argument: order to stop possibly running read_ahead
71 answr_readahead_stopped, //< no argument: answer that the readahead has ended or no read ahead was running
72 order_wakeup, //< no argument: order to continue reading/writing loop (reading suspendend because of pipe full, writing because of pipe was empty)
73 data_partial, //< + data : beside data in input/output data pipes
74 data_completed //< + data : beside data in output data pipe when EOF has been reached
75 };
76
77 extern bool msg_equivalent(msg_type arg1, msg_type arg2);
78 extern bool msg_continues(msg_type msg);
79 extern char msg_type2char(msg_type x);
80 extern msg_type char2msg_type(char x);
81 extern msg_type msg_continuation_of(msg_type x);
82
84
85 class messaging_decode
86 {
87 public:
88 messaging_decode() {msgt = msg_type::unset; };
89 messaging_decode(const messaging_decode & ref) = default;
90 messaging_decode(messaging_decode && ref) noexcept = default;
91 messaging_decode & operator = (const messaging_decode & ref) = default;
92 messaging_decode & operator = (messaging_decode && ref) noexcept = default;
93 ~messaging_decode() = default;
94
96 void clear();
97
104 bool add_block(const char *x_input, U_I x_size);
105
107 msg_type get_type() const { return msgt; };
108
110 infinint get_infinint() const;
111
113 U_I get_U_I() const;
114
116 std::string get_string() const;
117
119 bool get_bool() const;
120
122 label get_label() const;
123
124 private:
125 msg_type msgt;
126 memory_file buffer;
127
128 };
129
131
132 class messaging_encode
133 {
134 public:
136 messaging_encode() { msgt = msg_type::unset; };
137 messaging_encode(const messaging_encode & ref) = default;
138 messaging_encode(messaging_encode && ref) noexcept = default;
139 messaging_encode & operator = (const messaging_encode & ref) = default;
140 messaging_encode & operator = (messaging_encode && ref) noexcept = default;
141 ~messaging_encode() = default;
142
144 void clear();
145
147 void set_type(msg_type val) { msgt = val; };
148
150 void set_infinint(const infinint & val);
151
153 void set_U_I(U_I val);
154
156 void set_string(const std::string & val);
157
159 void set_bool(bool val);
160
162 void set_label(const label & val);
163
165 void reset_get_block();
166
177 bool get_block(char * ptr, unsigned int & size);
178
179 private:
180 msg_type msgt;
181 memory_file buffer;
182
183 };
184
186
187 } // end of namespace
188
189 #endif
libdar::messaging_encode::clear
void clear()
reset the object to its initial state
libdar::messaging_encode::set_label
void set_label(const label &val)
set label attribute
libdar::messaging_encode::set_string
void set_string(const std::string &val)
add string attribute
libdar::messaging_decode::get_string
std::string get_string() const
for messages of type order_set_context
libdar::messaging_encode::reset_get_block
void reset_get_block()
set the read block pointer to the first block
libdar::messaging_decode::get_bool
bool get_bool() const
for messages of type anwsr_oldarchive
libdar::label
manage label data structure used in archive slice headers
Definition: label.hpp:43
libdar::messaging_decode
decoding received messages
Definition: messaging.hpp:86
libdar::messaging_encode::set_bool
void set_bool(bool val)
set boolean attribute
infinint.hpp
switch module to limitint (32 ou 64 bits integers) or infinint
libdar::infinint
the arbitrary large positive integer class
Definition: real_infinint.hpp:62
libdar::messaging_encode::set_U_I
void set_U_I(U_I val)
add U_I attribute
libdar::messaging_encode::messaging_encode
messaging_encode()
constructor
Definition: messaging.hpp:136
libdar::messaging_decode::get_label
label get_label() const
for messages of type answr_get_dataname,
label.hpp
define the datastructure "label" used to identify slice membership to an archive
libdar::messaging_encode
encoding messages to be sent
Definition: messaging.hpp:133
libdar::messaging_decode::get_type
msg_type get_type() const
get the type of message pointed to at construction time
Definition: messaging.hpp:107
libdar::messaging_encode::set_infinint
void set_infinint(const infinint &val)
add infininit attribute
libdar::messaging_decode::clear
void clear()
reset the object to its initial state
memory_file.hpp
Memory_file is a generic_file class that only uses virtual memory.
libdar::memory_file
generic_file stored in memory
Definition: memory_file.hpp:41
libdar::messaging_decode::add_block
bool add_block(const char *x_input, U_I x_size)
libdar::messaging_decode::get_infinint
infinint get_infinint() const
for messages of type order_skip, answr_filesize, order_read_ahead, answr_filesize,
libdar::messaging_decode::get_U_I
U_I get_U_I() const
for messages of type order_read
libdar::msg_type
msg_type
the different types of messages
Definition: messaging.hpp:47
libdar::messaging_encode::set_type
void set_type(msg_type val)
define the type of the message to generate
Definition: messaging.hpp:147
libdar::messaging_encode::get_block
bool get_block(char *ptr, unsigned int &size)
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47