27 #ifndef _CALCIUM_CXXINTERFACE_HXX_ 
   28 #define _CALCIUM_CXXINTERFACE_HXX_ 
   30 #if defined(__CONST_H) || defined(__CALCIUM_H) 
   31 #error "The header CalciumCxxInterface.hxx must be included before calcium.h" 
   37 #include "Superv_Component_i.hxx" 
   38 #include "CalciumException.hxx" 
   39 #include "CalciumTypes.hxx" 
   40 #include "CalciumGenericUsesPort.hxx" 
   41 #include "Copy2UserSpace.hxx" 
   42 #include "Copy2CorbaSpace.hxx" 
   43 #include "CalciumPortTraits.hxx" 
   49 template <
typename T1, 
typename T2>
 
   51   static const bool value = 
false;
 
   53 template <
typename T1>
 
   55   static const bool value = 
true;
 
   58 extern const char * CPMESSAGE[];
 
   62 #include <boost/type_traits/remove_all_extents.hpp> 
   64 namespace CalciumInterface {
 
   72     CORBA::String_var componentName=component.
instanceName();
 
   74     if (instanceName.empty()) instanceName=componentName;
 
   81     CORBA::String_var componentName=component.
instanceName();
 
   85     std::vector<std::string> usesPortNames;
 
   86     std::vector<std::string>::const_iterator it;
 
   95     for (it=usesPortNames.begin(); it != usesPortNames.end(); ++it) 
 
   99             myCalciumUsesPort= component.Superv_Component_i::get_port< 
calcium_uses_port >((*it).c_str());
 
  106             std::cerr << 
"-------- CalciumInterface(ecp_fin) MARK 1 -|"<< *it <<
"|----"<< 
 
  108               typeid(myCalciumUsesPort).name() <<
"-------------" << std::endl;
 
  115             myCalciumUsesPort->disconnect(provideLastGivenValue);
 
  147   template <
typename T1, 
typename T2> 
static void 
  148   ecp_free ( T1 * dataPtr )
 
  151     typedef typename PortType::DataManipulator            DataManipulator;
 
  152     typedef typename DataManipulator::Type                DataType; 
 
  153     typedef typename DataManipulator::InnerType           InnerType;
 
  158   template <
typename T1> 
static void 
  159   ecp_free ( T1 * dataPtr )
 
  161     ecp_free<T1,T1> ( dataPtr );
 
  173   template <
typename T1, 
typename T2 > 
static void 
  175                int    const  & dependencyType,
 
  179                const std::string  & nomVar, 
 
  186     CORBA::String_var componentName=component.
instanceName();
 
  190     typedef typename PortType::DataManipulator            DataManipulator;
 
  191     typedef typename DataManipulator::Type                CorbaDataType; 
 
  192     typedef typename DataManipulator::InnerType           InnerType;
 
  193     CalciumTypes::DependencyType _dependencyType=                
 
  194       static_cast<CalciumTypes::DependencyType
>(dependencyType);
 
  196     CorbaDataType     corbaData;
 
  199     std::cerr << 
"-------- CalciumInterface(ecp_lecture) MARK 1 ------------------" << std::endl;
 
  209     std::cout << 
"-------- CalciumInterface(lecture) MARK 2 --"<<
typeid(port).name()<<
"----------------" << std::endl;
 
  212     std::cout << 
"-------- CalciumInterface(lecture) MARK 2b1 -----" << 
typeid(t1).name() << 
"-------------" << std::endl;
 
  213     std::cout << 
"-------- CalciumInterface(lecture) MARK 2b2 -----" << 
typeid(t2).name() << 
"-------------" << std::endl;
 
  218         port  = component.Superv_Component_i::get_port< PortType > (nomVar.c_str());
 
  220         std::cout << 
"-------- CalciumInterface(ecp_lecture) MARK 3 ------------------" << std::endl;
 
  241     CalciumTypes::DependencyType portDependencyType = port->getDependencyType();
 
  243     if ( portDependencyType == CalciumTypes::UNDEFINED_DEPENDENCY )
 
  246         throw CalciumException(CalciumTypes::CPIT, LOC(
OSS()<<
"Dependency mode of variable " << nomVar << 
" is undefined."));
 
  249     if ( ( portDependencyType != _dependencyType ) && ( _dependencyType != CalciumTypes::SEQUENCE_DEPENDENCY ) ) 
 
  252                    "Dependency mode is not the same as the required one");
 
  253         throw CalciumException(CalciumTypes::CPITVR, LOC(
OSS()<<
"Dependency mode of variable " << nomVar << 
": "  
  254                                 << portDependencyType << 
" is not the same as the required one."));
 
  258     std::stringstream msgout,msg;
 
  259     if ( _dependencyType == CalciumTypes::TIME_DEPENDENCY ) 
 
  264             msg << 
