X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Flib%2Fserver_finder.h;h=8aa07c0696145918cc64f5a8cc09fb35f98cbbb3;hp=202bee8f920d9610bd82c50b6951ea701199ed25;hb=aeb835a18c8df347e0ed68fb24631b320abeb611;hpb=ad49361b303d1ceff7048fa0e89ba609ca9ce376 diff --git a/src/lib/server_finder.h b/src/lib/server_finder.h index 202bee8f9..8aa07c069 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,70 @@ */ +/** @file src/lib/server_finder.h + * @brief ServerFinder class. + */ + +#include "signaller.h" +#include "server_description.h" +#include "config.h" +#include "exception_store.h" #include -#include "server.h" +#include + +class Socket; -class ServerFinder : public ExceptionStore +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 start (); - 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; + 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 ServerFinder* _instance; };