*/
+/** @file src/lib/update.h
+ * @brief UpdateChecker class.
+ */
+
+#include <boost/signals2.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/condition.hpp>
+#include <boost/thread.hpp>
+#include <curl/curl.h>
+
+/** Class to check for the existance of an update for DCP-o-matic on a remote server */
class UpdateChecker
{
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 the version string of the latest stable version (if _state == YES or NO) */
+ std::string stable () {
+ boost::mutex::scoped_lock lm (_data_mutex);
+ return _stable;
+ }
+
+ /** @return the version string of the latest test version (if _state == YES or NO) */
+ std::string 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);
+ boost::signals2::signal<void (void)> StateChanged;
+
+ static UpdateChecker* instance ();
+
private:
+ static UpdateChecker* _instance;
+
+ 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;
+ std::string _stable;
+ std::string _test;
+ int _emits;
+
+ boost::thread* _thread;
+ boost::mutex _process_mutex;
+ boost::condition _condition;
+ int _to_do;
};