"ti=" << ti << 
", tf=" << tf ;
 
  266             corbaData = port->get(tt,tf, 0);
 
  267             msgout << 
"read t=" << tt ;
 
  269             std::cout << 
"-------- CalciumInterface(ecp_lecture) MARK 5 ------------------" << std::endl;
 
  278     else if ( _dependencyType == CalciumTypes::ITERATION_DEPENDENCY ) 
 
  284             corbaData = port->get(0, i);
 
  285             msgout << 
"read i=" << i ;
 
  287             std::cout << 
"-------- CalciumInterface(ecp_lecture) MARK 6 ------------------" << std::endl;
 
  302             std::cout << 
"-------- CalciumInterface(ecp_lecture) MARK 7 ------------------" << std::endl;
 
  305             corbaData = port->next(ti,i);
 
  307             if(i==0)msgout<< 
"t=" <<ti;
 
  308             else msgout<< 
"i=" <<i;
 
  318     std::cout << 
"-------- CalciumInterface(ecp_lecture) MARK 8 ------------------" << std::endl;
 
  320     size_t corbaDataSize = DataManipulator::size(corbaData);
 
  322     std::cout << 
"-------- CalciumInterface(ecp_lecture) corbaDataSize : " << corbaDataSize << std::endl;
 
  328         if ( bufferLength != 0 ) 
 
  330             MESSAGE(
"bufferLength devrait valoir 0 pour l'utilisation du mode sans copie (data==NULL)");
 
  332         nRead = corbaDataSize;
 
  336         std::cout << 
"-------- CalciumInterface(ecp_lecture) MARK 9 ------------------" << std::endl;
 
  348         std::cout << 
"-------- CalciumInterface(ecp_lecture) MARK 10 ------------------" << std::endl;
 
  363         nRead = std::min < size_t > (corbaDataSize,bufferLength);
 
  365         std::cout << 
"-------- CalciumInterface(ecp_lecture) MARK 11 ------------------" << std::endl;
 
  371         std::cout << 
"-------- CalciumInterface(ecp_lecture) MARK 12 ------------------" << std::endl;
 
  375     std::cout << 
"-------- CalciumInterface(ecp_lecture), Valeur de data : " << std::endl;
 
  376     std::copy(data,data+nRead,std::ostream_iterator<T1>(std::cout,
" "));
 
  377     std::cout << 
"Ptr :" << data << std::endl;
 
  378     std::cout << 
"-------- CalciumInterface(ecp_lecture) MARK 13 ------------------" << std::endl;
 
  385   template <
typename T1 > 
static void 
  387                int    const      & dependencyType,
 
  391                const std::string & nomVar, 
 
  396     ecp_lecture<T1,T1> (component,dependencyType,ti,tf,
 
  397                         i,nomVar,bufferLength,nRead,data);
 
  405   template <
typename T1, 
typename T2> 
static void 
  407                  int    const      & dependencyType,
 
  410                  const std::string & nomVar, 
 
  416     CORBA::String_var componentName=component.
