aboutsummaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/apps.h10
-rw-r--r--apps/mqtt-publish.cpp10
-rw-r--r--apps/sample-add-timestamp.cpp33
-rw-r--r--apps/sample-convert.cpp6
-rw-r--r--apps/sample-select.cpp6
-rw-r--r--apps/sm-get-value.cpp4
-rw-r--r--apps/sm-serial-read-all.cpp2
-rw-r--r--apps/sm-serial-read.cpp2
8 files changed, 31 insertions, 42 deletions
diff --git a/apps/apps.h b/apps/apps.h
index 9173ae0..21a25a3 100644
--- a/apps/apps.h
+++ b/apps/apps.h
@@ -126,12 +126,6 @@ std::string get_hostname();
int real_main(app *app, int argc, const char *argv[]);
-template<typename T>
-class noop_delete {
-public:
- void operator()(T *) const { }
-};
-
static inline void noop_deleter(void *) { }
-}
-}
+} // namespace apps
+} // namespace trygvis
diff --git a/apps/mqtt-publish.cpp b/apps/mqtt-publish.cpp
index 25e8ae9..1498b73 100644
--- a/apps/mqtt-publish.cpp
+++ b/apps/mqtt-publish.cpp
@@ -22,12 +22,12 @@ using namespace trygvis::sensor;
using namespace trygvis::sensor::io;
using namespace trygvis::mqtt_support;
-class MqttSampleOutputStream : public SampleOutputStream {
+class MqttSampleOutputStream : public SampleConsumer {
public:
MqttSampleOutputStream(const o<string> &client_id, bool clean_session, string host, unsigned int port,
string topic_name,
unsigned int keep_alive)
- : SampleOutputStream(),
+ : SampleConsumer(),
client(host, port, keep_alive, client_id, clean_session),
topic_name(topic_name) {
client.connect();
@@ -37,15 +37,15 @@ public:
client.disconnect();
};
- void write(SampleRecord const &sample) override {
+ void onSample(SampleRecord const &sample) override {
if (sample.empty()) {
return;
}
// make a string of the sample
auto buf = make_shared<stringstream>();
- KeyValueSampleOutputStream out(buf, sample.dict);
- out.write(sample);
+ KeyValueWriterSampleConsumer out(buf, sample.dict);
+ out.onSample(sample);
string s = buf->str();
cout << "sample: " << s;
diff --git a/apps/sample-add-timestamp.cpp b/apps/sample-add-timestamp.cpp
index 8bc4bac..841782e 100644
--- a/apps/sample-add-timestamp.cpp
+++ b/apps/sample-add-timestamp.cpp
@@ -1,8 +1,6 @@
#include "trygvis/sensor.h"
#include "trygvis/sensor/io.h"
#include "apps.h"
-#include <vector>
-#include "apps.h"
namespace trygvis {
namespace apps {
@@ -13,10 +11,10 @@ using namespace trygvis::sensor;
using namespace trygvis::sensor::io;
namespace po = boost::program_options;
-class TimestampAddingSampleOutputStream : public SampleOutputStream {
+class TimestampAddingSampleOutputStream : public SampleConsumer {
public:
- TimestampAddingSampleOutputStream(shared_ptr<SampleOutputStream> output, KeyDictionary &dict, string timestamp_name)
- : timestamp_key(dict.indexOf(timestamp_name)) {
+ TimestampAddingSampleOutputStream(shared_ptr<SampleConsumer> output, KeyDictionary &dict, string timestamp_name)
+ : output_(output), timestamp_key(dict.indexOf(timestamp_name)) {
if (input_time_resolution_ == time_resolution::MILLISECONDS) {
factor = 1000;
} else {
@@ -24,21 +22,21 @@ public:
}
}
- virtual void write(SampleRecord const &sample) override {
+ virtual void onSample(const SampleRecord &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);
+ output_->onSample(updated_sample);
};
private:
const SampleKey *timestamp_key;
- time_resolution input_time_resolution_;
+ const time_resolution input_time_resolution_ = time_resolution::MILLISECONDS;
int factor;
- shared_ptr<SampleOutputStream> output_;
+ shared_ptr<SampleConsumer> output_;
};
class sample_add_timestamp : public app {
@@ -62,25 +60,22 @@ public:
const int buffer_size = 1024;
int main(app_execution &execution) override {
- shared_ptr<istream> input;
-
- input = shared_ptr<istream>(&cin, noop_deleter);
+ auto stdin = shared_ptr<istream>(&cin, noop_deleter);
+ auto stdout = shared_ptr<ostream>(&cout, 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 writer = open_sample_writer(stdout, dict, output_format, options);
+ auto p = make_shared<TimestampAddingSampleOutputStream>(std::move(writer), dict, timestamp_name);
auto parser = open_sample_stream_parser(p, dict);
int recordCount = 0;
- while (!input->eof()) {
+ while (!stdin->eof()) {
char buffer[buffer_size];
- input->read(buffer, buffer_size);
- size_t gcount = (size_t) input->gcount();
+ stdin->read(buffer, buffer_size);
+ auto gcount = static_cast<size_t>(stdin->gcount());
recordCount++;
diff --git a/apps/sample-convert.cpp b/apps/sample-convert.cpp
index 81c08ca..2142462 100644
--- a/apps/sample-convert.cpp
+++ b/apps/sample-convert.cpp
@@ -93,13 +93,13 @@ public:
options.push_back(&fs);
}
- unique_ptr<SampleOutputStream> o = open_sample_output_stream(outputStream, dict, output_format, options);
+ unique_ptr<SampleConsumer> o = open_sample_writer(outputStream, dict, output_format, options);
if (add_timestamp) {
- o = make_unique<AddTimestampSampleOutputStream>(move(o), dict, timestamp_field);
+ o = make_unique<AddTimestampSampleConsumer>(move(o), dict, timestamp_field);
}
- shared_ptr<SampleOutputStream> output(move(o));
+ shared_ptr<SampleConsumer> output(move(o));
auto input = make_shared<KeyValueSampleStreamParser>(output, dict);
diff --git a/apps/sample-select.cpp b/apps/sample-select.cpp
index d067af4..1db1443 100644
--- a/apps/sample-select.cpp
+++ b/apps/sample-select.cpp
@@ -91,10 +91,10 @@ public:
}
vector<sample_output_stream_option*> options = {};
- unique_ptr<SampleOutputStream> unique_output_stream = open_sample_output_stream(shared_ptr<ostream>(&cout,
+ unique_ptr<SampleConsumer> unique_output_stream = open_sample_writer(shared_ptr<ostream>(&cout,
noop_deleter), dict, parser->type(), options);
- shared_ptr<SampleOutputStream> output_stream{std::move(unique_output_stream)};
- shared_ptr<SampleOutputStream> p = make_shared<TimestampFixingSampleOutputStream>(output_stream, dict,
+ shared_ptr<SampleConsumer> output_stream{std::move(unique_output_stream)};
+ shared_ptr<SampleConsumer> p = make_shared<TimestampFixingSampleOutputStream>(output_stream, dict,
timestamp_name, relative_name, relative_resolution, start_time);
parser = open_sample_stream_parser(p, dict, parser->type());
diff --git a/apps/sm-get-value.cpp b/apps/sm-get-value.cpp
index 42f5da3..483df70 100644
--- a/apps/sm-get-value.cpp
+++ b/apps/sm-get-value.cpp
@@ -109,7 +109,7 @@ public:
auto epoch = system_clock::now().time_since_epoch();
auto timestamp = duration_cast<seconds>(epoch).count();
auto unique_output_stream = open_sample_output_stream(shared_ptr<ostream>(&cout, noop_deleter), dict, format);
- shared_ptr<SampleOutputStream> output_stream{std::move(unique_output_stream)};
+ shared_ptr<SampleConsumer> output_stream{std::move(unique_output_stream)};
auto sample = SampleRecord(dict)
.set(hostname_key, get_hostname())
@@ -138,7 +138,7 @@ public:
i++;
}
- output_stream->write(sample);
+ output_stream->onSample(sample);
}
void withConnection(sample_format_type format, shared_ptr<BluetoothGatt> gatt) {
diff --git a/apps/sm-serial-read-all.cpp b/apps/sm-serial-read-all.cpp
index a81a016..3c2b617 100644
--- a/apps/sm-serial-read-all.cpp
+++ b/apps/sm-serial-read-all.cpp
@@ -115,7 +115,7 @@ public:
auto output_stream = shared_ptr<ostream>(&cout, noop_deleter);
auto output = open_sample_output_stream(output_stream, outputDict, format);
auto tso = thread_safe_sample_output_stream(move(output));
- shared_ptr<SampleOutputStream> thread_safe_output(move(tso));
+ shared_ptr<SampleConsumer> thread_safe_output(move(tso));
while (run) {
// Port cleanup
diff --git a/apps/sm-serial-read.cpp b/apps/sm-serial-read.cpp
index 980a3f6..69931a0 100644
--- a/apps/sm-serial-read.cpp
+++ b/apps/sm-serial-read.cpp
@@ -90,7 +90,7 @@ public:
}
shared_ptr<ostream> outputStream = shared_ptr<ostream>(&cout, noop_deleter);
- shared_ptr<SampleOutputStream> output = open_sample_output_stream(outputStream, dict, format);
+ shared_ptr<SampleConsumer> output = open_sample_output_stream(outputStream, dict, format);
shared_ptr<KeyValueSampleStreamParser> input = make_shared<KeyValueSampleStreamParser>(output, dict);