Merge branch '1.0' of ssh://main.carlh.net/home/carl/git/libdcp into 1.0
[libdcp.git] / src / dcp.h
1 /*
2     Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /** @file  src/dcp.h
21  *  @brief DCP class.
22  */
23
24 #ifndef LIBDCP_DCP_H
25 #define LIBDCP_DCP_H
26
27 #include "types.h"
28 #include "certificate.h"
29 #include "metadata.h"
30 #include <boost/shared_ptr.hpp>
31 #include <boost/signals2.hpp>
32 #include <string>
33 #include <vector>
34
35 namespace xmlpp {
36         class Document;
37         class Element;
38 }
39
40 /** @brief Namespace for everything in libdcp */
41 namespace dcp
42 {
43
44 class Content;
45 class Reel;
46 class CPL;
47 class XMLMetadata;
48 class Signer;
49 class DecryptedKDM;
50 class Asset;
51 class DCPReadError;
52
53 /** @class DCP
54  *  @brief A class to create or read a DCP.
55  */
56
57 class DCP : public boost::noncopyable
58 {
59 public:
60         /** Construct a DCP.  You can pass an existing DCP's directory
61          *  as the parameter; alternatively, directory will be created
62          *  if it does not exist.  Note that if you pass an existing DCP
63          *  into this constructor it will not be read until you call ::read().
64          *
65          *  @param directory Directory containing the DCP's files.
66          */
67         DCP (boost::filesystem::path directory);
68
69         typedef std::list<boost::shared_ptr<DCPReadError> > ReadErrors;
70
71         /** Read the DCP's structure into this object.
72          *  @param keep_going true to try to keep going in the face of (some) errors.
73          *  @param errors List of errors that will be added to if keep_going is true.
74          */
75         void read (bool keep_going = false, ReadErrors* errors = 0);
76
77         /** Compare this DCP with another, according to various options.
78          *  @param other DCP to compare this one to.
79          *  @param options Options to define what "equality" means.
80          *  @param note Functor to handle notes made by the equality operation.
81          *  @return true if the DCPs are equal according to EqualityOptions, otherwise false.
82          */
83         bool equals (DCP const & other, EqualityOptions options, NoteHandler note) const;
84
85         void add (boost::shared_ptr<CPL> cpl);
86
87         std::list<boost::shared_ptr<CPL> > cpls () const;
88         std::list<boost::shared_ptr<Asset> > assets () const;
89
90         bool encrypted () const;
91
92         void add (DecryptedKDM const &);
93
94         void write_xml (
95                 Standard standard,
96                 XMLMetadata metadata = XMLMetadata (),
97                 boost::shared_ptr<const Signer> signer = boost::shared_ptr<const Signer> ()
98         );
99
100 private:
101
102         /** Write the PKL file.
103          *  @param pkl_uuid UUID to use.
104          */
105         boost::filesystem::path write_pkl (
106                 Standard standard,
107                 std::string pkl_uuid,
108                 XMLMetadata metadata,
109                 boost::shared_ptr<const Signer> signer
110                 ) const;
111
112         void write_volindex (Standard standard) const;
113
114         /** Write the ASSETMAP file.
115          *  @param pkl_uuid UUID of our PKL.
116          *  @param pkl_length Length of our PKL in bytes.
117          */
118         void write_assetmap (Standard standard, std::string pkl_uuid, int pkl_length, XMLMetadata metadata) const;
119
120         /** the directory that we are writing to */
121         boost::filesystem::path _directory;
122         /** the CPLs that make up this DCP */
123         std::list<boost::shared_ptr<CPL> > _cpls;
124 };
125
126 }
127
128 #endif