From 0dc2cc6503386c809266ad6564ba675803cf8cc7 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 22 Mar 2015 14:27:46 +0100 Subject: o First version of a tool to continuously read and discover serial ports. --- apps/SoilMoistureIo.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'apps/SoilMoistureIo.cpp') diff --git a/apps/SoilMoistureIo.cpp b/apps/SoilMoistureIo.cpp index 4d2e03d..1d9281b 100644 --- a/apps/SoilMoistureIo.cpp +++ b/apps/SoilMoistureIo.cpp @@ -278,7 +278,7 @@ void SqlSampleOutputStream::write(SampleRecord const &values) { // (*stream.get()) << "INSERT INTO " << table_name << "(" << fs << ") VALUES(" << vs << ");" << endl; } -void KeyValueSampleParser::process(mutable_buffers_1 buffer) { +void KeyValueSampleStreamParser::process(mutable_buffers_1 buffer) { size_t size = buffer_size(buffer); @@ -303,7 +303,7 @@ void KeyValueSampleParser::process(mutable_buffers_1 buffer) { } -void KeyValueSampleParser::process_line(shared_ptr> packet) { +void KeyValueSampleStreamParser::process_line(shared_ptr> packet) { auto timestamp = std::chrono::system_clock::now().time_since_epoch().count(); auto s = std::string((char *) packet->data(), packet->size()); @@ -332,7 +332,7 @@ void KeyValueSampleParser::process_line(shared_ptr> packet) { } AutoSampleParser::AutoSampleParser(shared_ptr output, KeyDictionary &dict) : - SampleStreamParser(sample_format_type::AUTO), keyValueParser(new KeyValueSampleParser(output, dict)) { + SampleStreamParser(sample_format_type::AUTO), keyValueParser(new KeyValueSampleStreamParser(output, dict)) { // Directly select the parser now until we have more than one parser parser = std::move(keyValueParser); type_ = sample_format_type::KEY_VALUE; @@ -393,7 +393,7 @@ unique_ptr open_sample_input_stream( KeyDictionary &dict, sample_format_type type) { if (type == sample_format_type::KEY_VALUE) { - return make_unique(output, dict); + return make_unique(output, dict); } else if (type == sample_format_type::AUTO) { return make_unique(output, dict); } else { @@ -441,5 +441,16 @@ unique_ptr open_sample_output_stream( } } +//template +ThreadSafeSampleOutputStream::ThreadSafeSampleOutputStream(unique_ptr underlying) : underlying(move(underlying)) { +} + +//template +void ThreadSafeSampleOutputStream::write(SampleRecord const &sample) { + std::unique_lock lock(mutex); + + underlying->write(sample); +} + } } -- cgit v1.2.3