Line data Source code
1 : // Copyright (c) 2020-2021 Made to Order Software Corp.
2 : // All rights reserved
3 : //
4 : // https://snapwebsites.org/project/eventdispatcher
5 : // contact@m2osw.com
6 : //
7 : // This program 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 2 of the License, or
10 : // (at your option) any later version.
11 : //
12 : // This program 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 this program; if not, write to the Free Software
19 : // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 :
21 : // self
22 : //
23 : #include "eventdispatcher/logrotate_udp_messenger.h"
24 :
25 :
26 : // last include
27 : //
28 : #include <snapdev/poison.h>
29 :
30 :
31 :
32 : namespace ed
33 : {
34 :
35 :
36 :
37 : /** \brief The UDP server initialization.
38 : *
39 : * The UDP server creates a new UDP server to listen on incoming
40 : * messages over a UDP connection.
41 : *
42 : * This UDP implementation is used to listen to the LOG message specifically.
43 : * It is often that you want to restart the snaplogger and this can be used
44 : * as the way to do it. The UDP message can be sent using the ed-signal
45 : * command line tool:
46 : *
47 : * \code
48 : * ed-signal --server 127.0.0.1:1234 --message LOG --type udp
49 : * \endcode
50 : *
51 : * The reaction of the server is to restart the snaplogger as implemented in
52 : * the default dispatcher messages (see the messages.cpp for details).
53 : *
54 : * If you already have a UDP service in your application, you can simply
55 : * add the default dispatcher messages and the LOG message will automatically
56 : * be handled for you. No need to create yet another network connection.
57 : * We do so in this constructor like so:
58 : *
59 : * \code
60 : * f_dispatcher->add_communicator_commands();
61 : * \endcode
62 : *
63 : * \param[in] addr The address/port to listen on. Most often it is the private
64 : * address (127.0.0.1).
65 : * \param[in] secret_code A secret code to verify in order to accept UDP
66 : * messages.
67 : */
68 0 : logrotate_udp_messenger::logrotate_udp_messenger(
69 : addr::addr const & address
70 0 : , std::string const & secret_code)
71 0 : : ed::udp_server_message_connection(address.to_ipv4or6_string(addr::addr::string_ip_t::STRING_IP_BRACKETS), address.get_port())
72 : , f_dispatcher(std::make_shared<ed::dispatcher<logrotate_udp_messenger>>(
73 : this
74 0 : , ed::dispatcher<logrotate_udp_messenger>::dispatcher_match::vector_t()))
75 : {
76 0 : set_secret_code(secret_code);
77 0 : f_dispatcher->add_communicator_commands();
78 : #ifdef _DEBUG
79 0 : f_dispatcher->set_trace();
80 : #endif
81 0 : set_dispatcher(f_dispatcher);
82 0 : }
83 :
84 :
85 : /** \brief The logrotate messenger destructor.
86 : *
87 : * This function is here because the logrotate_udp_messenger derives from
88 : * classes that have virtual functions and the destructor of such classes
89 : * have to be defined virtual.
90 : */
91 0 : logrotate_udp_messenger::~logrotate_udp_messenger()
92 : {
93 0 : }
94 :
95 :
96 : /** \brief Implement a send message for it is required.
97 : *
98 : * This function does nothing. It has to be defined because one of the
99 : * dependencies of this class has a pure virtual function named send_message().
100 : *
101 : * In a later implementation we may change this implementation.
102 : *
103 : * \param[in] msg The message to be sent (ignored).
104 : * \param[in] cache Whether to cache the message if it can't immediately be
105 : * sent (ignored).
106 : *
107 : * \return Always returns true (as if the message was sent successfully).
108 : */
109 0 : bool logrotate_udp_messenger::send_message(ed::message const & msg, bool cache)
110 : {
111 0 : snap::NOT_USED(msg, cache);
112 0 : return true;
113 : }
114 :
115 :
116 6 : } // namespace ed
117 : // vim: ts=4 sw=4 et
|