X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Flib%2Fserver_finder.h;h=8aa07c0696145918cc64f5a8cc09fb35f98cbbb3;hp=c0f1feb66e1d329167e55007ec8bdf4f6ac09521;hb=aeb835a18c8df347e0ed68fb24631b320abeb611;hpb=00ee110ef1de083759c4f74bdfeff78752b6198f diff --git a/src/lib/server_finder.h b/src/lib/server_finder.h index c0f1feb66..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,14 +17,22 @@ */ -#include "server.h" +/** @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 + +class Socket; -class ServerFinder : public ExceptionStore +class ServerFinder : public Signaller, public ExceptionStore { public: - void connect (boost::function); - static ServerFinder* instance (); static void drop (); @@ -32,32 +40,47 @@ public: _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 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); - 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; };