aboutsummaryrefslogtreecommitdiff
path: root/apps/sample-add-timestamp.h
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-07-19 21:39:28 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2015-07-19 21:49:03 +0200
commitae2d05eee4ffcec4c0611d907779ce8ef61d3a6e (patch)
tree6b86d64d03dfda4efc4a41e5814a229507289cb9 /apps/sample-add-timestamp.h
parent0374af511d7efdb856af372f126e66e5a78841d7 (diff)
downloadble-toys-ae2d05eee4ffcec4c0611d907779ce8ef61d3a6e.tar.gz
ble-toys-ae2d05eee4ffcec4c0611d907779ce8ef61d3a6e.tar.bz2
ble-toys-ae2d05eee4ffcec4c0611d907779ce8ef61d3a6e.tar.xz
ble-toys-ae2d05eee4ffcec4c0611d907779ce8ef61d3a6e.zip
o Going back to a bunch of cpp files instead of launcher+bunch of header files. This ends up with an easier build file and faster builds with CMake's "OBJECT" library type.
Diffstat (limited to 'apps/sample-add-timestamp.h')
-rw-r--r--apps/sample-add-timestamp.h95
1 files changed, 0 insertions, 95 deletions
diff --git a/apps/sample-add-timestamp.h b/apps/sample-add-timestamp.h
deleted file mode 100644
index 8439519..0000000
--- a/apps/sample-add-timestamp.h
+++ /dev/null
@@ -1,95 +0,0 @@
-#include "trygvis/sensor.h"
-#include "trygvis/sensor/io.h"
-#include "apps.h"
-#include <vector>
-
-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<SampleOutputStream> 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<SampleOutputStream> 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("resolution", po::value<time_resolution>(&resolution)->default_value(time_resolution::SECONDS));
- options("timestamp-name", po::value<string>(&timestamp_name)->default_value("timestamp"));
- options("output-format",
- po::value<sample_format_type>(&output_format)->default_value(sample_format_type::KEY_VALUE));
- }
-
- const int buffer_size = 1024;
-
- int main(app_execution &execution) override {
- shared_ptr<istream> input;
-
- input = shared_ptr<istream>(&cin, noop_deleter);
-
- KeyDictionary dict;
-
- sample_output_stream_options options = {};
- auto unique_output_stream =
- open_sample_output_stream(shared_ptr<ostream>(&cout, noop_deleter), dict, output_format, options);
- shared_ptr<SampleOutputStream> output_stream{std::move(unique_output_stream)};
- auto p = make_shared<TimestampAddingSampleOutputStream>(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;
- };
-};
-}
-}