Various bits mostly related to colour conversions.
[dcpomatic.git] / src / lib / server.h
index d06df34e9e649dd84d49a85dc6472f6c5cf2b87a..56a1fdab9f20d133f9436c0c028015a8e13a4339 100644 (file)
 
 */
 
+#ifndef DCPOMATIC_SERVER_H
+#define DCPOMATIC_SERVER_H
+
 /** @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 <libxml++/libxml++.h>
+#include "log.h"
+
+class Socket;
 
-/** @class Server
+namespace cxml {
+       class Node;
+}
+
+/** @class ServerDescription
  *  @brief Class to describe a server to which we can send encoding work.
  */
-class Server
+class ServerDescription
 {
 public:
+       ServerDescription ()
+               : _host_name ("")
+               , _threads (1)
+       {}
+       
        /** @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)
        {}
 
+       ServerDescription (boost::shared_ptr<const cxml::Node>);
+
+       /* Default copy constructor is fine */
+       
        /** @return server's host name or IP address in string form */
        std::string host_name () const {
                return _host_name;
@@ -56,9 +79,9 @@ public:
                _threads = t;
        }
 
-       std::string as_metadata () const;
+       void as_xml (xmlpp::Node *) const;
        
-       static Server * create_from_metadata (std::string v);
+       static boost::optional<ServerDescription> create_from_metadata (std::string);
 
 private:
        /** server's host name */
@@ -66,3 +89,23 @@ private:
        /** number of threads to use on the server */
        int _threads;
 };
+
+class Server : public boost::noncopyable
+{
+public:
+       Server (boost::shared_ptr<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;
+       boost::shared_ptr<Log> _log;
+};
+
+#endif