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

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

user_interaction.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
33
35 // IMPORTANT : THIS FILE MUST ALWAYS BE INCLUDE AFTER infinint.hpp //
36 // (and infinint.hpp must be included too, always) //
38 #include "infinint.hpp"
40
41
42
43 #ifndef USER_INTERACTION_HPP
44 #define USER_INTERACTION_HPP
45
46 #include "../my_config.h"
47
48 #include <string>
49 #include "erreurs.hpp"
50 #include "integers.hpp"
51 #include "secu_string.hpp"
52 #include "on_pool.hpp"
53
54 namespace libdar
55 {
56
59
60
61
63
98 class user_interaction : public on_pool
99 {
100 public:
101
103 user_interaction();
104 virtual ~user_interaction() {};
105
107
111 virtual void pause(const std::string & message)
112 {
113 if(!pause2(message))
114 throw Euser_abort(message);
115 };
116
118
125 virtual bool pause2(const std::string & message)
126 { throw Elibcall("user_interaction::pause2", "user_interaction::pause() or pause2() must be overwritten !"); };
127
128
134 void warning(const std::string & message);
135
137
141 virtual std::string get_string(const std::string & message, bool echo) = 0;
142
144
148 virtual secu_string get_secu_string(const std::string & message, bool echo) = 0;
149
150
157
169 virtual void listing(const std::string & flag,
170 const std::string & perm,
171 const std::string & uid,
172 const std::string & gid,
173 const std::string & size,
174 const std::string & date,
175 const std::string & filename,
176 bool is_dir,
177 bool has_children);
178
179
180
187
192 virtual void dar_manager_show_files(const std::string & filename,
193 bool data_change,
194 bool ea_change);
195
196
203
208 virtual void dar_manager_contents(U_I number,
209 const std::string & chemin,
210 const std::string & archive_name);
211
218
225 virtual void dar_manager_statistics(U_I number,
226 const infinint & data_count,
227 const infinint & total_data,
228 const infinint & ea_count,
229 const infinint & total_ea);
230
237
244 virtual void dar_manager_show_version(U_I number,
245 const std::string & data_date,
246 const std::string & data_presence,
247 const std::string & ea_date,
248 const std::string & ea_presence);
249
251
259 void printf(const char *format, ...);
260
264
266 bool get_use_listing() const { return use_listing; };
268 bool get_use_dar_manager_show_files() const { return use_dar_manager_show_files; };
270 bool get_use_dar_manager_contents() const { return use_dar_manager_contents; };
272 bool get_use_dar_manager_statistics() const { return use_dar_manager_statistics; };
274 bool get_use_dar_manager_show_version() const { return use_dar_manager_show_version; };
275
276
278
284 virtual user_interaction *clone() const = 0;
285
287
292 void warning_with_more(U_I num) { at_once = num; count = 0; };
293
294 protected:
295
297
302 void set_use_listing(bool val) { use_listing = val; };
303
305 void set_use_dar_manager_show_files(bool val) { use_dar_manager_show_files = val; };
306
308 void set_use_dar_manager_contents(bool val) { use_dar_manager_contents = val; };
309
311 void set_use_dar_manager_statistics(bool val) { use_dar_manager_statistics = val; };
312
314 void set_use_dar_manager_show_version(bool val) { use_dar_manager_show_version = val; };
315
317
320 virtual void inherited_warning(const std::string & message) = 0;
321
322 private:
323 bool use_listing;
324 bool use_dar_manager_show_files;
325 bool use_dar_manager_contents;
326 bool use_dar_manager_statistics;
327 bool use_dar_manager_show_version;
328 U_I at_once, count;
329
330 };
331
332
334
338 class user_interaction_callback : public user_interaction
339 {
340 public:
341
343
354 user_interaction_callback(void (*x_warning_callback)(const std::string &x, void *context),
355 bool (*x_answer_callback)(const std::string &x, void *context),
356 std::string (*x_string_callback)(const std::string &x, bool echo, void *context),
357 secu_string (*x_secu_string_callback)(const std::string &x, bool echo, void *context),
358 void *context_value);
359
361 void pause(const std::string & message);
363 std::string get_string(const std::string & message, bool echo);
365 secu_string get_secu_string(const std::string & message, bool echo);
367 void listing(const std::string & flag,
368 const std::string & perm,
369 const std::string & uid,
370 const std::string & gid,
371 const std::string & size,
372 const std::string & date,
373 const std::string & filename,
374 bool is_dir,
375 bool has_children);
376
378 void dar_manager_show_files(const std::string & filename,
379 bool available_data,
380 bool available_ea);
381
383 void dar_manager_contents(U_I number,
384 const std::string & chemin,
385 const std::string & archive_name);
386
388 void dar_manager_statistics(U_I number,
389 const infinint & data_count,
390 const infinint & total_data,
391 const infinint & ea_count,
392 const infinint & total_ea);
393
395 void dar_manager_show_version(U_I number,
396 const std::string & data_date,
397 const std::string & data_presence,
398 const std::string & ea_date,
399 const std::string & ea_presence);
400
402
406 void set_listing_callback(void (*callback)(const std::string & flag,
407 const std::string & perm,
408 const std::string & uid,
409 const std::string & gid,
410 const std::string & size,
411 const std::string & date,
412 const std::string & filename,
413 bool is_dir,
414 bool has_children,
415 void *context))
416 {
417 tar_listing_callback = callback;
418 set_use_listing(true); // this is to inform libdar to use listing()
419 };
420
421 // You can set a dar_manager_show_files callback thanks to this method
422
423 void set_dar_manager_show_files_callback(void (*callback)(const std::string & filename,
424 bool available_data,
425 bool available_ea,
426 void *context))
427 {
428 dar_manager_show_files_callback = callback;
429 set_use_dar_manager_show_files(true); // this is to inform libdar to use the dar_manager_show_files() method
430 };
431
432 void set_dar_manager_contents_callback(void (*callback)(U_I number,
433 const std::string & chemin,
434 const std::string & archive_name,
435 void *context))
436 {
437 dar_manager_contents_callback = callback;
438 set_use_dar_manager_contents(true); // this is to inform libdar to use the dar_manager_contents() method
439 };
440
441 void set_dar_manager_statistics_callback(void (*callback)(U_I number,
442 const infinint & data_count,
443 const infinint & total_data,
444 const infinint & ea_count,
445 const infinint & total_ea,
446 void *context))
447 {
448 dar_manager_statistics_callback = callback;
449 set_use_dar_manager_statistics(true); // this is to inform libdar to use the dar_manager_statistics() method
450 };
451
452 void set_dar_manager_show_version_callback(void (*callback)(U_I number,
453 const std::string & data_date,
454 const std::string & data_presence,
455 const std::string & ea_date,
456 const std::string & ea_presence,
457 void *context))
458 {
459 dar_manager_show_version_callback = callback;
460 set_use_dar_manager_show_version(true); // this is to inform libdar to use the dar_manager_show_version() method
461 };
462
463
465 virtual user_interaction *clone() const;
466
467 protected:
469 void change_context_value(void *new_value) { context_val = new_value; };
470
472 void inherited_warning(const std::string & message);
473
474 private:
475 void (*warning_callback)(const std::string & x, void *context); // pointer to function
476 bool (*answer_callback)(const std::string & x, void *context); // pointer to function
477 std::string (*string_callback)(const std::string & x, bool echo, void *context); // pointer to function
478 secu_string (*secu_string_callback)(const std::string & x, bool echo, void *context); // pointer to function
479 void (*tar_listing_callback)(const std::string & flags,
480 const std::string & perm,
481 const std::string & uid,
482 const std::string & gid,
483 const std::string & size,
484 const std::string & date,
485 const std::string & filename,
486 bool is_dir,
487 bool has_children,
488 void *context);
489 void (*dar_manager_show_files_callback)(const std::string & filename,
490 bool available_data,
491 bool available_ea,
492 void *context);
493 void (*dar_manager_contents_callback)(U_I number,
494 const std::string & chemin,
495 const std::string & archive_name,
496 void *context);
497 void (*dar_manager_statistics_callback)(U_I number,
498 const infinint & data_count,
499 const infinint & total_data,
500 const infinint & ea_count,
501 const infinint & total_ea,
502 void *context);
503 void (*dar_manager_show_version_callback)(U_I number,
504 const std::string & data_date,
505 const std::string & data_presence,
506 const std::string & ea_date,
507 const std::string & ea_presence,
508 void *context);
509
510 void *context_val;
511 };
512
513
515
516 class user_interaction_blind : public user_interaction
517 {
518 public:
519 bool pause2(const std::string & message) { return false; };
520
521 std::string get_string(const std::string & message, bool echo) { return "user_interaction_blind, is blindly answering no"; };
522 secu_string get_secu_string(const std::string & message, bool echo) { return secu_string(); };
523
524 user_interaction *clone() const { user_interaction *ret = new (get_pool()) user_interaction_blind(); if(ret == nullptr) throw Ememory("user_interaction_blind::clone"); return ret; };
525
526 protected:
527 void inherited_warning(const std::string & message) {}; // do not display any warning, this is "bind user_interaction" !
528
529 };
530
532
533 } // end of namespace
534
535 #endif
libdar::on_pool
Definition: on_pool.hpp:52
libdar::user_interaction::warning
void warning(const std::string &message)
method used to display a warning or a message to the user.
libdar::Elibcall
exception used to signal an error in the argument given to libdar call of the API ...
Definition: erreurs.hpp:272
libdar::user_interaction_blind::get_string
std::string get_string(const std::string &message, bool echo)
method used to ask a question that needs an arbitrary answer.
Definition: user_interaction.hpp:521
libdar::user_interaction_blind::inherited_warning
void inherited_warning(const std::string &message)
need to be overwritten in place of the warning() method since API 3.1.x
Definition: user_interaction.hpp:527
integers.hpp
are defined here basic integer types that tend to be portable
libdar::user_interaction::set_use_listing
void set_use_listing(bool val)
method to be called with true as argument if you have defined a listing() method. ...
Definition: user_interaction.hpp:302
libdar::user_interaction::dar_manager_show_version
virtual void dar_manager_show_version(U_I number, const std::string &data_date, const std::string &data_presence, const std::string &ea_date, const std::string &ea_presence)
libdar::user_interaction_callback::inherited_warning
void inherited_warning(const std::string &message)
overwritting method from parent class.
libdar::user_interaction_callback::get_string
std::string get_string(const std::string &message, bool echo)
overwritting method from parent class.
libdar::user_interaction_callback::set_listing_callback
void set_listing_callback(void(*callback)(const std::string &flag, const std::string &perm, const std::string &uid, const std::string &gid, const std::string &size, const std::string &date, const std::string &filename, bool is_dir, bool has_children, void *context))
You can set a listing callback thanks to this method.
Definition: user_interaction.hpp:406
libdar::user_interaction::dar_manager_statistics
virtual void dar_manager_statistics(U_I number, const infinint &data_count, const infinint &total_data, const infinint &ea_count, const infinint &total_ea)
libdar::user_interaction_callback::dar_manager_show_version
void dar_manager_show_version(U_I number, const std::string &data_date, const std::string &data_presence, const std::string &ea_date, const std::string &ea_presence)
overwritting method from parent class
libdar::user_interaction::pause2
virtual bool pause2(const std::string &message)
alternative method to the pause() method
Definition: user_interaction.hpp:125
libdar::user_interaction::listing
virtual void listing(const std::string &flag, const std::string &perm, const std::string &uid, const std::string &gid, const std::string &size, const std::string &date, const std::string &filename, bool is_dir, bool has_children)
libdar::user_interaction
This is a pure virtual class that is used by libdar when interaction with the user is required...
Definition: user_interaction.hpp:98
libdar::user_interaction_callback::clone
virtual user_interaction * clone() const
overwritting method from parent class.
libdar::user_interaction::get_use_dar_manager_show_version
bool get_use_dar_manager_show_version() const
this is not a virtual method, it has not to be overwritten in inherited classes.
Definition: user_interaction.hpp:274
libdar::user_interaction::dar_manager_contents
virtual void dar_manager_contents(U_I number, const std::string &chemin, const std::string &archive_name)
libdar::user_interaction::pause
virtual void pause(const std::string &message)
method used to ask a boolean question to the user.
Definition: user_interaction.hpp:111
libdar::user_interaction::clone
virtual user_interaction * clone() const =0
make a newly allocated object which has the same properties as "this".
libdar::user_interaction::get_use_listing
bool get_use_listing() const
this is not a virtual method, it has not to be overwritten in inherited classes.
Definition: user_interaction.hpp:266
libdar::user_interaction::set_use_dar_manager_show_files
void set_use_dar_manager_show_files(bool val)
method to be called with true as argument if you have defined a dar_manager_show_files() method...
Definition: user_interaction.hpp:305
libdar::user_interaction_callback::pause
void pause(const std::string &message)
overwritting method from parent class.
libdar::user_interaction::get_secu_string
virtual secu_string get_secu_string(const std::string &message, bool echo)=0
same a get_string() but uses secu_string instead
libdar::user_interaction::get_string
virtual std::string get_string(const std::string &message, bool echo)=0
method used to ask a question that needs an arbitrary answer.
libdar::user_interaction_callback
full implemented class for user_interaction based on callback functions.
Definition: user_interaction.hpp:338
libdar::on_pool::get_pool
memory_pool * get_pool() const
Definition: on_pool.hpp:144
libdar::user_interaction::get_use_dar_manager_contents
bool get_use_dar_manager_contents() const
this is not a virtual method, it has not to be overwritten in inherited classes.
Definition: user_interaction.hpp:270
libdar::user_interaction_blind::clone
user_interaction * clone() const
make a newly allocated object which has the same properties as "this".
Definition: user_interaction.hpp:524
libdar::user_interaction_callback::get_secu_string
secu_string get_secu_string(const std::string &message, bool echo)
overwritting method from parent class.
libdar::user_interaction_callback::listing
void listing(const std::string &flag, const std::string &perm, const std::string &uid, const std::string &gid, const std::string &size, const std::string &date, const std::string &filename, bool is_dir, bool has_children)
overwritting method from parent class.
libdar::user_interaction_blind::get_secu_string
secu_string get_secu_string(const std::string &message, bool echo)
same a get_string() but uses secu_string instead
Definition: user_interaction.hpp:522
libdar::user_interaction::dar_manager_show_files
virtual void dar_manager_show_files(const std::string &filename, bool data_change, bool ea_change)
libdar::Ememory
exception used when memory has been exhausted
Definition: erreurs.hpp:111
libdar::user_interaction_blind
full implementation class for user_interaction, which shows nothing and assumes answer "no" to any qu...
Definition: user_interaction.hpp:516
libdar::user_interaction::user_interaction
user_interaction()
class constructor.
libdar::user_interaction::get_use_dar_manager_show_files
bool get_use_dar_manager_show_files() const
this is not a virtual method, it has not to be overwritten in inherited classes.
Definition: user_interaction.hpp:268
libdar::user_interaction_callback::user_interaction_callback
user_interaction_callback(void(*x_warning_callback)(const std::string &x, void *context), bool(*x_answer_callback)(const std::string &x, void *context), std::string(*x_string_callback)(const std::string &x, bool echo, void *context), secu_string(*x_secu_string_callback)(const std::string &x, bool echo, void *context), void *context_value)
constructor which receive the callback functions.
libdar::user_interaction_callback::dar_manager_contents
void dar_manager_contents(U_I number, const std::string &chemin, const std::string &archive_name)
overwritting method from parent class
libdar::user_interaction::get_use_dar_manager_statistics
bool get_use_dar_manager_statistics() const
this is not a virtual method, it has not to be overwritten in inherited classes.
Definition: user_interaction.hpp:272
erreurs.hpp
contains all the excetion class thrown by libdar
libdar::user_interaction::warning_with_more
void warning_with_more(U_I num)
make a pause each N line of output when calling the warning method
Definition: user_interaction.hpp:292
infinint.hpp
switch module to limitint (32 ou 64 bits integers) or infinint
libdar::user_interaction::set_use_dar_manager_show_version
void set_use_dar_manager_show_version(bool val)
method to be called with true as argument if you have defined a dar_manager_show_version() method...
Definition: user_interaction.hpp:314
libdar::user_interaction_blind::pause2
bool pause2(const std::string &message)
alternative method to the pause() method
Definition: user_interaction.hpp:519
libdar::user_interaction_callback::dar_manager_statistics
void dar_manager_statistics(U_I number, const infinint &data_count, const infinint &total_data, const infinint &ea_count, const infinint &total_ea)
overwritting method from parent class
libdar::user_interaction_callback::change_context_value
void change_context_value(void *new_value)
change the context value of the object that will be given to callback functions
Definition: user_interaction.hpp:469
libdar::user_interaction::inherited_warning
virtual void inherited_warning(const std::string &message)=0
need to be overwritten in place of the warning() method since API 3.1.x
libdar::secu_string
class secu_string
Definition: secu_string.hpp:57
libdar::user_interaction_callback::dar_manager_show_files
void dar_manager_show_files(const std::string &filename, bool available_data, bool available_ea)
overwritting method from parent class
on_pool.hpp
this is the base class of object that can be allocated on a memory pool
libdar::Euser_abort
exception used to signal that the user has aborted the operation
Definition: erreurs.hpp:232
libdar::infinint
the arbitrary large positive integer class
Definition: real_infinint.hpp:59
libdar::user_interaction::set_use_dar_manager_contents
void set_use_dar_manager_contents(bool val)
method to be called with true as argument if you have defined a dar_manager_contents() method...
Definition: user_interaction.hpp:308
libdar::user_interaction::set_use_dar_manager_statistics
void set_use_dar_manager_statistics(bool val)
method to be called with true as argument if you have defined a dar_manager_statistics() method...
Definition: user_interaction.hpp:311
libdar::user_interaction::printf
void printf(const char *format,...)
libdar uses this call to format output before send to warning() method.
secu_string.hpp
this file contains the definition of secu_string class, a std::string like class but allocated in sec...
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47