diff options
| author | Carl Hetherington <cth@carlh.net> | 2018-11-13 00:04:23 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2018-11-13 00:04:23 +0000 |
| commit | 264583479e79b481251f1772b228f82cd77552d3 (patch) | |
| tree | 868f3347c1784ecde6ee626f6799334f3ef235b6 /src/lib | |
| parent | f80010debf14112a632f42ddc7588995698b3d19 (diff) | |
swaroop: only allow playback if configured lock file is present.v2.13.72
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/checker.cc | 95 | ||||
| -rw-r--r-- | src/lib/checker.h | 65 | ||||
| -rw-r--r-- | src/lib/config.cc | 5 | ||||
| -rw-r--r-- | src/lib/config.h | 18 | ||||
| -rw-r--r-- | src/lib/lock_file_checker.cc | 54 | ||||
| -rw-r--r-- | src/lib/lock_file_checker.h | 36 | ||||
| -rw-r--r-- | src/lib/monitor_checker.cc | 62 | ||||
| -rw-r--r-- | src/lib/monitor_checker.h | 21 | ||||
| -rw-r--r-- | src/lib/wscript | 2 |
9 files changed, 285 insertions, 73 deletions
diff --git a/src/lib/checker.cc b/src/lib/checker.cc new file mode 100644 index 000000000..13d9aacee --- /dev/null +++ b/src/lib/checker.cc @@ -0,0 +1,95 @@ +/* + Copyright (C) 2018 Carl Hetherington <cth@carlh.net> + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + +#ifdef DCPOMATIC_VARIANT_SWAROOP + +#include "checker.h" +#include "config.h" +#include "cross.h" + +using boost::bind; +using boost::ref; + +Checker::Checker (int period) + : _thread (0) + , _terminate (false) + , _ok (true) + , _period (period) +{ + +} + +void +Checker::run () +{ + _thread = new boost::thread (boost::bind (&Checker::thread, this)); +} + +Checker::~Checker () +{ + { + boost::mutex::scoped_lock lm (_mutex); + _terminate = true; + } + + if (_thread) { + /* Ideally this would be a DCPOMATIC_ASSERT(_thread->joinable()) but we + can't throw exceptions from a destructor. + */ + _thread->interrupt (); + try { + if (_thread->joinable ()) { + _thread->join (); + } + } catch (boost::thread_interrupted& e) { + /* No problem */ + } + } + delete _thread; +} + +void +Checker::thread () +{ + while (true) { + boost::mutex::scoped_lock lm (_mutex); + if (_terminate) { + break; + } + + bool const was_ok = _ok; + _ok = check(); + if (was_ok != _ok) { + emit (bind(boost::ref(StateChanged))); + } + + lm.unlock (); + dcpomatic_sleep (_period); + } +} + +bool +Checker::ok () const +{ + boost::mutex::scoped_lock lm (_mutex); + return _ok; +} + +#endif diff --git a/src/lib/checker.h b/src/lib/checker.h new file mode 100644 index 000000000..fee3fc3d9 --- /dev/null +++ b/src/lib/checker.h @@ -0,0 +1,65 @@ +/* + Copyright (C) 2018 Carl Hetherington <cth@carlh.net> + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + +/** @file src/lib/checker.h + * @brief Checker class. + */ + +#ifndef DCPOMATIC_CHECKER_H +#define DCPOMATIC_CHECKER_H + +#include "signaller.h" +#include <boost/signals2.hpp> + +/** Parent for classes which check some condition every so often and signal + * when the state of the condition changes. + */ +class Checker : public Signaller, public boost::noncopyable +{ +public: + virtual ~Checker (); + + void run (); + + bool ok () const; + + /** Emitted when the state of our condition changes */ + boost::signals2::signal<void (void)> StateChanged; + +protected: + + Checker (int period); + + /** @return true if the condition is `ok', otherwise false */ + virtual bool check () const = 0; + +private: + + void thread (); + + boost::thread* _thread; + mutable boost::mutex _mutex; + bool _terminate; + bool _ok; + /** check period in seconds */ + int _period; +}; + +#endif diff --git a/src/lib/config.cc b/src/lib/config.cc index b64690aad..31ae15b36 100644 --- a/src/lib/config.cc +++ b/src/lib/config.cc @@ -177,6 +177,7 @@ Config::set_defaults () _player_watermark_period = 1; _player_watermark_duration = 50; _allow_spl_editing = true; + _player_lock_file = boost::none; #endif _allowed_dcp_frame_rates.clear (); @@ -529,6 +530,7 @@ try _required_monitors.push_back(Monitor(i)); } _allow_spl_editing = f.optional_bool_child("AllowSPLEditing").get_value_or(true); + _player_lock_file = f.optional_string_child("PlayerLockFile"); #endif /* Replace any cinemas from config.xml with those from the configured file */ @@ -942,6 +944,9 @@ Config::write_config () const i.as_xml(root->add_child("RequiredMonitor")); } root->add_child("AllowSPLEditing")->add_child_text(_allow_spl_editing ? "1" : "0"); + if (_player_lock_file) { + root->add_child("PlayerLockFile")->add_child_text(_player_lock_file->string()); + } #endif try { diff --git a/src/lib/config.h b/src/lib/config.h index a162750fe..dd20b58e7 100644 --- a/src/lib/config.h +++ b/src/lib/config.h @@ -524,6 +524,10 @@ public: std::vector<Monitor> required_monitors () const { return _required_monitors; } + + boost::optional<boost::filesystem::path> player_lock_file () const { + return _player_lock_file; + } #endif bool allow_spl_editing () const { @@ -1020,6 +1024,18 @@ public: void set_required_monitors (std::vector<Monitor> monitors) { maybe_set (_required_monitors, monitors); } + + void set_player_lock_file (boost::filesystem::path p) { + maybe_set (_player_lock_file, p); + } + + void unset_player_lock_file () { + if (!_player_lock_file) { + return; + } + _player_lock_file = boost::none; + changed (); + } #endif void set_allow_spl_editing (bool s) { @@ -1229,6 +1245,8 @@ private: /** watermark duration in milliseconds */ int _player_watermark_duration; std::vector<Monitor> _required_monitors; + /** a file which, if specified, must be present for the player to work */ + boost::optional<boost::filesystem::path> _player_lock_file; #endif bool _allow_spl_editing; diff --git a/src/lib/lock_file_checker.cc b/src/lib/lock_file_checker.cc new file mode 100644 index 000000000..9543c2c9f --- /dev/null +++ b/src/lib/lock_file_checker.cc @@ -0,0 +1,54 @@ +/* + Copyright (C) 2018 Carl Hetherington <cth@carlh.net> + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + +#ifdef DCPOMATIC_VARIANT_SWAROOP + +#include "lock_file_checker.h" +#include "config.h" +#include "cross.h" + +using boost::bind; +using boost::ref; + +LockFileChecker* LockFileChecker::_instance = 0; + +LockFileChecker::LockFileChecker () + : Checker (10) +{ + +} + +bool +LockFileChecker::check () const +{ + return !Config::instance()->player_lock_file() || boost::filesystem::is_regular_file(Config::instance()->player_lock_file().get()); +} + +LockFileChecker * +LockFileChecker::instance () +{ + if (!_instance) { + _instance = new LockFileChecker (); + } + + return _instance; +} + +#endif diff --git a/src/lib/lock_file_checker.h b/src/lib/lock_file_checker.h new file mode 100644 index 000000000..76c00717d --- /dev/null +++ b/src/lib/lock_file_checker.h @@ -0,0 +1,36 @@ +/* + Copyright (C) 2018 Carl Hetherington <cth@carlh.net> + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + +#include "checker.h" +#include <boost/signals2.hpp> + +class LockFileChecker : public Checker +{ +public: + LockFileChecker (); + + static LockFileChecker* instance (); + +protected: + bool check () const; + +private: + static LockFileChecker* _instance; +}; diff --git a/src/lib/monitor_checker.cc b/src/lib/monitor_checker.cc index 19d8d8181..d15dee63f 100644 --- a/src/lib/monitor_checker.cc +++ b/src/lib/monitor_checker.cc @@ -24,75 +24,21 @@ #include "config.h" #include "cross.h" -using boost::bind; -using boost::ref; - MonitorChecker* MonitorChecker::_instance = 0; MonitorChecker::MonitorChecker () - : _thread (0) - , _terminate (false) - , _ok (true) + : Checker (60) { } -void -MonitorChecker::run () -{ - _thread = new boost::thread (boost::bind (&MonitorChecker::thread, this)); -} - -MonitorChecker::~MonitorChecker () -{ - { - boost::mutex::scoped_lock lm (_mutex); - _terminate = true; - } - - if (_thread) { - /* Ideally this would be a DCPOMATIC_ASSERT(_thread->joinable()) but we - can't throw exceptions from a destructor. - */ - _thread->interrupt (); - try { - if (_thread->joinable ()) { - _thread->join (); - } - } catch (boost::thread_interrupted& e) { - /* No problem */ - } - } - delete _thread; -} - -void -MonitorChecker::thread () -{ - while (true) { - boost::mutex::scoped_lock lm (_mutex); - if (_terminate) { - break; - } - - bool const was_ok = _ok; - _ok = Config::instance()->required_monitors().empty() || get_monitors() == Config::instance()->required_monitors(); - if (was_ok != _ok) { - emit (bind(boost::ref(StateChanged))); - } - - lm.unlock (); - dcpomatic_sleep (60); - } -} - bool -MonitorChecker::ok () const +MonitorChecker::check () const { - boost::mutex::scoped_lock lm (_mutex); - return _ok; + return Config::instance()->required_monitors().empty() || get_monitors() == Config::instance()->required_monitors(); } + MonitorChecker * MonitorChecker::instance () { diff --git a/src/lib/monitor_checker.h b/src/lib/monitor_checker.h index 4f856f41f..f99ab4b2a 100644 --- a/src/lib/monitor_checker.h +++ b/src/lib/monitor_checker.h @@ -18,28 +18,19 @@ */ -#include "signaller.h" +#include "checker.h" #include <boost/signals2.hpp> -class MonitorChecker : public Signaller, public boost::noncopyable +class MonitorChecker : public Checker { public: - ~MonitorChecker (); + MonitorChecker (); - void run (); + static MonitorChecker* instance (); - bool ok () const; - boost::signals2::signal<void (void)> StateChanged; +protected: + bool check () const; - static MonitorChecker* instance (); private: static MonitorChecker* _instance; - - MonitorChecker (); - void thread (); - - boost::thread* _thread; - mutable boost::mutex _mutex; - bool _terminate; - bool _ok; }; diff --git a/src/lib/wscript b/src/lib/wscript index e78227b6b..88cec75ec 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -41,6 +41,7 @@ sources = """ text_content.cc text_decoder.cc case_insensitive_sorter.cc + checker.cc check_content_change_job.cc cinema.cc cinema_kdms.cc @@ -113,6 +114,7 @@ sources = """ job_manager.cc j2k_encoder.cc json_server.cc + lock_file_checker.cc log.cc log_entry.cc mid_side_decoder.cc |
