Changes to libdcp API.
[dcpomatic.git] / src / lib / server_finder.h
index 8b56022de693fc36694c5cd20e210fff48a077c7..c0f1feb66e1d329167e55007ec8bdf4f6ac09521 100644 (file)
 
 */
 
-#include <boost/signals2.hpp>
 #include "server.h"
+#include <boost/signals2.hpp>
 
-class ServerFinder
+class ServerFinder : public ExceptionStore
 {
 public:
-       ServerFinder ();
-       ~ServerFinder ();
+       void connect (boost::function<void (ServerDescription)>);
 
-       boost::signals2::signal<void (ServerDescription)> ServerFound;
+       static ServerFinder* instance ();
+       static void drop ();
+
+       void disable () {
+               _disabled = true;
+       }
 
 private:
+       ServerFinder ();
+       ~ServerFinder ();
+
        void broadcast_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> socket);
+
+       boost::signals2::signal<void (ServerDescription)> ServerFound;
+
+       bool _disabled;
        
-       /** A thread to periodically issue broadcasts to find encoding servers */
+       /** Thread to periodically issue broadcasts to find encoding servers */
        boost::thread* _broadcast_thread;
+       /** Thread to listen to the responses from servers */
        boost::thread* _listen_thread;
 
-       bool _terminate;
-       boost::mutex _mutex;
+       std::list<ServerDescription> _servers;
+       mutable boost::mutex _mutex;
+
+       boost::asio::io_service _listen_io_service;
+       boost::shared_ptr<boost::asio::ip::tcp::acceptor> _listen_acceptor;
+       bool _stop;
+
+       static ServerFinder* _instance;
 };