Merge branch 'master' of /home/carl/git/dvdomatic
[dcpomatic.git] / src / lib / server.h
index f7a0abb800163985e22129c413790135b80528bb..32ba8dc4b96757fe0d3938317e2fe1c0c9abff2b 100644 (file)
 
 /** @file src/server.h
  *  @brief Class to describe a server to which we can send
- *  encoding work.
+ *  encoding work, and a class to implement such a server.
  */
 
 #include <string>
+#include <boost/thread.hpp>
+#include <boost/asio.hpp>
+#include <boost/thread/condition.hpp>
+#include "log.h"
 
-/** @class Server
+class Socket;
+
+/** @class ServerDescription
  *  @brief Class to describe a server to which we can send encoding work.
  */
-class Server
+class ServerDescription
 {
 public:
        /** @param h Server host name or IP address in string form.
         *  @param t Number of threads to use on the server.
         */
-       Server (std::string h, int t)
+       ServerDescription (std::string h, int t)
                : _host_name (h)
                , _threads (t)
        {}
@@ -48,9 +54,17 @@ public:
                return _threads;
        }
 
+       void set_host_name (std::string n) {
+               _host_name = n;
+       }
+
+       void set_threads (int t) {
+               _threads = t;
+       }
+
        std::string as_metadata () const;
        
-       static Server * create_from_metadata (std::string v);
+       static ServerDescription * create_from_metadata (std::string v);
 
 private:
        /** server's host name */
@@ -58,3 +72,21 @@ private:
        /** number of threads to use on the server */
        int _threads;
 };
+
+class Server
+{
+public:
+       Server (Log* log);
+
+       void run (int num_threads);
+
+private:
+       void worker_thread ();
+       int process (boost::shared_ptr<Socket> socket);
+
+       std::vector<boost::thread *> _worker_threads;
+       std::list<boost::shared_ptr<Socket> > _queue;
+       boost::mutex _worker_mutex;
+       boost::condition _worker_condition;
+       Log* _log;
+};