diff --git a/src/CouchDB.cxx b/src/CouchDB.cxx index d4572bf..8b564e7 100644 --- a/src/CouchDB.cxx +++ b/src/CouchDB.cxx @@ -1,4 +1,4 @@ -/* Copyright 2011 (C) Daniel Richman. License: GNU GPL 3; see LICENSE. */ +/* Copyright 2011-2012 (C) Daniel Richman. License: GNU GPL 3; see LICENSE. */ #include "CouchDB.h" #include diff --git a/src/Uploader.cxx b/src/Uploader.cxx index 11ab7df..aade647 100644 --- a/src/Uploader.cxx +++ b/src/Uploader.cxx @@ -1,4 +1,4 @@ -/* Copyright 2011 (C) Daniel Richman. License: GNU GPL 3; see LICENSE. */ +/* Copyright 2011-2012 (C) Daniel Richman. License: GNU GPL 3; see LICENSE. */ #include "Uploader.h" #include diff --git a/src/Uploader.h b/src/Uploader.h index 42b57f1..9e14cb3 100644 --- a/src/Uploader.h +++ b/src/Uploader.h @@ -1,4 +1,4 @@ -/* Copyright 2011 (C) Daniel Richman. License: GNU GPL 3; see LICENSE. */ +/* Copyright 2011-2012 (C) Daniel Richman. License: GNU GPL 3; see LICENSE. */ #ifndef HABITAT_UPLOADER_H #define HABITAT_UPLOADER_H diff --git a/src/UploaderThread.cxx b/src/UploaderThread.cxx index c836e23..fa6ec9b 100644 --- a/src/UploaderThread.cxx +++ b/src/UploaderThread.cxx @@ -1,4 +1,4 @@ -/* Copyright 2011 (C) Daniel Richman. License: GNU GPL 3; see LICENSE. */ +/* Copyright 2011-2012 (C) Daniel Richman. License: GNU GPL 3; see LICENSE. */ #include "UploaderThread.h" #include diff --git a/src/UploaderThread.h b/src/UploaderThread.h index de282ea..da17555 100644 --- a/src/UploaderThread.h +++ b/src/UploaderThread.h @@ -1,4 +1,4 @@ -/* Copyright 2011 (C) Daniel Richman. License: GNU GPL 3; see LICENSE. */ +/* Copyright 2011-2012 (C) Daniel Richman. License: GNU GPL 3; see LICENSE. */ #ifndef HABITAT_UPLOADERTHREAD_H #define HABITAT_UPLOADERTHREAD_H diff --git a/tests/test_uploader.py b/tests/test_uploader.py index bf6383a..f374c10 100644 --- a/tests/test_uploader.py +++ b/tests/test_uploader.py @@ -1,4 +1,4 @@ -# Copyright 2011 (C) Daniel Richman. License: GNU GPL 3; see LICENSE +# Copyright 2011-2012 (C) Daniel Richman. License: GNU GPL 3; see LICENSE import subprocess import os diff --git a/tests/test_uploader_main.cxx b/tests/test_uploader_main.cxx index 06a99a2..2258f33 100644 --- a/tests/test_uploader_main.cxx +++ b/tests/test_uploader_main.cxx @@ -1,4 +1,4 @@ -/* Copyright 2011 (C) Daniel Richman. License: GNU GPL 3; see LICENSE. */ +/* Copyright 2011-2012 (C) Daniel Richman. License: GNU GPL 3; see LICENSE. */ #include #include @@ -85,15 +85,10 @@ static SafeValue last_time(10000); static EZ::Queue callback_responses; #endif +#ifndef THREADED int main(int argc, char **argv) { -#ifndef THREADED auto_ptr u; -#else - enable_callbacks.set(true); - TestSubject thread; - thread.start(); -#endif for (;;) { @@ -102,9 +97,6 @@ int main(int argc, char **argv) if (line[0] == '\0') { -#ifdef THREADED - enable_callbacks.set(false); -#endif break; } @@ -119,7 +111,6 @@ int main(int argc, char **argv) string command_name = command[0u].asString(); -#ifndef THREADED if (!u.get() && command_name != "init") throw runtime_error("You must initialise it first"); @@ -166,7 +157,39 @@ int main(int argc, char **argv) } enable_callbacks.set(false); -#else + } + + return 0; +} +#else /* defined THREADED */ +int main(int argc, char **argv) +{ + enable_callbacks.set(true); + TestSubject thread; + thread.start(); + + for (;;) + { + char line[1024]; + cin.getline(line, 1024); + + if (line[0] == '\0') + { + enable_callbacks.set(false); + break; + } + + Json::Reader reader; + Json::Value command; + + if (!reader.parse(line, command, false)) + throw runtime_error("JSON parsing failed"); + + if (!command.isArray() || !command[0u].isString()) + throw runtime_error("Invalid JSON input"); + + string command_name = command[0u].asString(); + if (command_name == "init") proxy_constructor(&thread, command); else if (command_name == "reset") @@ -183,16 +206,14 @@ int main(int argc, char **argv) proxy_payloads(&thread); else if (command_name == "return") callback_responses.put(command); -#endif } -#ifdef THREADED thread.shutdown(); thread.join(); -#endif return 0; } +#endif time_t time(time_t *t) throw() { @@ -220,11 +241,11 @@ time_t time(time_t *t) throw() return value; } +#ifndef THREADED static Json::Value proxy_callback(const string &name, const Json::Value &args) { report_result("callback", name, args); -#ifndef THREADED char line[1024]; cin.getline(line, 1024); @@ -239,12 +260,17 @@ static Json::Value proxy_callback(const string &name, const Json::Value &args) if (response[0u].asString() != "return") throw runtime_error("Callback failed"); -#else - Json::Value response = callback_responses.get(); -#endif return response[1u]; } +#else /* defined THREADED */ +static Json::Value proxy_callback(const string &name, const Json::Value &args) +{ + report_result("callback", name, args); + Json::Value response = callback_responses.get(); + return response[1u]; +} +#endif #ifndef THREADED static habitat::Uploader *proxy_constructor(Json::Value command) @@ -333,27 +359,31 @@ static r_string proxy_payload_telemetry(TestSubject *u, Json::Value command) return u->payload_telemetry(data.asString(), metadata, tc.asInt()); } +#ifndef THREADED static r_json proxy_flights(TestSubject *u) { -#ifndef THREADED vector *result = u->flights(); auto_ptr< vector > destroyer(result); return vector_to_json(*result); -#else - u->flights(); -#endif } static r_json proxy_payloads(TestSubject *u) { -#ifndef THREADED vector *result = u->payloads(); auto_ptr< vector > destroyer(result); return vector_to_json(*result); -#else - u->payloads(); -#endif } +#else /* defined THREADED */ +static r_json proxy_flights(TestSubject *u) +{ + u->flights(); +} + +static r_json proxy_payloads(TestSubject *u) +{ + u->payloads(); +} +#endif static Json::Value vector_to_json(const vector &vect) {