X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fupdate.h;h=5bb9e95016de1ed2bace2ec556fd54f9dccfef07;hb=a112eeb4d052b1212f94e95efd83a215213da691;hp=2063dd4840be698ec4f09351528acc1f634232e5;hpb=95faa6568854b5f861db07e9b8697169aaceec3c;p=dcpomatic.git diff --git a/src/lib/update.h b/src/lib/update.h index 2063dd484..5bb9e9501 100644 --- a/src/lib/update.h +++ b/src/lib/update.h @@ -17,23 +17,87 @@ */ -class UpdateChecker +/** @file src/lib/update.h + * @brief UpdateChecker class. + */ + +#include +#include +#include +#include +#include + +struct update_checker_test; + +/** Class to check for the existance of an update for DCP-o-matic on a remote server */ +class UpdateChecker : public boost::noncopyable { public: UpdateChecker (); ~UpdateChecker (); - enum Result { - YES, - MAYBE, - NO + void run (); + + enum State { + YES, ///< there is an update + FAILED, ///< the check failed, so we don't know + NO, ///< there is no update + NOT_RUN ///< the check has not been run (yet) }; - Result run (); + /** @return state of the checker */ + State state () { + boost::mutex::scoped_lock lm (_data_mutex); + return _state; + } + + /** @return new stable version, if there is one */ + boost::optional stable () { + boost::mutex::scoped_lock lm (_data_mutex); + return _stable; + } + + /** @return new test version, if there is one and Config is set to look for it */ + boost::optional test () { + boost::mutex::scoped_lock lm (_data_mutex); + return _test; + } + + /** @return true if the last signal emission was the first */ + bool last_emit_was_first () const { + boost::mutex::scoped_lock lm (_data_mutex); + return _emits == 1; + } size_t write_callback (void *, size_t, size_t); -private: + boost::signals2::signal StateChanged; + + static UpdateChecker* instance (); + +private: + friend struct update_checker_test; + + static UpdateChecker* _instance; + + static bool version_less_than (std::string const & a, std::string const & b); + + void set_state (State); + void thread (); + char* _buffer; int _offset; + CURL* _curl; + + /** mutex to protect _state, _stable, _test and _emits */ + mutable boost::mutex _data_mutex; + State _state; + boost::optional _stable; + boost::optional _test; + int _emits; + + boost::thread* _thread; + boost::mutex _process_mutex; + boost::condition _condition; + int _to_do; };