Basics of send-to-batch-converter; not tested on Windows nor OS X.
[dcpomatic.git] / src / tools / dcpomatic_batch.cc
index 7db05c0ddde0182489b889bdb88a99a64d3e0719..677861c3d4ae688dd58da8d759ae38c6583f3f4d 100644 (file)
 #include "lib/util.h"
 #include "lib/film.h"
 #include "lib/job_manager.h"
+#include "lib/dcpomatic_socket.h"
 #include <wx/aboutdlg.h>
 #include <wx/stdpaths.h>
 #include <wx/cmdline.h>
 #include <wx/preferences.h>
 #include <wx/wx.h>
+#include <iostream>
 
 using std::exception;
+using std::string;
+using std::cout;
 using boost::shared_ptr;
+using boost::thread;
+using boost::scoped_array;
 
 static std::string film_to_load;
 
@@ -118,6 +124,19 @@ public:
                Bind (wxEVT_SIZE, boost::bind (&DOMFrame::sized, this, _1));
        }
 
+       void start_job (boost::filesystem::path path)
+       {
+               try {
+                       shared_ptr<Film> film (new Film (path));
+                       film->read_metadata ();
+                       film->make_dcp ();
+               } catch (std::exception& e) {
+                       wxString p = std_to_wx (path.string ());
+                       wxCharBuffer b = p.ToUTF8 ();
+                       error_dialog (this, wxString::Format (_("Could not open film at %s (%s)"), p.data(), std_to_wx (e.what()).data()));
+               }
+       }
+
 private:
        void sized (wxSizeEvent& ev)
        {
@@ -207,15 +226,7 @@ private:
                }
 
                if (r == wxID_OK) {
-                       try {
-                               shared_ptr<Film> film (new Film (wx_to_std (c->GetPath ())));
-                               film->read_metadata ();
-                               film->make_dcp ();
-                       } catch (std::exception& e) {
-                               wxString p = c->GetPath ();
-                               wxCharBuffer b = p.ToUTF8 ();
-                               error_dialog (this, wxString::Format (_("Could not open film at %s (%s)"), p.data(), std_to_wx (e.what()).data()));
-                       }
+                       start_job (wx_to_std (c->GetPath ()));
                }
 
                _last_parent = boost::filesystem::path (wx_to_std (c->GetPath ())).parent_path ();
@@ -234,6 +245,32 @@ static const wxCmdLineEntryDesc command_line_description[] = {
        { wxCMD_LINE_NONE, "", "", "", wxCmdLineParamType (0), 0 }
 };
 
+class JobServer : public Server
+{
+public:
+       JobServer (DOMFrame* frame)
+               : Server (Config::instance()->server_port_base() + 2)
+               , _frame (frame)
+       {}
+
+       void handle (shared_ptr<Socket> socket)
+       {
+               try {
+                       int const length = socket->read_uint32 ();
+                       cout << "len=" << length << "\n";
+                       scoped_array<char> buffer (new char[length]);
+                       socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length);
+                       string s (buffer.get());
+                       _frame->start_job (s);
+               } catch (...) {
+
+               }
+       }
+
+private:
+       DOMFrame* _frame;
+};
+
 class App : public wxApp
 {
        bool OnInit ()
@@ -273,6 +310,9 @@ class App : public wxApp
                f->Maximize ();
                f->Show ();
 
+               JobServer* server = new JobServer (f);
+               new thread (boost::bind (&JobServer::run, server));
+
                signal_manager = new wxSignalManager (this);
                this->Bind (wxEVT_IDLE, boost::bind (&App::idle, this));