Loading...
Searching...
No Matches
user_interaction.hpp
Go to the documentation of this file.
/*********************************************************************/
// dar - disk archive - a backup/restoration program
// Copyright (C) 2002-2026 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_HPP
#define USER_INTERACTION_HPP
#include "../my_config.h"
extern "C"
{
#if MUTEX_WORKS
#if HAVE_PTHREAD_H
#include <pthread.h>
#endif
#endif
}
#include <string>
#include <list>
#include "secu_string.hpp"
#include "infinint.hpp"
#include "thread_cancellation.hpp"
namespace libdar
{
class user_interaction
{
public:
user_interaction() {};
user_interaction(const user_interaction & ref) = default;
user_interaction(user_interaction && ref) noexcept = default;
user_interaction & operator = (const user_interaction & ref) = default;
user_interaction & operator = (user_interaction && ref) noexcept = default;
virtual ~user_interaction() = default;
// the following methode are used by libdar and rely in their inherited_* versions
// than must be defined in the inherited classes
void message(const std::string & message);
void pause(const std::string & message);
std::string get_string(const std::string & message, bool echo);
secu_string get_secu_string(const std::string & message, bool echo);
virtual void printf(const char *format, ...);
bool cancellation_requested() const;
void add_thread_to_monitor(pthread_t tid);
void remove_thread_from_monitor(pthread_t tid);
protected:
virtual void inherited_message(const std::string & message) = 0;
virtual bool inherited_pause(const std::string & message) = 0;
virtual std::string inherited_get_string(const std::string & message, bool echo) = 0;
virtual secu_string inherited_get_secu_string(const std::string & message, bool echo) = 0;
private:
#if MUTEX_WORKS
#if HAVE_PTHREAD_H
thread_cancellation thcancel;
std::list<pthread_t> monitoring;
#endif
#endif
};
} // end of namespace
#endif
libdar::secu_string
class secu_string
Definition secu_string.hpp:54
libdar::thread_cancellation
class to be used as parent to provide checkpoints to inherited classes
Definition thread_cancellation.hpp:69
libdar::user_interaction::inherited_pause
virtual bool inherited_pause(const std::string &message)=0
method used to ask a boolean question to the user.
libdar::user_interaction::inherited_message
virtual void inherited_message(const std::string &message)=0
libdar::user_interaction::inherited_get_string
virtual std::string inherited_get_string(const std::string &message, bool echo)=0
method used to ask a question that needs an arbitrary answer.
libdar::user_interaction::add_thread_to_monitor
void add_thread_to_monitor(pthread_t tid)
add a thread to monitor
libdar::user_interaction::printf
virtual void printf(const char *format,...)
libdar uses this call to format output before sending to the message() method.
libdar::user_interaction::inherited_get_secu_string
virtual secu_string inherited_get_secu_string(const std::string &message, bool echo)=0
same a get_string() but uses libdar::secu_string instead of std::string
libdar::user_interaction::remove_thread_from_monitor
void remove_thread_from_monitor(pthread_t tid)
remove a thread from monitoring
libdar::user_interaction::cancellation_requested
bool cancellation_requested() const
known whether cancellation was requested for the current thread or an added thread
infinint.hpp
switch module to limitint (32 ou 64 bits integers) or infinint
my_config.h
include macro defined by the configure script and some specific additional ones
libdar
libdar namespace encapsulate all libdar symbols
Definition archive.hpp:47
secu_string.hpp
this file contains the definition of secu_string class, a std::string like class but allocated in sec...
thread_cancellation.hpp
to be able to cancel libdar operation while running in a given thread.