All going downhill. dkdm
authorCarl Hetherington <cth@carlh.net>
Sun, 3 May 2020 23:03:26 +0000 (01:03 +0200)
committerCarl Hetherington <cth@carlh.net>
Sun, 3 May 2020 23:03:26 +0000 (01:03 +0200)
src/lib/cinema_kdms.cc
src/lib/cinema_kdms.h
src/lib/kdm.cc [new file with mode: 0644]
src/lib/kdm.h [new file with mode: 0644]
src/lib/recipient_with_dkdm.cc
src/lib/recipient_with_dkdm.h
src/lib/recipient_with_kdm.h [new file with mode: 0644]
src/lib/screen_with_kdm.cc
src/lib/screen_with_kdm.h
src/lib/wscript
src/tools/dcpomatic_kdm_cli.cc

index a5f28c62a5f3a7c2358be7f36c468677ebbd8758..40a8feade8604a03260c129d8d27d57d91371423 100644 (file)
@@ -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 <boost/foreach.hpp>
 
 #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<ScreenWithKDM> i, screen_kdms) {
-               name_values['s'] = i->screen->name;
-               name_values['i'] = i->kdm_id ();
+       BOOST_FOREACH (shared_ptr<RecipientWithKDM> 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>
-CinemaKDMs::collect (list<shared_ptr<ScreenWithKDM> > screen_kdms)
+CinemaKDMs::collect (list<shared_ptr<RecipientWithKDM> > kdms)
 {
        list<CinemaKDMs> 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<ScreenWithKDM> j, i.screen_kdms) {
-                       screens += j->screen->name + ", ";
+               BOOST_FOREACH (shared_ptr<RecipientWithKDM> j, i.screen_kdms) {
+                       /* XXX */
+                       shared_ptr<ScreenWithKDM> s = dynamic_pointer_cast<ScreenWithKDM>(j);
+                       if (s) {
+                               screens += s->screen->name + ", ";
+                       }
                }
                boost::algorithm::replace_all (body, "$SCREENS", screens.substr (0, screens.length() - 2));
 
index 0a4f28a8f0dec0ca6cec20522a8dbf1080371a72..a3a3e215ee3c3c3b4acd6d8b0f7380d88be024c0 100644 (file)
@@ -58,5 +58,5 @@ public:
                );
 
        boost::shared_ptr<Cinema> cinema;
-       std::list<boost::shared_ptr<ScreenWithKDM> > screen_kdms;
+       std::list<boost::shared_ptr<RecipientWithKDM> > kdms;
 };
