Disk ARchive  2.5.6
Full featured and portable backup and archiving tool
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 
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 
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 
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
void warning(const std::string &message)
method used to display a warning or a message to the user.
exception used to signal an error in the argument given to libdar call of the API ...
Definition: erreurs.hpp:272
std::string get_string(const std::string &message, bool echo)
method used to ask a question that needs an arbitrary answer.
void inherited_warning(const std::string &message)
need to be overwritten in place of the warning() method since API 3.1.x
memory_pool * get_pool() const
Definition: on_pool.hpp:144
are defined here basic integer types that tend to be portable
void set_use_listing(bool val)
method to be called with true as argument if you have defined a listing() method. ...
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)
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.
virtual void dar_manager_statistics(U_I number, const infinint &data_count, const infinint &total_data, const infinint &ea_count, const infinint &total_ea)
virtual bool pause2(const std::string &message)
alternative method to the pause() method
bool get_use_listing() const
this is not a virtual method, it has not to be overwritten in inherited classes.
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)
user_interaction * clone() const
make a newly allocated object which has the same properties as "this".
This is a pure virtual class that is used by libdar when interaction with the user is required...
virtual void dar_manager_contents(U_I number, const std::string &chemin, const std::string &archive_name)
virtual void pause(const std::string &message)
method used to ask a boolean question to the user.
virtual user_interaction * clone() const =0
make a newly allocated object which has the same properties as "this".
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...
bool get_use_dar_manager_contents() const
this is not a virtual method, it has not to be overwritten in inherited classes.
virtual secu_string get_secu_string(const std::string &message, bool echo)=0
same a get_string() but uses secu_string instead
virtual std::string get_string(const std::string &message, bool echo)=0
method used to ask a question that needs an arbitrary answer.
full implemented class for user_interaction based on callback functions.
secu_string get_secu_string(const std::string &message, bool echo)
same a get_string() but uses secu_string instead
virtual void dar_manager_show_files(const std::string &filename, bool data_change, bool ea_change)
exception used when memory has been exhausted
Definition: erreurs.hpp:111
full implementation class for user_interaction, which shows nothing and assumes answer "no" to any qu...
user_interaction()
class constructor.
bool get_use_dar_manager_show_version() const
this is not a virtual method, it has not to be overwritten in inherited classes.
contains all the excetion class thrown by libdar
void warning_with_more(U_I num)
make a pause each N line of output when calling the warning method
switch module to limitint (32 ou 64 bits integers) or infinint
bool get_use_dar_manager_statistics() const
this is not a virtual method, it has not to be overwritten in inherited classes.
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...
bool pause2(const std::string &message)
alternative method to the pause() method
void change_context_value(void *new_value)
change the context value of the object that will be given to callback functions
bool get_use_dar_manager_show_files() const
this is not a virtual method, it has not to be overwritten in inherited classes.
virtual void inherited_warning(const std::string &message)=0
need to be overwritten in place of the warning() method since API 3.1.x
class secu_string
Definition: secu_string.hpp:57
this is the base class of object that can be allocated on a memory pool
exception used to signal that the user has aborted the operation
Definition: erreurs.hpp:232
the arbitrary large positive integer class
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...
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...
void printf(const char *format,...)
libdar uses this call to format output before send to warning() method.
this file contains the definition of secu_string class, a std::string like class but allocated in sec...
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47