Skip to content

Commit

Permalink
Reformat stream_producer.h
Browse files Browse the repository at this point in the history
  • Loading branch information
mairas committed Oct 7, 2024
1 parent e91dbe7 commit 5676b4e
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions src/sensesp/system/stream_producer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ namespace sensesp {
class StreamCharProducer : public ValueProducer<char> {
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:
Expand All @@ -34,28 +33,29 @@ class StreamCharProducer : public ValueProducer<char> {
*/
class StreamLineProducer : public ValueProducer<String> {
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:
Expand Down

0 comments on commit 5676b4e

Please sign in to comment.