| Disk ARchive 2.6.11 Full featured and portable backup and archiving tool

generic_thread.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 GENERIC_THREAD_HPP
28 #define GENERIC_THREAD_HPP
29
30 #include "../my_config.h"
31
32 #include "generic_file.hpp"
33 #include "messaging.hpp"
34 #include "slave_thread.hpp"
35
36 namespace libdar
37 {
38
41
43
44 class generic_thread : public generic_file
45 {
46 public:
47 // default values for constuctor
48 static constexpr unsigned int tampon_block_size = 102401;
49 static constexpr unsigned int tampon_num_block = 1000;
50 static constexpr unsigned int tampon_block_size_ctrl = 1024;
51 static constexpr unsigned int tampon_num_block_ctrl = 10;
52
54
62 generic_thread(generic_file *ptr,
63 U_I data_block_size = tampon_block_size,
64 U_I data_num_block = tampon_num_block,
65 U_I ctrl_block_size = tampon_block_size_ctrl,
66 U_I ctrl_num_block = tampon_num_block_ctrl);
67 generic_thread(const generic_thread & ref) = delete;
68 generic_thread(generic_thread && ref) noexcept = delete;
69 generic_thread & operator = (const generic_thread & ref) = delete;
70 generic_thread & operator = (generic_thread && ref) noexcept = delete;
71 virtual ~generic_thread();
72
73 // inherited methods from generic_file
74
75 virtual bool skippable(skippability direction, const infinint & amount) override;
76 virtual bool skip(const infinint & pos) override;
77 virtual bool skip_to_eof() override;
78 virtual bool skip_relative(S_I x) override;
79 virtual infinint get_position() const override;
80
81 protected:
82 // inherited from generic_file
83 virtual void inherited_read_ahead(const infinint & amount) override;
84 virtual U_I inherited_read(char *a, U_I size) override;
85 virtual void inherited_write(const char *a, U_I size) override;
86
88
91 virtual void inherited_sync_write() override;
92 virtual void inherited_flush_read() override;
93 virtual void inherited_terminate() override;
94
95
96 private:
97 libthreadar::fast_tampon<char> toslave_data;
98 libthreadar::fast_tampon<char> tomaster_data;
99 libthreadar::fast_tampon<char> toslave_ctrl;
100 libthreadar::fast_tampon<char> tomaster_ctrl;
101 slave_thread *remote;
102 bool reached_eof;
103 char data_header;
104 char data_header_eof;
105 bool running;
106 pthread_t tid;
107
108 // the following variables are locally used in quite all methods
109 // they do not contain valuable information outside each method call
110 messaging_encode order;
111 messaging_decode answer;
112 unsigned int num;
113 char *ptr;
114 label dataname;
115
116 void send_order();
117 void read_answer();
118 void check_answer(msg_type expected);
119 void wake_up_slave_if_asked();
120 void release_block_answer() { tomaster_ctrl.fetch_recycle(ptr); ptr = nullptr; };
121 void release_data_ptr();
122 void purge_data_pipe();
123 void my_run();
124 void my_join();
125 };
126
127 } // end of namespace
128
129 #endif
libdar::generic_thread::purge_data_pipe
void purge_data_pipe()
drops all data in the toslave_data pipe
libdar::generic_thread::inherited_read_ahead
virtual void inherited_read_ahead(const infinint &amount) override
tells the object that several calls to read() will follow to probably obtain at least the given amoun...
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::generic_thread::skippable
virtual bool skippable(skippability direction, const infinint &amount) override
whether the implementation is able to skip
libdar::generic_thread::inherited_terminate
virtual void inherited_terminate() override
destructor-like call, except that it is allowed to throw exceptions
libdar::infinint
the arbitrary large positive integer class
Definition: real_infinint.hpp:62
messaging.hpp
messaging_decode and messaging_encode are used to insert messages in a flow of data blocks
libdar::generic_thread::data_header
char data_header
contains 1 byte header for data
Definition: generic_thread.hpp:103
libdar::generic_thread::inherited_read
virtual U_I inherited_read(char *a, U_I size) override
implementation of read() operation
libdar::generic_thread::data_header_eof
char data_header_eof
contains 1 byte header for data + eof
Definition: generic_thread.hpp:104
libdar::generic_thread::inherited_write
virtual void inherited_write(const char *a, U_I size) override
implementation of the write() operation
libdar::generic_thread::skip_relative
virtual bool skip_relative(S_I x) override
skip relatively to the current position
libdar::generic_thread::get_position
virtual infinint get_position() const override
get the current read/write position
libdar::messaging_encode
encoding messages to be sent
Definition: messaging.hpp:133
libdar::generic_thread::wake_up_slave_if_asked
void wake_up_slave_if_asked()
check whether an order to wakeup the slave has been received, and send wake up the slave
generic_file.hpp
class generic_file is defined here as well as class fichier
libdar::generic_thread::inherited_sync_write
virtual void inherited_sync_write() override
generic_file inherited method to sync all pending writes
libdar::generic_thread
let a generic_file be managed by another thread
Definition: generic_thread.hpp:45
libdar::generic_thread::skip_to_eof
virtual bool skip_to_eof() override
skip to the end of file
libdar::generic_thread::reached_eof
bool reached_eof
whether we reached end of file
Definition: generic_thread.hpp:102
libdar::generic_file
this is the interface class from which all other data transfer classes inherit
Definition: generic_file.hpp:77
libdar::generic_thread::skip
virtual bool skip(const infinint &pos) override
skip at the absolute position
libdar::generic_thread::tid
pthread_t tid
thread id of remote
Definition: generic_thread.hpp:106
libdar::generic_thread::inherited_flush_read
virtual void inherited_flush_read() override
reset internal engine, flush caches in order to read the data at current position
libdar::generic_thread::running
bool running
whether a remote is expected to run, tid is then set
Definition: generic_thread.hpp:105
slave_thread.hpp
class slave_thread is runs a I/O operations on a given generic_file in a separated thread
libdar::msg_type
msg_type
the different types of messages
Definition: messaging.hpp:47
libdar::generic_thread::generic_thread
generic_thread(generic_file *ptr, U_I data_block_size=tampon_block_size, U_I data_num_block=tampon_num_block, U_I ctrl_block_size=tampon_block_size_ctrl, U_I ctrl_num_block=tampon_num_block_ctrl)
constructor
libdar::generic_thread::read_answer
void read_answer()
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47