From: Carl Hetherington Date: Sun, 3 May 2020 23:03:26 +0000 (+0200) Subject: All going downhill. X-Git-Url: https://git.carlh.net/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fdkdm;p=dcpomatic.git All going downhill. --- diff --git a/src/lib/cinema_kdms.cc b/src/lib/cinema_kdms.cc index a5f28c62a..40a8feade 100644 --- a/src/lib/cinema_kdms.cc +++ b/src/lib/cinema_kdms.cc @@ -28,7 +28,9 @@ #include "compose.hpp" #include "log.h" #include "zipper.h" +#include "kdm.h" #include "dcpomatic_log.h" +#include "recipient_with_kdm.h" #include #include "i18n.h" @@ -39,6 +41,7 @@ using std::string; using std::runtime_error; using boost::shared_ptr; using boost::function; +using boost::dynamic_pointer_cast; void CinemaKDMs::make_zip_file (boost::filesystem::path zip_file, dcp::NameFormat name_format, dcp::NameFormat::Map name_values) const @@ -47,9 +50,8 @@ CinemaKDMs::make_zip_file (boost::filesystem::path zip_file, dcp::NameFormat nam name_values['c'] = cinema->name; - BOOST_FOREACH (shared_ptr i, screen_kdms) { - name_values['s'] = i->screen->name; - name_values['i'] = i->kdm_id (); + BOOST_FOREACH (shared_ptr i, screen_kdms) { + i->add_name_values (name_values); string const name = careful_string_filter(name_format.get(name_values, ".xml")); zipper.add (name, i->kdm_as_xml()); } @@ -61,7 +63,7 @@ CinemaKDMs::make_zip_file (boost::filesystem::path zip_file, dcp::NameFormat nam * CinemaKDM contains the KDMs for its cinema. */ list -CinemaKDMs::collect (list > screen_kdms) +CinemaKDMs::collect (list > kdms) { list cinema_kdms; @@ -117,7 +119,7 @@ CinemaKDMs::write_directories ( path /= container_name_format.get(name_values, ""); if (!boost::filesystem::exists (path) || confirm_overwrite (path)) { boost::filesystem::create_directories (path); - ScreenWithKDM::write_files (i.screen_kdms, path, filename_format, name_values, confirm_overwrite); + write_kdm_files (i.screen_kdms, path, filename_format, name_values, confirm_overwrite); } written += i.screen_kdms.size(); } @@ -209,8 +211,12 @@ CinemaKDMs::email ( boost::algorithm::replace_all (body, "$CINEMA_NAME", i.cinema->name); string screens; - BOOST_FOREACH (shared_ptr j, i.screen_kdms) { - screens += j->screen->name + ", "; + BOOST_FOREACH (shared_ptr j, i.screen_kdms) { + /* XXX */ + shared_ptr s = dynamic_pointer_cast(j); + if (s) { + screens += s->screen->name + ", "; + } } boost::algorithm::replace_all (body, "$SCREENS", screens.substr (0, screens.length() - 2)); diff --git a/src/lib/cinema_kdms.h b/src/lib/cinema_kdms.h index 0a4f28a8f..a3a3e215e 100644 --- a/src/lib/cinema_kdms.h +++ b/src/lib/cinema_kdms.h @@ -58,5 +58,5 @@ public: ); boost::shared_ptr cinema; - std::list > screen_kdms; + std::list > kdms; }; diff --git a/src/lib/kdm.cc b/src/lib/kdm.cc new file mode 100644 index 000000000..b89fb1861 --- /dev/null +++ b/src/lib/kdm.cc @@ -0,0 +1,49 @@ +#include "util.h" +#include "recipient_with_kdm.h" +#include +#include +#include +#include +#include + +using std::list; +using std::cout; +using boost::shared_ptr; + +int +write_kdm_files ( + list > kdms, + boost::filesystem::path directory, + dcp::NameFormat name_format, + dcp::NameFormat::Map name_values, + boost::function confirm_overwrite + ) +{ + int written = 0; + + if (directory == "-") { + /* Write KDMs to the stdout */ + BOOST_FOREACH (shared_ptr i, kdms) { + cout << i->kdm_as_xml (); + ++written; + } + + return written; + } + + if (!boost::filesystem::exists (directory)) { + boost::filesystem::create_directories (directory); + } + + /* Write KDMs to the specified directory */ + BOOST_FOREACH (shared_ptr i, kdms) { + i->add_name_values (name_values); + boost::filesystem::path out = directory / careful_string_filter(name_format.get(name_values, ".xml")); + if (!boost::filesystem::exists(out) || confirm_overwrite(out)) { + i->kdm_as_xml_to_file (out); + ++written; + } + } + + return written; +} diff --git a/src/lib/kdm.h b/src/lib/kdm.h new file mode 100644 index 000000000..f07c7f72d --- /dev/null +++ b/src/lib/kdm.h @@ -0,0 +1,11 @@ +#include "recipient_with_kdm.h" +#include +#include + +extern int write_kdm_files ( + std::list > kdms, + boost::filesystem::path directory, + dcp::NameFormat name_format, + dcp::NameFormat::Map name_values, + boost::function confirm_overwrite + ); diff --git a/src/lib/recipient_with_dkdm.cc b/src/lib/recipient_with_dkdm.cc index ebe966fe4..34e66269a 100644 --- a/src/lib/recipient_with_dkdm.cc +++ b/src/lib/recipient_with_dkdm.cc @@ -120,30 +120,8 @@ RecipientWithDKDM::email ( } -int -RecipientWithDKDM::write_files ( - vector kdms, - boost::filesystem::path directory, - dcp::NameFormat name_format, - dcp::NameFormat::Map name_values, - boost::function confirm_overwrite - ) +void +RecipientWithDKDM::add_name_values (dcp::NameFormat::Map& values) { - int written = 0; - - if (!boost::filesystem::exists (directory)) { - boost::filesystem::create_directories (directory); - } - - /* Write KDMs to the specified directory */ - BOOST_FOREACH (RecipientWithDKDM const& i, kdms) { - name_values['i'] = i.kdm.cpl_id (); - boost::filesystem::path out = directory / careful_string_filter(name_format.get(name_values, ".xml")); - if (!boost::filesystem::exists (out) || confirm_overwrite (out)) { - i.kdm.as_xml (out); - ++written; - } - } - - return written; + values['i'] = kdm.cpl_id (); } diff --git a/src/lib/recipient_with_dkdm.h b/src/lib/recipient_with_dkdm.h index 8aed95275..1420d5f09 100644 --- a/src/lib/recipient_with_dkdm.h +++ b/src/lib/recipient_with_dkdm.h @@ -22,10 +22,11 @@ #define DCPOMATIC_RECIPIENT_WITH_DKDM_H #include "dkdm_recipient.h" +#include "recipient_with_kdm.h" #include #include -class RecipientWithDKDM +class RecipientWithDKDM : public RecipientWithKDM { public: RecipientWithDKDM (boost::shared_ptr r, dcp::EncryptedKDM k) @@ -33,13 +34,17 @@ public: , kdm (k) {} - void make_zip_file (boost::filesystem::path zip_file, dcp::NameFormat name_format, dcp::NameFormat::Map name_values) const; + void add_name_values (dcp::NameFormat::Map& values); - static int write_files ( - std::vector kdms, boost::filesystem::path directory, - dcp::NameFormat name_format, dcp::NameFormat::Map name_values, - boost::function confirm_overwrite - ); + std::string kdm_as_xml () const { + return kdm.as_xml (); + } + + void kdm_as_xml_to_file (boost::filesystem::path out) const { + return kdm.as_xml (out); + } + + void make_zip_file (boost::filesystem::path zip_file, dcp::NameFormat name_format, dcp::NameFormat::Map name_values) const; static void email ( std::vector kdms, diff --git a/src/lib/recipient_with_kdm.h b/src/lib/recipient_with_kdm.h new file mode 100644 index 000000000..892a082fd --- /dev/null +++ b/src/lib/recipient_with_kdm.h @@ -0,0 +1,15 @@ +#ifndef DCPOMATIC_RECIPIENT_WITH_KDM_H +#define DCPOMATIC_RECIPIENT_WITH_KDM_H + +#include +#include + +class RecipientWithKDM +{ +public: + virtual void add_name_values (dcp::NameFormat::Map& values) = 0; + virtual std::string kdm_as_xml () const = 0; + virtual void kdm_as_xml_to_file (boost::filesystem::path out) const = 0; +}; + +#endif diff --git a/src/lib/screen_with_kdm.cc b/src/lib/screen_with_kdm.cc index d6cfd47da..2eaf74bef 100644 --- a/src/lib/screen_with_kdm.cc +++ b/src/lib/screen_with_kdm.cc @@ -29,42 +29,11 @@ using std::cout; using std::list; using boost::shared_ptr; -int -ScreenWithKDM::write_files ( - list > screen_kdms, - boost::filesystem::path directory, - dcp::NameFormat name_format, - dcp::NameFormat::Map name_values, - boost::function confirm_overwrite - ) +void +ScreenWithKDM::add_name_values (dcp::NameFormat::Map& values) { - int written = 0; - - if (directory == "-") { - /* Write KDMs to the stdout */ - BOOST_FOREACH (shared_ptr i, screen_kdms) { - cout << i->kdm_as_xml (); - ++written; - } - - return written; - } - - if (!boost::filesystem::exists (directory)) { - boost::filesystem::create_directories (directory); - } - - /* Write KDMs to the specified directory */ - BOOST_FOREACH (shared_ptr i, screen_kdms) { - name_values['c'] = i->screen->cinema ? i->screen->cinema->name : ""; - name_values['s'] = i->screen->name; - name_values['i'] = i->kdm_id (); - boost::filesystem::path out = directory / careful_string_filter(name_format.get(name_values, ".xml")); - if (!boost::filesystem::exists (out) || confirm_overwrite (out)) { - i->kdm_as_xml (out); - ++written; - } - } - - return written; + values['c'] = screen->cinema ? screen->cinema->name : ""; + values['s'] = screen->name; + values['i'] = kdm_id (); } + diff --git a/src/lib/screen_with_kdm.h b/src/lib/screen_with_kdm.h index 53fbebf3c..31ed38875 100644 --- a/src/lib/screen_with_kdm.h +++ b/src/lib/screen_with_kdm.h @@ -24,6 +24,7 @@ #ifdef DCPOMATIC_VARIANT_SWAROOP #include "encrypted_ecinema_kdm.h" #endif +#include "recipient_with_kdm.h" #include #include #include @@ -33,7 +34,7 @@ namespace dcpomatic { } /** Simple class to collect a screen and an encrypted KDM */ -class ScreenWithKDM +class ScreenWithKDM : public RecipientWithKDM { public: ScreenWithKDM (boost::shared_ptr s) @@ -42,15 +43,9 @@ public: virtual ~ScreenWithKDM () {} - virtual std::string kdm_as_xml () const = 0; - virtual void kdm_as_xml (boost::filesystem::path out) const = 0; virtual std::string kdm_id () const = 0; - static int write_files ( - std::list > screen_kdms, boost::filesystem::path directory, - dcp::NameFormat name_format, dcp::NameFormat::Map name_values, - boost::function confirm_overwrite - ); + void add_name_values (dcp::NameFormat::Map& values); boost::shared_ptr screen; }; @@ -67,7 +62,7 @@ public: return kdm.as_xml (); } - void kdm_as_xml (boost::filesystem::path out) const { + void kdm_as_xml_to_file (boost::filesystem::path out) const { return kdm.as_xml (out); } @@ -91,7 +86,7 @@ public: return kdm.as_xml (); } - void kdm_as_xml (boost::filesystem::path out) const { + void kdm_as_xml_to_file (boost::filesystem::path out) const { return kdm.as_xml (out); } diff --git a/src/lib/wscript b/src/lib/wscript index 1f9b1d176..1f7c1e694 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -126,6 +126,7 @@ sources = """ job_manager.cc j2k_encoder.cc json_server.cc + kdm.cc kdm_recipient.cc lock_file_checker.cc log.cc diff --git a/src/tools/dcpomatic_kdm_cli.cc b/src/tools/dcpomatic_kdm_cli.cc index 9ced2d4bf..f0c05c89d 100644 --- a/src/tools/dcpomatic_kdm_cli.cc +++ b/src/tools/dcpomatic_kdm_cli.cc @@ -31,6 +31,7 @@ #include "lib/screen.h" #include "lib/cinema.h" #include "lib/cinema_kdms.h" +#include "lib/kdm.h" #include #include #include @@ -131,7 +132,7 @@ always_overwrite () void write_files ( - list > screen_kdms, + list > kdms, bool zip, boost::filesystem::path output, dcp::NameFormat container_name_format, @@ -142,7 +143,7 @@ write_files ( { if (zip) { int const N = CinemaKDMs::write_zip_files ( - CinemaKDMs::collect (screen_kdms), + CinemaKDMs::collect (kdms), output, container_name_format, filename_format, @@ -154,8 +155,8 @@ write_files ( cout << "Wrote " << N << " ZIP files to " << output << "\n"; } } else { - int const N = ScreenWithKDM::write_files ( - screen_kdms, output, filename_format, values, + int const N = write_kdm_files ( + kdms, output, filename_format, values, bind (&always_overwrite) );