]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
CCAR: add two requests to CALCIUM API (CPEFFI and CPEFFT)
authorcaremoli <caremoli>
Fri, 19 Mar 2010 16:57:56 +0000 (16:57 +0000)
committercaremoli <caremoli>
Fri, 19 Mar 2010 16:57:56 +0000 (16:57 +0000)
These requests remove all dataid before a given time (cpefft) or iteration number (cpeffi)
C, Fortran and Python API are implemented

src/DSC/DSC_Python/calcium.i
src/DSC/DSC_User/Datastream/Calcium/Calcium.c
src/DSC/DSC_User/Datastream/Calcium/CalciumCInterface.cxx
src/DSC/DSC_User/Datastream/Calcium/CalciumCInterface.hxx
src/DSC/DSC_User/Datastream/Calcium/CalciumCouplingPolicy.hxx
src/DSC/DSC_User/Datastream/Calcium/CalciumCxxInterface.hxx
src/DSC/DSC_User/Datastream/Calcium/CalciumGenericProvidesPort.hxx
src/DSC/DSC_User/Datastream/Calcium/calcium_provides_port.hxx
src/DSC/DSC_User/Datastream/Calcium/calciumf.c
src/DSC/DSC_User/Datastream/CouplingPolicy.hxx
src/DSC/DSC_User/Datastream/GenericPort.hxx

