X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fupdate_checker.cc;h=8aeca030bf79f8ba4a7a599ebcce4bf1e11bda88;hb=249ae25148213a2ab5d76980133182e7f2521524;hp=634328e6aef992c0bee26d0f170657484415d9a6;hpb=6904ca547ce503c9ea06b4def9b9a716068e493c;p=dcpomatic.git diff --git a/src/lib/update_checker.cc b/src/lib/update_checker.cc index 634328e6a..8aeca030b 100644 --- a/src/lib/update_checker.cc +++ b/src/lib/update_checker.cc @@ -1,32 +1,32 @@ /* Copyright (C) 2014-2015 Carl Hetherington - This program is free software; you can redistribute it and/or modify + 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. - This program is distributed in the hope that it will be useful, + 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 this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with DCP-o-matic. If not, see . */ #include "update_checker.h" #include "version.h" -#include "safe_stringstream.h" -#include "config.h" #include "util.h" -#include "raw_convert.h" +#include #include #include #include #include +#include #define BUFFER_SIZE 1024 @@ -36,6 +36,7 @@ using std::string; using std::vector; using boost::is_any_of; using boost::ends_with; +using dcp::raw_convert; /** Singleton instance */ UpdateChecker* UpdateChecker::_instance = 0; @@ -55,7 +56,9 @@ UpdateChecker::UpdateChecker () , _curl (0) , _state (NOT_RUN) , _emits (0) + , _thread (0) , _to_do (0) + , _terminate (false) { _curl = curl_easy_init (); @@ -66,13 +69,31 @@ UpdateChecker::UpdateChecker () string const agent = "dcpomatic/" + string (dcpomatic_version); curl_easy_setopt (_curl, CURLOPT_USERAGENT, agent.c_str ()); +} +void +UpdateChecker::start () +{ _thread = new boost::thread (boost::bind (&UpdateChecker::thread, this)); } UpdateChecker::~UpdateChecker () { - /* We are not cleaning up our thread, but hey well */ + { + boost::mutex::scoped_lock lm (_process_mutex); + _terminate = true; + } + + _condition.notify_all (); + if (_thread) { + /* Ideally this would be a DCPOMATIC_ASSERT(_thread->joinable()) but we + can't throw exceptions from a destructor. + */ + if (_thread->joinable ()) { + _thread->join (); + } + } + delete _thread; curl_easy_cleanup (_curl); delete[] _buffer; @@ -93,9 +114,14 @@ UpdateChecker::thread () while (true) { /* Block until there is something to do */ boost::mutex::scoped_lock lock (_process_mutex); - while (_to_do == 0) { + while (_to_do == 0 && !_terminate) { _condition.wait (lock); } + + if (_terminate) { + return; + } + --_to_do; lock.unlock (); @@ -132,7 +158,7 @@ UpdateChecker::thread () _stable = stable; } - if (Config::instance()->check_for_test_updates() && version_less_than (dcpomatic_version, test)) { + if (version_less_than (dcpomatic_version, test)) { _test = test; } @@ -173,6 +199,7 @@ UpdateChecker::instance () { if (!_instance) { _instance = new UpdateChecker (); + _instance->start (); } return _instance;