Disk ARchive 2.8.3
Full featured and portable backup and archiving tool
Loading...
Searching...
No Matches
dar64-2.8.3-win64/include/dar/user_interaction.hpp
Go to the documentation of this file.
1/*********************************************************************/
2// dar - disk archive - a backup/restoration program
3// Copyright (C) 2002-2026 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18//
19// to contact the author, see the AUTHOR file
20/*********************************************************************/
21
25
26#ifndef USER_INTERACTION_HPP
27#define USER_INTERACTION_HPP
28
29#include "//include/dar/libdar_my_config.h"
30
31extern "C"
32{
33#if LIBDAR_MUTEX_WORKS
34#if LIBDAR_HAS_PTHREAD_H
35#include <pthread.h>
36#endif
37#endif
38}
39
40#include <string>
41#include <list>
42#include "//include/dar/secu_string.hpp"
43#include "//include/dar/infinint.hpp"
44#include "//include/dar/thread_cancellation.hpp"
45
46namespace libdar
47{
48
51
53
57 class user_interaction
58 {
59 public:
60 user_interaction() {};
61 user_interaction(const user_interaction & ref) = default;
62 user_interaction(user_interaction && ref) noexcept = default;
63 user_interaction & operator = (const user_interaction & ref) = default;
64 user_interaction & operator = (user_interaction && ref) noexcept = default;
65 virtual ~user_interaction() = default;
66
67 // the following methode are used by libdar and rely in their inherited_* versions
68 // than must be defined in the inherited classes
69
70 void message(const std::string & message);
71 void pause(const std::string & message);
72 std::string get_string(const std::string & message, bool echo);
73 secu_string get_secu_string(const std::string & message, bool echo);
74
76
84 virtual void printf(const char *format, ...);
85
87
89
91
104
105 void add_thread_to_monitor(pthread_t tid);
106
108
109 void remove_thread_from_monitor(pthread_t tid);
110
111
112 protected:
118 virtual void inherited_message(const std::string & message) = 0;
119
121
126 virtual bool inherited_pause(const std::string & message) = 0;
127
128
130
136 virtual std::string inherited_get_string(const std::string & message, bool echo) = 0;
137
139
145 virtual secu_string inherited_get_secu_string(const std::string & message, bool echo) = 0;
146
147 private:
148
149#if LIBDAR_MUTEX_WORKS
150#if LIBDAR_HAS_PTHREAD_H
151 thread_cancellation thcancel;
152
153 std::list<pthread_t> monitoring;
154#endif
155#endif
156
157 };
158
160
161} // end of namespace
162
163#endif
class to be used as parent to provide checkpoints to inherited classes
virtual bool inherited_pause(const std::string &message)=0
method used to ask a boolean question to the user.
virtual void inherited_message(const std::string &message)=0
virtual std::string inherited_get_string(const std::string &message, bool echo)=0
method used to ask a question that needs an arbitrary answer.
void add_thread_to_monitor(pthread_t tid)
add a thread to monitor
virtual void printf(const char *format,...)
libdar uses this call to format output before sending to the message() method.
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
void remove_thread_from_monitor(pthread_t tid)
remove a thread from monitoring
bool cancellation_requested() const
known whether cancellation was requested for the current thread or an added thread
libdar namespace encapsulate all libdar symbols