blob: 722786b77d8a65de4fb649dcc56cceb4b97c7050 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
/*
Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
DCP-o-matic is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
DCP-o-matic is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file src/lib/encode_server_finder.h
* @brief EncodeServerFinder class.
*/
#include "config.h"
#include "encode_server_description.h"
#include "exception_store.h"
#include "signaller.h"
#include <boost/signals2.hpp>
#include <boost/thread/condition.hpp>
class Socket;
/** @class EncodeServerFinder
* @brief Locater of encoding servers.
*
* This class finds active (i.e. responding) encode servers. Depending on
* configuration it finds servers by:
*
* 1. broadcasting a request to the local subnet and
* 2. checking to see if any of the configured server hosts are up.
*/
class EncodeServerFinder : public Signaller, public ExceptionStore
{
public:
static EncodeServerFinder* instance ();
static void drop ();
std::list<EncodeServerDescription> servers () const;
/** Emitted whenever the list of servers changes */
boost::signals2::signal<void ()> ServersListChanged;
private:
EncodeServerFinder ();
~EncodeServerFinder ();
void start ();
void stop ();
void search_thread ();
void listen_thread ();
void start_accept ();
void handle_accept (boost::system::error_code ec);
void config_changed (Config::Property what);
/** Thread to periodically issue broadcasts and requests to find encoding servers */
boost::thread _search_thread;
/** Thread to listen to the responses from servers */
boost::thread _listen_thread;
/** Available servers */
std::list<EncodeServerDescription> _servers;
/** Mutex for _servers */
mutable boost::mutex _servers_mutex;
dcpomatic::io_context _listen_io_context;
std::shared_ptr<boost::asio::ip::tcp::acceptor> _listen_acceptor;
bool _stop;
boost::condition _search_condition;
boost::mutex _search_condition_mutex;
std::shared_ptr<Socket> _accept_socket;
static EncodeServerFinder* _instance;
};
|