diff --git a/simulators/c++2/src_simulator/Parameter.h b/simulators/c++2/src_simulator/Parameter.h index 8e48b8cf9c101d087a1fe34499def50531980d20..82d904ad50cef0dc4a7fd83a24c694124d94670d 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 e93e027919deef40dab1374e50dd89e40d614653..8e2e207eeb2a9862f222f583938792d6d8882068 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 17d486426dbbe8cbf10f0e85dbb25547ea90ae97..d56ae722c50cb82b20c924c02836e524e0c45fc0 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 c5b10dafe71e7dd9c99f395562e7bd9384caf1f9..42d965d6f8617c6eb287d958ca6ed4c1f6556664 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 c03a855ff6c1ef529f757f64eafdaec78387f170..0f0eb2bba1d84f8cda9d6e71677d33028e5e0ac0 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 dd0a279ad7dd76a3c655fd773d0695fb56bbb705..198e15c621e7ce1c2dc0c19f123cf9cb9bb87d74 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 da176b892f773ad4c9c461fa64b465fcc3ce2164..8c6e934d24d034c659e0944bbd536f891334be33 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 ce1ebdfce043f03b285808f203d233ae7a048645..d567ac96500ca9aa71a8afccaf5431b6f4d13d89 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 50ed288fa0d571845374849e96c056079f6202de..50a50828846a18cac1547f6ee082acd366e45854 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 73f43153a995cc7e4545f612c5884d26eb57280c..63cd2ed2caad6769a57a74d80de81d9e34096807 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 9c3c951acaed19e798370b9f5a74abd81d0d8daf..e10c027f95090c9bfbf8a51c92dda0601d844086 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 60c41c007c5727156f95f600e0a38f71df3c3740..6fc735cc4a1fc2cdd001a4e5da66927b0881be06 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 cfbb62e7e7abb934e08f696f9e3461cce8cc70b9..5d1cb605483a4e379a4088d15faa152da6dbf0cf 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 f419fccb4df3d9403ea28fa370aaca12662bd872..2a1986b225aa09a54da0c81da6b0420d7d748270 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 4ec855fa3cfd518a37b96327724c5565399c7b2a..04707d088d047be693baaaa98dbba2656796ab3c 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 e0982e66639cc5f598eb1645b05284e8d55fa453..a9954fb15ac8fcc9fa3846a0e8be829a96bc56f4 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 fb08a4760c3a236e1283522c5e6aadd37e2fb298..dd0c68b81ed2d4fdcb7e7a62a69e5dbccd3af9e8 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 e5d093abb93bf576358e307ec3656cb5d9d53603..415e9b26d71ee349875efde4b9bfe5562396eb7b 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 f44ab9b4dea78e61c70dc3cd3cd1320df15e62d3..4049133bc65a925e3a1bfdb754637dc40927aeeb 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 4beab14e6b597abcd6d9a02b25f554323f9f0dce..c75da64104f9383b1a502adf167d39694ce658b6 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 73956896d55f39c7d46a269755fc0226b0af75b1..439235015c4f7472343eae67789ce37475518bb9 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;