index 5f36a91bf737ecb2ad292b6c7cc26c2648749319..b21c432d7ee3b611134e4b6c26c564dd0445040b 100644 (file)
@@ -906,5 +906,8 @@ int cp_lch(Superv_Component_i *component,int dep,float  *ti,float  *tf,int *nite
 int cp_llg(Superv_Component_i *component,int dep,float  *ti,float  *tf,int *niter,char *nom,int nmax,int *nval,long   *lval);
 int cp_lln(Superv_Component_i *component,int dep,float  *ti,float  *tf,int *niter,char *nom,int nmax,int *nval,long   *lval);
 
+int cp_effi(Superv_Component_i *component,char *nom, int n);
+int cp_efft(Superv_Component_i *component,char *nom, float t);
+
 int cp_fin(Superv_Component_i *component,int cp_end);
 
index 86064a721549bf9b7f1a50d4258f44605b1cf3f6..8005bcd02fd4bea880392c11ef7bfaeedf68100d 100644 (file)
@@ -36,6 +36,9 @@
 typedef int InfoType;
 typedef char bool;
 
+//TODO: ajouter les prototypes pour eviter les pbs de passage par valeur
+InfoType ecp_efft_ (void * component, char* nomVar, float t);
+InfoType ecp_effi_ (void * component, char* nomVar, int i);
 
 /************************************/
 /* INTERFACES DE LECTURE EN 0 COPIE */
@@ -322,3 +325,18 @@ CALCIUM_ECR_INTERFACE_C_(ech_fort_,float ,cal_int,char  ,str,STAR,LCH_LAST_PARAM
 
 CALCIUM_ECR_INTERFACE_C_(eln_fort_,float ,cal_int,long   ,long,,);
 
+/***************************/
+/*  Interface for cleaning */
+/***************************/
+
+InfoType cp_effi (void * component, char * nomvar, int i)
+{
+  InfoType info =  ecp_effi_(component,nomvar,i);
+  return info;
+}
+
+InfoType cp_efft (void * component, char * nomvar, float t)
+{
+  InfoType info =  ecp_efft_(component,nomvar,t);
+  return info;
+}
index 960473900fafbab9f6dd08c085d42673013f6550..697cd1f2219dcf0129d8702178569081f682f1cd 100644 (file)
@@ -80,6 +80,40 @@ ecp_cd_ (void * component, char * instanceName) {
   return CalciumTypes::CPOK;
 }
 
+// Interface for cleaning
+extern "C" CalciumTypes::InfoType 
+ecp_effi_ (void * component, char* nomvar, int i)
+{
+  Superv_Component_i * _component = static_cast<Superv_Component_i *>(component); 
+  try
+    {
+      CalciumInterface::ecp_effi( *_component,nomvar,i);
+    }
+  catch ( const CalciumException & ex)
+    {
+      DEBTRACE( ex.what() );
+      return ex.getInfo();
+    }
+  return CalciumTypes::CPOK;
+
+}
+
+extern "C" CalciumTypes::InfoType 
+ecp_efft_ (void * component, char* nomvar, float t)
+{
+  Superv_Component_i * _component = static_cast<Superv_Component_i *>(component); 
+  try
+    {
+      CalciumInterface::ecp_efft( *_component,nomvar,t);
+    }
+  catch ( const CalciumException & ex)
+    {
+      DEBTRACE( ex.what() );
+      return ex.getInfo();
+    }
+  return CalciumTypes::CPOK;
+}
+
 // INTERFACE C/CPP pour les chaines de caractères
 // Le paramètre supplémentaire strsize n'étant pas utilisé
 // j'utilise la génération par la macro CALCIUM_C2CPP_INTERFACE_(str,char*,);
index 92eff648b46430c78e20c52c8b78f44761ef7af4..c643f63076b60053f4ac862ef5e4127a44a7bb95 100644 (file)
@@ -89,5 +89,7 @@ CALCIUM_C2CPP_INTERFACE_HXX_(str,str,char*,);
 /* Déclaration de ecp_fin */
 extern "C" CalciumTypes::InfoType ecp_fin_ (void * component, int code);
 extern "C" CalciumTypes::InfoType ecp_cd_ (void * component, char* instanceName);
+extern "C" CalciumTypes::InfoType ecp_effi_ (void * component, char* nomVar, int i);
+extern "C" CalciumTypes::InfoType ecp_efft_ (void * component, char* nomVar, float t);
 
 #endif
index ca587bb99bef33c391fb855941da4c0f6576d4c0..a0e5bf26685f25e454cb936a72c25978b387da16 100644 (file)
@@ -51,6 +51,7 @@ public:
   template <typename DataManipulator, 
     class EnableIf >                  friend class BoundedDataIdProcessor;
   template <typename DataManipulator >        friend class EraseDataIdProcessor;
+  template <typename DataManipulator >        friend class EraseDataIdBeforeTagProcessor;
   template <typename DataManipulator >        friend class DisconnectProcessor;
 
   typedef CalciumTypes::DependencyType       DependencyType;
@@ -112,6 +113,7 @@ public:
             class EnableIf = void >    struct BoundedDataIdProcessor;
   //template <typename DataManipulator>  struct BoundedDataIdProcessor;
   template <typename DataManipulator>  struct EraseDataIdProcessor;
+  template <typename DataManipulator>  struct EraseDataIdBeforeTagProcessor;
   template <typename DataManipulator>  struct DisconnectProcessor;
 
   // Renvoie isEqual si le dataId attendu est trouvé dans storedDataIds :
@@ -347,6 +349,43 @@ bool CalciumCouplingPolicy::isDataIdConveniant( AssocContainer & storedDatas, co
   return isEqual || isBounded;
 }
 
+//Remove DataId before a given time or tag
+template < typename DataManipulator > 
+struct CalciumCouplingPolicy::EraseDataIdBeforeTagProcessor
+{
+  CalciumCouplingPolicy &_couplingPolicy;
+    
+  EraseDataIdBeforeTagProcessor(CalciumCouplingPolicy &couplingPolicy):
+    _couplingPolicy(couplingPolicy) {};
+
+  template < typename Container,typename TimeType,typename TagType >
+  void apply(Container & storedDatas, TimeType time, TagType tag) const 
+    {
+      typedef typename Container::iterator   iterator;
+
+      if(_couplingPolicy._dependencyType == CalciumTypes::TIME_DEPENDENCY)
+        {
+          iterator it=storedDatas.begin();
+          while(it != storedDatas.end() && it->first.first <= time)
+            {
+              DataManipulator::delete_data(it->second);
+              storedDatas.erase(it);
+              it=storedDatas.begin();
+            }
+        }
+      else
+        {
+          iterator it=storedDatas.begin();
+          while(it != storedDatas.end() && it->first.second <= tag)
+            {
+              DataManipulator::delete_data(it->second);
+              storedDatas.erase(it);
+              it=storedDatas.begin();
+            }
+        }
+    }
+};
+
 // TODO :PAS ENCORE TESTE AVEC UN NIVEAU POSITIONNE
 // Supprime les DataId et les données associées
 // du container associatif quand le nombre
index e1129154c01ae6f51ad249ed460601bbb1b380e2..603bb3e91045ec9a5dd0aa339fedf319395c4070 100644 (file)
@@ -618,6 +618,123 @@ namespace CalciumInterface {
     ecp_ecriture<T1,T1> (component,dependencyType,t,i,nomVar,bufferLength,data); 
   };
 
+  static void
+  ecp_effi(Superv_Component_i & component,const std::string  & nomVar,long const  & i)
+  {
+    CORBA::String_var componentName=component.instanceName();
+    std::string containerName=component.getContainerName();
+
+    if (nomVar.empty())
+      {
+        Engines_DSC_interface::writeEvent("CP_EFFI",containerName,componentName,"",CPMESSAGE[CalciumTypes::CPNMVR],"");
+        throw CalciumException(CalciumTypes::CPNMVR, LOC("Empty variable name"));
+      }
+
+    calcium_provides_port* port;
+
+    try
+      {
+        port = component.Superv_Component_i::get_port< calcium_provides_port >(nomVar.c_str());
+      }
+    catch ( const Superv_Component_i::PortNotDefined & ex)
+      {
+        Engines_DSC_interface::writeEvent("CP_EFFI",containerName,componentName,nomVar.c_str(),CPMESSAGE[CalciumTypes::CPNMVR],ex.what());
+        throw (CalciumException(CalciumTypes::CPNMVR,ex));
+      }
+    catch ( const Superv_Component_i::PortNotConnected & ex)
+      {
+        Engines_DSC_interface::writeEvent("CP_EFFI",containerName,componentName,nomVar.c_str(),CPMESSAGE[CalciumTypes::CPLIEN],ex.what());
+        throw (CalciumException(CalciumTypes::CPLIEN,ex));
+      }
+    catch ( const Superv_Component_i::BadCast & ex)
+      {
+        Engines_DSC_interface::writeEvent("CP_EFFI",containerName,componentName,nomVar.c_str(),CPMESSAGE[CalciumTypes::CPTPVR],ex.what());
+        throw (CalciumException(CalciumTypes::CPTPVR,ex));
+      }
+
+    // get dependency mode
+    CalciumTypes::DependencyType portDependencyType = port->getDependencyType();
+
+    if ( portDependencyType == CalciumTypes::UNDEFINED_DEPENDENCY )
+      {
+        Engines_DSC_interface::writeEvent("CP_EFFI",containerName,componentName,nomVar.c_str(),CPMESSAGE[CalciumTypes::CPIT],"Dependency mode is undefined");
+        throw CalciumException(CalciumTypes::CPIT, LOC(OSS()<<"Dependency mode of variable " << nomVar << " is undefined."));
+      }
+
+    if ( portDependencyType != CalciumTypes::ITERATION_DEPENDENCY )
+      {
+        Engines_DSC_interface::writeEvent("CP_EFFI",containerName,componentName,nomVar.c_str(),CPMESSAGE[CalciumTypes::CPIT],
+                   "Dependency mode must be iteration mode");
+        throw CalciumException(CalciumTypes::CPITVR, LOC(OSS()<<"Dependency mode of variable " << nomVar << ": "
+                                << portDependencyType << " must be iteration mode."));
+      }
+
+    port->calcium_erase(0., i);
+
+    std::stringstream msg;
+    msg << "i<=" << i ;
+    Engines_DSC_interface::writeEvent("CP_EFFI",containerName,componentName,nomVar.c_str(),"",msg.str().c_str());
+
+  };
+
+  static void
+  ecp_efft(Superv_Component_i & component,const std::string  & nomVar,double const  & t)
+  {
+    CORBA::String_var componentName=component.instanceName();
+    std::string containerName=component.getContainerName();
+
+    if (nomVar.empty())
+      {
+        Engines_DSC_interface::writeEvent("CP_EFFT",containerName,componentName,"",CPMESSAGE[CalciumTypes::CPNMVR],"");
+        throw CalciumException(CalciumTypes::CPNMVR, LOC("Empty variable name"));
+      }
+
+    calcium_provides_port* port;
+
+    try
+      {
+        port = component.Superv_Component_i::get_port< calcium_provides_port >(nomVar.c_str());
+      }
+    catch ( const Superv_Component_i::PortNotDefined & ex)
+      {
+        Engines_DSC_interface::writeEvent("CP_EFFT",containerName,componentName,nomVar.c_str(),CPMESSAGE[CalciumTypes::CPNMVR],ex.what());
+        throw (CalciumException(CalciumTypes::CPNMVR,ex));
+      }
+    catch ( const Superv_Component_i::PortNotConnected & ex)
+      {
+        Engines_DSC_interface::writeEvent("CP_EFFT",containerName,componentName,nomVar.c_str(),CPMESSAGE[CalciumTypes::CPLIEN],ex.what());
+        throw (CalciumException(CalciumTypes::CPLIEN,ex));
+      }
+    catch ( const Superv_Component_i::BadCast & ex)
+      {
+        Engines_DSC_interface::writeEvent("CP_EFFT",containerName,componentName,nomVar.c_str(),CPMESSAGE[CalciumTypes::CPTPVR],ex.what());
+        throw (CalciumException(CalciumTypes::CPTPVR,ex));
+      }
+
+    // get dependency mode
+    CalciumTypes::DependencyType portDependencyType = port->getDependencyType();
+
+    if ( portDependencyType == CalciumTypes::UNDEFINED_DEPENDENCY )
+      {
+        Engines_DSC_interface::writeEvent("CP_EFFT",containerName,componentName,nomVar.c_str(),CPMESSAGE[CalciumTypes::CPIT],"Dependency mode is undefined");
+        throw CalciumException(CalciumTypes::CPIT, LOC(OSS()<<"Dependency mode of variable " << nomVar << " is undefined."));
+      }
+
+    if ( portDependencyType != CalciumTypes::TIME_DEPENDENCY )
+      {
+        Engines_DSC_interface::writeEvent("CP_EFFT",containerName,componentName,nomVar.c_str(),CPMESSAGE[CalciumTypes::CPIT],
+                   "Dependency mode must be time mode");
+        throw CalciumException(CalciumTypes::CPITVR, LOC(OSS()<<"Dependency mode of variable " << nomVar << ": "
+                                << portDependencyType << " must be time mode."));
+      }
+
+    port->calcium_erase(t, 0);
+
+    std::stringstream msg;
+    msg << "t<=" << t ;
+    Engines_DSC_interface::writeEvent("CP_EFFT",containerName,componentName,nomVar.c_str(),"",msg.str().c_str());
+
+  };
 };
 
 #endif
index b5474d71d040cf4f1bc9293ec51a99bb6d334f06..176f2a231817a974aff6300da05b612ecee1410b 100644 (file)
     virtual void provides_port_changed(int connection_nbr,              \
                                        const Engines::DSC::Message message) { \
       if ( message == Engines::DSC::AddingConnection)                   \
-        {                                                 \
-          _disconnect_mutex.lock();                \
-          _mustnotdisconnect++;                           \
-          _disconnect_mutex.unlock();              \
-        }                                                 \
+        {                                                               \
+          _disconnect_mutex.lock();                              \
+          _mustnotdisconnect++;                                         \
+          _disconnect_mutex.unlock();                            \
+        }                                                               \
       else if ( message == Engines::DSC::RemovingConnection )           \
-        {                                                 \
-          disconnect(false);                              \
-        }                                                 \
+        {                                                               \
+          disconnect(false);                                            \
+        }                                                               \
+    }                                                                   \
+                                                                        \
+    inline void calcium_erase(float t,long i)                           \
+    {                                                                   \
+      erase(t,i);                                                       \
     }                                                                   \
   };                                                                    \
 