diff --git a/src/lib/kdm.cc b/src/lib/kdm.cc
new file mode 100644 (file)
index 0000000..b89fb18
--- /dev/null
@@ -0,0 +1,49 @@
+#include "util.h"
+#include "recipient_with_kdm.h"
+#include <dcp/name_format.h>
+#include <boost/foreach.hpp>
+#include <boost/function.hpp>
+#include <boost/filesystem.hpp>
+#include <iostream>
+
+using std::list;
+using std::cout;
+using boost::shared_ptr;
+
+int
+write_kdm_files (
+       list<shared_ptr<RecipientWithKDM> > kdms,
+       boost::filesystem::path directory,
+       dcp::NameFormat name_format,
+       dcp::NameFormat::Map name_values,
+       boost::function<bool (boost::filesystem::path)> confirm_overwrite
+       )
+{
+       int written = 0;
+
+       if (directory == "-") {
+               /* Write KDMs to the stdout */
+               BOOST_FOREACH (shared_ptr<RecipientWithKDM> 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<RecipientWithKDM> 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 (file)
index 0000000..f07c7f7
--- /dev/null
@@ -0,0 +1,11 @@
+#include "recipient_with_kdm.h"
+#include <boost/function.hpp>
+#include <list>
+
+extern int write_kdm_files (
+       std::list<boost::shared_ptr<RecipientWithKDM> > kdms,
+       boost::filesystem::path directory,
+       dcp::NameFormat name_format,
+       dcp::NameFormat::Map name_values,
+       boost::function<bool (boost::filesystem::path)> confirm_overwrite
+       );
index ebe966fe4302283de1476eb1c3c80f36da035406..34e66269a0149a1272e21cd559a686a2e62945fb 100644 (file)
@@ -120,30 +120,8 @@ RecipientWithDKDM::email (
 }
 
 
-int
-RecipientWithDKDM::write_files (
-       vector<RecipientWithDKDM> kdms,
-       boost::filesystem::path directory,
-       dcp::NameFormat name_format,
-       dcp::NameFormat::Map name_values,
-       boost::function<bool (boost::filesystem::path)> 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 ();
 }
index 8aed9527525525143b819e29437b1b478854d552..1420d5f099777c45949c2880ab32c0a5146a706e 100644 (file)
 #define DCPOMATIC_RECIPIENT_WITH_DKDM_H
 
 #include "dkdm_recipient.h"
+#include "recipient_with_kdm.h"
 #include <dcp/encrypted_kdm.h>
 #include <dcp/name_format.h>
 
-class RecipientWithDKDM
+class RecipientWithDKDM : public RecipientWithKDM
 {
 public:
        RecipientWithDKDM (boost::shared_ptr<DKDMRecipient> 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<RecipientWithDKDM> kdms, boost::filesystem::path directory,
-               dcp::NameFormat name_format, dcp::NameFormat::Map name_values,
-               boost::function<bool (boost::filesystem::path)> 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<RecipientWithDKDM> kdms,
diff --git a/src/lib/recipient_with_kdm.h b/src/lib/recipient_with_kdm.h
new file mode 100644 (file)
index 0000000..892a082
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef DCPOMATIC_RECIPIENT_WITH_KDM_H
+#define DCPOMATIC_RECIPIENT_WITH_KDM_H
+
+#include <dcp/name_format.h>
+#include <boost/filesystem.hpp>
+
+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
index d6cfd47da65333a3e3936115a52c64128523526e..2eaf74befe50724c5e22d616d75fa29f8f505b02 100644 (file)
@@ -29,42 +29,11 @@ using std::cout;
 using std::list;
 using boost::shared_ptr;
 
-int
-ScreenWithKDM::write_files (
-       list<shared_ptr<ScreenWithKDM> > screen_kdms,
-       boost::filesystem::path directory,
-       dcp::NameFormat name_format,
-       dcp::NameFormat::Map name_values,
-       boost::function<bool (boost::filesystem::path)> 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<ScreenWithKDM> 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<ScreenWithKDM> 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 ();
 }
+
index 53fbebf3c099ed3f628e2d36baca50d7a2f23423..31ed38875f33ae0ee7a188d5155d60b9255bf3e7 100644 (file)
@@ -24,6 +24,7 @@
 #ifdef DCPOMATIC_VARIANT_SWAROOP
 #include "encrypted_ecinema_kdm.h"
 #endif
+#include "recipient_with_kdm.h"
 #include <dcp/encrypted_kdm.h>
 #include <dcp/name_format.h>
 #include <boost/shared_ptr.hpp>
@@ -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<dcpomatic::Screen> 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<boost::shared_ptr<ScreenWithKDM> > screen_kdms, boost::filesystem::path directory,
-               dcp::NameFormat name_format, dcp::NameFormat::Map name_values,
-               boost::function<bool (boost::filesystem::path)> confirm_overwrite
-               );
+       void add_name_values (dcp::NameFormat::Map& values);
 
        boost::shared_ptr<dcpomatic::Screen> 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);
        }
 
index 1f9b1d1762f4d51f067ce155d843807595caa314..1f7c1e694012a7280a35b5bcef5b1920bcf225a1 100644 (file)
@@ -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
index 9ced2d4bff3165116524d00128ba3d5b55f31811..f0c05c89d7be42ad7a17204c8b46050896aa6538 100644 (file)
@@ -31,6 +31,7 @@
 #include "lib/screen.h"
 #include "lib/cinema.h"
 #include "lib/cinema_kdms.h"
+#include "lib/kdm.h"
 #include <dcp/certificate.h>
 #include <dcp/decrypted_kdm.h>
 #include <dcp/encrypted_kdm.h>
@@ -131,7 +132,7 @@ always_overwrite ()
 
 void
 write_files (
-       list<shared_ptr<ScreenWithKDM> > screen_kdms,
+       list<shared_ptr<RecipientWithKDM> > 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)
                        );