instanceName();
 
  420     typedef typename boost::remove_all_extents< T1 >::type           T1_without_extent;
 
  421     typedef typename boost::remove_all_extents< T2 >::type           T2_without_extent;
 
  424     typedef typename ProvidesPortType::DataManipulator               DataManipulator;
 
  427     typedef typename DataManipulator::Type                           CorbaDataType; 
 
  428     typedef typename DataManipulator::InnerType                      InnerType;
 
  430     T1_without_extent 
const & _data = data;
 
  432     CalciumTypes::DependencyType _dependencyType=                
 
  433       static_cast<CalciumTypes::DependencyType
>(dependencyType);
 
  436     std::cerr << 
"-------- CalciumInterface(ecriture) MARK 1 ------------------" << std::endl;
 
  438     if ( nomVar.empty() )
 
  445     std::cout << 
"-------- CalciumInterface(ecriture) MARK 2 ---"<<
typeid(port).name()<<
"---------------" << std::endl;
 
  448     std::cout << 
"-------- CalciumInterface(ecriture) MARK 2b1 -----" << 
typeid(t1).name() << 
"-------------" << std::endl;
 
  449     std::cout << 
"-------- CalciumInterface(ecriture) MARK 2b2 -----" << 
typeid(t2).name() << 
"-------------" << std::endl;
 
  454         port  = component.Superv_Component_i::get_port< UsesPortType > (nomVar.c_str());
 
  456         std::cout << 
"-------- CalciumInterface(ecriture) MARK 3 ------------------" << std::endl;
 
  489     if ( _dependencyType == CalciumTypes::UNDEFINED_DEPENDENCY )
 
  492         throw CalciumException(CalciumTypes::CPIT, LOC(
OSS()<<
"Dependency mode of variable " << nomVar << 
" is undefined."));
 
  495     if ( _dependencyType == CalciumTypes::SEQUENCE_DEPENDENCY )
 
  498                    "SEQUENCE_DEPENDENCY mode is not possible when writing");
 
  499         throw CalciumException(CalciumTypes::CPIT, LOC(
OSS()<<
"Dependency mode SEQUENCE_DEPENDENCY for variable " << nomVar 
 
  500                                << 
" is not possible when writing."));
 
  514     if ( bufferLength < 1 )
 
  520     CorbaDataType corbaData;
 
  522     std::cout << 
"-------- CalciumInterface(ecriture) MARK 4 ------------------" << std::endl;
 
  546     T1_without_extent t1b;
 
  548     std::cout << 
"-------- CalciumInterface(ecriture) MARK 4b1 -----" << 
typeid(t1b).name() << 
"-------------" << std::endl;
 
  549     std::cout << 
"-------- CalciumInterface(ecriture) MARK 4b2 -----" << 
typeid(t2b).name() << 
"-------------" << std::endl;
 
  555     if ( _dependencyType == CalciumTypes::TIME_DEPENDENCY ) 
 
  559             port->put(*corbaData,t, -1); 
 
  560             std::stringstream msg;
 
  572         std::cout << 
"-------- CalciumInterface(ecriture) MARK 5 ------------------" << std::endl;
 
  575     else if ( _dependencyType == CalciumTypes::ITERATION_DEPENDENCY ) 
 
  579             port->put(*corbaData,-1, i);
 
  580             std::stringstream msg;
 
  590         std::cout << 
"-------- CalciumInterface(ecriture) MARK 6 ------------------" << std::endl;
 
  595     std::cout << 
"-------- CalciumInterface(ecriture), Valeur de corbaData : " << std::endl;
 
  596     for (
int i = 0; i < corbaData->length(); ++i)
 
  597       std::cout << 
"-------- CalciumInterface(ecriture), corbaData[" << i << 
"] = " << (*corbaData)[i] << std::endl;
 
  605     std::cout << 
