+Analytics::~Analytics ()
+{
+ if (!_thread) {
+ return;
+ }
+
+ _thread->interrupt();
+ if (_thread->joinable()) {
+ try {
+ _thread->join();
+ } catch (...) {
+ /* Too late to do anything about this */
+ }
+ }
+
+ delete _thread;
+}
+
+void
+Analytics::start ()
+{
+ _thread = new boost::thread (boost::bind(&Analytics::thread, this));
+#ifdef DCPOMATIC_LINUX
+ pthread_setname_np (_thread->native_handle(), "update-checker");
+#endif
+}
+
+void
+Analytics::thread ()
+try
+{
+ while (true) {
+
+ {
+ boost::mutex::scoped_lock lm (_mutex);
+ if (_events.empty ()) {
+ continue;
+ }
+
+ CURL* curl = curl_easy_init ();
+ if (!curl) {
+ continue;
+ }
+
+ curl_easy_setopt (curl, CURLOPT_URL, "https://dcpomatic.com/analytics");
+ xmlpp::Document doc;
+ xmlpp_document (doc);
+ curl_easy_setopt (curl, CURLOPT_POST, 1);
+ curl_easy_setopt (curl, CURLOPT_COPYPOSTFIELDS, doc.write_to_string().c_str());
+ CURLcode res = curl_easy_perform (curl);
+ if (res == CURLE_OK) {
+ _events.clear ();
+ }
+ curl_easy_cleanup (curl);
+ write ();
+
+ }
+
+ dcpomatic_sleep (60);
+ }
+}
+catch (...) {
+ /* Never mind */
+}
+