170 lines
4.9 KiB
C++
170 lines
4.9 KiB
C++
#ifndef DEBUGSERVICE_H
|
|
#define DEBUGSERVICE_H
|
|
|
|
#include "MessageI.h"
|
|
#include "StreamString.h"
|
|
#include "BasicUDPSocket.h"
|
|
#include "BasicTCPSocket.h"
|
|
#include "ReferenceContainer.h"
|
|
#include "SingleThreadService.h"
|
|
#include "EmbeddedServiceMethodBinderI.h"
|
|
#include "Object.h"
|
|
#include "DebugCore.h"
|
|
|
|
namespace MARTe {
|
|
|
|
class MemoryMapBroker;
|
|
class DebugService;
|
|
|
|
/**
|
|
* @brief Interface for instrumented brokers to allow service adoption.
|
|
*/
|
|
class DebugBrokerI {
|
|
public:
|
|
virtual ~DebugBrokerI() {}
|
|
virtual void SetService(DebugService* service) = 0;
|
|
virtual bool IsLinked() const = 0;
|
|
};
|
|
|
|
struct SignalExecuteInfo {
|
|
void* memoryAddress;
|
|
void* forcedValue;
|
|
uint32 internalID;
|
|
uint32 size;
|
|
};
|
|
|
|
struct BrokerActiveSet {
|
|
SignalExecuteInfo* forcedSignals;
|
|
uint32 numForced;
|
|
SignalExecuteInfo* tracedSignals;
|
|
uint32 numTraced;
|
|
};
|
|
|
|
struct BrokerInfo {
|
|
DebugSignalInfo** signalPointers;
|
|
uint32 numSignals;
|
|
MemoryMapBroker* broker;
|
|
BrokerActiveSet sets[2];
|
|
volatile uint32 currentSetIdx;
|
|
volatile bool* anyActiveFlag;
|
|
};
|
|
|
|
struct SignalAlias {
|
|
StreamString name;
|
|
uint32 signalIndex;
|
|
};
|
|
|
|
class DebugService : public ReferenceContainer, public MessageI, public EmbeddedServiceMethodBinderI {
|
|
public:
|
|
friend class DebugServiceTest;
|
|
CLASS_REGISTER_DECLARATION()
|
|
|
|
DebugService();
|
|
virtual ~DebugService();
|
|
|
|
virtual bool Initialise(StructuredDataI & data);
|
|
|
|
DebugSignalInfo* RegisterSignal(void* memoryAddress, TypeDescriptor type, const char8* name);
|
|
|
|
static inline void CopySignal(void* dst, const void* src, const uint32 size) {
|
|
if (size == 4u) *static_cast<uint32*>(dst) = *static_cast<const uint32*>(src);
|
|
else if (size == 8u) *static_cast<uint64*>(dst) = *static_cast<const uint64*>(src);
|
|
else if (size == 1u) *static_cast<uint8*>(dst) = *static_cast<const uint8*>(src);
|
|
else if (size == 2u) *static_cast<uint16*>(dst) = *static_cast<const uint16*>(src);
|
|
else MemoryOperationsHelper::Copy(dst, src, size);
|
|
}
|
|
|
|
void ProcessSignal(DebugSignalInfo* signalInfo, uint32 size, uint64 timestamp);
|
|
|
|
void RegisterBroker(DebugSignalInfo** signalPointers, uint32 numSignals, MemoryMapBroker* broker, volatile bool* anyActiveFlag);
|
|
|
|
virtual ErrorManagement::ErrorType Execute(ExecutionInfo & info);
|
|
|
|
static DebugService* Instance();
|
|
|
|
bool IsPaused() const { return isPaused; }
|
|
void SetPaused(bool paused) { isPaused = paused; }
|
|
|
|
static bool GetFullObjectName(const Object &obj, StreamString &fullPath);
|
|
|
|
uint32 ForceSignal(const char8* name, const char8* valueStr);
|
|
uint32 UnforceSignal(const char8* name);
|
|
uint32 TraceSignal(const char8* name, bool enable, uint32 decimation = 1);
|
|
void Discover(BasicTCPSocket *client);
|
|
void ListNodes(const char8* path, BasicTCPSocket *client);
|
|
void InfoNode(const char8* path, BasicTCPSocket *client);
|
|
|
|
void UpdateBrokersActiveStatus();
|
|
|
|
BrokerInfo* GetBrokerInfo(uint32 index) {
|
|
if (index < numberOfBrokers) return &brokers[index];
|
|
return NULL_PTR(BrokerInfo*);
|
|
}
|
|
|
|
// PERFORMANCE-CRITICAL MEMBERS
|
|
static const uint32 MAX_BROKERS = 256;
|
|
BrokerInfo brokers[MAX_BROKERS];
|
|
uint32 numberOfBrokers;
|
|
TraceRingBuffer traceBuffer;
|
|
|
|
static const uint32 MAX_SIGNALS = 512;
|
|
DebugSignalInfo signals[MAX_SIGNALS];
|
|
uint32 numberOfSignals;
|
|
|
|
static const uint32 MAX_ALIASES = 1024;
|
|
SignalAlias aliases[MAX_ALIASES];
|
|
uint32 numberOfAliases;
|
|
|
|
private:
|
|
void HandleCommand(StreamString cmd, BasicTCPSocket *client);
|
|
uint32 ExportTree(ReferenceContainer *container, StreamString &json);
|
|
void PatchRegistry();
|
|
|
|
ErrorManagement::ErrorType Server(ExecutionInfo & info);
|
|
ErrorManagement::ErrorType Streamer(ExecutionInfo & info);
|
|
|
|
uint16 controlPort;
|
|
uint16 streamPort;
|
|
StreamString streamIP;
|
|
bool isServer;
|
|
bool suppressTimeoutLogs;
|
|
volatile bool isPaused;
|
|
|
|
BasicTCPSocket tcpServer;
|
|
BasicUDPSocket udpSocket;
|
|
|
|
class ServiceBinder : public EmbeddedServiceMethodBinderI {
|
|
public:
|
|
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);
|
|
return parent->Server(info);
|
|
}
|
|
private:
|
|
DebugService *parent;
|
|
ServiceType type;
|
|
};
|
|
|
|
ServiceBinder binderServer;
|
|
ServiceBinder binderStreamer;
|
|
|
|
SingleThreadService threadService;
|
|
SingleThreadService streamerService;
|
|
|
|
ThreadIdentifier serverThreadId;
|
|
ThreadIdentifier streamerThreadId;
|
|
|
|
FastPollingMutexSem mutex;
|
|
|
|
static const uint32 MAX_CLIENTS = 16;
|
|
BasicTCPSocket* activeClients[MAX_CLIENTS];
|
|
FastPollingMutexSem clientsMutex;
|
|
};
|
|
|
|
extern DebugService* GlobalDebugServiceInstance;
|
|
|
|
}
|
|
|
|
#endif
|