projects
/
dcpomatic.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge master.
[dcpomatic.git]
/
src
/
lib
/
update.cc
diff --git
a/src/lib/update.cc
b/src/lib/update.cc
index 34eaf385c92e77340b361ad634705083a938a459..c50022091fbe3ab6abb0169e86fa00e7444c4cb3 100644
(file)
--- a/
src/lib/update.cc
+++ b/
src/lib/update.cc
@@
-18,23
+18,23
@@
*/
#include <string>
*/
#include <string>
-#include <sstream>
#include <boost/algorithm/string.hpp>
#include <curl/curl.h>
#include <libcxml/cxml.h>
#include <boost/algorithm/string.hpp>
#include <curl/curl.h>
#include <libcxml/cxml.h>
-#include <
lib
dcp/raw_convert.h>
+#include <dcp/raw_convert.h>
#include "update.h"
#include "version.h"
#include "ui_signaller.h"
#include "update.h"
#include "version.h"
#include "ui_signaller.h"
+#include "safe_stringstream.h"
#define BUFFER_SIZE 1024
using std::cout;
using std::min;
using std::string;
#define BUFFER_SIZE 1024
using std::cout;
using std::min;
using std::string;
-using std::stringstream;
-using libdcp::raw_convert;
+using dcp::raw_convert;
+/** Singleton instance */
UpdateChecker* UpdateChecker::_instance = 0;
static size_t
UpdateChecker* UpdateChecker::_instance = 0;
static size_t
@@
-43,6
+43,9
@@
write_callback_wrapper (void* data, size_t size, size_t nmemb, void* user)
return reinterpret_cast<UpdateChecker*>(user)->write_callback (data, size, nmemb);
}
return reinterpret_cast<UpdateChecker*>(user)->write_callback (data, size, nmemb);
}
+/** Construct an UpdateChecker. This sets things up and starts a thread to
+ * do the work.
+ */
UpdateChecker::UpdateChecker ()
: _buffer (new char[BUFFER_SIZE])
, _offset (0)
UpdateChecker::UpdateChecker ()
: _buffer (new char[BUFFER_SIZE])
, _offset (0)
@@
-74,6
+77,7
@@
UpdateChecker::~UpdateChecker ()
delete[] _buffer;
}
delete[] _buffer;
}
+/** Start running the update check */
void
UpdateChecker::run ()
{
void
UpdateChecker::run ()
{
@@
-85,7
+89,8
@@
UpdateChecker::run ()
void
UpdateChecker::thread ()
{
void
UpdateChecker::thread ()
{
- while (1) {
+ while (true) {
+ /* Block until there is something to do */
boost::mutex::scoped_lock lock (_process_mutex);
while (_to_do == 0) {
_condition.wait (lock);
boost::mutex::scoped_lock lock (_process_mutex);
while (_to_do == 0) {
_condition.wait (lock);
@@
-95,18
+100,21
@@
UpdateChecker::thread ()
try {
_offset = 0;
try {
_offset = 0;
+
+ /* Perform the request */
int r = curl_easy_perform (_curl);
if (r != CURLE_OK) {
set_state (FAILED);
return;
}
int r = curl_easy_perform (_curl);
if (r != CURLE_OK) {
set_state (FAILED);
return;
}
+
+ /* Parse the reply */
_buffer[_offset] = '\0';
_buffer[_offset] = '\0';
- stringstream s;
- s << _buffer;
+ string s (_buffer);
cxml::Document doc ("Update");
cxml::Document doc ("Update");
- doc.read_str
eam
(s);
+ doc.read_str
ing
(s);
{
boost::mutex::scoped_lock lm (_data_mutex);
{
boost::mutex::scoped_lock lm (_data_mutex);