user_interaction_callback5.hpp
Go to the documentation of this file.
/*********************************************************************/
// dar - disk archive - a backup/restoration program
// Copyright (C) 2002-2023 Denis Corbin
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// to contact the author, see the AUTHOR file
/*********************************************************************/
#ifndef USER_INTERACTION_CALLBACK5_HPP
#define USER_INTERACTION_CALLBACK5_HPP
#include "../my_config.h"
#include "user_interaction5.hpp"
namespace libdar5
{
class user_interaction_callback : public user_interaction
{
public:
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);
user_interaction_callback(const user_interaction_callback & ref) = default;
user_interaction_callback(user_interaction_callback && ref) noexcept = default;
user_interaction_callback & operator = (const user_interaction_callback & ref) = default;
user_interaction_callback & operator = (user_interaction_callback && ref) noexcept = default;
~user_interaction_callback() = default;
virtual void pause(const std::string & message) override;
virtual std::string get_string(const std::string & message, bool echo) override;
virtual secu_string get_secu_string(const std::string & message, bool echo) override;
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) override;
virtual void dar_manager_show_files(const std::string & filename,
bool available_data,
bool available_ea) override;
virtual void dar_manager_contents(U_I number,
const std::string & chemin,
const std::string & archive_name) override;
virtual void dar_manager_statistics(U_I number,
const infinint & data_count,
const infinint & total_data,
const infinint & ea_count,
const infinint & total_ea) override;
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) override;
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))
{
tar_listing_callback = callback;
set_use_listing(true); // this is to inform libdar to use listing()
};
void set_dar_manager_show_files_callback(void (*callback)(const std::string & filename,
bool available_data,
bool available_ea,
void *context))
{
dar_manager_show_files_callback = callback;
set_use_dar_manager_show_files(true); // this is to inform libdar to use the dar_manager_show_files() method
};
void set_dar_manager_contents_callback(void (*callback)(U_I number,
const std::string & chemin,
const std::string & archive_name,
void *context))
{
dar_manager_contents_callback = callback;
set_use_dar_manager_contents(true); // this is to inform libdar to use the dar_manager_contents() method
};
void set_dar_manager_statistics_callback(void (*callback)(U_I number,
const infinint & data_count,
const infinint & total_data,
const infinint & ea_count,
const infinint & total_ea,
void *context))
{
dar_manager_statistics_callback = callback;
set_use_dar_manager_statistics(true); // this is to inform libdar to use the dar_manager_statistics() method
};
void set_dar_manager_show_version_callback(void (*callback)(U_I number,
const std::string & data_date,
const std::string & data_presence,
const std::string & ea_date,
const std::string & ea_presence,
void *context))
{
dar_manager_show_version_callback = callback;
set_use_dar_manager_show_version(true); // this is to inform libdar to use the dar_manager_show_version() method
};
virtual user_interaction *clone() const override;
protected:
void change_context_value(void *new_value) { context_val = new_value; };
virtual void inherited_warning(const std::string & message) override;
private:
void (*warning_callback)(const std::string & x, void *context); // pointer to function
bool (*answer_callback)(const std::string & x, void *context); // pointer to function
std::string (*string_callback)(const std::string & x, bool echo, void *context); // pointer to function
secu_string (*secu_string_callback)(const std::string & x, bool echo, void *context); // pointer to function
void (*tar_listing_callback)(const std::string & flags,
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);
void (*dar_manager_show_files_callback)(const std::string & filename,
bool available_data,
bool available_ea,
void *context);
void (*dar_manager_contents_callback)(U_I number,
const std::string & chemin,
const std::string & archive_name,
void *context);
void (*dar_manager_statistics_callback)(U_I number,
const infinint & data_count,
const infinint & total_data,
const infinint & ea_count,
const infinint & total_ea,
void *context);
void (*dar_manager_show_version_callback)(U_I number,
const std::string & data_date,
const std::string & data_presence,
const std::string & ea_date,
const std::string & ea_presence,
void *context);
void *context_val;
};
} // end of namespace
#endif
libdar5::user_interaction_callback
full implemented class for user_interaction based on callback functions.
Definition: user_interaction_callback5.hpp:47
libdar5::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_callback5.hpp:119
libdar5::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_callback5.hpp:181
libdar5::user_interaction_callback::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) override
overwritting method from parent class.
libdar5::user_interaction_callback::inherited_warning
virtual void inherited_warning(const std::string &message) override
overwritting method from parent class.
libdar5::user_interaction_callback::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) override
overwritting method from parent class
libdar5::user_interaction_callback::dar_manager_show_files
virtual void dar_manager_show_files(const std::string &filename, bool available_data, bool available_ea) override
overwritting method from parent class
libdar5::user_interaction_callback::clone
virtual user_interaction * clone() const override
overwritting method from parent class.
libdar5::user_interaction_callback::dar_manager_contents
virtual void dar_manager_contents(U_I number, const std::string &chemin, const std::string &archive_name) override
overwritting method from parent class
libdar5::user_interaction_callback::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) override
overwritting method from parent class
libdar5::user_interaction_callback::set_dar_manager_show_files_callback
void set_dar_manager_show_files_callback(void(*callback)(const std::string &filename, bool available_data, bool available_ea, void *context))
You can set a dar_manager_show_files callback thanks to this method.
Definition: user_interaction_callback5.hpp:135
libdar5::user_interaction_callback::pause
virtual void pause(const std::string &message) override
overwritting method from parent class.
libdar5::user_interaction_callback::get_secu_string
virtual secu_string get_secu_string(const std::string &message, bool echo) override
overwritting method from parent class.
libdar5::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.
libdar5::user_interaction_callback::get_string
virtual std::string get_string(const std::string &message, bool echo) override
overwritting method from parent class.
libdar5::user_interaction
This is a pure virtual class that is used by libdar when interaction with the user is required.
Definition: user_interaction5.hpp:88
libdar5::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_interaction5.hpp:292
libdar5::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_interaction5.hpp:298
libdar5::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_interaction5.hpp:286
libdar5::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_interaction5.hpp:289
libdar5::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_interaction5.hpp:295
libdar::infinint
the arbitrary large positive integer class
Definition: real_infinint.hpp:62
libdar::secu_string
class secu_string
Definition: secu_string.hpp:54
libdar5
libdar5 namespace encapsulate all libdar symbols
Definition: archive5.hpp:37
user_interaction5.hpp
API v5 backward compatible class user_interaction.