aboutsummaryrefslogtreecommitdiff
path: root/apps/sample-add-timestamp.cpp
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-06-21 00:15:04 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2015-06-21 00:15:43 +0200
commitc56840f03cf139d60c6d90b55cf16e70f6ae2bc2 (patch)
treec9f19ab065496ac704fbf855da031ef5643eefa3 /apps/sample-add-timestamp.cpp
parentd91e500592790f1ef22ebfe921f273a61ff6252f (diff)
downloadble-toys-c56840f03cf139d60c6d90b55cf16e70f6ae2bc2.tar.gz
ble-toys-c56840f03cf139d60c6d90b55cf16e70f6ae2bc2.tar.bz2
ble-toys-c56840f03cf139d60c6d90b55cf16e70f6ae2bc2.tar.xz
ble-toys-c56840f03cf139d60c6d90b55cf16e70f6ae2bc2.zip
o Going all header file based and single-executable to launch all apps.
o Ading CMake magic to generate the launcher
Diffstat (limited to 'apps/sample-add-timestamp.cpp')
-rw-r--r--apps/sample-add-timestamp.cpp105
1 files changed, 0 insertions, 105 deletions
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 <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
- ("help", "produce this help message")
- ("resolution", po::value<time_resolution>(&resolution)->default_value(time_resolution::SECONDS))
- ("timestamp-name", po::value<string>(&timestamp_name)->default_value("timestamp"))
- ("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 = {};
- unique_ptr<SampleOutputStream> 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)};
- shared_ptr<SampleOutputStream> 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;
- };
-};
-
-}
-}
-
-using namespace trygvis::apps;
-
-int main(int argc, char *argv[]) {
- sample_add_timestamp app;
- return launch_app(argc, argv, app);
-}