std::shared_ptr
[dcpomatic.git] / src / lib / encode_server_finder.h
index 58c7677f66229c97a03ded812932a3c794a5054b..a58c75382e35fcf0f30b6296b1b141091ad2d169 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2013-2015 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2013-2018 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 
 class Socket;
 
+/** @class EncodeServerFinder
+ *  @brief Locater of encoding servers.
+ *
+ *  This class finds active (i.e. responding) encode servers.  Depending on
+ *  configuration it finds servers by:
+ *
+ *  1. broadcasting a request to the local subnet and
+ *  2. checking to see if any of the configured server hosts are up.
+ */
 class EncodeServerFinder : public Signaller, public ExceptionStore
 {
 public:
        static EncodeServerFinder* instance ();
        static void drop ();
 
-       void disable () {
-               _disabled = true;
-       }
-
-       bool disabled () const {
-               return _disabled;
-       }
+       void stop ();
 
        std::list<EncodeServerDescription> servers () const;
 
@@ -59,24 +62,24 @@ private:
        void search_thread ();
        void listen_thread ();
 
-       bool server_found (std::string) const;
+       boost::optional<std::list<EncodeServerDescription>::iterator> server_found (std::string);
        void start_accept ();
-       void handle_accept (boost::system::error_code ec, boost::shared_ptr<Socket> socket);
+       void handle_accept (boost::system::error_code ec, std::shared_ptr<Socket> socket);
 
        void config_changed (Config::Property what);
 
-       bool _disabled;
-
        /** Thread to periodically issue broadcasts and requests to find encoding servers */
-       boost::thread* _search_thread;
+       boost::thread _search_thread;
        /** Thread to listen to the responses from servers */
-       boost::thread* _listen_thread;
+       boost::thread _listen_thread;
 
+       /** Available servers */
        std::list<EncodeServerDescription> _servers;
+       /** Mutex for _servers */
        mutable boost::mutex _servers_mutex;
 
        boost::asio::io_service _listen_io_service;
-       boost::shared_ptr<boost::asio::ip::tcp::acceptor> _listen_acceptor;
+       std::shared_ptr<boost::asio::ip::tcp::acceptor> _listen_acceptor;
        bool _stop;
 
        boost::condition _search_condition;