From: Carl Hetherington Date: Sat, 9 Jun 2018 21:52:08 +0000 (+0100) Subject: Factor out sending a message to another tool (possibly starting it first). X-Git-Tag: v2.13.29~4 X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=e706ae3919667c690cfd5639423bdfffa4c2e681 Factor out sending a message to another tool (possibly starting it first). --- 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 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 (BATCH_JOB_PORT)); + boost::asio::ip::tcp::resolver::query query ("127.0.0.1", raw_convert (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 ()