Implemented separate TCP logger service
This commit is contained in:
@@ -17,23 +17,17 @@
|
||||
#include "ClassRegistryDatabase.h"
|
||||
#include "ErrorManagement.h"
|
||||
#include "AdvancedErrorManagement.h"
|
||||
#include "LoggerConsumerI.h"
|
||||
#include "Threads.h"
|
||||
#include "EventSem.h"
|
||||
|
||||
namespace MARTe {
|
||||
|
||||
struct LogEntry {
|
||||
ErrorManagement::ErrorInformation info;
|
||||
char8 description[MAX_ERROR_MESSAGE_SIZE];
|
||||
};
|
||||
|
||||
struct SignalAlias {
|
||||
StreamString name;
|
||||
uint32 signalIndex;
|
||||
};
|
||||
|
||||
class DebugService : public ReferenceContainer, public MessageI, public EmbeddedServiceMethodBinderI, public LoggerConsumerI {
|
||||
class DebugService : public ReferenceContainer, public MessageI, public EmbeddedServiceMethodBinderI {
|
||||
public:
|
||||
CLASS_REGISTER_DECLARATION()
|
||||
|
||||
@@ -46,16 +40,12 @@ public:
|
||||
void ProcessSignal(DebugSignalInfo* signalInfo, uint32 size);
|
||||
|
||||
virtual ErrorManagement::ErrorType Execute(ExecutionInfo & info);
|
||||
virtual void ConsumeLogMessage(LoggerPage *logPage);
|
||||
static void LogCallback(const ErrorManagement::ErrorInformation &errorInfo, const char8 * const errorDescription);
|
||||
void InsertLogIntoQueue(LoggerPage *logPage);
|
||||
|
||||
bool IsPaused() const { return isPaused; }
|
||||
void SetPaused(bool paused) { isPaused = paused; }
|
||||
|
||||
static bool GetFullObjectName(const Object &obj, StreamString &fullPath);
|
||||
|
||||
// Made public for integration tests and debug access
|
||||
uint32 ForceSignal(const char8* name, const char8* valueStr);
|
||||
uint32 UnforceSignal(const char8* name);
|
||||
uint32 TraceSignal(const char8* name, bool enable, uint32 decimation = 1);
|
||||
@@ -71,11 +61,9 @@ private:
|
||||
|
||||
ErrorManagement::ErrorType Server(ExecutionInfo & info);
|
||||
ErrorManagement::ErrorType Streamer(ExecutionInfo & info);
|
||||
ErrorManagement::ErrorType LogStreamer(ExecutionInfo & info);
|
||||
|
||||
uint16 controlPort;
|
||||
uint16 streamPort;
|
||||
uint16 logPort;
|
||||
StreamString streamIP;
|
||||
bool isServer;
|
||||
bool suppressTimeoutLogs;
|
||||
@@ -83,15 +71,13 @@ private:
|
||||
|
||||
BasicTCPSocket tcpServer;
|
||||
BasicUDPSocket udpSocket;
|
||||
BasicTCPSocket logServer;
|
||||
|
||||
class ServiceBinder : public EmbeddedServiceMethodBinderI {
|
||||
public:
|
||||
enum ServiceType { ServerType, StreamerType, LogStreamerType };
|
||||
enum ServiceType { ServerType, StreamerType };
|
||||
ServiceBinder(DebugService *parent, ServiceType type) : parent(parent), type(type) {}
|
||||
virtual ErrorManagement::ErrorType Execute(ExecutionInfo & info) {
|
||||
if (type == StreamerType) return parent->Streamer(info);
|
||||
if (type == LogStreamerType) return parent->LogStreamer(info);
|
||||
return parent->Server(info);
|
||||
}
|
||||
private:
|
||||
@@ -101,15 +87,12 @@ private:
|
||||
|
||||
ServiceBinder binderServer;
|
||||
ServiceBinder binderStreamer;
|
||||
ServiceBinder binderLogStreamer;
|
||||
|
||||
SingleThreadService threadService;
|
||||
SingleThreadService streamerService;
|
||||
SingleThreadService logStreamerService;
|
||||
|
||||
ThreadIdentifier serverThreadId;
|
||||
ThreadIdentifier streamerThreadId;
|
||||
ThreadIdentifier logStreamerThreadId;
|
||||
|
||||
static const uint32 MAX_SIGNALS = 4096;
|
||||
DebugSignalInfo signals[MAX_SIGNALS];
|
||||
@@ -126,17 +109,7 @@ private:
|
||||
BasicTCPSocket* activeClients[MAX_CLIENTS];
|
||||
FastPollingMutexSem clientsMutex;
|
||||
|
||||
BasicTCPSocket* activeLogClients[MAX_CLIENTS];
|
||||
FastPollingMutexSem logClientsMutex;
|
||||
|
||||
static const uint32 LOG_QUEUE_SIZE = 1024;
|
||||
LogEntry logQueue[LOG_QUEUE_SIZE];
|
||||
volatile uint32 logQueueRead;
|
||||
volatile uint32 logQueueWrite;
|
||||
EventSem logEvent;
|
||||
|
||||
static DebugService* instance;
|
||||
static ErrorManagement::ErrorProcessFunctionType originalLogCallback;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
66
Headers/TcpLogger.h
Normal file
66
Headers/TcpLogger.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#ifndef TCPLOGGER_H
|
||||
#define TCPLOGGER_H
|
||||
|
||||
#include "LoggerConsumerI.h"
|
||||
#include "ReferenceContainer.h"
|
||||
#include "EmbeddedServiceMethodBinderI.h"
|
||||
#include "BasicTCPSocket.h"
|
||||
#include "SingleThreadService.h"
|
||||
#include "FastPollingMutexSem.h"
|
||||
#include "EventSem.h"
|
||||
#include "StreamString.h"
|
||||
|
||||
namespace MARTe {
|
||||
|
||||
struct TcpLogEntry {
|
||||
ErrorManagement::ErrorInformation info;
|
||||
char8 description[MAX_ERROR_MESSAGE_SIZE];
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Logger consumer that publishes framework logs to TCP and stdout.
|
||||
* @details Implements LoggerConsumerI to be used inside a LoggerService.
|
||||
*/
|
||||
class TcpLogger : public ReferenceContainer, public LoggerConsumerI, public EmbeddedServiceMethodBinderI {
|
||||
public:
|
||||
CLASS_REGISTER_DECLARATION()
|
||||
|
||||
TcpLogger();
|
||||
virtual ~TcpLogger();
|
||||
|
||||
virtual bool Initialise(StructuredDataI & data);
|
||||
|
||||
/**
|
||||
* @brief Implementation of LoggerConsumerI.
|
||||
* Called by LoggerService.
|
||||
*/
|
||||
virtual void ConsumeLogMessage(LoggerPage *logPage);
|
||||
|
||||
/**
|
||||
* @brief Worker thread method for TCP streaming.
|
||||
*/
|
||||
virtual ErrorManagement::ErrorType Execute(ExecutionInfo & info);
|
||||
|
||||
private:
|
||||
void InsertLogIntoQueue(const ErrorManagement::ErrorInformation &info, const char8 * const description);
|
||||
|
||||
uint16 port;
|
||||
BasicTCPSocket server;
|
||||
|
||||
static const uint32 MAX_CLIENTS = 8;
|
||||
BasicTCPSocket* activeClients[MAX_CLIENTS];
|
||||
FastPollingMutexSem clientsMutex;
|
||||
|
||||
SingleThreadService service;
|
||||
ThreadIdentifier workerThreadId;
|
||||
|
||||
static const uint32 QUEUE_SIZE = 1024;
|
||||
TcpLogEntry queue[QUEUE_SIZE];
|
||||
volatile uint32 readIdx;
|
||||
volatile uint32 writeIdx;
|
||||
EventSem eventSem;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user