From 5676b4e4c0e81e99321ee85444dfea4281ffe851 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Mon, 7 Oct 2024 10:40:09 +0300 Subject: [PATCH] Reformat stream_producer.h --- src/sensesp/system/stream_producer.h | 50 ++++++++++++++-------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/sensesp/system/stream_producer.h b/src/sensesp/system/stream_producer.h index 10ae1960d..b4132b27b 100644 --- a/src/sensesp/system/stream_producer.h +++ b/src/sensesp/system/stream_producer.h @@ -15,13 +15,12 @@ namespace sensesp { class StreamCharProducer : public ValueProducer { public: StreamCharProducer(Stream* stream) : stream_{stream} { - read_event_ = - event_loop()->onAvailable(*stream_, [this]() { - while (stream_->available()) { - char c = stream_->read(); - this->emit(c); - } - }); + read_event_ = event_loop()->onAvailable(*stream_, [this]() { + while (stream_->available()) { + char c = stream_->read(); + this->emit(c); + } + }); } protected: @@ -34,28 +33,29 @@ class StreamCharProducer : public ValueProducer { */ class StreamLineProducer : public ValueProducer { public: - StreamLineProducer(Stream* stream, int max_line_length = 256) + StreamLineProducer(Stream* stream, + reactesp::EventLoop* event_loop = event_loop(), + int max_line_length = 256) : stream_{stream}, max_line_length_{max_line_length} { static int buf_pos = 0; buf_ = new char[max_line_length_ + 1]; - read_event_ = - event_loop()->onAvailable(*stream_, [this]() { - while (stream_->available()) { - char c = stream_->read(); - if (c == '\n') { - // Include the newline character in the output - buf_[buf_pos++] = c; - buf_[buf_pos] = '\0'; - this->emit(buf_); - buf_pos = 0; - } else { - buf_[buf_pos++] = c; - if (buf_pos >= max_line_length_ - 1) { - buf_pos = 0; - } - } + read_event_ = event_loop->onAvailable(*stream_, [this]() { + while (stream_->available()) { + char c = stream_->read(); + if (c == '\n') { + // Include the newline character in the output + buf_[buf_pos++] = c; + buf_[buf_pos] = '\0'; + this->emit(buf_); + buf_pos = 0; + } else { + buf_[buf_pos++] = c; + if (buf_pos >= max_line_length_ - 1) { + buf_pos = 0; } - }); + } + } + }); } protected: