#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"
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
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());
}
* 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;
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();
}
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));
);
boost::shared_ptr<Cinema> cinema;
- std::list<boost::shared_ptr<ScreenWithKDM> > screen_kdms;
+ std::list<boost::shared_ptr<RecipientWithKDM> > kdms;
};
--- /dev/null
+#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;
+}
--- /dev/null
+#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
+ );
}
-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 ();
}
#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)
, 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,
--- /dev/null
+#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
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 ();
}
+
#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>
}
/** Simple class to collect a screen and an encrypted KDM */
-class ScreenWithKDM
+class ScreenWithKDM : public RecipientWithKDM
{
public:
ScreenWithKDM (boost::shared_ptr<dcpomatic::Screen> s)
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;
};
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);
}
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);
}
job_manager.cc
j2k_encoder.cc
json_server.cc
+ kdm.cc
kdm_recipient.cc
lock_file_checker.cc
log.cc
#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>
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,
{
if (zip) {
int const N = CinemaKDMs::write_zip_files (
- CinemaKDMs::collect (screen_kdms),
+ CinemaKDMs::collect (kdms),
output,
container_name_format,
filename_format,
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)
);