From c2fa8cdeb793bc04ae9f839cdb1baf5ad7be25a9 Mon Sep 17 00:00:00 2001 From: Daniel Knorreck <daniel.knorreck@telecom-paristech.fr> Date: Mon, 18 May 2009 11:51:52 +0000 Subject: [PATCH] Parameter storage improved --- simulators/c++2/src_simulator/Parameter.h | 45 ++++++++++++------- .../c++2/src_simulator/SchedulableDevice.h | 1 + .../c++2/src_simulator/SimComponents.cpp | 3 ++ simulators/c++2/src_simulator/TMLChannel.cpp | 4 +- simulators/c++2/src_simulator/TMLCommand.cpp | 14 ++++-- simulators/c++2/src_simulator/TMLCommand.h | 10 ++--- .../c++2/src_simulator/TMLEventBChannel.cpp | 43 ++++++++++-------- .../c++2/src_simulator/TMLEventChannel.cpp | 23 +++++----- .../c++2/src_simulator/TMLEventFBChannel.cpp | 17 +++---- .../c++2/src_simulator/TMLEventFChannel.cpp | 17 +++---- .../c++2/src_simulator/TMLRequestCommand.cpp | 2 +- .../c++2/src_simulator/TMLRequestCommand.h | 2 +- .../c++2/src_simulator/TMLSelectCommand.cpp | 15 ++++--- .../c++2/src_simulator/TMLSelectCommand.h | 11 ++--- .../c++2/src_simulator/TMLSendCommand.cpp | 2 +- .../c++2/src_simulator/TMLSendCommand.h | 4 +- .../c++2/src_simulator/TMLStateChannel.cpp | 1 + simulators/c++2/src_simulator/TMLTask.cpp | 19 ++++++-- .../c++2/src_simulator/TMLWaitCommand.cpp | 4 +- .../c++2/src_simulator/TMLWaitCommand.h | 4 +- simulators/c++2/src_simulator/definitions.h | 9 ++-- 21 files changed, 146 insertions(+), 104 deletions(-) diff --git a/simulators/c++2/src_simulator/Parameter.h b/simulators/c++2/src_simulator/Parameter.h index 8e48b8cf9c..82d904ad50 100644 --- a/simulators/c++2/src_simulator/Parameter.h +++ b/simulators/c++2/src_simulator/Parameter.h @@ -41,7 +41,7 @@ Ludovic Apvrille, Renaud Pacalet #ifndef ParameterH #define ParameterH -#include <RefValUnion.h> +#include <definitions.h> ///This class encapsulates three parameters template <typename T> class Parameter{ @@ -52,27 +52,33 @@ public: \param ip2 Value 2 \param ip3 Value 3 */ - Parameter(const RefValUnion<T>& ip1,const RefValUnion<T>& ip2,const RefValUnion<T>& ip3):_p1(ip1),_p2(ip2),_p3(ip3){} - Parameter(std::istream& s, unsigned int iAdr):_p1(s,iAdr), _p2(s,iAdr), _p3(s,iAdr){} - ///Assignement operator, copies all parameters - const Parameter<T>& operator=(const Parameter<T>& rhs){ - _p1()=rhs._p1(); - _p2()=rhs._p2(); - _p3()=rhs._p3(); - return *this; + Parameter(const T& ip1,const T& ip2,const T& ip3):_p1(ip1),_p2(ip2),_p3(ip3){} + Parameter():_p1(0),_p2(0),_p3(0){} + Parameter(std::istream& s){ + READ_STREAM(s, _p1); + READ_STREAM(s, _p2); + READ_STREAM(s, _p3); } + /////Assignement operator, copies all parameters + /*const Parameter<T>& operator=(const Parameter<T>& rhs){ + _p1=rhs._p1; + _p2=rhs._p2; + _p3=rhs._p3; + return *this; + }*/ ///Print function for testing purposes void print() const{ - std::cout << "p1:" << _p1.print() << " p2:" << _p2.print() << " p3:" << _p3.print() << std::endl; + //if (_p1!=0 || _p2!=0 || _p3!=0) + std::cout << "p1:" << _p1 << " p2:" << _p2 << " p3:" << _p3 << std::endl; } - inline std::ostream& writeObject(std::ostream& s, unsigned int iAdr){ - _p1.writeObject(s,iAdr); - _p2.writeObject(s,iAdr); - _p3.writeObject(s,iAdr); + inline std::ostream& writeObject(std::ostream& s){ + WRITE_STREAM(s, _p1); + WRITE_STREAM(s, _p2); + WRITE_STREAM(s, _p3); return s; } friend std::istream& operator >>(std::istream &is,Parameter<T> &obj){ - is >>obj._p1 >> obj._p2 >> obj._p3; + is >> obj._p1 >> obj._p2 >> obj._p3; return is; } //inline static void * operator new(size_t size){ @@ -81,9 +87,16 @@ public: //inline static void operator delete(void *p, size_t size){ // memPool.pfree(p, size); //} + inline T getP1(){ return _p1;} + inline T getP2(){ return _p2;} + inline T getP3(){ return _p3;} + inline void setP1(T iP1){ _p1=iP1;} + inline void setP2(T iP2){ _p2=iP2;} + inline void setP3(T iP3){ _p3=iP3;} private: + ///Three parameters - RefValUnion<T> _p1,_p2,_p3; + T _p1,_p2,_p3; //static Pool<Parameter<T> > memPool; }; #endif diff --git a/simulators/c++2/src_simulator/SchedulableDevice.h b/simulators/c++2/src_simulator/SchedulableDevice.h index e93e027919..8e2e207eeb 100644 --- a/simulators/c++2/src_simulator/SchedulableDevice.h +++ b/simulators/c++2/src_simulator/SchedulableDevice.h @@ -90,6 +90,7 @@ public: virtual void schedule2TXT(std::ofstream& myfile) const =0; virtual std::string toString() const =0; virtual std::istream& readObject(std::istream &is){ + std::cout << "Read Object Schedulable Device " << _name << std::endl; READ_STREAM(is,_endSchedule); return is; } diff --git a/simulators/c++2/src_simulator/SimComponents.cpp b/simulators/c++2/src_simulator/SimComponents.cpp index 17d486426d..d56ae722c5 100644 --- a/simulators/c++2/src_simulator/SimComponents.cpp +++ b/simulators/c++2/src_simulator/SimComponents.cpp @@ -119,10 +119,13 @@ std::ostream& SimComponents::writeObject(std::ostream& s){ } std::istream& SimComponents::readObject(std::istream& s){ + std::cout << "Read Object SimComponents" << std::endl; for(SerializableList::const_iterator i=_serList.begin(); i != _serList.end(); ++i){ + std::cout << "SimComponents --> next Device" << std::endl; (*i)->readObject(s); } return s; + std::cout << "End Read Object SimComponents" << std::endl; } void SimComponents::reset(){ diff --git a/simulators/c++2/src_simulator/TMLChannel.cpp b/simulators/c++2/src_simulator/TMLChannel.cpp index c5b10dafe7..42d965d6f8 100644 --- a/simulators/c++2/src_simulator/TMLChannel.cpp +++ b/simulators/c++2/src_simulator/TMLChannel.cpp @@ -130,8 +130,8 @@ std::istream& TMLChannel::readObject(std::istream& s){ void TMLChannel::reset(){ //std::cout << "Channel reset" << std::endl; - _readTask=0; - _writeTask=0; + //_readTask=0; + //_writeTask=0; _writeTrans=0; _readTrans=0; _writeTransCurrHop=0; diff --git a/simulators/c++2/src_simulator/TMLCommand.cpp b/simulators/c++2/src_simulator/TMLCommand.cpp index c03a855ff6..0f0eb2bba1 100644 --- a/simulators/c++2/src_simulator/TMLCommand.cpp +++ b/simulators/c++2/src_simulator/TMLCommand.cpp @@ -45,7 +45,7 @@ Ludovic Apvrille, Renaud Pacalet #include <CommandListener.h> #include <Parameter.h> -TMLCommand::TMLCommand(unsigned int iID, TMLTask* iTask, TMLLength iLength, Parameter<ParamType>* iParam): _ID(iID), _length(iLength), _progress(0), _currTransaction(0), _task(iTask), _nextCommand(0), _param(iParam), _breakpoint(0){ +TMLCommand::TMLCommand(unsigned int iID, TMLTask* iTask, TMLLength iLength, ParamFuncPointer iParamFunc): _ID(iID), _length(iLength), _progress(0), _currTransaction(0), _task(iTask), _nextCommand(0), _paramFunc(iParamFunc), _breakpoint(0){ _instanceList.push_back(this); _task->addCommand(iID, this); } @@ -54,7 +54,7 @@ TMLCommand::~TMLCommand(){ if (_currTransaction!=0) delete _currTransaction; //if (_currTransaction!=0) std::cout << "transaction not yet deleted: " << getCommandStr() << std::endl; if (_nextCommand!=0) delete[] _nextCommand; - if (_param!=0) delete _param; + //if (_param!=0) delete _param; _instanceList.remove(this); removeBreakpoint(); } @@ -133,10 +133,14 @@ bool TMLCommand::channelUnknown() const{ return false; } -Parameter<ParamType>* TMLCommand::getParam() const{ - return _param; +ParamFuncPointer TMLCommand::getParamFuncPointer() const{ + return _paramFunc; } +//Parameter<ParamType>* TMLCommand::getParam() const{ +// return _param; +//} + #ifdef ADD_COMMENTS std::string TMLCommand::getCommentString(Comment* iCom) const{ return "no comment available"; @@ -163,7 +167,9 @@ std::ostream& TMLCommand::writeObject(std::ostream& s){ } std::istream& TMLCommand::readObject(std::istream& s){ + std::cout << "Read Object TMLCommand " << _ID << std::endl; READ_STREAM(s,_progress); + std::cout << "End Read Object TMLCommand " << _ID << std::endl; return s; } diff --git a/simulators/c++2/src_simulator/TMLCommand.h b/simulators/c++2/src_simulator/TMLCommand.h index dd0a279ad7..198e15c621 100644 --- a/simulators/c++2/src_simulator/TMLCommand.h +++ b/simulators/c++2/src_simulator/TMLCommand.h @@ -59,9 +59,9 @@ public: \param iID ID of the command \param iTask Pointer to the task the command belongs to \param iLength Virtual length of the command - \param iParam Pointer to a parameter data structure + \param iParam Pointer to a parameter function */ - TMLCommand(unsigned int iID, TMLTask* iTask, TMLLength iLength,Parameter<ParamType>* iParam); + TMLCommand(unsigned int iID, TMLTask* iTask, TMLLength iLength, ParamFuncPointer iParamFunc); ///Destructor virtual ~TMLCommand(); ///Initializes the command and passes the control flow to the prepare() method of the next command if necessary @@ -108,7 +108,7 @@ public: /** \return Pointer to parameter data structure */ - virtual Parameter<ParamType>* getParam() const; + virtual ParamFuncPointer getParamFuncPointer() const; ///Returns a string representation of the command /** \return Detailed string representation @@ -170,8 +170,8 @@ protected: TMLTask* _task; ///Pointer to an array of pointers to the next commands TMLCommand** _nextCommand; - ///Pointer to the parameters of the command - Parameter<ParamType>* _param; + ///Pointer to the parameter function of the command + ParamFuncPointer _paramFunc; ///Breakpoint CommandListener* _breakpoint; ///Determines the next command based on the _nextCommand array diff --git a/simulators/c++2/src_simulator/TMLEventBChannel.cpp b/simulators/c++2/src_simulator/TMLEventBChannel.cpp index da176b892f..8c6e934d24 100644 --- a/simulators/c++2/src_simulator/TMLEventBChannel.cpp +++ b/simulators/c++2/src_simulator/TMLEventBChannel.cpp @@ -62,12 +62,11 @@ void TMLEventBChannel::readNextEvents(){ //std::cout << "vv" << std::endl; if (_eventFile->is_open()){ int i=0; - Parameter<ParamType>* aNewParam; + Parameter<ParamType> aNewParam; //NEW while (++i<NO_EVENTS_TO_LOAD && !_eventFile->eof()){ - //while (++i<2 && !_eventFile->eof()){ _content++; - aNewParam = new Parameter<ParamType>(0,0,0); - *_eventFile >> *aNewParam; + (*_eventFile) >> aNewParam; //NEW + //aNewParam.readTxtStream(*_eventFile); _paramQueue.push_back(aNewParam); } }else @@ -76,7 +75,11 @@ void TMLEventBChannel::readNextEvents(){ void TMLEventBChannel::testWrite(TMLTransaction* iTrans){ _writeTrans=iTrans; - _tmpParam=(iTrans->getCommand()->getParam()==0)? Parameter<ParamType>(0,0,0): *(iTrans->getCommand()->getParam()); //added!!! + if (iTrans->getCommand()->getParamFuncPointer()!=0){ + (_writeTask->*(iTrans->getCommand()->getParamFuncPointer()))(_tmpParam); //NEW + //std::cout << "written: "; + //_tmpParam.print(); + } _writeTrans->setVirtualLength(WAIT_SEND_VLEN); } @@ -92,8 +95,7 @@ void TMLEventBChannel::write(){ void TMLEventBChannel::write(TMLTransaction* iTrans){ _content++; - //_paramQueue.push_back(iTrans->getCommand()->getParam()); - _paramQueue.push_back(new Parameter<ParamType>(_tmpParam)); //modified!!! + _paramQueue.push_back(_tmpParam); //NEW if (_readTrans!=0 && _readTrans->getVirtualLength()==0){ _readTrans->setRunnableTime(iTrans->getEndTime()); _readTrans->setVirtualLength(WAIT_SEND_VLEN); @@ -102,19 +104,21 @@ void TMLEventBChannel::write(TMLTransaction* iTrans){ } bool TMLEventBChannel::read(){ - Parameter<ParamType> *pRead,*pWrite; if (_content<1){ return false; }else{ _content--; if (_content==0 && _sourceIsFile) readNextEvents(); - pRead=_readTrans->getCommand()->getParam(); - pWrite=_paramQueue.front(); - if (pWrite!=0){ //modified!!! - if (pRead!=0) *pRead=*pWrite; - delete pWrite; - } - _paramQueue.pop_front(); + //std::cout << "read next" << std::endl; + //if (_writeTrans->getCommand()->getParamFuncPointer()!=0){ //NEW + //std::cout << "in if" << std::endl; + if (_readTrans->getCommand()->getParamFuncPointer()!=0) (_readTask->*(_readTrans->getCommand()->getParamFuncPointer()))(_paramQueue.front()); //NEW + //std::cout << "read: "; + //_paramQueue.front().print(); + //std::cout << "after 2nd if" << std::endl; + _paramQueue.pop_front(); //NEW + //} + //std::cout << "after if" << std::endl; FOR_EACH_TRANSLISTENER (*i)->transExecuted(_readTrans); _readTrans=0; return true; @@ -152,6 +156,7 @@ std::ostream& TMLEventBChannel::writeObject(std::ostream& s){ std::istream& TMLEventBChannel::readObject(std::istream& s){ std::istream::streampos aPos; TMLEventChannel::readObject(s); + std::cout << "Read Object TMLEventBChannel " << _name << std::endl; if (_eventFile!=0){ READ_STREAM(s,aPos); _eventFile->seekg(aPos); @@ -160,14 +165,14 @@ std::istream& TMLEventBChannel::readObject(std::istream& s){ } void TMLEventBChannel::reset(){ - Parameter<ParamType> param(0,0,0); + //Parameter<ParamType> param(0,0,0); TMLEventChannel::reset(); if (_eventFile!=0){ _eventFile->clear(); _eventFile->seekg(0,std::ios::beg); - std::cout << "EventB reset " << _eventFile->eof() << std::endl; - *_eventFile >> param; - param.print(); + //std::cout << "EventB reset " << _eventFile->eof() << std::endl; + //*_eventFile >> param; + //param.print(); readNextEvents(); std::cout << "no of events: " << _content << std::endl; } diff --git a/simulators/c++2/src_simulator/TMLEventChannel.cpp b/simulators/c++2/src_simulator/TMLEventChannel.cpp index ce1ebdfce0..d567ac9650 100644 --- a/simulators/c++2/src_simulator/TMLEventChannel.cpp +++ b/simulators/c++2/src_simulator/TMLEventChannel.cpp @@ -44,10 +44,10 @@ TMLEventChannel::TMLEventChannel(unsigned int iID, std::string iName, unsigned i } TMLEventChannel::~TMLEventChannel(){ - ParamQueue::iterator i; + /*ParamQueue::iterator i; for(i=_paramQueue.begin(); i != _paramQueue.end(); ++i){ delete (*i); - } + }*/ } TMLLength TMLEventChannel::getContent() const{ @@ -63,7 +63,7 @@ std::ostream& TMLEventChannel::writeObject(std::ostream& s){ std::cout << "write size of channel " << _name << " :" << _content << std::endl; TMLStateChannel::writeObject(s); for(i=_paramQueue.begin(); i != _paramQueue.end(); ++i){ - (*i)->writeObject(s, (unsigned int)_writeTask); + i->writeObject(s); } //for_each( _paramQueue.begin(), _paramQueue.end(), std::bind2nd(std::bind1st(std::mem_fun(&(Parameter<ParamType>::writeObject)),s),(unsigned int)_writeTask)); return s; @@ -72,32 +72,33 @@ std::ostream& TMLEventChannel::writeObject(std::ostream& s){ std::istream& TMLEventChannel::readObject(std::istream& s){ TMLLength aParamNo; ParamQueue::iterator i; - Parameter<ParamType>* aNewParam; + //Parameter<ParamType>* aNewParam; TMLStateChannel::readObject(s); - std::cout << "read new size of channel " << _name << " :" << _content << std::endl; + std::cout << "Read Object TMLEventChannel " << _name << std::endl; + //std::cout << "read new size of channel " << _name << " :" << _content << std::endl; //for(i=_paramQueue.begin(); i != _paramQueue.end(); ++i){ // delete (*i); //} //_paramQueue.clear(); for(aParamNo=0; aParamNo < _content; aParamNo++){ - aNewParam = new Parameter<ParamType>(s, (unsigned int) _writeTask); - _paramQueue.push_back(aNewParam); + //aNewParam = new Parameter<ParamType>(s, (unsigned int) _writeTask); + _paramQueue.push_back(Parameter<ParamType>(s)); } return s; } void TMLEventChannel::print() const{ for(ParamQueue::const_iterator i=_paramQueue.begin(); i != _paramQueue.end(); ++i){ - (*i)->print(); + i->print(); } } void TMLEventChannel::reset(){ //std::cout << "EventChannel reset" << std::endl; TMLStateChannel::reset(); - for(ParamQueue::iterator i=_paramQueue.begin(); i != _paramQueue.end(); ++i){ - delete (*i); - } + //for(ParamQueue::iterator i=_paramQueue.begin(); i != _paramQueue.end(); ++i){ + // delete (*i); + //} _paramQueue.clear(); //std::cout << "EventChannel reset end" << std::endl; //_tmpParam=Parameter<ParamType>(0,0,0); diff --git a/simulators/c++2/src_simulator/TMLEventFBChannel.cpp b/simulators/c++2/src_simulator/TMLEventFBChannel.cpp index 50ed288fa0..50a5082884 100644 --- a/simulators/c++2/src_simulator/TMLEventFBChannel.cpp +++ b/simulators/c++2/src_simulator/TMLEventFBChannel.cpp @@ -47,7 +47,7 @@ TMLEventFBChannel::TMLEventFBChannel(unsigned int iID, std::string iName, unsign void TMLEventFBChannel::testWrite(TMLTransaction* iTrans){ _writeTrans=iTrans; - _tmpParam=(iTrans->getCommand()->getParam()==0)? Parameter<ParamType>(0,0,0): *(iTrans->getCommand()->getParam()); //added!!! + if (iTrans->getCommand()->getParamFuncPointer()!=0) (_writeTask->*(iTrans->getCommand()->getParamFuncPointer()))(_tmpParam); //NEW _writeTrans->setVirtualLength((_length-_content>0)?WAIT_SEND_VLEN:0); } @@ -59,7 +59,7 @@ void TMLEventFBChannel::testRead(TMLTransaction* iTrans){ void TMLEventFBChannel::write(){ _content++; //_paramQueue.push_back(_writeTrans->getCommand()->getParam()); - _paramQueue.push_back(new Parameter<ParamType>(_tmpParam)); //modified!!! + _paramQueue.push_back(_tmpParam); //NEW if (_readTrans!=0 && _readTrans->getVirtualLength()==0){ _readTrans->setRunnableTime(_writeTrans->getEndTime()); _readTrans->setVirtualLength(WAIT_SEND_VLEN); @@ -69,19 +69,14 @@ void TMLEventFBChannel::write(){ } bool TMLEventFBChannel::read(){ - Parameter<ParamType> *pRead,*pWrite; if (_content<1){ return false; }else{ _content--; - pRead=_readTrans->getCommand()->getParam(); - pWrite=_paramQueue.front(); - //if (pRead!=0 && pWrite!=0) *pRead=*pWrite; - if (pWrite!=0){ //modified!!! - if (pRead!=0) *pRead=*pWrite; - delete pWrite; - } - _paramQueue.pop_front(); + //if (_writeTrans->getCommand()->getParamFuncPointer()!=0){ //NEW + if (_readTrans->getCommand()->getParamFuncPointer()!=0) (_readTask->*(_readTrans->getCommand()->getParamFuncPointer()))(_paramQueue.front()); //NEW + _paramQueue.pop_front(); //NEW + //} if (_writeTrans!=0 && _writeTrans->getVirtualLength()==0){ _writeTrans->setRunnableTime(_readTrans->getEndTime()); _writeTrans->setVirtualLength(WAIT_SEND_VLEN); diff --git a/simulators/c++2/src_simulator/TMLEventFChannel.cpp b/simulators/c++2/src_simulator/TMLEventFChannel.cpp index 73f43153a9..63cd2ed2ca 100644 --- a/simulators/c++2/src_simulator/TMLEventFChannel.cpp +++ b/simulators/c++2/src_simulator/TMLEventFChannel.cpp @@ -47,7 +47,7 @@ TMLEventFChannel::TMLEventFChannel(unsigned int iID, std::string iName, unsigned void TMLEventFChannel::testWrite(TMLTransaction* iTrans){ _writeTrans=iTrans; - _tmpParam=(iTrans->getCommand()->getParam()==0)? Parameter<ParamType>(0,0,0): *(iTrans->getCommand()->getParam()); //added!!! + if (iTrans->getCommand()->getParamFuncPointer()!=0) (_writeTask->*(iTrans->getCommand()->getParamFuncPointer()))(_tmpParam); //NEW _writeTrans->setVirtualLength(WAIT_SEND_VLEN); } @@ -60,7 +60,7 @@ void TMLEventFChannel::write(){ if (_content<_length){ _content++; //_paramQueue.push_back(_writeTrans->getCommand()->getParam()); - _paramQueue.push_back(new Parameter<ParamType>(_tmpParam)); //modified!!! + _paramQueue.push_back(_tmpParam); //NEW if (_readTrans!=0 && _readTrans->getVirtualLength()==0){ _readTrans->setRunnableTime(_writeTrans->getEndTime()); _readTrans->setVirtualLength(WAIT_SEND_VLEN); @@ -71,19 +71,14 @@ void TMLEventFChannel::write(){ } bool TMLEventFChannel::read(){ - Parameter<ParamType> *pRead,*pWrite; if (_content<1){ return false; }else{ _content--; - pRead=_readTrans->getCommand()->getParam(); - pWrite=_paramQueue.front(); - //if (pRead!=0 && pWrite!=0) *pRead=*pWrite; - if (pWrite!=0){ //modified!!! - if (pRead!=0) *pRead=*pWrite; - delete pWrite; - } - _paramQueue.pop_front(); + //if (_writeTrans->getCommand()->getParamFuncPointer()!=0){ //NEW + if (_readTrans->getCommand()->getParamFuncPointer()!=0) (_readTask->*(_readTrans->getCommand()->getParamFuncPointer()))(_paramQueue.front()); //NEW + _paramQueue.pop_front(); //NEW + //} FOR_EACH_TRANSLISTENER (*i)->transExecuted(_readTrans); _readTrans=0; return true; diff --git a/simulators/c++2/src_simulator/TMLRequestCommand.cpp b/simulators/c++2/src_simulator/TMLRequestCommand.cpp index 9c3c951aca..e10c027f95 100644 --- a/simulators/c++2/src_simulator/TMLRequestCommand.cpp +++ b/simulators/c++2/src_simulator/TMLRequestCommand.cpp @@ -44,7 +44,7 @@ Ludovic Apvrille, Renaud Pacalet #include <TMLTransaction.h> #include <Bus.h> -TMLRequestCommand::TMLRequestCommand(unsigned int iID, TMLTask* iTask,TMLEventBChannel* iChannel,Parameter<ParamType>* iParam):TMLCommand(iID, iTask,WAIT_SEND_VLEN,iParam),_channel(iChannel){ +TMLRequestCommand::TMLRequestCommand(unsigned int iID, TMLTask* iTask, TMLEventBChannel* iChannel, ParamFuncPointer iParamFunc): TMLCommand(iID, iTask, WAIT_SEND_VLEN, iParamFunc), _channel(iChannel){ } void TMLRequestCommand::execute(){ diff --git a/simulators/c++2/src_simulator/TMLRequestCommand.h b/simulators/c++2/src_simulator/TMLRequestCommand.h index 60c41c007c..6fc735cc4a 100644 --- a/simulators/c++2/src_simulator/TMLRequestCommand.h +++ b/simulators/c++2/src_simulator/TMLRequestCommand.h @@ -56,7 +56,7 @@ public: \param iChannel Pointer to the channel on which the event is conveyed \param iParam Pointer to the parameter data structure */ - TMLRequestCommand(unsigned int iID, TMLTask* iTask,TMLEventBChannel* iChannel,Parameter<ParamType>* iParam); + TMLRequestCommand(unsigned int iID, TMLTask* iTask, TMLEventBChannel* iChannel, ParamFuncPointer iParamFunc); void execute(); TMLTask* getDependentTask() const; TMLChannel* getChannel() const; diff --git a/simulators/c++2/src_simulator/TMLSelectCommand.cpp b/simulators/c++2/src_simulator/TMLSelectCommand.cpp index cfbb62e7e7..5d1cb60548 100644 --- a/simulators/c++2/src_simulator/TMLSelectCommand.cpp +++ b/simulators/c++2/src_simulator/TMLSelectCommand.cpp @@ -44,14 +44,13 @@ Ludovic Apvrille, Renaud Pacalet #include <TMLTransaction.h> #include <Bus.h> -TMLSelectCommand::TMLSelectCommand(unsigned int iID, TMLTask* iTask,TMLEventChannel** iChannel,unsigned int iNumbChannels,Parameter<ParamType>** iParam ):TMLCommand(iID, iTask,WAIT_SEND_VLEN,0),_channel(iChannel),_params(iParam),_numbChannels(iNumbChannels),_indexNextCommand(0),_maxChannelIndex(0){ +TMLSelectCommand::TMLSelectCommand(unsigned int iID, TMLTask* iTask, TMLEventChannel** iChannel, unsigned int iNumbChannels, ParamFuncPointer* iParamFuncs):TMLCommand(iID, iTask,WAIT_SEND_VLEN,0), _channel(iChannel), _paramFuncs(iParamFuncs), _numbChannels(iNumbChannels), _indexNextCommand(0), _maxChannelIndex(0){ } TMLSelectCommand::~TMLSelectCommand(){ if (_channel!=0) delete[] _channel; - if (_params!=0){ - for (unsigned int i=0;i<_numbChannels;i++) delete _params[i]; - delete [] _params; + if (_paramFuncs!=0){ + delete [] _paramFuncs; } } @@ -120,10 +119,14 @@ TMLCommand* TMLSelectCommand::getNextCommand() const{ } -Parameter<ParamType>* TMLSelectCommand::getParam() const{ - return (_params==0)?0:_params[_indexNextCommand]; +ParamFuncPointer TMLSelectCommand::getParamFuncPointer() const{ + return (_paramFuncs==0)?0:_paramFuncs[_indexNextCommand]; } +//Parameter<ParamType>* TMLSelectCommand::getParam() const{ +// return (_params==0)?0:_params[_indexNextCommand]; +//} + std::string TMLSelectCommand::toString() const{ std::ostringstream outp; outp << "SelectEvent in " << TMLCommand::toString() << " " << _channel[_indexNextCommand]->toString(); diff --git a/simulators/c++2/src_simulator/TMLSelectCommand.h b/simulators/c++2/src_simulator/TMLSelectCommand.h index f419fccb4d..2a1986b225 100644 --- a/simulators/c++2/src_simulator/TMLSelectCommand.h +++ b/simulators/c++2/src_simulator/TMLSelectCommand.h @@ -55,16 +55,17 @@ public: \param iTask Pointer to the task the command belongs to \param iChannel Pointer to an array of pointers to channels conveying the desired signals \param iNumbChannels Number of channels in the array - \param iParam Pointer to the parameter data structure + \param iParam Pointer to an array of parameter functions pointers */ - TMLSelectCommand(unsigned int iID, TMLTask* iTask,TMLEventChannel** iChannel,unsigned int iNumbChannels,Parameter<ParamType>** iParam); + TMLSelectCommand(unsigned int iID, TMLTask* iTask,TMLEventChannel** iChannel, unsigned int iNumbChannels, ParamFuncPointer* iParamFunc); ///Destructor ~TMLSelectCommand(); void execute(); TMLTask* getDependentTask() const; TMLChannel* getChannel() const; bool channelUnknown() const; - Parameter<ParamType>* getParam() const; + //Parameter<ParamType>* getParam() const; + ParamFuncPointer getParamFuncPointer() const; std::string toString() const; std::string toShortString() const; std::string getCommandStr() const; @@ -76,8 +77,8 @@ protected: TMLCommand* getNextCommand() const; ///Pointer to an array of pointers to channels conveying the desired signals TMLEventChannel** _channel; - ///Pointer to an array of parameters - Parameter<ParamType>** _params; + ///Pointer to an array of parameter function pointers + ParamFuncPointer* _paramFuncs; ///Number of channels in the array unsigned int _numbChannels; ///Index of the next command within the _nextCommand array diff --git a/simulators/c++2/src_simulator/TMLSendCommand.cpp b/simulators/c++2/src_simulator/TMLSendCommand.cpp index 4ec855fa3c..04707d088d 100644 --- a/simulators/c++2/src_simulator/TMLSendCommand.cpp +++ b/simulators/c++2/src_simulator/TMLSendCommand.cpp @@ -44,7 +44,7 @@ Ludovic Apvrille, Renaud Pacalet #include <TMLTransaction.h> #include <Bus.h> -TMLSendCommand::TMLSendCommand(unsigned int iID, TMLTask* iTask, TMLEventChannel* iChannel, Parameter<ParamType>* iParam): TMLCommand(iID, iTask, WAIT_SEND_VLEN, iParam), _channel(iChannel){ +TMLSendCommand::TMLSendCommand(unsigned int iID, TMLTask* iTask, TMLEventChannel* iChannel, ParamFuncPointer iParamFunc): TMLCommand(iID, iTask, WAIT_SEND_VLEN, iParamFunc), _channel(iChannel){ } void TMLSendCommand::execute(){ diff --git a/simulators/c++2/src_simulator/TMLSendCommand.h b/simulators/c++2/src_simulator/TMLSendCommand.h index e0982e6663..a9954fb15a 100644 --- a/simulators/c++2/src_simulator/TMLSendCommand.h +++ b/simulators/c++2/src_simulator/TMLSendCommand.h @@ -54,9 +54,9 @@ public: \param iID ID of the command \param iTask Pointer to the task the command belongs to \param iChannel Pointer to the channel on which the event is conveyed - \param iParam Pointer to the parameter data structure + \param iParam Pointer to a parameter function */ - TMLSendCommand(unsigned int iID, TMLTask* iTask,TMLEventChannel* iChannel,Parameter<ParamType>* iParam); + TMLSendCommand(unsigned int iID, TMLTask* iTask, TMLEventChannel* iChannel, ParamFuncPointer iParamFunc); void execute(); TMLTask* getDependentTask() const; TMLChannel* getChannel() const; diff --git a/simulators/c++2/src_simulator/TMLStateChannel.cpp b/simulators/c++2/src_simulator/TMLStateChannel.cpp index fb08a4760c..dd0c68b81e 100644 --- a/simulators/c++2/src_simulator/TMLStateChannel.cpp +++ b/simulators/c++2/src_simulator/TMLStateChannel.cpp @@ -53,6 +53,7 @@ std::ostream& TMLStateChannel::writeObject(std::ostream& s){ std::istream& TMLStateChannel::readObject(std::istream& s){ TMLChannel::readObject(s); + std::cout << "Read Object TMLStateChannel " << _name << std::endl; READ_STREAM(s,_content); return s; } diff --git a/simulators/c++2/src_simulator/TMLTask.cpp b/simulators/c++2/src_simulator/TMLTask.cpp index e5d093abb9..415e9b26d7 100644 --- a/simulators/c++2/src_simulator/TMLTask.cpp +++ b/simulators/c++2/src_simulator/TMLTask.cpp @@ -190,7 +190,12 @@ std::ostream& TMLTask::writeObject(std::ostream& s){ aCurrCmd=0; WRITE_STREAM(s,aCurrCmd); }else{ - aCurrCmd=(unsigned int)_currCommand-(unsigned int)this; + //if (((unsigned int)_currCommand)<((unsigned int)this)){ std::cout<< "Schrrrrrrecklich!!!" << std::endl; exit(1);} + //aCurrCmd=((unsigned int)_currCommand)-((unsigned int)this); + aCurrCmd=_currCommand->getID(); + if (aCurrCmd>1000 && aCurrCmd!=((unsigned int)-1)){ + std::cout << "BIIIIIIIIIIIIIIIIIIIIIIIG number: " << aCurrCmd << std::endl; + } WRITE_STREAM(s,aCurrCmd); _currCommand->writeObject(s); } @@ -200,13 +205,21 @@ std::ostream& TMLTask::writeObject(std::ostream& s){ std::istream& TMLTask::readObject(std::istream& s){ unsigned int aCurrCmd; //_previousTransEndTime=0; _busyCycles=0; _CPUContentionDelay=0; _noCPUTransactions=0; + std::cout << "Read Object TMLTask " << _name << std::endl; READ_STREAM(s, _endLastTransaction); READ_STREAM(s, aCurrCmd); - _currCommand=(aCurrCmd==0)?0:(TMLCommand*)(aCurrCmd+((unsigned int)this)); - if (_currCommand!=0){ + //_currCommand=(aCurrCmd==0)?0:(TMLCommand*)(aCurrCmd+((unsigned int)this)); + //_currCommand=(aCurrCmd==0)? 0 : getCommandByID(aCurrCmd); + //std::cout << "after ? " << std::endl; + if (aCurrCmd!=0){ + std::cout << "cmd ID: " << aCurrCmd << std::endl; + _currCommand=getCommandByID(aCurrCmd); + std::cout << "cmd adr: " << _currCommand << std::endl; + //std::cout << "before read cmd " << std::endl; _currCommand->readObject(s); //_currCommand->prepare(); } + std::cout << "End Read Object TMLTask " << _name << std::endl; return s; } diff --git a/simulators/c++2/src_simulator/TMLWaitCommand.cpp b/simulators/c++2/src_simulator/TMLWaitCommand.cpp index f44ab9b4de..4049133bc6 100644 --- a/simulators/c++2/src_simulator/TMLWaitCommand.cpp +++ b/simulators/c++2/src_simulator/TMLWaitCommand.cpp @@ -44,11 +44,13 @@ Ludovic Apvrille, Renaud Pacalet #include <TMLTransaction.h> #include <Bus.h> -TMLWaitCommand::TMLWaitCommand(unsigned int iID, TMLTask* iTask, TMLEventChannel* iChannel, Parameter<ParamType>* iParam):TMLCommand(iID, iTask, WAIT_SEND_VLEN, iParam),_channel(iChannel){ +TMLWaitCommand::TMLWaitCommand(unsigned int iID, TMLTask* iTask, TMLEventChannel* iChannel, ParamFuncPointer iParamFunc):TMLCommand(iID, iTask, WAIT_SEND_VLEN, iParamFunc),_channel(iChannel){ } void TMLWaitCommand::execute(){ + //std::cout << "execute wait " << std::endl; _channel->read(); + //std::cout << "after ch->read " << std::endl; _progress+=_currTransaction->getVirtualLength(); //_task->setEndLastTransaction(_currTransaction->getEndTime()); _task->addTransaction(_currTransaction); diff --git a/simulators/c++2/src_simulator/TMLWaitCommand.h b/simulators/c++2/src_simulator/TMLWaitCommand.h index 4beab14e6b..c75da64104 100644 --- a/simulators/c++2/src_simulator/TMLWaitCommand.h +++ b/simulators/c++2/src_simulator/TMLWaitCommand.h @@ -54,9 +54,9 @@ public: \param iID ID of the command \param iTask Pointer to the task the command belongs to \param iChannel Pointer to the channel on which the event is conveyed - \param iParam Pointer to the parameter data structure + \param iParam Pointer to a parameter function */ - TMLWaitCommand(unsigned int iID, TMLTask* iTask,TMLEventChannel* iChannel,Parameter<ParamType>* iParam); + TMLWaitCommand(unsigned int iID, TMLTask* iTask,TMLEventChannel* iChannel, ParamFuncPointer iParamFunc); void execute(); TMLTask* getDependentTask() const; TMLChannel* getChannel() const; diff --git a/simulators/c++2/src_simulator/definitions.h b/simulators/c++2/src_simulator/definitions.h index 73956896d5..439235015c 100644 --- a/simulators/c++2/src_simulator/definitions.h +++ b/simulators/c++2/src_simulator/definitions.h @@ -62,8 +62,8 @@ Ludovic Apvrille, Renaud Pacalet #include <netinet/in.h> #include <pthread.h> -#define WRITE_STREAM(s,v) s.write((char*) &v,sizeof(v)) -#define READ_STREAM(s,v) s.read((char*) &v,sizeof(v)) +#define WRITE_STREAM(s,v) s.write((char*) &v,sizeof(v)); std::cout << sizeof(v) << " bytes written" << std::endl; +#define READ_STREAM(s,v) s.read((char*) &v,sizeof(v)); std::cout << sizeof(v) << " bytes read" << std::endl; using std::min; using std::max; @@ -137,15 +137,18 @@ typedef std::map<SchedulableCommDevice*, BusMasterInfo*> MasterPriorityHashTab; ///Datatype for event parameters typedef int ParamType; ///Datatype used in EventChannels to store parameters of events -typedef std::deque<Parameter<ParamType>*> ParamQueue; +typedef std::deque<Parameter<ParamType> > ParamQueue; ///Type of member function pointer used to indicate a function encapsulating a condition (for TMLChoiceCommand) typedef unsigned int (TMLTask::*CondFuncPointer) (); ///Type of member function pointer used to indicate a function encapsulating an action (for TMLActionCommand) typedef unsigned int (TMLTask::*ActionFuncPointer) (); ///Type of member function pointer used to indicate a function encapsulating a condition (for TMLChoiceCommand) typedef unsigned int (TMLTask::*LengthFuncPointer) (); +///Type of member function pointer used to indicate a function encapsulating parameter manipulation (for TMLWaitCommand, TMLSendCommand) +typedef unsigned int (TMLTask::*ParamFuncPointer) (Parameter<ParamType>& ioParam); ///Datatype holding references to TraceableDevices (for VCD output) typedef std::list<TraceableDevice*> TraceableDeviceList; + struct ltstr{ bool operator()(const char* s1, const char* s2) const{ return strcmp(s1, s2) < 0; -- GitLab