diff options
| author | Carl Hetherington <cth@carlh.net> | 2018-06-09 22:52:08 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2018-06-09 22:52:08 +0100 |
| commit | e706ae3919667c690cfd5639423bdfffa4c2e681 (patch) | |
| tree | 0c49e825e2df02f55be43722f231f747171e23b1 /src | |
| parent | 43254ee65acd9100573cff5a6faef3d3ec3e46b1 (diff) | |
Factor out sending a message to another tool (possibly starting it first).
Diffstat (limited to 'src')
| -rw-r--r-- | src/tools/dcpomatic.cc | 56 |
1 files changed, 32 insertions, 24 deletions
diff --git a/src/tools/dcpomatic.cc b/src/tools/dcpomatic.cc index 4f034b2b5..f349a7cf3 100644 --- a/src/tools/dcpomatic.cc +++ b/src/tools/dcpomatic.cc @@ -110,6 +110,7 @@ using std::exception; using boost::shared_ptr; using boost::dynamic_pointer_cast; using boost::optional; +using boost::function; using dcp::raw_convert; class FilmChangedClosingDialog : public boost::noncopyable @@ -680,55 +681,62 @@ private: _kdm_dialog->Show (); } - void jobs_make_dcp_batch () + /** @return false if we succeeded, true if not */ + bool send_to_other_tool (int port, function<void(boost::filesystem::path)> start, string message) { - if (!_film) { - return; - } - - if (!get_hints(_film).empty() && Config::instance()->show_hints_before_make_dcp()) { - HintsDialog* hints = new HintsDialog (this, _film, false); - int const r = hints->ShowModal(); - hints->Destroy (); - if (r == wxID_CANCEL) { - return; - } - } - - _film->write_metadata (); - /* i = 0; try to connect via socket - i = 1; try again, and then try to start the batch converter + i = 1; try again, and then try to start the tool i = 2 onwards; try again. */ for (int i = 0; i < 8; ++i) { try { boost::asio::io_service io_service; boost::asio::ip::tcp::resolver resolver (io_service); - boost::asio::ip::tcp::resolver::query query ("127.0.0.1", raw_convert<string> (BATCH_JOB_PORT)); + boost::asio::ip::tcp::resolver::query query ("127.0.0.1", raw_convert<string> (port)); boost::asio::ip::tcp::resolver::iterator endpoint_iterator = resolver.resolve (query); Socket socket (5); socket.connect (*endpoint_iterator); DCPOMATIC_ASSERT (_film->directory ()); - string s = _film->directory()->string (); - socket.write (s.length() + 1); - socket.write ((uint8_t *) s.c_str(), s.length() + 1); + socket.write (message.length() + 1); + socket.write ((uint8_t *) message.c_str(), message.length() + 1); /* OK\0 */ uint8_t ok[3]; socket.read (ok, 3); - return; + return false; } catch (exception& e) { } if (i == 1) { - start_batch_converter (wx_to_std (wxStandardPaths::Get().GetExecutablePath())); + start (wx_to_std (wxStandardPaths::Get().GetExecutablePath())); } dcpomatic_sleep (1); } - error_dialog (this, _("Could not find batch converter.")); + return true; + } + + void jobs_make_dcp_batch () + { + if (!_film) { + return; + } + + if (!get_hints(_film).empty() && Config::instance()->show_hints_before_make_dcp()) { + HintsDialog* hints = new HintsDialog (this, _film, false); + int const r = hints->ShowModal(); + hints->Destroy (); + if (r == wxID_CANCEL) { + return; + } + } + + _film->write_metadata (); + + if (send_to_other_tool (BATCH_JOB_PORT, bind (&start_batch_converter, _1), _film->directory()->string())) { + error_dialog (this, _("Could not find batch converter.")); + } } void jobs_make_self_dkdm () |
