2 Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
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.
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.
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.
20 /** @file src/config.h
21 * @brief Class holding configuration.
24 #ifndef DCPOMATIC_CONFIG_H
25 #define DCPOMATIC_CONFIG_H
27 #include "isdcf_metadata.h"
29 #include <dcp/certificate_chain.h>
30 #include <dcp/encrypted_kdm.h>
31 #include <boost/shared_ptr.hpp>
32 #include <boost/signals2.hpp>
33 #include <boost/filesystem.hpp>
36 class CinemaSoundProcessor;
42 * @brief A singleton class holding configuration.
44 class Config : public boost::noncopyable
47 /** @return number of threads to use for J2K encoding on the local machine */
48 int num_local_encoding_threads () const {
49 return _num_local_encoding_threads;
52 boost::filesystem::path default_directory () const {
53 return _default_directory;
56 boost::filesystem::path default_directory_or (boost::filesystem::path a) const;
64 /** @return base port number to use for J2K encoding servers */
65 int server_port_base () const {
66 return _server_port_base;
69 void set_use_any_servers (bool u) {
71 changed (USE_ANY_SERVERS);
74 bool use_any_servers () const {
75 return _use_any_servers;
78 /** @param s New list of servers */
79 void set_servers (std::vector<std::string> s) {
84 /** @return Host names / IP addresses of J2K encoding servers that should definitely be used */
85 std::vector<std::string> servers () const {
89 bool only_servers_encode () const {
90 return _only_servers_encode;
93 Protocol tms_protocol () const {
97 /** @return The IP address of a TMS that we can copy DCPs to */
98 std::string tms_ip () const {
102 /** @return The path on a TMS that we should changed DCPs to */
103 std::string tms_path () const {
107 /** @return User name to log into the TMS with */
108 std::string tms_user () const {
112 /** @return Password to log into the TMS with */
113 std::string tms_password () const {
114 return _tms_password;
117 /** @return The cinema sound processor that we are using */
118 CinemaSoundProcessor const * cinema_sound_processor () const {
119 return _cinema_sound_processor;
122 std::list<boost::shared_ptr<Cinema> > cinemas () const {
126 std::list<int> allowed_dcp_frame_rates () const {
127 return _allowed_dcp_frame_rates;
130 bool allow_any_dcp_frame_rate () const {
131 return _allow_any_dcp_frame_rate;
134 ISDCFMetadata default_isdcf_metadata () const {
135 return _default_isdcf_metadata;
138 boost::optional<std::string> language () const {
142 int default_still_length () const {
143 return _default_still_length;
146 Ratio const * default_container () const {
147 return _default_container;
150 DCPContentType const * default_dcp_content_type () const {
151 return _default_dcp_content_type;
154 std::string dcp_issuer () const {
158 std::string dcp_creator () const {
162 int default_j2k_bandwidth () const {
163 return _default_j2k_bandwidth;
166 int default_audio_delay () const {
167 return _default_audio_delay;
170 bool default_interop () const {
171 return _default_interop;
174 std::string mail_server () const {
178 int mail_port () const {
182 std::string mail_user () const {
186 std::string mail_password () const {
187 return _mail_password;
190 std::string kdm_subject () const {
194 std::string kdm_from () const {
198 std::string kdm_cc () const {
202 std::string kdm_bcc () const {
206 std::string kdm_email () const {
210 boost::shared_ptr<const dcp::CertificateChain> signer_chain () const {
211 return _signer_chain;
214 boost::shared_ptr<const dcp::CertificateChain> decryption_chain () const {
215 return _decryption_chain;
218 bool check_for_updates () const {
219 return _check_for_updates;
222 bool check_for_test_updates () const {
223 return _check_for_test_updates;
226 int maximum_j2k_bandwidth () const {
227 return _maximum_j2k_bandwidth;
230 int log_types () const {
234 bool automatic_audio_analysis () const {
235 return _automatic_audio_analysis;
238 #ifdef DCPOMATIC_WINDOWS
239 bool win32_console () const {
240 return _win32_console;
244 std::vector<boost::filesystem::path> history () const {
248 std::vector<dcp::EncryptedKDM> dkdms () const {
252 /** @param n New number of local encoding threads */
253 void set_num_local_encoding_threads (int n) {
254 maybe_set (_num_local_encoding_threads, n);
257 void set_default_directory (boost::filesystem::path d) {
258 maybe_set (_default_directory, d);
261 /** @param p New server port */
262 void set_server_port_base (int p) {
263 maybe_set (_server_port_base, p);
266 void set_only_servers_encode (bool o) {
267 maybe_set (_only_servers_encode, o);
270 void set_tms_protocol (Protocol p) {
271 maybe_set (_tms_protocol, p);
274 /** @param i IP address of a TMS that we can copy DCPs to */
275 void set_tms_ip (std::string i) {
276 maybe_set (_tms_ip, i);
279 /** @param p Path on a TMS that we should changed DCPs to */
280 void set_tms_path (std::string p) {
281 maybe_set (_tms_path, p);
284 /** @param u User name to log into the TMS with */
285 void set_tms_user (std::string u) {
286 maybe_set (_tms_user, u);
289 /** @param p Password to log into the TMS with */
290 void set_tms_password (std::string p) {
291 maybe_set (_tms_password, p);
294 void add_cinema (boost::shared_ptr<Cinema> c) {
295 _cinemas.push_back (c);
299 void remove_cinema (boost::shared_ptr<Cinema> c) {
304 void set_allowed_dcp_frame_rates (std::list<int> const & r) {
305 maybe_set (_allowed_dcp_frame_rates, r);
308 void set_allow_any_dcp_frame_rate (bool a) {
309 maybe_set (_allow_any_dcp_frame_rate, a);
312 void set_default_isdcf_metadata (ISDCFMetadata d) {
313 maybe_set (_default_isdcf_metadata, d);
316 void set_language (std::string l) {
317 if (_language && _language.get() == l) {
324 void unset_language () {
329 _language = boost::none;
333 void set_default_still_length (int s) {
334 maybe_set (_default_still_length, s);
337 void set_default_container (Ratio const * c) {
338 maybe_set (_default_container, c);
341 void set_default_dcp_content_type (DCPContentType const * t) {
342 maybe_set (_default_dcp_content_type, t);
345 void set_dcp_issuer (std::string i) {
346 maybe_set (_dcp_issuer, i);
349 void set_dcp_creator (std::string c) {
350 maybe_set (_dcp_creator, c);
353 void set_default_j2k_bandwidth (int b) {
354 maybe_set (_default_j2k_bandwidth, b);
357 void set_default_audio_delay (int d) {
358 maybe_set (_default_audio_delay, d);
361 void set_default_interop (bool i) {
362 maybe_set (_default_interop, i);
365 void set_mail_server (std::string s) {
366 maybe_set (_mail_server, s);
369 void set_mail_port (int p) {
370 maybe_set (_mail_port, p);
373 void set_mail_user (std::string u) {
374 maybe_set (_mail_user, u);
377 void set_mail_password (std::string p) {
378 maybe_set (_mail_password, p);
381 void set_kdm_subject (std::string s) {
382 maybe_set (_kdm_subject, s);
385 void set_kdm_from (std::string f) {
386 maybe_set (_kdm_from, f);
389 void set_kdm_cc (std::string f) {
390 maybe_set (_kdm_cc, f);
393 void set_kdm_bcc (std::string f) {
394 maybe_set (_kdm_bcc, f);
397 void set_kdm_email (std::string e) {
398 maybe_set (_kdm_email, e);
401 void reset_kdm_email ();
403 void set_signer_chain (boost::shared_ptr<const dcp::CertificateChain> s) {
404 maybe_set (_signer_chain, s);
407 void set_decryption_chain (boost::shared_ptr<const dcp::CertificateChain> c) {
408 maybe_set (_decryption_chain, c);
411 void set_check_for_updates (bool c) {
412 maybe_set (_check_for_updates, c);
414 set_check_for_test_updates (false);
418 void set_check_for_test_updates (bool c) {
419 maybe_set (_check_for_test_updates, c);
422 void set_maximum_j2k_bandwidth (int b) {
423 maybe_set (_maximum_j2k_bandwidth, b);
426 void set_log_types (int t) {
427 maybe_set (_log_types, t);
430 void set_automatic_audio_analysis (bool a) {
431 maybe_set (_automatic_audio_analysis, a);
434 #ifdef DCPOMATIC_WINDOWS
435 void set_win32_console (bool c) {
436 maybe_set (_win32_console, c);
440 void set_dkdms (std::vector<dcp::EncryptedKDM> dkdms)
446 void clear_history () {
451 void add_to_history (boost::filesystem::path p);
453 void changed (Property p = OTHER);
454 boost::signals2::signal<void (Property)> Changed;
458 static Config* instance ();
460 static void restore_defaults ();
461 static bool have_existing ();
465 static boost::filesystem::path file (bool create_directories = true);
467 void set_defaults ();
468 void set_kdm_email_to_default ();
469 boost::shared_ptr<dcp::CertificateChain> create_certificate_chain ();
472 void maybe_set (T& member, T new_value) {
473 if (member == new_value) {
480 /** number of threads to use for J2K encoding on the local machine */
481 int _num_local_encoding_threads;
482 /** default directory to put new films in */
483 boost::filesystem::path _default_directory;
484 /** base port number to use for J2K encoding servers;
485 * this port and the two above it will be used.
487 int _server_port_base;
488 /** true to broadcast on the `any' address to look for servers */
489 bool _use_any_servers;
490 /** J2K encoding servers that should definitely be used */
491 std::vector<std::string> _servers;
492 bool _only_servers_encode;
493 Protocol _tms_protocol;
494 /** The IP address of a TMS that we can copy DCPs to */
496 /** The path on a TMS that we should write DCPs to */
497 std::string _tms_path;
498 /** User name to log into the TMS with */
499 std::string _tms_user;
500 /** Password to log into the TMS with */
501 std::string _tms_password;
502 /** Our cinema sound processor */
503 CinemaSoundProcessor const * _cinema_sound_processor;
504 std::list<int> _allowed_dcp_frame_rates;
505 /** Allow any video frame rate for the DCP; if true, overrides _allowed_dcp_frame_rates */
506 bool _allow_any_dcp_frame_rate;
507 /** Default ISDCF metadata for newly-created Films */
508 ISDCFMetadata _default_isdcf_metadata;
509 boost::optional<std::string> _language;
510 /** Default length of still image content (seconds) */
511 int _default_still_length;
512 Ratio const * _default_container;
513 DCPContentType const * _default_dcp_content_type;
514 std::string _dcp_issuer;
515 std::string _dcp_creator;
516 int _default_j2k_bandwidth;
517 int _default_audio_delay;
518 bool _default_interop;
519 std::list<boost::shared_ptr<Cinema> > _cinemas;
520 std::string _mail_server;
522 std::string _mail_user;
523 std::string _mail_password;
524 std::string _kdm_subject;
525 std::string _kdm_from;
527 std::string _kdm_bcc;
528 std::string _kdm_email;
529 boost::shared_ptr<const dcp::CertificateChain> _signer_chain;
530 /** Chain used to decrypt KDMs; the leaf of this chain is the target
531 * certificate for making KDMs given to DCP-o-matic.
533 boost::shared_ptr<const dcp::CertificateChain> _decryption_chain;
534 /** true to check for updates on startup */
535 bool _check_for_updates;
536 bool _check_for_test_updates;
537 /** maximum allowed J2K bandwidth in bits per second */
538 int _maximum_j2k_bandwidth;
540 bool _automatic_audio_analysis;
541 #ifdef DCPOMATIC_WINDOWS
544 std::vector<boost::filesystem::path> _history;
545 std::vector<dcp::EncryptedKDM> _dkdms;
547 /** Singleton instance, or 0 */
548 static Config* _instance;