Webdar 1.0.0
Web user interface to libdar
web_user_interaction.hpp
1/*********************************************************************/
2// webdar - a web server and interface program to libdar
3// Copyright (C) 2013-2025 Denis Corbin
4//
5// This file is part of Webdar
6//
7// Webdar is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// Webdar is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with Webdar. If not, see <http://www.gnu.org/licenses/>
19//
20//----
21// to contact the author: dar.linux@free.fr
22/*********************************************************************/
23
24#ifndef WEB_USER_INTERACTION_HPP
25#define WEB_USER_INTERACTION_HPP
26
27 // C system header files
28#include "my_config.h"
29extern "C"
30{
31
32}
33
34 // C++ system header files
35#include <string>
36#include <list>
37#include <dar/libdar.hpp>
38#include <libthreadar/libthreadar.hpp>
39
40 // webdar headers
41
42
44
49
55
56class web_user_interaction : public libdar::user_interaction
57{
58public:
59 web_user_interaction(unsigned int x_warn_size = 10);
60 web_user_interaction(const web_user_interaction & ref) = delete;
61 web_user_interaction(web_user_interaction && ref) noexcept = delete;
62 web_user_interaction & operator = (const web_user_interaction & ref) = delete;
63 web_user_interaction & operator = (web_user_interaction && ref) noexcept = delete;
65
67 void set_warning_list_size(unsigned int size);
68
70 void clear();
71
73 std::list<std::string> get_warnings();
74
76 bool pending_pause(std::string & msg) const;
77
79 bool pending_get_string(std::string & msg, bool & echo) const;
80
82 bool pending_get_secu_string(std::string & msg, bool & echo) const;
83
85 void set_pause_answer(bool val);
86
88 void set_get_string_answer(const std::string & val);
89
91 void set_get_secu_string_answer(const libdar::secu_string & val);
92
94 bool has_libdar_pending() const;
95
96protected:
97
98 // inherited from libdar::user_interaction
99
100 virtual void inherited_message(const std::string & message) override;
101 virtual bool inherited_pause(const std::string & message) override;
102 virtual std::string inherited_get_string(const std::string & message, bool echo) override;
103 virtual libdar::secu_string inherited_get_secu_string(const std::string & message, bool echo) override;
104
105private:
106 mutable libthreadar::condition control;
107
108 // pause() fields
109 bool pause_pending;
110 bool pause_answered;
111 std::string pause_msg;
112 bool pause_ans;
113
114
115 // get_string() fields
116 bool get_string_pending;
117 bool get_string_answered;
118 std::string get_string_msg;
119 bool get_string_echo;
120 std::string get_string_ans;
121
122 // get_secu_string() fields
123 bool get_secu_string_pending;
124 bool get_secu_string_answered;
125 std::string get_secu_string_msg;
126 bool get_secu_string_echo;
127 libdar::secu_string get_secu_string_ans;
128
129 // libdar warnings (= logs)
130 std::list<std::string> warnings;
131 unsigned warn_size;
132};
133
134#endif
135
class web_user_interaction provides a libdar::user_interaction interface to libdar
Definition: web_user_interaction.hpp:57
void set_pause_answer(bool val)
provide the answer to libdar for pause() request
Definition: web_user_interaction.cpp:213
void clear()
clear logs and reset the object
Definition: web_user_interaction.cpp:87
std::list< std::string > get_warnings()
obtain a copy of the current log buffer
Definition: web_user_interaction.cpp:109
bool has_libdar_pending() const
whether libdar is waiting for an answer
Definition: web_user_interaction.cpp:291
void set_warning_list_size(unsigned int size)
change the number of last warnings to display
Definition: web_user_interaction.cpp:66
void set_get_string_answer(const std::string &val)
provide the answer to libdar for get_string() request
Definition: web_user_interaction.cpp:239
web_user_interaction(unsigned int x_warn_size=10)
the argument is the number latest message to retain from libdar
Definition: web_user_interaction.cpp:44
bool pending_get_string(std::string &msg, bool &echo) const
wether libdar is pending for get_string answer
Definition: web_user_interaction.cpp:157
bool pending_get_secu_string(std::string &msg, bool &echo) const
wether libdar is pending for a get_secu_string answer
Definition: web_user_interaction.cpp:185
bool pending_pause(std::string &msg) const
wether libdar is pending for pause answer
Definition: web_user_interaction.cpp:132
void set_get_secu_string_answer(const libdar::secu_string &val)
provide the answer to libdar for get_secu_string() request
Definition: web_user_interaction.cpp:265