Line data Source code
1 : // Copyright (c) 2012-2019 Made to Order Software Corp. All Rights Reserved
2 : //
3 : // https://snapwebsites.org/project/eventdispatcher
4 : // contact@m2osw.com
5 : //
6 : // This program is free software; you can redistribute it and/or modify
7 : // it under the terms of the GNU General Public License as published by
8 : // the Free Software Foundation; either version 2 of the License, or
9 : // (at your option) any later version.
10 : //
11 : // This program is distributed in the hope that it will be useful,
12 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : // GNU General Public License for more details.
15 : //
16 : // You should have received a copy of the GNU General Public License
17 : // along with this program; if not, write to the Free Software
18 : // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 : #pragma once
20 :
21 : /** \file
22 : * \brief Declaration of the communicator class.
23 : *
24 : * The communicator is the manager of the event dispatcher connections.
25 : * It handles the run() function with a poll() loop listening to all the
26 : * connections and calling your virtual connection functions.
27 : */
28 :
29 :
30 : // self
31 : //
32 : #include "eventdispatcher/connection.h"
33 :
34 :
35 :
36 : namespace ed
37 : {
38 :
39 :
40 :
41 : // WARNING: a snap_communicator object must be allocated and held in a shared pointer (see pointer_t)
42 : #pragma GCC diagnostic push
43 : #pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
44 0 : class communicator
45 : : public std::enable_shared_from_this<communicator>
46 : {
47 : public:
48 : typedef std::shared_ptr<communicator> pointer_t;
49 :
50 : static pointer_t instance();
51 :
52 : connection::vector_t const & get_connections() const;
53 : bool add_connection(connection::pointer_t connection);
54 : bool remove_connection(connection::pointer_t connection);
55 : void set_force_sort(bool status = true);
56 :
57 : virtual bool run();
58 :
59 : private:
60 : communicator();
61 : communicator(communicator const & communicator) = delete;
62 :
63 : communicator & operator = (communicator const & communicator) = delete;
64 :
65 : connection::vector_t f_connections = connection::vector_t();
66 : bool f_force_sort = true;
67 : };
68 : #pragma GCC diagnostic pop
69 :
70 :
71 : } // namespace snap
72 : // vim: ts=4 sw=4 et
|