fsfw/src/fsfw/serviceinterface/ServiceInterfaceStream.h

68 lines
2.1 KiB
C
Raw Normal View History

#ifndef FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACESTREAM_H_
#define FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACESTREAM_H_
2022-02-02 10:29:30 +01:00
#include "ServiceInterfaceBuffer.h"
2022-09-14 19:59:02 +02:00
#include "fsfw/FSFW.h"
2022-02-02 10:29:30 +01:00
2021-01-03 14:16:52 +01:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2021-01-03 14:08:40 +01:00
#include <cstdio>
2022-02-02 10:29:30 +01:00
#include <iostream>
2020-06-04 14:08:26 +02:00
/**
* Generic service interface stream which can be used like std::cout or
* std::cerr but has additional capability. Add preamble and timestamp
* to output. Can be run in buffered or unbuffered mode.
*/
2020-06-04 19:37:33 +02:00
class ServiceInterfaceStream : public std::ostream {
2022-02-02 10:29:30 +01:00
public:
/**
* This constructor is used by specifying the preamble message.
* Optionally, the output can be directed to stderr and a CR character
* can be prepended to the preamble.
* @param setMessage message of preamble.
* @param addCrToPreamble Useful for applications like Puttty.
* @param buffered specify whether to use buffered mode.
* @param errStream specify which output stream to use (stderr or stdout).
*/
ServiceInterfaceStream(std::string setMessage, bool addCrToPreamble = false, bool buffered = true,
bool errStream = false, uint16_t port = 1234);
2022-02-02 10:29:30 +01:00
//! An inactive stream will not print anything.
void setActive(bool);
2022-02-02 10:29:30 +01:00
/**
* This can be used to retrieve the preamble in case it should be printed in
* the unbuffered mode.
* @return Preamle consisting of log message and timestamp.
*/
std::string* getPreamble();
2020-06-04 14:08:26 +02:00
2022-02-02 10:29:30 +01:00
/**
* Can be used to determine if the stream was configured to add CR characters in addition
* to newline characters.
* @return
*/
bool crAdditionEnabled() const;
2021-01-15 18:07:32 +01:00
2021-07-24 07:15:24 +02:00
#if FSFW_COLORED_OUTPUT == 1
2022-02-02 10:29:30 +01:00
void setAsciiColorPrefix(std::string asciiColorCode);
2021-07-24 07:15:24 +02:00
#endif
2021-06-11 14:52:09 +02:00
2022-02-02 10:29:30 +01:00
protected:
ServiceInterfaceBuffer streambuf;
};
2020-06-04 14:08:26 +02:00
// Forward declaration of interface streams. These should be instantiated in
// main. They can then be used like std::cout or std::cerr.
namespace sif {
2020-06-04 14:08:26 +02:00
extern ServiceInterfaceStream debug;
extern ServiceInterfaceStream info;
extern ServiceInterfaceStream warning;
extern ServiceInterfaceStream error;
2022-02-02 10:29:30 +01:00
} // namespace sif
2021-01-03 14:16:52 +01:00
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
2021-01-03 14:08:40 +01:00
#endif /* FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACESTREAM_H_ */