2 Copyright (C) 2014 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/lib/update.h
21 * @brief UpdateChecker class.
24 #include "signaller.h"
25 #include <curl/curl.h>
26 #include <boost/signals2.hpp>
27 #include <boost/thread/mutex.hpp>
28 #include <boost/thread/condition.hpp>
29 #include <boost/thread.hpp>
31 struct update_checker_test;
33 /** Class to check for the existance of an update for DCP-o-matic on a remote server */
34 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 and Config is set to look for it */
62 boost::optional<std::string> test () {
63 boost::mutex::scoped_lock lm (_data_mutex);
67 /** @return true if the last signal emission was the first */
68 bool last_emit_was_first () const {
69 boost::mutex::scoped_lock lm (_data_mutex);
73 size_t write_callback (void *, size_t, size_t);
75 boost::signals2::signal<void (void)> StateChanged;
77 static UpdateChecker* instance ();
80 friend struct update_checker_test;
82 static UpdateChecker* _instance;
84 static bool version_less_than (std::string const & a, std::string const & b);
86 void set_state (State);
93 /** mutex to protect _state, _stable, _test and _emits */
94 mutable boost::mutex _data_mutex;
96 boost::optional<std::string> _stable;
97 boost::optional<std::string> _test;
100 boost::thread* _thread;
101 boost::mutex _process_mutex;
102 boost::condition _condition;