2016-06-15 23:48:41 +02:00
|
|
|
#ifndef FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACESTREAM_H_
|
|
|
|
#define FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACESTREAM_H_
|
|
|
|
|
|
|
|
#include <framework/serviceinterface/ServiceInterfaceBuffer.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include <cstdio>
|
|
|
|
|
2020-06-03 22:56:03 +02:00
|
|
|
// Unfortunately, there must be a forward declaration of the log front end
|
2020-04-08 18:08:14 +02:00
|
|
|
// (MUST be defined in main), to let the system know where to write to.
|
2020-06-03 23:26:27 +02:00
|
|
|
// The ServiceInterfaceStream instances (declared below and instantiated in main)
|
|
|
|
// can be passed to these front ends by passing their underlying buffers
|
|
|
|
// with .rdbuf()
|
2020-04-23 19:13:18 +02:00
|
|
|
namespace sif {
|
2016-06-15 23:48:41 +02:00
|
|
|
extern std::ostream debug;
|
|
|
|
extern std::ostream info;
|
|
|
|
extern std::ostream warning;
|
|
|
|
extern std::ostream error;
|
2020-04-23 19:13:18 +02:00
|
|
|
}
|
|
|
|
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-04-10 17:06:06 +02:00
|
|
|
class ServiceInterfaceStream :
|
2020-06-03 22:56:03 +02:00
|
|
|
public std::ostream {
|
2016-06-15 23:48:41 +02:00
|
|
|
protected:
|
|
|
|
ServiceInterfaceBuffer buf;
|
|
|
|
public:
|
2020-06-03 22:56:03 +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 set_message
|
|
|
|
* @param errStream
|
|
|
|
* @param addCrToPreamble
|
|
|
|
* @param port
|
|
|
|
*/
|
|
|
|
ServiceInterfaceStream(std::string setMessage,
|
|
|
|
bool errStream = false, bool addCrToPreamble = false,
|
|
|
|
uint16_t port = 1234);
|
|
|
|
|
|
|
|
//! An inactive stream will not print anything.
|
2016-06-15 23:48:41 +02:00
|
|
|
void setActive( bool );
|
2020-06-03 22:56:03 +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.
|
|
|
|
*/
|
|
|
|
std::string getPreamble();
|
2016-06-15 23:48:41 +02:00
|
|
|
};
|
|
|
|
|
2020-06-03 23:10:04 +02:00
|
|
|
// Forward declaration of interface streams. These are needed so the public
|
|
|
|
// functions can be used by including this header
|
|
|
|
namespace sif {
|
|
|
|
extern ServiceInterfaceStream debugStream;
|
|
|
|
extern ServiceInterfaceStream infoStream;
|
|
|
|
extern ServiceInterfaceStream warningStream;
|
|
|
|
extern ServiceInterfaceStream errorStream;
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
#endif /* FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACESTREAM_H_ */
|