index abb0e83038fa6380d75050045ec5edac451bab7f..8f1780d51face5ade1da357e01b3008d2764b98b 100644 (file)
@@ -62,6 +62,7 @@ public :
   virtual  InterpolationSchem getInterpolationSchem () const  =0;
   virtual  ExtrapolationSchem getExtrapolationSchem () const  =0;
 
+  virtual void calcium_erase (float t,long i) {};
 };
 
 #endif
index fedab9d3499a59ee70decade481be59e641349e0..02411f23847a47e600dfe4ca7e9079d67a93af4f 100644 (file)
@@ -85,6 +85,23 @@ void F_FUNC(cpfin,CPFIN)(long *compo,cal_int *dep,cal_int *err)
   *err=cp_fin((void *)*compo,(int)*dep);
 }
 
+void F_FUNC(cpeffi,CPEFFI)(long *compo,STR_PSTR(nom),cal_int *i, cal_int *err STR_PLEN(nom));
+void F_FUNC(cpefft,CPEFFT)(long *compo,STR_PSTR(nom),float *t, cal_int *err STR_PLEN(nom));
+
+void F_FUNC(cpeffi,CPEFFI)(long *compo,STR_PSTR(nom),cal_int *i, cal_int *err STR_PLEN(nom))
+{
+  char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
+  *err=cp_effi((void *)*compo,cnom,*i);
+  free_str1(cnom);
+}
+
+void F_FUNC(cpefft,CPEFFT)(long *compo,STR_PSTR(nom),float *t, cal_int *err STR_PLEN(nom))
+{
+  char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
+  *err=cp_efft((void *)*compo,cnom,*t);
+  free_str1(cnom);
+}
+
 /**************************************/
 /* INTERFACES DE LECTURE              */
 /**************************************/
