2 Copyright (C) 2014-2021 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/>.
22 /** @file src/lib/update_checker.h
23 * @brief UpdateChecker class.
27 #include "signaller.h"
28 #include <curl/curl.h>
29 #include <boost/signals2.hpp>
30 #include <boost/thread/mutex.hpp>
31 #include <boost/thread/condition.hpp>
32 #include <boost/thread.hpp>
35 struct update_checker_test;
38 /** Class to check for the existance of an update for DCP-o-matic on a remote server */
39 class UpdateChecker : public Signaller
44 UpdateChecker (UpdateChecker const &);
45 UpdateChecker& operator= (UpdateChecker const &);
50 YES, ///< there is an update
51 FAILED, ///< the check failed, so we don't know
52 NO, ///< there is no update
53 NOT_RUN ///< the check has not been run (yet)
56 /** @return state of the checker */
58 boost::mutex::scoped_lock lm (_data_mutex);
62 /** @return new stable version, if there is one */
63 boost::optional<std::string> stable () {
64 boost::mutex::scoped_lock lm (_data_mutex);
68 /** @return new test version, if there is one */
69 boost::optional<std::string> test () {
70 boost::mutex::scoped_lock lm (_data_mutex);
74 size_t write_callback (void *, size_t, size_t);
76 boost::signals2::signal<void (void)> StateChanged;
78 static UpdateChecker* instance ();
81 friend struct update_checker_test;
83 static UpdateChecker* _instance;
85 static bool version_less_than (std::string const & a, std::string const & b);
89 void set_state (State);
92 std::vector<char> _buffer;
94 CURL* _curl = nullptr;
96 /** mutex to protect _state, _stable, _test and _emits */
97 mutable boost::mutex _data_mutex;
99 boost::optional<std::string> _stable;
100 boost::optional<std::string> _test;
102 boost::thread _thread;
103 boost::mutex _process_mutex;
104 boost::condition _condition;
106 bool _terminate = false;