Line data Source code
1 : // Snap Websites Server -- snap websites server
2 : // Copyright (c) 2011-2019 Made to Order Software Corp. All Rights Reserved
3 : //
4 : // This program is free software; you can redistribute it and/or modify
5 : // it under the terms of the GNU General Public License as published by
6 : // the Free Software Foundation; either version 2 of the License, or
7 : // (at your option) any later version.
8 : //
9 : // This program is distributed in the hope that it will be useful,
10 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 : // GNU General Public License for more details.
13 : //
14 : // You should have received a copy of the GNU General Public License
15 : // along with this program; if not, write to the Free Software
16 : // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 :
18 : #pragma once
19 :
20 : #include <snapwebsites/snap_thread.h>
21 :
22 : #include <libdbproxy/libdbproxy.h>
23 :
24 : namespace snap
25 : {
26 :
27 :
28 0 : class snap_initialize_website_exception : public snap_exception
29 : {
30 : public:
31 0 : explicit snap_initialize_website_exception(char const * whatmsg) : snap_exception("snap_initialize_website", whatmsg) {}
32 : explicit snap_initialize_website_exception(std::string const & whatmsg) : snap_exception("snap_initialize_website", whatmsg) {}
33 : explicit snap_initialize_website_exception(QString const & whatmsg) : snap_exception("snap_initialize_website", whatmsg) {}
34 : };
35 :
36 0 : class snap_initialize_website_exception_invalid_parameter : public snap_initialize_website_exception
37 : {
38 : public:
39 0 : explicit snap_initialize_website_exception_invalid_parameter(char const * whatmsg) : snap_initialize_website_exception(whatmsg) {}
40 : explicit snap_initialize_website_exception_invalid_parameter(std::string const & whatmsg) : snap_initialize_website_exception(whatmsg) {}
41 : explicit snap_initialize_website_exception_invalid_parameter(QString const & whatmsg) : snap_initialize_website_exception(whatmsg) {}
42 : };
43 :
44 :
45 :
46 :
47 :
48 : class snap_initialize_website
49 : {
50 : public:
51 : typedef std::shared_ptr<snap_initialize_website> pointer_t;
52 :
53 : snap_initialize_website(QString const & snap_host, int snap_port, bool secure,
54 : QString const & website_uri, int destination_port,
55 : QString const & query_string, QString const & protocol);
56 :
57 : bool start_process();
58 : bool is_done() const;
59 : QString get_status();
60 :
61 : private:
62 0 : class snap_initialize_website_runner
63 : : public snap_thread::snap_runner
64 : {
65 : public:
66 : snap_initialize_website_runner(snap_initialize_website * parent,
67 : QString const & snap_host, int snap_port, bool secure,
68 : QString const & website_uri, int destination_port,
69 : QString const & query_string, QString const & protocol);
70 :
71 : snap_initialize_website_runner(snap_initialize_website_runner const & rhs) = delete;
72 : snap_initialize_website_runner & operator = (snap_initialize_website_runner const & rhs) = delete;
73 :
74 : // from class snap_thread
75 : virtual void run();
76 :
77 : bool is_done() const;
78 : QString next_message();
79 :
80 : private:
81 : void done();
82 : void message(QString const & msg);
83 : void send_init_command();
84 :
85 : snap_initialize_website * f_parent = nullptr;
86 : mutable snap_thread::snap_mutex f_mutex = snap_thread::snap_mutex();
87 : bool f_done = false;
88 : QString const f_snap_host;
89 : int32_t f_snap_port = 0;
90 : bool f_secure = false;
91 : QString const f_website_uri; // 'const' so it is mandatory anyway
92 : int32_t const f_destination_port; // 'const' so it is mandatory anyway
93 : QString const f_query_string; // 'const' so it is mandatory anyway
94 : QString const f_protocol; // 'const' so it is mandatory anyway
95 : std::deque<QString> f_message_queue = std::deque<QString>(); // TODO: look into reusing the message queue from the thread with T = QString!?
96 : };
97 :
98 : std::unique_ptr<snap_initialize_website_runner> f_website_runner = std::unique_ptr<snap_initialize_website_runner>();
99 : std::unique_ptr<snap_thread> f_process_thread = std::unique_ptr<snap_thread>();
100 : };
101 :
102 :
103 : }
104 : // namespace snap
105 : // vim: ts=4 sw=4 et
|