Disk ARchive  2.4.15
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
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 
53 namespace libdar
54 {
55 
58 
59 
60 
62 
98  {
99  public:
100 
103  virtual ~user_interaction() {};
104 
106 
110  virtual void pause(const std::string & message)
111  {
112  if(!pause2(message))
113  throw Euser_abort(message);
114  };
115 
117 
124  virtual bool pause2(const std::string & message)
125  { throw Elibcall("user_interaction::pause2", "user_interaction::pause() or pause2() must be overwritten !"); };
126 
127 
133  void warning(const std::string & message);
134 
136 
140  virtual std::string get_string(const std::string & message, bool echo) = 0;
141 
143 
147  virtual secu_string get_secu_string(const std::string & message, bool echo) = 0;
148 
149 
156 
168  virtual void listing(const std::string & flag,
169  const std::string & perm,
170  const std::string & uid,
171  const std::string & gid,
172  const std::string & size,
173  const std::string & date,
174  const std::string & filename,
175  bool is_dir,
176  bool has_children);
177 
178 
179 
186 
191  virtual void dar_manager_show_files(const std::string & filename,
192  bool data_change,
193  bool ea_change);
194 
195 
202 
207  virtual void dar_manager_contents(U_I number,
208  const std::string & chemin,
209  const std::string & archive_name);
210 
217 
224  virtual void dar_manager_statistics(U_I number,
225  const infinint & data_count,
226  const infinint & total_data,
227  const infinint & ea_count,
228  const infinint & total_ea);
229 
236 
243  virtual void dar_manager_show_version(U_I number,
244  const std::string & data_date,
245  const std::string & data_presence,
246  const std::string & ea_date,
247  const std::string & ea_presence);
248 
250 
258  void printf(const char *format, ...);
259 
263 
265  bool get_use_listing() const { return use_listing; };
267  bool get_use_dar_manager_show_files() const { return use_dar_manager_show_files; };
269  bool get_use_dar_manager_contents() const { return use_dar_manager_contents; };
271  bool get_use_dar_manager_statistics() const { return use_dar_manager_statistics; };
273  bool get_use_dar_manager_show_version() const { return use_dar_manager_show_version; };
274 
275 
277 
283  virtual user_interaction *clone() const = 0;
284 
286 
291  void warning_with_more(U_I num) { at_once = num; count = 0; };
292 
293  protected:
294 
296 
301  void set_use_listing(bool val) { use_listing = val; };
302 
304  void set_use_dar_manager_show_files(bool val) { use_dar_manager_show_files = val; };
305 
307  void set_use_dar_manager_contents(bool val) { use_dar_manager_contents = val; };
308 
310  void set_use_dar_manager_statistics(bool val) { use_dar_manager_statistics = val; };
311 
313  void set_use_dar_manager_show_version(bool val) { use_dar_manager_show_version = val; };
314 
316 
319  virtual void inherited_warning(const std::string & message) = 0;
320 
321  private:
322  bool use_listing;
323  bool use_dar_manager_show_files;
324  bool use_dar_manager_contents;
325  bool use_dar_manager_statistics;
326  bool use_dar_manager_show_version;
327  U_I at_once, count;
328 
329  };
330 
331 
333 
338  {
339  public:
340 
342 
353  user_interaction_callback(void (*x_warning_callback)(const std::string &x, void *context),
354  bool (*x_answer_callback)(const std::string &x, void *context),
355  std::string (*x_string_callback)(const std::string &x, bool echo, void *context),
356  secu_string (*x_secu_string_callback)(const std::string &x, bool echo, void *context),
357  void *context_value);
358 
360  void pause(const std::string & message);
362  std::string get_string(const std::string & message, bool echo);
364  secu_string get_secu_string(const std::string & message, bool echo);
366  void listing(const std::string & flag,
367  const std::string & perm,
368  const std::string & uid,
369  const std::string & gid,
370  const std::string & size,
371  const std::string & date,
372  const std::string & filename,
373  bool is_dir,
374  bool has_children);
375 
377  void dar_manager_show_files(const std::string & filename,
378  bool available_data,
379  bool available_ea);
380 
382  void dar_manager_contents(U_I number,
383  const std::string & chemin,
384  const std::string & archive_name);
385 
387  void dar_manager_statistics(U_I number,
388  const infinint & data_count,
389  const infinint & total_data,
390  const infinint & ea_count,
391  const infinint & total_ea);
392 
394  void dar_manager_show_version(U_I number,
395  const std::string & data_date,
396  const std::string & data_presence,
397  const std::string & ea_date,
398  const std::string & ea_presence);
399 
401 
405  void set_listing_callback(void (*callback)(const std::string & flag,
406  const std::string & perm,
407  const std::string & uid,
408  const std::string & gid,
409  const std::string & size,
410  const std::string & date,
411  const std::string & filename,
412  bool is_dir,
413  bool has_children,
414  void *context))
415  {
416  tar_listing_callback = callback;
417  set_use_listing(true); // this is to inform libdar to use listing()
418  };
419 
420  // You can set a dar_manager_show_files callback thanks to this method
421 
422  void set_dar_manager_show_files_callback(void (*callback)(const std::string & filename,
423  bool available_data,
424  bool available_ea,
425  void *context))
426  {
427  dar_manager_show_files_callback = callback;
428  set_use_dar_manager_show_files(true); // this is to inform libdar to use the dar_manager_show_files() method
429  };
430 
431  void set_dar_manager_contents_callback(void (*callback)(U_I number,
432  const std::string & chemin,
433  const std::string & archive_name,
434  void *context))
435  {
436  dar_manager_contents_callback = callback;
437  set_use_dar_manager_contents(true); // this is to inform libdar to use the dar_manager_contents() method
438  };
439 
440  void set_dar_manager_statistics_callback(void (*callback)(U_I number,
441  const infinint & data_count,
442  const infinint & total_data,
443  const infinint & ea_count,
444  const infinint & total_ea,
445  void *context))
446  {
447  dar_manager_statistics_callback = callback;
448  set_use_dar_manager_statistics(true); // this is to inform libdar to use the dar_manager_statistics() method
449  };
450 
451  void set_dar_manager_show_version_callback(void (*callback)(U_I number,
452  const std::string & data_date,
453  const std::string & data_presence,
454  const std::string & ea_date,
455  const std::string & ea_presence,
456  void *context))
457  {
458  dar_manager_show_version_callback = callback;
459  set_use_dar_manager_show_version(true); // this is to inform libdar to use the dar_manager_show_version() method
460  };
461 
462 
464  virtual user_interaction *clone() const;
465 
466  protected:
468  void inherited_warning(const std::string & message);
469 
470  private:
471  void (*warning_callback)(const std::string & x, void *context); // pointer to function
472  bool (*answer_callback)(const std::string & x, void *context); // pointer to function
473  std::string (*string_callback)(const std::string & x, bool echo, void *context); // pointer to function
474  secu_string (*secu_string_callback)(const std::string & x, bool echo, void *context); // pointer to function
475  void (*tar_listing_callback)(const std::string & flags,
476  const std::string & perm,
477  const std::string & uid,
478  const std::string & gid,
479  const std::string & size,
480  const std::string & date,
481  const std::string & filename,
482  bool is_dir,
483  bool has_children,
484  void *context);
485  void (*dar_manager_show_files_callback)(const std::string & filename,
486  bool available_data,
487  bool available_ea,
488  void *context);
489  void (*dar_manager_contents_callback)(U_I number,
490  const std::string & chemin,
491  const std::string & archive_name,
492  void *context);
493  void (*dar_manager_statistics_callback)(U_I number,
494  const infinint & data_count,
495  const infinint & total_data,
496  const infinint & ea_count,
497  const infinint & total_ea,
498  void *context);
499  void (*dar_manager_show_version_callback)(U_I number,
500  const std::string & data_date,
501  const std::string & data_presence,
502  const std::string & ea_date,
503  const std::string & ea_presence,
504  void *context);
505 
506  void *context_val;
507  };
508 
509 
511 
513  {
514  public:
515  bool pause2(const std::string & message) { return false; };
516 
517  std::string get_string(const std::string & message, bool echo) { return "user_interaction_blind, is blindly answering no"; };
518  secu_string get_secu_string(const std::string & message, bool echo) { return secu_string(); };
519 
520  user_interaction *clone() const { user_interaction *ret = new (std::nothrow) user_interaction_blind(); if(ret == NULL) throw Ememory("user_interaction_blind::clone"); return ret; };
521 
522  protected:
523  void inherited_warning(const std::string & message) {}; // do not display any warning, this is "bind user_interaction" !
524 
525  };
526 
528 
529 } // end of namespace
530 
531 #endif
532 
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:266
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
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 inherited_warning(const std::string &message)
overwritting method from parent class.
std::string get_string(const std::string &message, bool echo)
overwritting method from parent class.
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)
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
virtual bool pause2(const std::string &message)
alternative method to the pause() method
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)
This is a pure virtual class that is used by libdar when interaction with the user is required...
virtual user_interaction * clone() const
overwritting method from parent class.
bool get_use_dar_manager_show_version() const
this is not a virtual method, it has not to be overwritten in inherited classes.
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".
bool get_use_listing() const
this is not a virtual method, it has not to be overwritten in inherited classes.
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...
void pause(const std::string &message)
overwritting method from parent class.
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.
bool get_use_dar_manager_contents() const
this is not a virtual method, it has not to be overwritten in inherited classes.
user_interaction * clone() const
make a newly allocated object which has the same properties as "this".
secu_string get_secu_string(const std::string &message, bool echo)
overwritting method from parent class.
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.
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:105
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_files() const
this is not a virtual method, it has not to be overwritten in inherited classes.
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.
void dar_manager_contents(U_I number, const std::string &chemin, const std::string &archive_name)
overwritting method from parent class
bool get_use_dar_manager_statistics() 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
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 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
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
void dar_manager_show_files(const std::string &filename, bool available_data, bool available_ea)
overwritting method from parent class
exception used to signal that the user has aborted the operation
Definition: erreurs.hpp:226
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...