X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fserver_finder.h;h=bd6d793044ffdf468d41e9b7cecc6950556fb38b;hb=1ad291db7e847fbb71e5bd9f2f81db6bfb2a022e;hp=202bee8f920d9610bd82c50b6951ea701199ed25;hpb=ad49361b303d1ceff7048fa0e89ba609ca9ce376;p=dcpomatic.git diff --git a/src/lib/server_finder.h b/src/lib/server_finder.h index 202bee8f9..bd6d79304 100644 --- a/src/lib/server_finder.h +++ b/src/lib/server_finder.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington + 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 @@ -17,39 +17,64 @@ */ +#include "signaller.h" +#include "server_description.h" +#include "config.h" +#include "exception_store.h" #include -#include "server.h" +#include -class ServerFinder : public ExceptionStore +class Socket; + +class ServerFinder : public Signaller, public ExceptionStore { public: - void connect (boost::function); - static ServerFinder* 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: ServerFinder (); + ~ServerFinder (); - void broadcast_thread (); + 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); - boost::signals2::signal ServerFound; + void config_changed (Config::Property what); + void search_now (); bool _disabled; - - /** Thread to periodically issue broadcasts to find encoding servers */ - boost::thread* _broadcast_thread; + + /** 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 _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 ServerFinder* _instance; };