aboutsummaryrefslogtreecommitdiff
path: root/sensor/include
diff options
context:
space:
mode:
Diffstat (limited to 'sensor/include')
-rw-r--r--sensor/include/trygvis/sensor.h2
-rw-r--r--sensor/include/trygvis/sensor/io.h55
2 files changed, 47 insertions, 10 deletions
diff --git a/sensor/include/trygvis/sensor.h b/sensor/include/trygvis/sensor.h
index 42362b2..4662bab 100644
--- a/sensor/include/trygvis/sensor.h
+++ b/sensor/include/trygvis/sensor.h
@@ -75,7 +75,7 @@ public:
}
KeyDictionary(KeyDictionary& that) = delete;
- SampleKey *indexOf(const string key) {
+ SampleKey *indexOf(const string &key) {
SampleKeyIndex i = 0;
for (auto ptr = keys.cbegin(); ptr != keys.cend(); ptr++, i++) {
if ((*ptr)->name == key) {
diff --git a/sensor/include/trygvis/sensor/io.h b/sensor/include/trygvis/sensor/io.h
index bbeb80e..f92b800 100644
--- a/sensor/include/trygvis/sensor/io.h
+++ b/sensor/include/trygvis/sensor/io.h
@@ -37,6 +37,25 @@ public:
string name;
};
+class sample_output_stream_options : public vector<sample_output_stream_option *> {
+public:
+ ~sample_output_stream_options() {
+ }
+
+ template<typename T>
+ o<T *> find_option() const {
+ for (auto it = begin(); it != end(); ++it) {
+ T *x = dynamic_cast<T *>(*it);
+
+ if (x != nullptr) {
+ return o<T *>(x);
+ }
+ }
+
+ return o<T *>();
+ }
+};
+
class SampleOutputStream {
public:
virtual void write(SampleRecord const &sample) = 0;
@@ -65,6 +84,20 @@ private:
std::mutex mutex;
};
+class AddTimestampSampleOutputStream : public SampleOutputStream {
+public:
+ AddTimestampSampleOutputStream(unique_ptr<SampleOutputStream> underlying, KeyDictionary &dict, const string &timestamp_name);
+
+ ~AddTimestampSampleOutputStream() {
+ }
+
+ void write(SampleRecord const &sample) override;
+
+private:
+ unique_ptr<SampleOutputStream> underlying_;
+ const SampleKey* timestamp_key;
+};
+
class CsvSampleOutputStream : public SampleOutputStream {
public:
CsvSampleOutputStream(shared_ptr<ostream> stream, KeyDictionary &dict);
@@ -132,16 +165,21 @@ private:
class SampleStreamParser {
public:
// TODO: return number of samples found for progress indication?
- virtual void process(mutable_buffers_1 buffer) = 0;
+ virtual void process(mutable_buffers_1 &buffer) = 0;
virtual sample_format_type type() {
return type_;
}
+ virtual KeyDictionary &dict() {
+ return dict_;
+ }
+
protected:
sample_format_type type_;
+ KeyDictionary &dict_;
- SampleStreamParser(const sample_format_type type) : type_(type) {
+ SampleStreamParser(const sample_format_type type, KeyDictionary &dict) : type_(type), dict_(dict) {
}
};
@@ -149,17 +187,16 @@ class KeyValueSampleStreamParser : public SampleStreamParser {
public:
KeyValueSampleStreamParser(shared_ptr<SampleOutputStream> output, KeyDictionary &dict) :
- SampleStreamParser(sample_format_type::CSV), output(output), dict(dict),
+ SampleStreamParser(sample_format_type::CSV, dict), output(output),
line(make_shared<vector<uint8_t>>()) {
}
- void process(mutable_buffers_1 buffer) override;
+ void process(mutable_buffers_1 &buffer) override;
private:
void process_line(shared_ptr<vector<uint8_t>> packet);
static const uint8_t packet_delimiter = '\n';
- KeyDictionary &dict;
shared_ptr<SampleOutputStream> output;
shared_ptr<vector<uint8_t>> line;
};
@@ -168,11 +205,11 @@ class AutoSampleParser : public SampleStreamParser {
public:
AutoSampleParser(shared_ptr<SampleOutputStream> output, KeyDictionary &dict);
+ virtual void process(mutable_buffers_1 &buffer) override;
+
private:
unique_ptr<SampleStreamParser> parser;
unique_ptr<KeyValueSampleStreamParser> keyValueParser;
-public:
- virtual void process(mutable_buffers_1 buffer);
};
unique_ptr<SampleStreamParser> open_sample_stream_parser(
@@ -184,14 +221,14 @@ unique_ptr<SampleOutputStream> open_sample_output_stream(
shared_ptr<ostream> output,
KeyDictionary &dict,
sample_format_type type,
- vector<sample_output_stream_option *> options);
+ sample_output_stream_options options);
static inline
unique_ptr<SampleOutputStream> open_sample_output_stream(
shared_ptr<ostream> output,
KeyDictionary &dict,
sample_format_type type) {
- vector<sample_output_stream_option *> options;
+ sample_output_stream_options options;
return open_sample_output_stream(output, dict, type, options);
}