Optimised failed test
This commit is contained in:
@@ -10,23 +10,11 @@
|
||||
#include "HighResolutionTimer.h"
|
||||
#include "ConfigurationDatabase.h"
|
||||
#include "GAM.h"
|
||||
|
||||
// Explicitly include target brokers for templating
|
||||
#include "MemoryMapInputBroker.h"
|
||||
#include "MemoryMapOutputBroker.h"
|
||||
#include "MemoryMapSynchronisedInputBroker.h"
|
||||
#include "MemoryMapSynchronisedOutputBroker.h"
|
||||
#include "MemoryMapInterpolatedInputBroker.h"
|
||||
#include "MemoryMapMultiBufferInputBroker.h"
|
||||
#include "MemoryMapMultiBufferOutputBroker.h"
|
||||
#include "MemoryMapSynchronisedMultiBufferInputBroker.h"
|
||||
#include "MemoryMapSynchronisedMultiBufferOutputBroker.h"
|
||||
#include "MemoryMapAsyncOutputBroker.h"
|
||||
#include "MemoryMapAsyncTriggerOutputBroker.h"
|
||||
#include "Atomic.h"
|
||||
|
||||
namespace MARTe {
|
||||
|
||||
DebugService* DebugService::instance = NULL_PTR(DebugService*);
|
||||
DebugService* GlobalDebugServiceInstance = NULL_PTR(DebugService*);
|
||||
|
||||
static void EscapeJson(const char8* src, StreamString &dst) {
|
||||
if (src == NULL_PTR(const char8*)) return;
|
||||
@@ -41,215 +29,12 @@ static void EscapeJson(const char8* src, StreamString &dst) {
|
||||
}
|
||||
}
|
||||
|
||||
CLASS_REGISTER(DebugService, "1.0")
|
||||
|
||||
DebugService::DebugService() :
|
||||
ReferenceContainer(), EmbeddedServiceMethodBinderI(),
|
||||
binderServer(this, ServiceBinder::ServerType),
|
||||
binderStreamer(this, ServiceBinder::StreamerType),
|
||||
threadService(binderServer),
|
||||
streamerService(binderStreamer)
|
||||
{
|
||||
controlPort = 0;
|
||||
streamPort = 8081;
|
||||
streamIP = "127.0.0.1";
|
||||
numberOfSignals = 0;
|
||||
numberOfAliases = 0;
|
||||
numberOfBrokers = 0;
|
||||
isServer = false;
|
||||
suppressTimeoutLogs = true;
|
||||
isPaused = false;
|
||||
for (uint32 i=0; i<MAX_CLIENTS; i++) {
|
||||
activeClients[i] = NULL_PTR(BasicTCPSocket*);
|
||||
}
|
||||
}
|
||||
|
||||
DebugService::~DebugService() {
|
||||
if (instance == this) {
|
||||
instance = NULL_PTR(DebugService*);
|
||||
}
|
||||
threadService.Stop();
|
||||
streamerService.Stop();
|
||||
tcpServer.Close();
|
||||
udpSocket.Close();
|
||||
for (uint32 i=0; i<MAX_CLIENTS; i++) {
|
||||
if (activeClients[i] != NULL_PTR(BasicTCPSocket*)) {
|
||||
activeClients[i]->Close();
|
||||
delete activeClients[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool DebugService::Initialise(StructuredDataI & data) {
|
||||
if (!ReferenceContainer::Initialise(data)) return false;
|
||||
if (!data.Read("ControlPort", controlPort)) {
|
||||
(void)data.Read("TcpPort", controlPort);
|
||||
}
|
||||
if (controlPort > 0) {
|
||||
isServer = true;
|
||||
instance = this;
|
||||
}
|
||||
if (!data.Read("StreamPort", streamPort)) {
|
||||
(void)data.Read("UdpPort", streamPort);
|
||||
}
|
||||
StreamString tempIP;
|
||||
if (data.Read("StreamIP", tempIP)) {
|
||||
streamIP = tempIP;
|
||||
} else {
|
||||
streamIP = "127.0.0.1";
|
||||
}
|
||||
uint32 suppress = 1;
|
||||
if (data.Read("SuppressTimeoutLogs", suppress)) {
|
||||
suppressTimeoutLogs = (suppress == 1);
|
||||
}
|
||||
if (isServer) {
|
||||
if (!traceBuffer.Init(8 * 1024 * 1024)) return false;
|
||||
PatchRegistry();
|
||||
ConfigurationDatabase threadData;
|
||||
threadData.Write("Timeout", (uint32)1000);
|
||||
threadService.Initialise(threadData);
|
||||
streamerService.Initialise(threadData);
|
||||
if (!tcpServer.Open()) return false;
|
||||
if (!tcpServer.Listen(controlPort)) return false;
|
||||
printf("[DebugService] TCP Server listening on port %u\n", controlPort);
|
||||
if (!udpSocket.Open()) return false;
|
||||
printf("[DebugService] UDP Streamer socket opened\n");
|
||||
if (threadService.Start() != ErrorManagement::NoError) return false;
|
||||
if (streamerService.Start() != ErrorManagement::NoError) return false;
|
||||
printf("[DebugService] Worker threads started.\n");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void PatchItemInternal(const char8* className, ObjectBuilder* builder) {
|
||||
ClassRegistryDatabase *db = ClassRegistryDatabase::Instance();
|
||||
ClassRegistryItem *item = (ClassRegistryItem*)db->Find(className);
|
||||
if (item != NULL_PTR(ClassRegistryItem*)) {
|
||||
item->SetObjectBuilder(builder);
|
||||
}
|
||||
}
|
||||
|
||||
void DebugService::PatchRegistry() {
|
||||
DebugMemoryMapInputBrokerBuilder* b1 = new DebugMemoryMapInputBrokerBuilder(); PatchItemInternal("MemoryMapInputBroker", b1);
|
||||
DebugMemoryMapOutputBrokerBuilder* b2 = new DebugMemoryMapOutputBrokerBuilder(); PatchItemInternal("MemoryMapOutputBroker", b2);
|
||||
DebugMemoryMapSynchronisedInputBrokerBuilder* b3 = new DebugMemoryMapSynchronisedInputBrokerBuilder(); PatchItemInternal("MemoryMapSynchronisedInputBroker", b3);
|
||||
DebugMemoryMapSynchronisedOutputBrokerBuilder* b4 = new DebugMemoryMapSynchronisedOutputBrokerBuilder(); PatchItemInternal("MemoryMapSynchronisedOutputBroker", b4);
|
||||
DebugMemoryMapInterpolatedInputBrokerBuilder* b5 = new DebugMemoryMapInterpolatedInputBrokerBuilder(); PatchItemInternal("MemoryMapInterpolatedInputBroker", b5);
|
||||
DebugMemoryMapMultiBufferInputBrokerBuilder* b6 = new DebugMemoryMapMultiBufferInputBrokerBuilder(); PatchItemInternal("MemoryMapMultiBufferInputBroker", b6);
|
||||
DebugMemoryMapMultiBufferOutputBrokerBuilder* b7 = new DebugMemoryMapMultiBufferOutputBrokerBuilder(); PatchItemInternal("MemoryMapMultiBufferOutputBroker", b7);
|
||||
DebugMemoryMapSynchronisedMultiBufferInputBrokerBuilder* b8 = new DebugMemoryMapSynchronisedMultiBufferInputBrokerBuilder(); PatchItemInternal("MemoryMapSynchronisedMultiBufferInputBroker", b8);
|
||||
DebugMemoryMapSynchronisedMultiBufferOutputBrokerBuilder* b9 = new DebugMemoryMapSynchronisedMultiBufferOutputBrokerBuilder(); PatchItemInternal("MemoryMapSynchronisedMultiBufferOutputBroker", b9);
|
||||
DebugMemoryMapAsyncOutputBrokerBuilder* b10 = new DebugMemoryMapAsyncOutputBrokerBuilder(); PatchItemInternal("MemoryMapAsyncOutputBroker", b10);
|
||||
DebugMemoryMapAsyncTriggerOutputBrokerBuilder* b11 = new DebugMemoryMapAsyncTriggerOutputBrokerBuilder(); PatchItemInternal("MemoryMapAsyncTriggerOutputBroker", b11);
|
||||
}
|
||||
|
||||
void DebugService::ProcessSignal(DebugSignalInfo* s, uint32 size, uint64 timestamp) {
|
||||
if (s != NULL_PTR(DebugSignalInfo*)) {
|
||||
if (s->isForcing) {
|
||||
MemoryOperationsHelper::Copy(s->memoryAddress, s->forcedValue, size);
|
||||
}
|
||||
if (s->isTracing) {
|
||||
if (s->decimationFactor <= 1) {
|
||||
(void)traceBuffer.Push(s->internalID, timestamp, s->memoryAddress, size);
|
||||
}
|
||||
else {
|
||||
if (s->decimationCounter == 0) {
|
||||
(void)traceBuffer.Push(s->internalID, timestamp, s->memoryAddress, size);
|
||||
s->decimationCounter = s->decimationFactor - 1;
|
||||
}
|
||||
else {
|
||||
s->decimationCounter--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DebugService::RegisterBroker(DebugSignalInfo** signalPointers, uint32 numSignals, MemoryMapBroker* broker, volatile bool* anyActiveFlag, Vector<uint32>* activeIndices, Vector<uint32>* activeSizes, FastPollingMutexSem* activeMutex) {
|
||||
mutex.FastLock();
|
||||
if (numberOfBrokers < MAX_BROKERS) {
|
||||
brokers[numberOfBrokers].signalPointers = signalPointers;
|
||||
brokers[numberOfBrokers].numSignals = numSignals;
|
||||
brokers[numberOfBrokers].broker = broker;
|
||||
brokers[numberOfBrokers].anyActiveFlag = anyActiveFlag;
|
||||
brokers[numberOfBrokers].activeIndices = activeIndices;
|
||||
brokers[numberOfBrokers].activeSizes = activeSizes;
|
||||
brokers[numberOfBrokers].activeMutex = activeMutex;
|
||||
numberOfBrokers++;
|
||||
}
|
||||
mutex.FastUnLock();
|
||||
}
|
||||
|
||||
void DebugService::UpdateBrokersActiveStatus() {
|
||||
// Already locked by caller (TraceSignal, ForceSignal, etc.)
|
||||
for (uint32 i = 0; i < numberOfBrokers; i++) {
|
||||
uint32 count = 0;
|
||||
for (uint32 j = 0; j < brokers[i].numSignals; j++) {
|
||||
DebugSignalInfo *s = brokers[i].signalPointers[j];
|
||||
if (s != NULL_PTR(DebugSignalInfo*) && (s->isTracing || s->isForcing)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
Vector<uint32> tempInd(count);
|
||||
Vector<uint32> tempSizes(count);
|
||||
uint32 idx = 0;
|
||||
for (uint32 j = 0; j < brokers[i].numSignals; j++) {
|
||||
DebugSignalInfo *s = brokers[i].signalPointers[j];
|
||||
if (s != NULL_PTR(DebugSignalInfo*) && (s->isTracing || s->isForcing)) {
|
||||
tempInd[idx] = j;
|
||||
tempSizes[idx] = (brokers[i].broker != NULL_PTR(MemoryMapBroker*)) ? brokers[i].broker->GetCopyByteSize(j) : 4;
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
|
||||
if (brokers[i].activeMutex) brokers[i].activeMutex->FastLock();
|
||||
|
||||
if (brokers[i].activeIndices) *(brokers[i].activeIndices) = tempInd;
|
||||
if (brokers[i].activeSizes) *(brokers[i].activeSizes) = tempSizes;
|
||||
if (brokers[i].anyActiveFlag) *(brokers[i].anyActiveFlag) = (count > 0);
|
||||
|
||||
if (brokers[i].activeMutex) brokers[i].activeMutex->FastUnLock();
|
||||
}
|
||||
}
|
||||
|
||||
DebugSignalInfo* DebugService::RegisterSignal(void* memoryAddress, TypeDescriptor type, const char8* name) {
|
||||
mutex.FastLock();
|
||||
DebugSignalInfo* res = NULL_PTR(DebugSignalInfo*);
|
||||
uint32 sigIdx = 0xFFFFFFFF;
|
||||
for(uint32 i=0; i<numberOfSignals; i++) {
|
||||
if(signals[i].memoryAddress == memoryAddress) {
|
||||
res = &signals[i];
|
||||
sigIdx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (res == NULL_PTR(DebugSignalInfo*) && numberOfSignals < MAX_SIGNALS) {
|
||||
sigIdx = numberOfSignals;
|
||||
res = &signals[numberOfSignals];
|
||||
res->memoryAddress = memoryAddress;
|
||||
res->type = type;
|
||||
res->name = name;
|
||||
res->isTracing = false;
|
||||
res->isForcing = false;
|
||||
res->internalID = numberOfSignals;
|
||||
res->decimationFactor = 1;
|
||||
res->decimationCounter = 0;
|
||||
numberOfSignals++;
|
||||
}
|
||||
if (sigIdx != 0xFFFFFFFF && numberOfAliases < MAX_ALIASES) {
|
||||
bool foundAlias = false;
|
||||
for (uint32 i=0; i<numberOfAliases; i++) {
|
||||
if (aliases[i].name == name) { foundAlias = true; break; }
|
||||
}
|
||||
if (!foundAlias) {
|
||||
aliases[numberOfAliases].name = name;
|
||||
aliases[numberOfAliases].signalIndex = sigIdx;
|
||||
numberOfAliases++;
|
||||
}
|
||||
}
|
||||
mutex.FastUnLock();
|
||||
return res;
|
||||
static bool SuffixMatch(const char8* target, const char8* pattern) {
|
||||
uint32 tLen = StringHelper::Length(target); uint32 pLen = StringHelper::Length(pattern);
|
||||
if (pLen > tLen) return false;
|
||||
const char8* suffix = target + (tLen - pLen);
|
||||
if (StringHelper::Compare(suffix, pattern) == 0) { if (tLen == pLen || *(suffix - 1) == '.') return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool RecursiveGetFullObjectName(ReferenceContainer *container, const Object &obj, StreamString &path) {
|
||||
@@ -276,6 +61,55 @@ bool DebugService::GetFullObjectName(const Object &obj, StreamString &fullPath)
|
||||
return false;
|
||||
}
|
||||
|
||||
CLASS_REGISTER(DebugService, "1.0")
|
||||
|
||||
DebugService* DebugService::Instance() {
|
||||
return GlobalDebugServiceInstance;
|
||||
}
|
||||
|
||||
void PatchItemInternal(const char8* className, ObjectBuilder* builder) {
|
||||
ClassRegistryDatabase *db = ClassRegistryDatabase::Instance();
|
||||
ClassRegistryItem *item = (ClassRegistryItem*)db->Find(className);
|
||||
if (item != NULL_PTR(ClassRegistryItem*)) {
|
||||
item->SetObjectBuilder(builder);
|
||||
}
|
||||
}
|
||||
|
||||
uint32 DebugService::ForceSignal(const char8* name, const char8* valueStr) {
|
||||
mutex.FastLock(); uint32 count = 0;
|
||||
for (uint32 i = 0; i < numberOfAliases; i++) {
|
||||
if (aliases[i].name == name || SuffixMatch(aliases[i].name.Buffer(), name)) {
|
||||
DebugSignalInfo &s = signals[aliases[i].signalIndex]; s.isForcing = true;
|
||||
AnyType dest(s.type, 0u, s.forcedValue); AnyType source(CharString, 0u, valueStr); (void)TypeConvert(dest, source);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
mutex.FastUnLock(); return count;
|
||||
}
|
||||
|
||||
uint32 DebugService::UnforceSignal(const char8* name) {
|
||||
mutex.FastLock(); uint32 count = 0;
|
||||
for (uint32 i = 0; i < numberOfAliases; i++) {
|
||||
if (aliases[i].name == name || SuffixMatch(aliases[i].name.Buffer(), name)) { signals[aliases[i].signalIndex].isForcing = false; count++; }
|
||||
}
|
||||
mutex.FastUnLock(); return count;
|
||||
}
|
||||
|
||||
uint32 DebugService::TraceSignal(const char8* name, bool enable, uint32 decimation) {
|
||||
mutex.FastLock(); uint32 count = 0;
|
||||
for (uint32 i = 0; i < numberOfAliases; i++) {
|
||||
if (aliases[i].name == name || SuffixMatch(aliases[i].name.Buffer(), name)) {
|
||||
uint32 sigIdx = aliases[i].signalIndex;
|
||||
DebugSignalInfo &s = signals[sigIdx];
|
||||
s.isTracing = enable;
|
||||
s.decimationFactor = decimation;
|
||||
s.decimationCounter = 0;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
mutex.FastUnLock(); return count;
|
||||
}
|
||||
|
||||
ErrorManagement::ErrorType DebugService::Execute(ExecutionInfo & info) {
|
||||
return ErrorManagement::FatalError;
|
||||
}
|
||||
@@ -284,10 +118,9 @@ ErrorManagement::ErrorType DebugService::Server(ExecutionInfo & info) {
|
||||
if (info.GetStage() == ExecutionInfo::TerminationStage) return ErrorManagement::NoError;
|
||||
if (info.GetStage() == ExecutionInfo::StartupStage) { serverThreadId = Threads::Id(); return ErrorManagement::NoError; }
|
||||
while (info.GetStage() == ExecutionInfo::MainStage) {
|
||||
BasicTCPSocket *newClient = tcpServer.WaitConnection(1);
|
||||
BasicTCPSocket *newClient = tcpServer.WaitConnection(10);
|
||||
if (newClient != NULL_PTR(BasicTCPSocket *)) {
|
||||
clientsMutex.FastLock();
|
||||
bool added = false;
|
||||
clientsMutex.FastLock(); bool added = false;
|
||||
for (uint32 i=0; i<MAX_CLIENTS; i++) { if (activeClients[i] == NULL_PTR(BasicTCPSocket*)) { activeClients[i] = newClient; added = true; break; } }
|
||||
clientsMutex.FastUnLock();
|
||||
if (!added) { newClient->Close(); delete newClient; }
|
||||
@@ -341,12 +174,222 @@ ErrorManagement::ErrorType DebugService::Streamer(ExecutionInfo & info) {
|
||||
return ErrorManagement::NoError;
|
||||
}
|
||||
|
||||
static bool SuffixMatch(const char8* target, const char8* pattern) {
|
||||
uint32 tLen = StringHelper::Length(target); uint32 pLen = StringHelper::Length(pattern);
|
||||
if (pLen > tLen) return false;
|
||||
const char8* suffix = target + (tLen - pLen);
|
||||
if (StringHelper::Compare(suffix, pattern) == 0) { if (tLen == pLen || *(suffix - 1) == '.') return true; }
|
||||
return false;
|
||||
DebugService::DebugService() :
|
||||
ReferenceContainer(), EmbeddedServiceMethodBinderI(),
|
||||
binderServer(this, ServiceBinder::ServerType),
|
||||
binderStreamer(this, ServiceBinder::StreamerType),
|
||||
threadService(binderServer),
|
||||
streamerService(binderStreamer)
|
||||
{
|
||||
GlobalDebugServiceInstance = this;
|
||||
controlPort = 0;
|
||||
streamPort = 8081;
|
||||
streamIP = "127.0.0.1";
|
||||
numberOfSignals = 0;
|
||||
numberOfAliases = 0;
|
||||
numberOfBrokers = 0;
|
||||
isServer = false;
|
||||
suppressTimeoutLogs = true;
|
||||
isPaused = false;
|
||||
for (uint32 i=0; i<MAX_CLIENTS; i++) {
|
||||
activeClients[i] = NULL_PTR(BasicTCPSocket*);
|
||||
}
|
||||
}
|
||||
|
||||
// Forced patching on library load
|
||||
__attribute__((constructor))
|
||||
static void GlobalDebugSuiteInit() {
|
||||
typedef DebugBrokerBuilder<DebugMemoryMapInputBroker> B1; PatchItemInternal("MemoryMapInputBroker", new B1());
|
||||
typedef DebugBrokerBuilder<DebugMemoryMapOutputBroker> B2; PatchItemInternal("MemoryMapOutputBroker", new B2());
|
||||
|
||||
typedef DebugBrokerBuilder<DebugMemoryMapSynchronisedInputBroker> B3; PatchItemInternal("MemoryMapSynchronisedInputBroker", new B3());
|
||||
typedef DebugBrokerBuilder<DebugMemoryMapSynchronisedOutputBroker> B4; PatchItemInternal("MemoryMapSynchronisedOutputBroker", new B4());
|
||||
|
||||
typedef DebugBrokerBuilder<DebugMemoryMapInterpolatedInputBroker> B5; PatchItemInternal("MemoryMapInterpolatedInputBroker", new B5());
|
||||
}
|
||||
|
||||
DebugService::~DebugService() {
|
||||
if (GlobalDebugServiceInstance == this) GlobalDebugServiceInstance = NULL_PTR(DebugService*);
|
||||
threadService.Stop(); streamerService.Stop();
|
||||
tcpServer.Close(); udpSocket.Close();
|
||||
for (uint32 i=0; i<MAX_CLIENTS; i++) {
|
||||
if (activeClients[i] != NULL_PTR(BasicTCPSocket*)) { activeClients[i]->Close(); delete activeClients[i]; }
|
||||
}
|
||||
for (uint32 i=0; i<numberOfBrokers; i++) {
|
||||
for (uint32 j=0; j<2; j++) {
|
||||
if (brokers[i].sets[j].forcedSignals) delete[] brokers[i].sets[j].forcedSignals;
|
||||
if (brokers[i].sets[j].tracedSignals) delete[] brokers[i].sets[j].tracedSignals;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool DebugService::Initialise(StructuredDataI & data) {
|
||||
if (!ReferenceContainer::Initialise(data)) return false;
|
||||
if (!data.Read("ControlPort", controlPort)) (void)data.Read("TcpPort", controlPort);
|
||||
if (controlPort > 0) { isServer = true; GlobalDebugServiceInstance = this; }
|
||||
if (!data.Read("StreamPort", streamPort)) (void)data.Read("UdpPort", streamPort);
|
||||
StreamString tempIP; if (data.Read("StreamIP", tempIP)) streamIP = tempIP; else streamIP = "127.0.0.1";
|
||||
uint32 suppress = 1; if (data.Read("SuppressTimeoutLogs", suppress)) suppressTimeoutLogs = (suppress == 1);
|
||||
|
||||
if (isServer) {
|
||||
if (!traceBuffer.Init(8 * 1024 * 1024)) return false;
|
||||
ConfigurationDatabase threadData; threadData.Write("Timeout", (uint32)1000);
|
||||
threadService.Initialise(threadData); streamerService.Initialise(threadData);
|
||||
if (!tcpServer.Open()) return false;
|
||||
if (!tcpServer.Listen(controlPort)) return false;
|
||||
printf("[DebugService] TCP Server listening on port %u\n", controlPort);
|
||||
if (!udpSocket.Open()) return false;
|
||||
printf("[DebugService] UDP Streamer socket opened\n");
|
||||
if (threadService.Start() != ErrorManagement::NoError) return false;
|
||||
if (streamerService.Start() != ErrorManagement::NoError) return false;
|
||||
printf("[DebugService] Worker threads started.\n");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void DebugService::PatchRegistry() {
|
||||
}
|
||||
|
||||
void DebugService::ProcessSignal(DebugSignalInfo* s, uint32 size, uint64 timestamp) {
|
||||
if (s == NULL_PTR(DebugSignalInfo*)) return;
|
||||
if (s->isForcing) CopySignal(s->memoryAddress, s->forcedValue, size);
|
||||
if (s->isTracing) {
|
||||
if (s->decimationFactor <= 1) (void)traceBuffer.Push(s->internalID, timestamp, s->memoryAddress, size);
|
||||
else {
|
||||
if (s->decimationCounter == 0) { (void)traceBuffer.Push(s->internalID, timestamp, s->memoryAddress, size); s->decimationCounter = s->decimationFactor - 1; }
|
||||
else s->decimationCounter--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DebugService::RegisterBroker(DebugSignalInfo** signalPointers, uint32 numSignals, MemoryMapBroker* broker, volatile bool* anyActiveFlag) {
|
||||
mutex.FastLock();
|
||||
for (uint32 i=0; i<numberOfBrokers; i++) { if (brokers[i].broker == broker) { mutex.FastUnLock(); return; } }
|
||||
if (numberOfBrokers < MAX_BROKERS) {
|
||||
printf("[DebugService] Registering Broker %u (%u signals, anyActiveFlag=%p)\n", numberOfBrokers, numSignals, (void*)anyActiveFlag);
|
||||
brokers[numberOfBrokers].signalPointers = signalPointers;
|
||||
brokers[numberOfBrokers].numSignals = numSignals;
|
||||
brokers[numberOfBrokers].broker = broker;
|
||||
brokers[numberOfBrokers].anyActiveFlag = anyActiveFlag;
|
||||
brokers[numberOfBrokers].currentSetIdx = 0;
|
||||
for (uint32 j=0; j<2; j++) {
|
||||
brokers[numberOfBrokers].sets[j].numForced = 0; brokers[numberOfBrokers].sets[j].numTraced = 0;
|
||||
brokers[numberOfBrokers].sets[j].forcedSignals = NULL_PTR(SignalExecuteInfo*); brokers[numberOfBrokers].sets[j].tracedSignals = NULL_PTR(SignalExecuteInfo*);
|
||||
}
|
||||
numberOfBrokers++;
|
||||
}
|
||||
mutex.FastUnLock();
|
||||
}
|
||||
|
||||
static void AdoptOrphans(ReferenceContainer *container, DebugService* service) {
|
||||
if (!container) return;
|
||||
for (uint32 i=0; i<container->Size(); i++) {
|
||||
Reference child = container->Get(i);
|
||||
if (child.IsValid()) {
|
||||
DebugBrokerI* b = dynamic_cast<DebugBrokerI*>(child.operator->());
|
||||
if (b && !b->IsLinked()) {
|
||||
b->SetService(service);
|
||||
}
|
||||
ReferenceContainer *inner = dynamic_cast<ReferenceContainer*>(child.operator->());
|
||||
if (inner) AdoptOrphans(inner, service);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DebugService::UpdateBrokersActiveStatus() {
|
||||
AdoptOrphans(ObjectRegistryDatabase::Instance(), this);
|
||||
for (uint32 i = 0; i < numberOfBrokers; i++) {
|
||||
uint32 nextIdx = (brokers[i].currentSetIdx + 1) % 2;
|
||||
BrokerActiveSet& nextSet = brokers[i].sets[nextIdx];
|
||||
uint32 forcedCount = 0; uint32 tracedCount = 0;
|
||||
for (uint32 j = 0; j < brokers[i].numSignals; j++) {
|
||||
DebugSignalInfo *s = brokers[i].signalPointers[j];
|
||||
if (s != NULL_PTR(DebugSignalInfo*)) {
|
||||
if (s->isForcing) forcedCount++;
|
||||
if (s->isTracing) tracedCount++;
|
||||
}
|
||||
}
|
||||
SignalExecuteInfo* newForced = (forcedCount > 0) ? new SignalExecuteInfo[forcedCount] : NULL_PTR(SignalExecuteInfo*);
|
||||
SignalExecuteInfo* newTraced = (tracedCount > 0) ? new SignalExecuteInfo[tracedCount] : NULL_PTR(SignalExecuteInfo*);
|
||||
uint32 fIdx = 0; uint32 tIdx = 0;
|
||||
for (uint32 j = 0; j < brokers[i].numSignals; j++) {
|
||||
DebugSignalInfo *s = brokers[i].signalPointers[j];
|
||||
if (s != NULL_PTR(DebugSignalInfo*)) {
|
||||
uint32 size = (brokers[i].broker != NULL_PTR(MemoryMapBroker*)) ? brokers[i].broker->GetCopyByteSize(j) : 4;
|
||||
if (s->isForcing) { newForced[fIdx].memoryAddress = s->memoryAddress; newForced[fIdx].forcedValue = s->forcedValue; newForced[fIdx].size = size; fIdx++; }
|
||||
if (s->isTracing) { newTraced[tIdx].memoryAddress = s->memoryAddress; newTraced[tIdx].internalID = s->internalID; newTraced[tIdx].size = size; tIdx++; }
|
||||
}
|
||||
}
|
||||
SignalExecuteInfo* oldForced = nextSet.forcedSignals; SignalExecuteInfo* oldTraced = nextSet.tracedSignals;
|
||||
nextSet.forcedSignals = newForced; nextSet.tracedSignals = newTraced; nextSet.numForced = forcedCount; nextSet.numTraced = tracedCount;
|
||||
Atomic::Exchange((int32*)&brokers[i].currentSetIdx, (int32)nextIdx);
|
||||
if (brokers[i].anyActiveFlag) *(brokers[i].anyActiveFlag) = (forcedCount > 0 || tracedCount > 0);
|
||||
if (oldForced) delete[] oldForced; if (oldTraced) delete[] oldTraced;
|
||||
}
|
||||
}
|
||||
|
||||
DebugSignalInfo* DebugService::RegisterSignal(void* memoryAddress, TypeDescriptor type, const char8* name) {
|
||||
mutex.FastLock();
|
||||
DebugSignalInfo* res = NULL_PTR(DebugSignalInfo*); uint32 sigIdx = 0xFFFFFFFF;
|
||||
for (uint32 i=0; i<numberOfAliases; i++) {
|
||||
if (aliases[i].name == name) {
|
||||
sigIdx = aliases[i].signalIndex; res = &signals[sigIdx];
|
||||
if (res->memoryAddress == NULL && memoryAddress != NULL) res->memoryAddress = memoryAddress;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (res == NULL_PTR(DebugSignalInfo*) && numberOfSignals < MAX_SIGNALS) {
|
||||
sigIdx = numberOfSignals; res = &signals[numberOfSignals];
|
||||
res->memoryAddress = memoryAddress; res->type = type; res->name = name;
|
||||
res->isTracing = false; res->isForcing = false; res->internalID = numberOfSignals;
|
||||
res->decimationFactor = 1; res->decimationCounter = 0; numberOfSignals++;
|
||||
}
|
||||
if (sigIdx != 0xFFFFFFFF && numberOfAliases < MAX_ALIASES) {
|
||||
bool foundAlias = false;
|
||||
for (uint32 i=0; i<numberOfAliases; i++) { if (aliases[i].name == name) { foundAlias = true; break; } }
|
||||
if (!foundAlias) { aliases[numberOfAliases].name = name; aliases[numberOfAliases].signalIndex = sigIdx; numberOfAliases++; }
|
||||
}
|
||||
mutex.FastUnLock(); return res;
|
||||
}
|
||||
|
||||
static void RecursivePopulate(ReferenceContainer *container, DebugService* service) {
|
||||
if (!container) return;
|
||||
for (uint32 i=0; i<container->Size(); i++) {
|
||||
Reference child = container->Get(i);
|
||||
if (child.IsValid()) {
|
||||
DataSourceI *ds = dynamic_cast<DataSourceI*>(child.operator->());
|
||||
if (ds) {
|
||||
StreamString dsPath;
|
||||
if (DebugService::GetFullObjectName(*ds, dsPath)) {
|
||||
for (uint32 j=0; j<ds->GetNumberOfSignals(); j++) {
|
||||
StreamString sname; (void)ds->GetSignalName(j, sname);
|
||||
StreamString fullName = dsPath; fullName += "."; fullName += sname;
|
||||
service->RegisterSignal(NULL, ds->GetSignalType(j), fullName.Buffer());
|
||||
}
|
||||
}
|
||||
}
|
||||
ReferenceContainer *inner = dynamic_cast<ReferenceContainer*>(child.operator->());
|
||||
if (inner) RecursivePopulate(inner, service);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DebugService::Discover(BasicTCPSocket *client) {
|
||||
if (client) {
|
||||
RecursivePopulate(ObjectRegistryDatabase::Instance(), this);
|
||||
StreamString json; json = "{\n \"Signals\": [\n";
|
||||
mutex.FastLock();
|
||||
for (uint32 i = 0; i < numberOfAliases; i++) {
|
||||
DebugSignalInfo &sig = signals[aliases[i].signalIndex];
|
||||
const char8* typeName = TypeDescriptor::GetTypeNameFromTypeDescriptor(sig.type);
|
||||
StreamString line;
|
||||
line.Printf(" {\"name\": \"%s\", \"id\": %u, \"type\": \"%s\", \"ready\": %s}",
|
||||
aliases[i].name.Buffer(), sig.internalID, typeName ? typeName : "Unknown", (sig.memoryAddress != NULL) ? "true" : "false");
|
||||
json += line; if (i < numberOfAliases - 1) json += ","; json += "\n";
|
||||
}
|
||||
mutex.FastUnLock();
|
||||
json += " ]\n}\nOK DISCOVER\n"; uint32 s = json.Size(); (void)client->Write(json.Buffer(), s);
|
||||
}
|
||||
}
|
||||
|
||||
void DebugService::HandleCommand(StreamString cmd, BasicTCPSocket *client) {
|
||||
@@ -388,6 +431,7 @@ void DebugService::HandleCommand(StreamString cmd, BasicTCPSocket *client) {
|
||||
else if (token == "LS") {
|
||||
StreamString path; if (cmd.GetToken(path, delims, term)) ListNodes(path.Buffer(), client); else ListNodes(NULL_PTR(const char8*), client);
|
||||
}
|
||||
UpdateBrokersActiveStatus();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -471,65 +515,4 @@ uint32 DebugService::ExportTree(ReferenceContainer *container, StreamString &jso
|
||||
return validCount;
|
||||
}
|
||||
|
||||
uint32 DebugService::ForceSignal(const char8* name, const char8* valueStr) {
|
||||
mutex.FastLock(); uint32 count = 0;
|
||||
for (uint32 i = 0; i < numberOfAliases; i++) {
|
||||
if (aliases[i].name == name || SuffixMatch(aliases[i].name.Buffer(), name)) {
|
||||
DebugSignalInfo &s = signals[aliases[i].signalIndex]; s.isForcing = true;
|
||||
AnyType dest(s.type, 0u, s.forcedValue); AnyType source(CharString, 0u, valueStr); (void)TypeConvert(dest, source);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
UpdateBrokersActiveStatus();
|
||||
mutex.FastUnLock(); return count;
|
||||
}
|
||||
|
||||
uint32 DebugService::UnforceSignal(const char8* name) {
|
||||
mutex.FastLock(); uint32 count = 0;
|
||||
for (uint32 i = 0; i < numberOfAliases; i++) {
|
||||
if (aliases[i].name == name || SuffixMatch(aliases[i].name.Buffer(), name)) { signals[aliases[i].signalIndex].isForcing = false; count++; }
|
||||
}
|
||||
UpdateBrokersActiveStatus();
|
||||
mutex.FastUnLock(); return count;
|
||||
}
|
||||
|
||||
uint32 DebugService::TraceSignal(const char8* name, bool enable, uint32 decimation) {
|
||||
mutex.FastLock(); uint32 count = 0;
|
||||
for (uint32 i = 0; i < numberOfAliases; i++) {
|
||||
if (aliases[i].name == name || SuffixMatch(aliases[i].name.Buffer(), name)) {
|
||||
DebugSignalInfo &s = signals[aliases[i].signalIndex]; s.isTracing = enable; s.decimationFactor = decimation; s.decimationCounter = 0; count++;
|
||||
printf("[Debug] Tracing state for %s (ID: %u) set to %d\n", aliases[i].name.Buffer(), s.internalID, enable);
|
||||
}
|
||||
}
|
||||
UpdateBrokersActiveStatus();
|
||||
mutex.FastUnLock(); return count;
|
||||
}
|
||||
|
||||
void DebugService::Discover(BasicTCPSocket *client) {
|
||||
if (client) {
|
||||
StreamString header = "{\n \"Signals\": [\n"; uint32 s = header.Size(); (void)client->Write(header.Buffer(), s);
|
||||
mutex.FastLock();
|
||||
for (uint32 i = 0; i < numberOfAliases; i++) {
|
||||
StreamString line; DebugSignalInfo &sig = signals[aliases[i].signalIndex];
|
||||
const char8* typeName = TypeDescriptor::GetTypeNameFromTypeDescriptor(sig.type);
|
||||
line.Printf(" {\"name\": \"%s\", \"id\": %d, \"type\": \"%s\"}", aliases[i].name.Buffer(), sig.internalID, typeName ? typeName : "Unknown");
|
||||
if (i < numberOfAliases - 1) line += ",";
|
||||
line += "\n"; s = line.Size(); (void)client->Write(line.Buffer(), s);
|
||||
}
|
||||
mutex.FastUnLock();
|
||||
StreamString footer = " ]\n}\nOK DISCOVER\n"; s = footer.Size(); (void)client->Write(footer.Buffer(), s);
|
||||
}
|
||||
}
|
||||
|
||||
void DebugService::ListNodes(const char8* path, BasicTCPSocket *client) {
|
||||
if (!client) return;
|
||||
Reference ref = (path == NULL_PTR(const char8*) || StringHelper::Length(path) == 0 || StringHelper::Compare(path, "/") == 0) ? ObjectRegistryDatabase::Instance() : ObjectRegistryDatabase::Instance()->Find(path);
|
||||
if (ref.IsValid()) {
|
||||
StreamString out; out.Printf("Nodes under %s:\n", path ? path : "/");
|
||||
ReferenceContainer *container = dynamic_cast<ReferenceContainer*>(ref.operator->());
|
||||
if (container) { for (uint32 i=0; i<container->Size(); i++) { Reference child = container->Get(i); if (child.IsValid()) out.Printf(" %s [%s]\n", child->GetName(), child->GetClassProperties()->GetName()); } }
|
||||
const char* okMsg = "OK LS\n"; out += okMsg; uint32 s = out.Size(); (void)client->Write(out.Buffer(), s);
|
||||
} else { const char* msg = "ERROR: Path not found\n"; uint32 s = StringHelper::Length(msg); (void)client->Write(msg, s); }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user