2016-06-15 23:48:41 +02:00
|
|
|
#ifndef FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACESTREAM_H_
|
|
|
|
#define FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACESTREAM_H_
|
|
|
|
|
2020-08-13 20:53:35 +02:00
|
|
|
#include "ServiceInterfaceBuffer.h"
|
2016-06-15 23:48:41 +02:00
|
|
|
#include <iostream>
|
|
|
|
#include <cstdio>
|
|
|
|
|
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 {
|
2016-06-15 23:48:41 +02:00
|
|
|
public:
|
2020-06-04 19:37:33 +02:00
|
|
|
/**
|
|
|
|
* 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,
|
2020-06-04 14:08:26 +02:00
|
|
|
bool errStream = false, uint16_t port = 1234);
|
2020-06-03 23:14:17 +02:00
|
|
|
|
2020-06-04 19:37:33 +02:00
|
|
|
//! An inactive stream will not print anything.
|
2016-06-15 23:48:41 +02:00
|
|
|
void setActive( bool );
|
2020-06-03 23:14:17 +02: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.
|
|
|
|
*/
|
2020-07-21 15:15:53 +02:00
|
|
|
std::string* getPreamble();
|
2020-06-04 14:08:26 +02:00
|
|
|
|
2020-06-04 19:37:33 +02:00
|
|
|
protected:
|
|
|
|
ServiceInterfaceBuffer streambuf;
|
2016-06-15 23:48:41 +02:00
|
|
|
};
|
|
|
|
|
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.
|
2020-06-03 23:14:17 +02:00
|
|
|
namespace sif {
|
2020-06-04 14:08:26 +02:00
|
|
|
extern ServiceInterfaceStream debug;
|
|
|
|
extern ServiceInterfaceStream info;
|
|
|
|
extern ServiceInterfaceStream warning;
|
|
|
|
extern ServiceInterfaceStream error;
|
2020-06-03 23:14:17 +02:00
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
#endif /* FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACESTREAM_H_ */
|