#ifndef DEBUGBROKERWRAPPER_H #define DEBUGBROKERWRAPPER_H #include "DebugService.h" #include "BrokerI.h" #include "MemoryMapBroker.h" #include "ObjectRegistryDatabase.h" #include "ObjectBuilder.h" #include "Vector.h" #include "FastPollingMutexSem.h" #include "HighResolutionTimer.h" #include "Atomic.h" // Original broker headers #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" namespace MARTe { /** * @brief Helper for optimized signal processing within brokers. */ class DebugBrokerHelper { public: static void Process(DebugService* service, BrokerInfo& info) { if (service == NULL_PTR(DebugService*)) return; while (service->IsPaused()) { Sleep::MSec(10); } if (*info.anyActiveFlag) { uint32 idx = info.currentSetIdx; BrokerActiveSet& set = info.sets[idx]; uint64 ts = (uint64)((float64)HighResolutionTimer::Counter() * HighResolutionTimer::Period() * 1000000.0); for (uint32 i = 0; i < set.numForced; i++) { SignalExecuteInfo& s = set.forcedSignals[i]; DebugService::CopySignal(s.memoryAddress, s.forcedValue, s.size); } for (uint32 i = 0; i < set.numTraced; i++) { SignalExecuteInfo& s = set.tracedSignals[i]; (void)service->traceBuffer.Push(s.internalID, ts, s.memoryAddress, s.size); } } } static void InitSignals(BrokerI* broker, DataSourceI &dataSourceIn, DebugService* &service, DebugSignalInfo** &signalInfoPointers, uint32 numCopies, MemoryMapBrokerCopyTableEntry* copyTable, const char8* functionName, SignalDirection direction, volatile bool* anyActiveFlag) { if (numCopies > 0) { signalInfoPointers = new DebugSignalInfo*[numCopies]; for (uint32 i=0; i(broker); for (uint32 i = 0; i < numCopies; i++) { void *addr = copyTable[i].dataSourcePointer; TypeDescriptor type = copyTable[i].type; uint32 dsIdx = i; if (mmb != NULL_PTR(MemoryMapBroker*)) dsIdx = mmb->GetDSCopySignalIndex(i); StreamString signalName; if (!dataSourceIn.GetSignalName(dsIdx, signalName)) { signalName.Printf("Signal_%u", dsIdx); } StreamString dsFullName = dsPath; if (dsFullName.Size() > 0) dsFullName += "."; dsFullName += signalName; service->RegisterSignal(addr, type, dsFullName.Buffer()); if (functionName != NULL_PTR(const char8*)) { StreamString gamFullName; const char8* dirStr = (direction == InputSignals) ? "In" : "Out"; Reference gamRef = ObjectRegistryDatabase::Instance()->Find(functionName); if (gamRef.IsValid()) { StreamString absGamPath; DebugService::GetFullObjectName(*(gamRef.operator->()), absGamPath); gamFullName = absGamPath; } else { gamFullName = functionName; } gamFullName += "."; gamFullName += dirStr; gamFullName += "."; gamFullName += signalName; signalInfoPointers[i] = service->RegisterSignal(addr, type, gamFullName.Buffer()); } else { signalInfoPointers[i] = service->RegisterSignal(addr, type, dsFullName.Buffer()); } } service->RegisterBroker(signalInfoPointers, numCopies, mmb, anyActiveFlag); } } }; class DebugMemoryMapInputBroker : public MemoryMapInputBroker, public DebugBrokerI { public: DebugMemoryMapInputBroker() : MemoryMapInputBroker(), service(NULL), infoPtr(NULL), anyActive(false) { (void)ObjectRegistryDatabase::Instance()->Insert(Reference(this)); } virtual void SetService(DebugService* s) { service = s; } virtual bool IsLinked() const { return infoPtr != NULL; } virtual bool Execute() { bool ret = MemoryMapInputBroker::Execute(); if (ret && infoPtr) DebugBrokerHelper::Process(service, *infoPtr); return ret; } virtual bool Init(SignalDirection direction, DataSourceI &ds, const char8 *const name, void *gamMem) { bool ret = MemoryMapInputBroker::Init(direction, ds, name, gamMem); if (ret) { DebugSignalInfo** sigPtrs = NULL; DebugBrokerHelper::InitSignals(this, ds, service, sigPtrs, GetNumberOfCopies(), this->copyTable, name, direction, &anyActive); if (service) infoPtr = service->GetBrokerInfo(service->numberOfBrokers - 1); } return ret; } DebugService* service; BrokerInfo* infoPtr; volatile bool anyActive; }; template class DebugGenericBroker : public T, public DebugBrokerI { public: DebugGenericBroker() : T(), service(NULL), infoPtr(NULL), anyActive(false) { (void)ObjectRegistryDatabase::Instance()->Insert(Reference(this)); } virtual void SetService(DebugService* s) { service = s; } virtual bool IsLinked() const { return infoPtr != NULL; } virtual bool Execute() { bool ret = T::Execute(); if (ret && infoPtr) DebugBrokerHelper::Process(service, *infoPtr); return ret; } virtual bool Init(SignalDirection direction, DataSourceI &ds, const char8 *const name, void *gamMem) { bool ret = T::Init(direction, ds, name, gamMem); if (ret) { DebugSignalInfo** sigPtrs = NULL; DebugBrokerHelper::InitSignals(this, ds, service, sigPtrs, this->GetNumberOfCopies(), this->copyTable, name, direction, &anyActive); if (service) infoPtr = service->GetBrokerInfo(service->numberOfBrokers - 1); } return ret; } DebugService* service; BrokerInfo* infoPtr; volatile bool anyActive; }; class DebugMemoryMapAsyncOutputBroker : public MemoryMapAsyncOutputBroker, public DebugBrokerI { public: DebugMemoryMapAsyncOutputBroker() : MemoryMapAsyncOutputBroker(), service(NULL), infoPtr(NULL), anyActive(false) { (void)ObjectRegistryDatabase::Instance()->Insert(Reference(this)); } virtual void SetService(DebugService* s) { service = s; } virtual bool IsLinked() const { return infoPtr != NULL; } virtual bool Execute() { bool ret = MemoryMapAsyncOutputBroker::Execute(); if (ret && infoPtr) DebugBrokerHelper::Process(service, *infoPtr); return ret; } virtual bool InitWithBufferParameters(const SignalDirection d, DataSourceI &ds, const char8* n, void* m, const uint32 nb, const ProcessorType& c, const uint32 s) { bool ret = MemoryMapAsyncOutputBroker::InitWithBufferParameters(d, ds, n, m, nb, c, s); if (ret) { DebugSignalInfo** sigPtrs = NULL; DebugBrokerHelper::InitSignals(this, ds, service, sigPtrs, this->GetNumberOfCopies(), this->copyTable, n, d, &anyActive); if (service) infoPtr = service->GetBrokerInfo(service->numberOfBrokers - 1); } return ret; } DebugService* service; BrokerInfo* infoPtr; volatile bool anyActive; }; class DebugMemoryMapAsyncTriggerOutputBroker : public MemoryMapAsyncTriggerOutputBroker, public DebugBrokerI { public: DebugMemoryMapAsyncTriggerOutputBroker() : MemoryMapAsyncTriggerOutputBroker(), service(NULL), infoPtr(NULL), anyActive(false) { (void)ObjectRegistryDatabase::Instance()->Insert(Reference(this)); } virtual void SetService(DebugService* s) { service = s; } virtual bool IsLinked() const { return infoPtr != NULL; } virtual bool Execute() { bool ret = MemoryMapAsyncTriggerOutputBroker::Execute(); if (ret && infoPtr) DebugBrokerHelper::Process(service, *infoPtr); return ret; } virtual bool InitWithTriggerParameters(const SignalDirection d, DataSourceI &ds, const char8* n, void* m, const uint32 nb, const uint32 pre, const uint32 post, const ProcessorType& c, const uint32 s) { bool ret = MemoryMapAsyncTriggerOutputBroker::InitWithTriggerParameters(d, ds, n, m, nb, pre, post, c, s); if (ret) { DebugSignalInfo** sigPtrs = NULL; DebugBrokerHelper::InitSignals(this, ds, service, sigPtrs, this->GetNumberOfCopies(), this->copyTable, n, d, &anyActive); if (service) infoPtr = service->GetBrokerInfo(service->numberOfBrokers - 1); } return ret; } DebugService* service; BrokerInfo* infoPtr; volatile bool anyActive; }; typedef DebugGenericBroker DebugMemoryMapOutputBroker; typedef DebugGenericBroker DebugMemoryMapSynchronisedInputBroker; typedef DebugGenericBroker DebugMemoryMapSynchronisedOutputBroker; typedef DebugGenericBroker DebugMemoryMapInterpolatedInputBroker; typedef DebugGenericBroker DebugMemoryMapMultiBufferInputBroker; typedef DebugGenericBroker DebugMemoryMapMultiBufferOutputBroker; typedef DebugGenericBroker DebugMemoryMapSynchronisedMultiBufferInputBroker; typedef DebugGenericBroker DebugMemoryMapSynchronisedMultiBufferOutputBroker; template class DebugBrokerBuilder : public ObjectBuilder { public: virtual Object *Build(HeapI* const heap) const { return new (heap) T(); } }; typedef DebugBrokerBuilder DebugMemoryMapInputBrokerBuilder; typedef DebugBrokerBuilder DebugMemoryMapOutputBrokerBuilder; typedef DebugBrokerBuilder DebugMemoryMapSynchronisedInputBrokerBuilder; typedef DebugBrokerBuilder DebugMemoryMapSynchronisedOutputBrokerBuilder; typedef DebugBrokerBuilder DebugMemoryMapInterpolatedInputBrokerBuilder; typedef DebugBrokerBuilder DebugMemoryMapMultiBufferInputBrokerBuilder; typedef DebugBrokerBuilder DebugMemoryMapMultiBufferOutputBrokerBuilder; typedef DebugBrokerBuilder DebugMemoryMapSynchronisedMultiBufferInputBrokerBuilder; typedef DebugBrokerBuilder DebugMemoryMapSynchronisedMultiBufferOutputBrokerBuilder; typedef DebugBrokerBuilder DebugMemoryMapAsyncOutputBrokerBuilder; typedef DebugBrokerBuilder DebugMemoryMapAsyncTriggerOutputBrokerBuilder; } #endif