Webdar 1.0.0
Web user interface to libdar
user_interface.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 USER_INTERFACE_HPP
25#define USER_INTERFACE_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 <libthreadar/libthreadar.hpp>
36
37 // webdar headers
38#include "responder.hpp"
39#include "saisie.hpp"
40#include "html_statistics.hpp"
41#include "events.hpp"
42#include "html_libdar_running_page.hpp"
43#include "html_error.hpp"
44#include "html_listing_page.hpp"
45#include "html_summary_page.hpp"
46#include "archive_test.hpp"
47#include "archive_restore.hpp"
48#include "archive_compare.hpp"
49#include "archive_create.hpp"
50#include "archive_isolate.hpp"
51#include "archive_merge.hpp"
52#include "archive_init_list.hpp"
53#include "archive_repair.hpp"
54#include "html_fichier.hpp"
55
57
66
67class user_interface : public responder, public events, public actor
68{
69public:
71 static const std::string closing;
72
74 user_interface(const user_interface & ref) = delete;
75 user_interface(user_interface && ref) noexcept = delete;
76 user_interface & operator = (const user_interface & ref) = delete;
77 user_interface & operator = (user_interface && ref) noexcept = delete;
79
81 virtual answer give_answer(const request & req) override;
82
84 virtual void on_event(const std::string & event_name) override;
85
87 std::string get_session_name() const;
88
90 void set_session_name(const std::string & name);
91
93 void set_username(const std::string & username) { parametrage.set_username(username); };
94
96 bool is_libdar_running() const { return in_action.is_libdar_running(); };
97
99 bool disconnection_requested() const { bool ret = disconnect_req; disconnect_req = false; return ret; };
100
101protected:
102
104 virtual void prefix_has_changed() override;
105
106private:
107 enum mode_type
108 {
109 config,
110 listing_open,
111 listing,
112 summary_open,
113 summary,
114 running,
115 error,
116 download
117 };
118
119 std::string sessname;
120 mutable libthreadar::mutex mut_sessname;
121 mode_type mode;
122 mode_type return_mode;
123 bool close_requested;
124 bool mode_changed;
125 mutable bool disconnect_req;
126
127 saisie parametrage;
128 html_libdar_running_page in_action;
129 html_error in_error;
130 html_listing_page in_list;
131 html_summary_page in_summ;
132 std::shared_ptr<html_fichier> data;
133
134 archive_test arch_test;
135 archive_restore arch_rest;
136 archive_compare arch_diff;
137 archive_create arch_create;
138 archive_isolate arch_isolate;
139 archive_merge arch_merge;
140 archive_repair arch_repair;
141 archive_init_list arch_init_list;
142 libthreadar::thread *current_thread;
143
145 const saisie & get_parametrage() const { return parametrage; };
146
148 std::shared_ptr<html_web_user_interaction> get_html_user_interaction() { return in_action.get_html_user_interaction(); };
149
150 void go_restore();
151 void go_diff();
152 void go_test();
153 void go_create();
154 void go_isolate();
155 void go_merge();
156 void go_init_list();
157 void go_repair();
158};
159
160#endif
class of object that are pointed/triggered to by others
Definition: actor.hpp:55
class answer provides easy means to set an HTTP answer and means to sent it back to a proto_connexion...
Definition: answer.hpp:49
class archive_compare run libdar comparison in a dedicated thread
Definition: archive_compare.hpp:54
class archive_create run libdar creation in a dedicated thread
Definition: archive_create.hpp:55
this objects is a thread object that provide access to the content of an existing archive
Definition: archive_init_list.hpp:55
class archive_isolate gather parameters and libdar isolation in a dedicated thread
Definition: archive_isolate.hpp:46
class archive_merge runs libdar merging operation in a dedicated thread
Definition: archive_merge.hpp:47
class archive_repair run libdar reparation in a dedicated thread
Definition: archive_repair.hpp:55
class archive_restore wraps libdar restoration operation in a dedicated thread
Definition: archive_restore.hpp:45
class archive_test wraps libdar archive testing operation in a dedicated thread
Definition: archive_test.hpp:45
class events
Definition: events.hpp:52
html page reporting an error
Definition: html_error.hpp:47
html_libdar_running_page wraps up an html_web_user_interaction in a html_page
Definition: html_libdar_running_page.hpp:47
bool is_libdar_running() const
whether a libdar thread is running under "this" management
Definition: html_libdar_running_page.hpp:76
std::shared_ptr< html_web_user_interaction > get_html_user_interaction()
propagate request to web_ui
Definition: html_libdar_running_page.hpp:67
html_listing_page is the page that shows when listing an existing archive content
Definition: html_listing_page.hpp:54
html_summary_page is the page that shows the summary of an existing archive
Definition: html_summary_page.hpp:54
class holding fields of an HTTP request (method, URI, header, cookies, and so on)
Definition: request.hpp:45
pure virtual class, base class for all classes that can generate an answer to a request
Definition: responder.hpp:46
class saisie
Definition: saisie.hpp:106
void set_username(const std::string &username)
define the username that the current session is owned by
Definition: saisie.hpp:184
main webdar html components that defines for a given session the type of output (config pages,...
Definition: user_interface.hpp:68
bool disconnection_requested() const
whether user has requested to disconnect
Definition: user_interface.hpp:99
virtual void prefix_has_changed() override
inherited from responder
Definition: user_interface.cpp:410
virtual void on_event(const std::string &event_name) override
inherited from actor
Definition: user_interface.cpp:188
void set_session_name(const std::string &name)
set the session name (customizable by user)
Definition: user_interface.cpp:381
bool is_libdar_running() const
whether a libdar thread is running
Definition: user_interface.hpp:96
virtual answer give_answer(const request &req) override
inherited from responder
Definition: user_interface.cpp:104
std::string get_session_name() const
provide the name of the session (given by the user);
Definition: user_interface.cpp:361
user_interface()
Definition: user_interface.cpp:45
void set_username(const std::string &username)
define the username that the current session is owned by
Definition: user_interface.hpp:93
static const std::string closing
available event for that class
Definition: user_interface.hpp:71
defines the event class