/******************************************************************* * * DESCRIPTION: class FlatCoordinator * * AUTHOR: Amir Barylko & Jorge Beyoglonian * Version 2: Daniel Rodriguez. * * EMAIL: mailto://amir@dc.uba.ar * mailto://jbeyoglo@dc.uba.ar * mailto://drodrigu@dc.uba.ar * * DATE: 27/06/1998 * DATE: 11/04/1999 (v2) * *******************************************************************/ // ** include files **// #include "flatcellcoor.h" //headers #include "flatcoup.h" // class FlatCoupledCell #include "msgadm.h" // SingleMessageAdm #include "cellstate.h" /******************************************************************* * Method: receive * Description: InitMessage ********************************************************************/ Processor &FlatCellCoordinator::receive( const InitMessage &msg ) { cout << "FlatCellCoor: going to process receive(Ini) message @ " << msg.time() << endl; FlatCoupledCell &coupled( static_cast< FlatCoupledCell & >( model() ) ) ; coupled.initFunction(); lastChange( msg.time() ) ; if( coupled.nextEventList().empty() ) nextChange( Time::Inf ); else nextChange( coupled.nextEventList().front().time ); DoneMessage doneMsg( msg.time(), this->Processor::id(), coupled.nextChange() , false) ; SingleMsgAdm::Instance().send( doneMsg, coupled.parentId() ) ; // if (FlatDebug().Active()) // coupled.printStateValues(msg.time()); return *this; } /******************************************************************* * Method: receive * Description: ExternalMessage ********************************************************************/ Processor &FlatCellCoordinator::receive( const ExternalMessage &msg ) { FlatCoupledCell &coupled( static_cast< FlatCoupledCell & >( model() ) ); VirtualPortList *xList( coupled.externalList() ); CellPosition counter( coupled.dimension().dimension(), 0 ); register bool overflow = false; while (!overflow){ for (VirtualPortList::iterator cursor = xList[ counter.calculateIndex( coupled.dimension() )].begin(); cursor != xList[ counter.calculateIndex( coupled.dimension() ) ].end(); cursor++) if ( *(cursor->second) == msg.port() ) { ExternalMessage* extMsg = dynamic_cast( msg.clone() ); extMsg->procId( this->Processor::id() ); coupled.cellsMsgs[counter.calculateIndex(coupled.dimension())].add( (ExternalMessage*)(extMsg->clone()) ); // coupled.externalFunction( msg.time(), *(const CellPosition *) &counter, true, msg.value(), cursor->first ); } overflow = counter.next( coupled.dimension() ); } cout << "added an ExternalMessage to the message bag " << endl; cout << "FlatCellCoor:processed receive(externalmessage) @ " << msg.time() << endl; return *this; /* lastChange( msg.time() ) ; if( coupled.nextEventList().empty() ) nextChange( Time::Inf ); else nextChange( coupled.nextEventList().front().time - lastChange() ); DoneMessage doneMsg( msg.time(), this->Processor::id(), coupled.nextChange() ) ; SingleMsgAdm::Instance().send( doneMsg, coupled.parentId() ) ; if ( FlatDebug().Active() ) { FlatDebug().Stream() << "Time: " << msg.time() << endl; coupled.cellState()->print( FlatDebug().Stream() ) ; } return *this; */ } /******************************************************************* * Method: receive * Description: IneternalMessage ********************************************************************/ Processor &FlatCellCoordinator::receive( const InternalMessage &msg ) { FlatCoupledCell &coupled( static_cast< FlatCoupledCell & >( model() ) ) ; coupled.internalFunction( msg ); lastChange( msg.time() ) ; if( coupled.nextEventList().empty() ) nextChange( Time::Inf ); else nextChange( coupled.nextEventList().front().time - lastChange() ); DoneMessage doneMsg( msg.time(), this->Processor::id(), coupled.nextChange() , false) ; SingleMsgAdm::Instance().send( doneMsg, coupled.parentId() ) ; if (FlatDebug().Active()) coupled.printStateValues(msg.time()); cout << "FlatCellCoor:processed receive(internal message) @ " << msg.time() << endl; return *this; /* if ( FlatDebug().Active() ) { FlatDebug().Stream() << "Time: " << msg.time() << endl; coupled.cellState()->print( FlatDebug().Stream() ) ; } return *this; */ } Processor &FlatCellCoordinator::receive( const CollectMessage &msg) { MASSERT( msg.time() == absoluteNext()) FlatCoupledCell &coupled( static_cast( model() ) ); lastChange( msg.time() ) ; nextChange(Time::Zero); coupled.outputFunction(msg); DoneMessage doneMsg( msg.time(), this->Processor::id(), coupled.nextChange() , false ) ; SingleMsgAdm::Instance().send( doneMsg, coupled.parentId() ) ; cout << "FlatCellCoor:processed receive(collect message) @ " << msg.time() << endl; return *this; /* if( coupled.nextEventList().empty() ) nextChange( Time::Inf ); else nextChange( coupled.nextEventList().front().time - lastChange() ); DoneMessage doneMsg( msg.time(), this->Processor::id(), coupled.nextChange() ) ; SingleMsgAdm::Instance().send( doneMsg, coupled.parentId() ) ; if ( FlatDebug().Active() ) { FlatDebug().Stream() << "Time: " << msg.time() << endl; coupled.cellState()->print( FlatDebug().Stream() ) ; } return *this; */ } /******************************************************************* * Method: receive * Description: OutputMessage ********************************************************************/ Processor &FlatCellCoordinator::receive( const OutputMessage & ) { MASSERT( false ); return *this; } /******************************************************************* * Method: receive ********************************************************************/ Processor &FlatCellCoordinator::receive( const DoneMessage & ) { MASSERT( false ); return *this; }