X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Flib%2Fmonitor_checker.cc;h=d15dee63f99f7d0ba9dbb0a7e60d1b11ebde45b2;hb=264583479e79b481251f1772b228f82cd77552d3;hp=19d8d8181943faaef5e58494d98b1a690c68feb5;hpb=f80010debf14112a632f42ddc7588995698b3d19;p=dcpomatic.git 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 () {