From c56840f03cf139d60c6d90b55cf16e70f6ae2bc2 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 21 Jun 2015 00:15:04 +0200 Subject: o Going all header file based and single-executable to launch all apps. o Ading CMake magic to generate the launcher --- apps/sample-add-timestamp.cpp | 105 ------------------------------------------ 1 file changed, 105 deletions(-) delete mode 100644 apps/sample-add-timestamp.cpp (limited to 'apps/sample-add-timestamp.cpp') diff --git a/apps/sample-add-timestamp.cpp b/apps/sample-add-timestamp.cpp deleted file mode 100644 index 22d81a6..0000000 --- a/apps/sample-add-timestamp.cpp +++ /dev/null @@ -1,105 +0,0 @@ -#include "trygvis/sensor.h" -#include "trygvis/sensor/io.h" -#include "apps.h" -#include - -namespace trygvis { -namespace apps { - -using namespace std; -using namespace trygvis::apps; -using namespace trygvis::sensor; -using namespace trygvis::sensor::io; -namespace po = boost::program_options; - -class TimestampAddingSampleOutputStream : public SampleOutputStream { - -public: - TimestampAddingSampleOutputStream(shared_ptr output, KeyDictionary &dict, string timestamp_name) - : - timestamp_key(dict.indexOf(timestamp_name)) { - if (input_time_resolution_ == time_resolution::MILLISECONDS) { - factor = 1000; - } else { - factor = 1; - } - } - - virtual void write(SampleRecord const &sample) override { - time_t now = time(NULL) * factor; - - SampleRecord updated_sample(sample); - - updated_sample.set(timestamp_key, std::to_string(now)); - - output_->write(updated_sample); - }; - -private: - const SampleKey *timestamp_key; - time_resolution input_time_resolution_; - int factor; - shared_ptr output_; -}; - -class sample_add_timestamp : public app { - -private: - string timestamp_name; - time_resolution resolution; - sample_format_type output_format; - -public: - sample_add_timestamp() : app("sample-add-timestamp") { - } - ~sample_add_timestamp() = default; - - void add_options(po::options_description_easy_init &options) override { - options - ("help", "produce this help message") - ("resolution", po::value(&resolution)->default_value(time_resolution::SECONDS)) - ("timestamp-name", po::value(×tamp_name)->default_value("timestamp")) - ("output-format", po::value(&output_format)->default_value(sample_format_type::KEY_VALUE)); - } - - const int buffer_size = 1024; - - int main(app_execution &execution) override { - shared_ptr input; - - input = shared_ptr(&cin, noop_deleter); - - KeyDictionary dict; - - sample_output_stream_options options = {}; - unique_ptr unique_output_stream = open_sample_output_stream(shared_ptr(&cout, noop_deleter), dict, output_format, options); - shared_ptr output_stream{std::move(unique_output_stream)}; - shared_ptr p = make_shared(output_stream, dict, timestamp_name); - auto parser = open_sample_stream_parser(p, dict); - - int recordCount = 0; - - while (!input->eof()) { - char buffer[buffer_size]; - input->read(buffer, buffer_size); - size_t gcount = (size_t)input->gcount(); - - recordCount++; - - mutable_buffers_1 b = boost::asio::buffer(buffer, gcount); - parser->process(b); - } - - return EXIT_SUCCESS; - }; -}; - -} -} - -using namespace trygvis::apps; - -int main(int argc, char *argv[]) { - sample_add_timestamp app; - return launch_app(argc, argv, app); -} -- cgit v1.2.3