"-------- CalciumInterface(ecriture) MARK 7 ------------------" << std::endl;
 
  611   template <
typename T1> 
static void 
  613                  int    const  & dependencyType,
 
  616                  const std::string  & nomVar, 
 
  620     ecp_ecriture<T1,T1> (component,dependencyType,t,i,nomVar,bufferLength,data); 
 
  626     CORBA::String_var componentName=component.
instanceName();
 
  658     CalciumTypes::DependencyType portDependencyType = port->getDependencyType();
 
  660     if ( portDependencyType == CalciumTypes::UNDEFINED_DEPENDENCY )
 
  663         throw CalciumException(CalciumTypes::CPIT, LOC(
OSS()<<
"Dependency mode of variable " << nomVar << 
" is undefined."));
 
  666     if ( portDependencyType != CalciumTypes::ITERATION_DEPENDENCY )
 
  669                    "Dependency mode must be iteration mode");
 
  670         throw CalciumException(CalciumTypes::CPITVR, LOC(
OSS()<<
"Dependency mode of variable " << nomVar << 
": " 
  671                                 << portDependencyType << 
" must be iteration mode."));
 
  674     port->calcium_erase(0., i,
true);
 
  676     std::stringstream msg;
 
  685     CORBA::String_var componentName=component.
instanceName();
 
  717     CalciumTypes::DependencyType portDependencyType = port->getDependencyType();
 
  719     if ( portDependencyType == CalciumTypes::UNDEFINED_DEPENDENCY )
 
  722         throw CalciumException(CalciumTypes::CPIT, LOC(
OSS()<<
"Dependency mode of variable " << nomVar << 
" is undefined."));
 
  725     if ( portDependencyType != CalciumTypes::TIME_DEPENDENCY )
 
  728                    "Dependency mode must be time mode");
 
  729         throw CalciumException(CalciumTypes::CPITVR, LOC(
OSS()<<
"Dependency mode of variable " << nomVar << 
": " 
  730                                 << portDependencyType << 
" must be time mode."));
 
  733     port->calcium_erase(t, 0,
true);
 
  735     std::stringstream msg;
 
  744     CORBA::String_var componentName=component.
instanceName();
 
  776     CalciumTypes::DependencyType portDependencyType = port->getDependencyType();
 
  778     if ( portDependencyType == CalciumTypes::UNDEFINED_DEPENDENCY )
 
  781         throw CalciumException(CalciumTypes::CPIT, LOC(
OSS()<<
"Dependency mode of variable " << nomVar << 
" is undefined."));
 
  784     if ( portDependencyType != CalciumTypes::ITERATION_DEPENDENCY )
 
  787                    "Dependency mode must be iteration mode");
 
  788         throw CalciumException(CalciumTypes::CPITVR, LOC(
OSS()<<
"Dependency mode of variable " << nomVar << 
": " 
  789                                 << portDependencyType << 
" must be iteration mode."));
 
  792     port->calcium_erase(0., i,
false);
 
  794     std::stringstream msg;
 
  803     CORBA::String_var componentName=component.
instanceName();
 
  835     CalciumTypes::DependencyType portDependencyType = port->getDependencyType();
 
  837     if ( portDependencyType == CalciumTypes::UNDEFINED_DEPENDENCY )
 
  840         throw CalciumException(CalciumTypes::CPIT, LOC(
OSS()<<
"Dependency mode of variable " << nomVar << 
" is undefined."));
 
  843     if ( portDependencyType != CalciumTypes::TIME_DEPENDENCY )
 
  846                    "Dependency mode must be time mode");
 
  847         throw CalciumException(CalciumTypes::CPITVR, LOC(
OSS()<<
"Dependency mode of variable " << nomVar << 
": " 
  848                                 << portDependencyType << 
" must be time mode."));
 
  851     port->calcium_erase(t, 0,
false);
 
  853     std::stringstream msg;