Logging improvements to allow prettier displays in the server GUI.
[dcpomatic.git] / src / lib / server_finder.h
index c43c2a422ee9c5e1dceeaa4d7962d0ad29cb1bf1..8aa07c0696145918cc64f5a8cc09fb35f98cbbb3 100644 (file)
 
 */
 
-#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 <boost/signals2.hpp>
+#include <boost/thread/condition.hpp>
+
+class Socket;
 
 class ServerFinder : public Signaller, public ExceptionStore
 {
@@ -45,7 +53,9 @@ private:
        ServerFinder ();
        ~ServerFinder ();
 
-       void broadcast_thread ();
+       void start ();
+
+       void search_thread ();
        void listen_thread ();
 
        bool server_found (std::string) const;
@@ -53,20 +63,24 @@ private:
        void handle_accept (boost::system::error_code ec, boost::shared_ptr<Socket> socket);
 
        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<ServerDescription> _servers;
-       mutable boost::mutex _mutex;
+       mutable boost::mutex _servers_mutex;
 
        boost::asio::io_service _listen_io_service;
        boost::shared_ptr<boost::asio::ip::tcp::acceptor> _listen_acceptor;
        bool _stop;
 
+       boost::condition _search_condition;
+       boost::mutex _search_condition_mutex;
+
        static ServerFinder* _instance;
 };