index 05dd5935aa6475c75786412f131e7ba30039ba7e..521fd438d66b21713edeb977da80022898f5e897 100644 (file)
@@ -150,6 +150,20 @@ public:
     }
   };
 
+  // Remove all DataId from a container before a given time or tag
+  template <typename DataManipulator>
+  struct EraseDataIdBeforeTagProcessor {
+
+    EraseDataIdBeforeTagProcessor(CouplingPolicy couplingPolicy) {};
+
+    template < typename Container , typename TimeType , typename TagType >
+    void apply(Container & storedDatas, TimeType time, TagType tag ) const {
+      typedef typename Container::key_type   key_type;
+      typedef typename Container::value_type value_type;
+      typedef typename Container::iterator iterator;
+    }
+  };
+
   // Permet de réveiller les méthodes d'un GenericPort en attente
   // depuis une CouplingPolicy
   virtual void wakeupWaiting(){};
index a760ee0110c4d23d9c891f2311fd2709eec97b6f..52eb345acb0918b2f550e42e9bd7843d313a8529 100644 (file)
@@ -73,6 +73,7 @@ public:
   template <typename TimeType,typename TagType> DataType next(TimeType &t, TagType  &tag );
   void      close (PortableServer::POA_var poa, PortableServer::ObjectId_var id);
   void wakeupWaiting();
+  template <typename TimeType,typename TagType> void erase(TimeType time, TagType tag );
 
 private:
 
@@ -338,6 +339,15 @@ void GenericPort<DataManipulator, COUPLING_POLICY>::put(CorbaInDataType dataPara
 
 }
 
+// erase data before time or tag
+template < typename DataManipulator, typename COUPLING_POLICY >
+template <typename TimeType,typename TagType>
+void
+GenericPort<DataManipulator, COUPLING_POLICY>::erase(TimeType time, TagType  tag)
+{
+  typename COUPLING_POLICY::template EraseDataIdBeforeTagProcessor<DataManipulator> processEraseDataId(*this);
+  processEraseDataId.apply(storedDatas,time,tag);
+}
 
 // Version du Get en 0 copy
 // ( n'effectue pas de recopie de la donnée trouvée dans storedDatas )