X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fencode_server_finder.h;fp=src%2Flib%2Fencode_server_finder.h;h=49433ad42fe2a9cd24aa7e6d872ec326cf9f9c07;hb=17df947ac256397311a11894062070f8069c7e75;hp=0000000000000000000000000000000000000000;hpb=d499ec381ea5fbbae954531be9d66c9cc723c230;p=dcpomatic.git diff --git a/src/lib/encode_server_finder.h b/src/lib/encode_server_finder.h new file mode 100644 index 000000000..49433ad42 --- /dev/null +++ b/src/lib/encode_server_finder.h @@ -0,0 +1,85 @@ +/* + Copyright (C) 2013-2015 Carl Hetherington + + This program 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. + + This program 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 this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +/** @file src/lib/encode_server_finder.h + * @brief EncodeServerFinder class. + */ + +#include "signaller.h" +#include "encode_server_description.h" +#include "config.h" +#include "exception_store.h" +#include +#include + +class Socket; + +class EncodeServerFinder : public Signaller, public ExceptionStore +{ +public: + static EncodeServerFinder* instance (); + static void drop (); + + void disable () { + _disabled = true; + } + + bool disabled () const { + return _disabled; + } + + std::list servers () const; + + /** Emitted whenever the list of servers changes */ + boost::signals2::signal ServersListChanged; + +private: + EncodeServerFinder (); + ~EncodeServerFinder (); + + void start (); + + void search_thread (); + void listen_thread (); + + bool server_found (std::string) const; + void start_accept (); + void handle_accept (boost::system::error_code ec, boost::shared_ptr socket); + + void config_changed (Config::Property what); + + bool _disabled; + + /** 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; + + std::list _servers; + mutable boost::mutex _servers_mutex; + + boost::asio::io_service _listen_io_service; + boost::shared_ptr _listen_acceptor; + bool _stop; + + boost::condition _search_condition; + boost::mutex _search_condition_mutex; + + static EncodeServerFinder* _instance; +};