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 
22     /// \file fichier_global.hpp
23     /// \brief class fichier_global definition. This class is a pure virtual class
24     /// class fichier_global is an abstraction of files objects whatever is their localisation
25     /// like local filesystem, remote ftp server, etc. inherited classes (like fichier_local)
26     /// provide full implementation
27 
28     /// \ingroup Private
29 
30 #ifndef FICHIER_GLOBAL_HPP
31 #define FICHIER_GLOBAL_HPP
32 
33 
34 #include "../my_config.h"
35 
36 extern "C"
37 {
38 #if HAVE_UNISTD_H
39 #include <unistd.h>
40 #endif
41 } // end extern "C"
42 
43 #include "integers.hpp"
44 #include "thread_cancellation.hpp"
45 #include "label.hpp"
46 #include "crc.hpp"
47 #include "user_interaction.hpp"
48 #include "mem_ui.hpp"
49 
50 #include <string>
51 
52 namespace libdar
53 {
54 
55 	/// \addtogroup Private
56 	/// @{
57 
58 	/// abstraction of filesystem files for entrepot
59 
60     class fichier_global : public generic_file, public thread_cancellation, public mem_ui
61     {
62     public :
63 	enum advise
64 	{
65 	    advise_normal,     //< no advise given by the application
66 	    advise_sequential, //< application expect to read the data sequentially
67 	    advise_random,     //< application expect to read the data in random order
68 	    advise_noreuse,    //< application does not expect to read the data more than once
69 	    advise_willneed,   //< application expect to read the data again in near future
70 	    advise_dontneed    //< application will not read the data in near future
71 	};
72 
73 	    /// constructors
74 	    ///
75 	    /// \note some well defined error case must generate an Esystem exception, other by Erange or more appropriated Egeneric exceptions
76 	    /// to known what type of error must be handled by Esystem object, see the Esystem::io_error enum
fichier_global(const user_interaction & dialog,gf_mode mode)77         fichier_global(const user_interaction & dialog, gf_mode mode): generic_file(mode), mem_ui(dialog) {};
fichier_global(const fichier_global & ref)78 	fichier_global(const fichier_global & ref) : generic_file(ref), thread_cancellation(ref), mem_ui(ref) {};
79 
80 	    // default assignment operator is fine here
81 	    // default destructor is fine too here
82 
83 	    /// set the ownership of the file
84 	virtual void change_ownership(const std::string & user, const std::string & group) = 0;
85 
86 	    /// change the permission of the file
87 	virtual void change_permission(U_I perm) = 0;
88 
89 	    /// return the size of the file
90         virtual infinint get_size() const = 0;
91 
92 	    /// set posix_fadvise for the whole file
93 	virtual void fadvise(advise adv) const = 0;
94 
95     protected :
96 	    /// replaces generic_file::inherited_write() method, to allow the return of partial writings
97 	    ///
98 	    /// a partial writing is allowed when no space is available for writing
99 	    /// this let global_ficher interact with the user asking whether it can make place
100 	    /// or if (s)he wants to abord
101 	    /// \param[in] a points to the start of the area of data to write
102 	    /// \param[in] size is the size in byte of the data to write
103 	    /// \return the amount of byte wrote. If the returned value is less than size, this
104 	    /// is a partial write, and is assumed that free storage space is missing to complete
105 	    /// the operation
106 	virtual U_I fichier_global_inherited_write(const char *a, U_I size) = 0;
107 
108 
109 	    /// replaces generic_file::inherited_read() method, to allow the return of partial reading
110 	    ///
111 	    /// a partial reading is signaled by the inherited class by returning false
112 	    /// \param[in] a points to the area where to store read data
113 	    /// \param[in] size is the available place to store data
114 	    /// \param[out] read is the total amount of data read so far
115 	    /// \param[out] message is the request to send to the user upon partial reading
116 	    /// \return true if the reading is full (either read the maximum allowed data or reached end of file)
117 	    /// false is returned if a user interaction can let the reading go further the message to display to the
118 	    /// user asking him for action. He will also be proposed to abort the current operation.
119 	virtual bool fichier_global_inherited_read(char *a, U_I size, U_I & read, std::string & message) = 0;
120 
121     private:
122 
123 	    // inherited from generic_file class and relocated as private methods
124 	void inherited_write(const char *a, U_I size);
125 	U_I inherited_read(char *a, U_I size);
126     };
127 
128 
129 	/// @}
130 
131 } // end of namespace
132 
133 #endif
134