/******************************************************************* * * DESCRIPTION: class Model * * 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/6/1998 * DATE: 25/4/1999 (v2) * *******************************************************************/ /** include files **/ #include "model.h" // class Model #include "strutil.h" // lowerCase #include "cppwrapper.h" /** public functions **/ /******************************************************************* * Function Name: Model * Description: constructor default ********************************************************************/ Model::Model( const string &name ) : ident( Processor::InvalidId ) , parent_id( Processor::InvalidId ) , descript( name ) , local_proc( Processor::InvalidId ) {} /******************************************************************* * Function Name: ~Model * Description: destructor ********************************************************************/ Model::~Model() { PortList::iterator cursor = inputList.begin(); for ( ; cursor != inputList.end() ; cursor++ ) delete cursor->second; for ( cursor = outputList.begin(); cursor != outputList.end(); cursor++ ) delete cursor->second; } /******************************************************************* * Function Name: addInputPort * Post: adds the port to the input list ********************************************************************/ Port &Model::addInputPort( const string &portName ) { Port *pPort = new Port( lowerCase( portName ), id() ); inputPorts()[ pPort->id() ] = pPort; return *pPort; } /******************************************************************* * Function Name: addOuputPort * Description: adds the port to the output list ********************************************************************/ Port &Model::addOutputPort( const string &portName ) { Port *pPort = new Port( lowerCase( portName ), id() ); outputList[ pPort->id() ] = pPort; return *pPort; } /******************************************************************* * Function Name: port * Description: Retorna el port solicitado ********************************************************************/ Port &Model::port( const string &n ) { string name( lowerCase( n ) ) ; PortList::iterator cursor = inputPorts().begin(); for( ; cursor != inputPorts().end() && cursor->second->name() != name; cursor++ ) ; if (cursor == inputPorts().end()) { for (cursor = outputPorts().begin(); cursor != outputPorts().end() && cursor->second->name() != name ; cursor++ ) ; if ( cursor == outputPorts().end() ) { InvalidPortRequest e ; e.addText( name + " port not found!" ) ; MTHROW( e ) ; } } MASSERT( cursor->second ); return *( cursor->second ); } /******************************************************************* * Function Name: nextChange ********************************************************************/ Model &Model::nextChange( const Time &t ) { //Rami // SingleProcessorAdmin::Instance().processor( id() ).nextChange(t); processor().nextChange(t); return *this; } Model &Model::lastChange( const Time &t) { //Rami // SingleProcessorAdmin::Instance().processor( id() ).lastChange(t) ; processor().lastChange(t); return *this; } Model &Model::addMachine(const MachineId &mid) { ModelPartition::const_iterator cursor ; for( cursor = model_partition.begin() ; cursor != model_partition.end() ; cursor++) if (cursor->first == mid) break; if (cursor == model_partition.end() ) model_partition[mid] = Processor::InvalidId; return *this; } const MachineId &Model::machineForProcId(const ProcId &pid) const { ModelPartition::const_iterator cursor ; for( cursor = model_partition.begin() ; cursor != model_partition.end() ; cursor++) if (cursor->second == pid) return cursor->first; MException e; e.addText(string("There is not Pid for Processor ") + pid + string(" in model ") + description() ) ; MTHROW(e); } bool Model::isLocalMaster() const { ModelPartition::const_iterator cursor; cursor = model_partition.begin(); if( cursor != model_partition.end() ) { int mid = SingleCPPWrapper::Instance().getMachineID(); if (mid == cursor->first) return true; } return false; } const ProcId &Model::masterId() const { ModelPartition::const_iterator cursor; cursor = model_partition.begin(); if( cursor != model_partition.end() ) return cursor->second; return Processor::InvalidId; } const ProcId &Model::procInMachine(const MachineId &mid) const { ModelPartition::const_iterator cursor = model_partition.find(mid); if( cursor != model_partition.end()) return cursor->second; return Processor::InvalidId; } Model &Model::setMachineProcId(const MachineId &mid, const ProcId &pid) { if (mid == SingleCPPWrapper::Instance().getMachineID()) local_proc = pid; model_partition[mid] = pid; SingleCPPWrapper::Instance().setMachineForProcId(pid, mid); SingleProcessorAdmin::Instance().model(pid, this); return *this; } Processor &Model::processor() const { return *proc; } Model &Model::processor( Processor * p) { if (localProc() == Processor::InvalidId ) { MException e; e.addText("The model " + description() + " does NOT have a processor on this machine"); MTHROW(e); } proc = p; return *this; } Model &Model::printModelPartition() { cout << "-------------------------------------------------------------" << endl; cout << "printing the model prtition for " << this->description() << endl; cout << "localProc is : " << this->localProc() << endl; cout << "parentId is : " << this->parentId() << endl; cout << "model parition : " << endl; ModelPartition::iterator cursor; for ( cursor = model_partition.begin(); cursor != model_partition.end(); cursor++) { cout << "MachineId : " << cursor->first << " ProcId " << cursor->second << endl; } cout << "-------------------------------------------------------------" << endl; }