Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

PsMomeOutput.h

Go to the documentation of this file.
00001 /*
00002  * This file is part of openMask © INRIA, CNRS, Universite de Rennes 1 1993-2002, thereinafter the Software
00003  * 
00004  * The Software has been developped within the Siames Project. 
00005  * INRIA, the University of Rennes 1 and CNRS jointly hold intellectual property rights
00006  * 
00007  * The Software has been registered with the Agence pour la Protection des
00008  * Programmes (APP) under registration number IDDN.FR.001.510008.00.S.P.2001.000.41200
00009  *
00010  * This file may be distributed under the terms of the Q Public License
00011  * version 1.0 as defined by Trolltech AS of Norway and appearing in the file
00012  * LICENSE.QPL included in the packaging of this file.
00013  *
00014  * Licensees holding valid specific licenses issued by INRIA, CNRS or Université de Rennes 1 
00015  * for the software may use this file in accordance with that specific license 
00016  *
00017  */
00018 #ifndef PsMomeOutputHEADER
00019 #define PsMomeOutputHEADER
00020 
00021 class PsnOutputSharedData;
00022 class PsMomeController;
00023 
00024 #include "PsEmptyFifoException.h"
00025 
00031 template <typename Type>
00032 class PsMomeOutput : public PsOutput<Type> {
00033 public :
00040    PsMomeOutput (const PsName & outputName, 
00041                  PsSimulatedObject & owner, 
00042                  const int historyLength,
00043                  PsPolatorNT * polator = NULL ) ;
00044 
00045 
00048    virtual ~PsMomeOutput (void) ;
00049 
00051    virtual void setValidity(bool);
00052 
00054    virtual void setUsedOutput(PsOutput<Type>  * output)  ;
00056    virtual void setDescendantOutput(PsOutput<Type> * output) ;
00058    virtual void extract(istream & = cin) ;
00060    virtual const Type & get (int & validiteRes,
00061                              const int niveauInterpol,
00062                              const PsDate & deltaT,
00063                              Type & resultPlaceHolder) const ;
00065    virtual void set (const Type & val) ; 
00066 protected:
00068    PsnOutputSharedData * _mesDonnees;
00071    PsDate _dateDernierChangementValeur;
00073    PsMomeController * _monControleur;
00075    PsnRelaxedMemoryManager * _myDataMemoryManager;
00076 } ; // PsMomeOutput
00077 
00078 
00079 #include <PsMomeController.h>
00080 #include <PsnOutputSharedData.h>
00081 
00082 //-----------------------------------------------------------------
00083 
00084 template <typename Type>
00085 void PsMomeOutput<Type>::extract(istream & in) {
00086    //on s'en fiche de in, puisqu'on a déjà les infos sous la bonne forme !
00088    //cerr<<"PsMomeOutput<Type>::extract"<<endl;
00089    if(_myDataMemoryManager->localAddressToGlobal(_mesDonnees->usedOutputDataOffset)!=NULL){
00090       
00091    }
00092    if(_myDataMemoryManager->localAddressToGlobal(_mesDonnees->principalAliasDataOffset)!=NULL){
00093 
00094    }
00095    if(_mesDonnees->_validity!=_validity){
00096       setValidity(_mesDonnees->_validity);
00097    }
00098       
00099 }
00100 
00101 //-----------------------------------------------------------------
00102 
00103 template <typename Type>
00104 inline PsMomeOutput<Type>::PsMomeOutput (const PsName & nom,
00105                                          PsSimulatedObject & prop,
00106                                          const int tailleFile,
00107                                          PsPolatorNT * interpolateur)
00108    : PsAttribute(prop,nom),
00109      PsOutput<Type> (nom,prop,tailleFile,interpolateur)
00110 {
00111    //cerr<<"PsMomeOutput<Type>::PsMomeOutput "<<endl;
00112    //on détruit la file classique, et on en crée (ou en en récupère) une adaptée, et on recole les morceaux
00113    delete _history;
00114 
00115    //Their is 4 cases : either we need to create a PsnMomeWriterFifo or a PsnMomeReaderFifo and either the internal data has allready been created or not
00116 
00117 
00118    _monControleur=dynamic_cast<PsMomeController *>(&_owner.getController());
00119 
00120    if (_monControleur!=NULL) {
00121 
00122       _myDataMemoryManager = PsMomeController::outputDataSharedMemoryManager;
00123 
00124       _mesDonnees = _monControleur->creerDonneesOutput(_owner.getName(),nom);
00125 
00126       _myDataMemoryManager->lockIfNeeded();
00127 
00128       _myDataMemoryManager->synchronizeAfterLock((void *)_mesDonnees,sizeof(PsnOutputSharedData));
00129 
00130       if (_myDataMemoryManager->invalidOffset(_mesDonnees->historyFifoOffset)) {
00131 
00132          if (tailleFile < _polator->getNumberOfNeededValuesForMaxPrecisionPolation() ) {
00133             cerr<<"Taille de file trop petite ("<<tailleFile
00134                 <<") alors que la output "<<nom<<" de "<<_owner.getName()
00135                 <<" nécessite "<<_polator->getNumberOfNeededValuesForMaxPrecisionPolation()
00136                 <<" valeurs pour un fonctionnement correct "<<endl;
00137             PsController::error("PsMomeOutput::constructeur");
00138          }
00139 #ifdef _DEBUGCREATIONOUTPUT
00140          cerr<<"PsMomeOutput<Type>::PsMomeOutput : creation d'une file Mome"<<endl;
00141 #endif
00142          
00143          if ( _monControleur->getObjectDescriptor().getProcess () == _owner.getObjectDescriptor().getProcess () ) {
00144             _history = new PsnMomeWriterFifo < Type > ( tailleFile , _myDataMemoryManager ) ;
00145          }
00146          else {
00147             _history = new PsnMomeReaderFifo <Type > ( tailleFile , _myDataMemoryManager ) ;
00148          }
00149 #ifdef _DEBUGCREATIONOUTPUT
00150          cerr<<"PsMomeOutput<Type>::PsMomeOutput : file Mome créée "<<endl;
00151 #endif
00152          _mesDonnees->historyFifoOffset=_myDataMemoryManager->globalAddressToLocal( ((PsnMomeFifo<Type> *)_history)->fifo() );
00153          
00154       }
00155       else {
00156          if (_monControleur->getObjectDescriptor().getProcess () == _owner.getObjectDescriptor().getProcess () ) {
00157 
00158             _history = new PsnMomeWriterFifo <Type > (_myDataMemoryManager->localAddressToGlobal(_mesDonnees->historyFifoOffset), tailleFile);
00159          }
00160          else {
00161             _history = new PsnMomeReaderFifo <Type > ( _myDataMemoryManager->localAddressToGlobal(_mesDonnees->historyFifoOffset),tailleFile); 
00162          }
00163 
00164       }
00165 
00166       _myDataMemoryManager->unlockIfNeeded();
00167       
00168    }
00169    else {
00170       cerr<<"PsMomeOutput<"<<typeid(Type).name()<<">::constructeur"
00171           <<"Controleur de type Mome attendu, mais de type "<<typeid(_owner.getController()).name()<<endl;
00172       PsController::error("");
00173    }
00174 
00175    _polator->setFifo(_history);
00176    //cerr<<"PsMomeOutput<Type>::PsMomeOutput fin de creation de la MomeOutput"<<endl;
00177 }
00178 
00179 //-----------------------------------------------------------------
00180 
00181 template <typename Type>
00182 inline PsMomeOutput<Type>::~PsMomeOutput (void)
00183 {
00184    //cerr<<"PsMomeOutput <"<<typeid(Type).name()<<">::~PsMomeOutput()"<<endl;
00185    //delete _history ;
00186    _history = NULL ;
00187    _monControleur->invalidateOutput(_owner.getName(),_name);
00188    //cerr<<"Fin destructeur de PsMomeOutput <"<<typeid(Type).name()<<">"<<endl;
00189 }
00190 
00191 //-----------------------------------------------------------------
00192 #include <unistd.h>
00193 template <typename Type>
00194 void PsMomeOutput<Type>::setValidity(bool b) {
00195    PsOutput<Type>::setValidity(b);
00196    _mesDonnees->_validity=b;
00197 }
00198 
00199 
00200 //-----------------------------------------------------------------
00201 
00202 template <typename Type>
00203 void PsMomeOutput<Type>::setDescendantOutput(PsOutput<Type> * output)  {
00204    //PsOutput<Type>::setDescendantOutput(output);
00205    assert (false) ;
00206    PsMomeOutput<Type> * laOutput  = dynamic_cast<PsMomeOutput<Type> *>(output);
00207    _mesDonnees->principalAliasDataOffset=_myDataMemoryManager->globalAddressToLocal(laOutput->_mesDonnees);
00208 }
00209 
00210 //-----------------------------------------------------------------
00211 
00212 template <typename Type>
00213 void PsMomeOutput<Type>::setUsedOutput(PsOutput<Type> * output)  {
00214    PsOutput<Type>::setUsedOutput(output);
00215    PsMomeOutput<Type> * laOutput  = dynamic_cast<PsMomeOutput<Type> *>(output);
00216    _mesDonnees->usedOutputDataOffset=_myDataMemoryManager->globalAddressToLocal(laOutput->_mesDonnees);
00217 }
00218 
00219 template <typename Type>
00220 const Type & PsMomeOutput<Type>::get(int & validiteRes,
00221                                      const int niveauInterpol,
00222                                      const PsDate & deltaT,
00223                                      Type & resultPlaceHolder) const
00224 {
00225 #ifdef _DEBUGATTRIBUTSMOME
00226    cerr<<"PsMomeOutput<"<<typeid(Type).name()<<">::"<<this<<"::get de "<<_name<<" "<<_owner.getName()<<endl;
00227    cerr<<"file : "<<_history<<endl;
00228 #endif
00229    if (! _validity) {
00230       _myDataMemoryManager->syncStepSyncedMemory();
00231       PsMomeOutput<Type> * uneCopieNonConst = const_cast< PsMomeOutput<Type> *> (this);
00232       uneCopieNonConst->extract();
00233    }
00234    try {
00235       try {
00236          return PsOutput<Type>::get(validiteRes,niveauInterpol,deltaT, resultPlaceHolder);
00237       }
00238       catch (PsUnInitialisedOutputException & s) {
00239          ((PsnMomeFifo <Type > *) _history )->resyncFifo (_myDataMemoryManager) ; 
00240          PsMomeOutput<Type> * uneAutreCopieNonConst = const_cast< PsMomeOutput<Type> *> (this);
00241          //assert (uneCopieNonConst != 0 );
00242          uneAutreCopieNonConst->extract();
00243          cerr<<"retry after syncing the memory of "<<_name<<" of object "<<_owner.getName()<<endl;
00244          return PsOutput<Type>::get(validiteRes,niveauInterpol,deltaT, resultPlaceHolder);      
00245       }
00246    }
00247    catch (PsEmptyFifoException & s) {
00248       cerr<<"PsMomeOutput<Type>::get : la file est vraiment vide !"<<endl;
00249       return PsOutput<Type>::get(validiteRes,niveauInterpol,deltaT, resultPlaceHolder);
00250    }
00251 }
00252 
00253 
00254 template <typename Type>
00255 void PsMomeOutput<Type>::set ( const Type & val) {
00256 #ifdef _DEBUGATTRIBUTSMOME
00257    cerr<<"PsMomeOutput<"<<typeid(Type).name()<<">::"<<this<<"set "<<_name<<" de "<<_owner.getName()<<" "<<val<<endl;
00258 #endif
00259    HeapStackTop specialContext(_myDataMemoryManager);
00260    //assert(HeapStackTop::globalMemoryManager != NULL );
00261    PsOutput< Type >::set(val) ;
00262    //cerr<<"PsMomeOutput<Type>::set fait"<<endl;
00263 }
00264 
00265 
00266 #endif
00267 
00268 
00269 
00270 
00271 
00272 
00273 
00274 
00275 

logo OpenMask

Documentation generated on Mon Nov 25 15:25:00 2002

Generated with doxygen 1.2.12 by Dimitri van Heesch ,   1997-2001