fsfw/serviceinterface/ServiceInterfaceStream.cpp

33 lines
867 B
C++
Raw Normal View History

#include <framework/serviceinterface/ServiceInterfaceStream.h>
ServiceInterfaceStream::ServiceInterfaceStream(std::string setMessage,
2020-06-04 14:08:26 +02:00
bool addCrToPreamble, bool buffered, bool errStream, uint16_t port) :
2020-06-04 19:37:33 +02:00
std::ostream(&streambuf),
streambuf(setMessage, addCrToPreamble, buffered, errStream, port) {}
void ServiceInterfaceStream::setActive( bool myActive) {
2020-06-04 19:37:33 +02:00
this->streambuf.isActive = myActive;
}
std::string ServiceInterfaceStream::getPreamble() {
2020-06-04 19:37:33 +02:00
return streambuf.getPreamble();
2020-06-04 14:08:26 +02:00
}
void ServiceInterfaceStream::print(std::string error,
bool withPreamble, bool withNewline, bool flush) {
2020-06-04 19:37:33 +02:00
if(not streambuf.isBuffered() and withPreamble) {
2020-06-04 14:08:26 +02:00
*this << getPreamble() << error;
}
else {
*this << error;
}
if(withNewline) {
*this << "\n";
}
// if mode is non-buffered, no need to flush.
2020-06-04 19:37:33 +02:00
if(flush and streambuf.isBuffered()) {
2020-06-04 14:08:26 +02:00
this->flush();
}
}