2 Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 /** @file src/lib/update.h
22 * @brief UpdateChecker class.
25 #include "signaller.h"
26 #include <curl/curl.h>
27 #include <boost/signals2.hpp>
28 #include <boost/thread/mutex.hpp>
29 #include <boost/thread/condition.hpp>
30 #include <boost/thread.hpp>
32 struct update_checker_test;
34 /** Class to check for the existance of an update for DCP-o-matic on a remote server */
35 class UpdateChecker : public Signaller, public boost::noncopyable
43 YES, ///< there is an update
44 FAILED, ///< the check failed, so we don't know
45 NO, ///< there is no update
46 NOT_RUN ///< the check has not been run (yet)
49 /** @return state of the checker */
51 boost::mutex::scoped_lock lm (_data_mutex);
55 /** @return new stable version, if there is one */
56 boost::optional<std::string> stable () {
57 boost::mutex::scoped_lock lm (_data_mutex);
61 /** @return new test version, if there is one */
62 boost::optional<std::string> test () {
63 boost::mutex::scoped_lock lm (_data_mutex);
67 size_t write_callback (void *, size_t, size_t);
69 boost::signals2::signal<void (void)> StateChanged;
71 static UpdateChecker* instance ();
74 friend struct update_checker_test;
76 static UpdateChecker* _instance;
78 static bool version_less_than (std::string const & a, std::string const & b);
82 void set_state (State);
89 /** mutex to protect _state, _stable, _test and _emits */
90 mutable boost::mutex _data_mutex;
92 boost::optional<std::string> _stable;
93 boost::optional<std::string> _test;
96 boost::thread* _thread;
97 boost::mutex _process_mutex;
98 boost::condition _condition;