Back to index

salome-kernel  6.5.0
GenericUsesPort.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  File   : GenericUsesPort.hxx
00024 //  Author : Eric Fayolle (EDF)
00025 //  Module : KERNEL
00026 // Modified by : $LastChangedBy$
00027 // Date        : $LastChangedDate: 2007-02-28 15:26:32 +0100 (mer, 28 fév 2007) $
00028 // Id          : $Id: GenericUsesPort.hxx,v 1.3.2.3.10.2.12.1 2012-04-12 14:05:06 vsr Exp $
00029 //
00030 #ifndef _GENERIC_USES_PORT_HXX_
00031 #define _GENERIC_USES_PORT_HXX_
00032 
00033 #include "CorbaTypeManipulator.hxx"
00034 
00035 #include "uses_port.hxx"
00036 #include "SALOME_Ports.hh"
00037 
00038 #include "DSC_Exception.hxx"
00039 
00040 // #define GENERATE_USES_PORT(dataManip,portType,portName)                      \
00041 //   const char * _repository_##portType##_name_ = "IDL:Ports/##portType##:1.0"; \
00042 //   GenericUsesPort< dataManip, portType, _repository_##portType##_name_ > portName;
00043 
00044 //ex : GENERATE_USES_PORT(Ports::Data_Short_Port,data_short_port);
00045 
00046 template <typename DataManipulator, typename CorbaPortType, char * repositoryName, 
00047           typename UsesPort=uses_port > 
00048 class GenericUsesPort : public UsesPort
00049 {
00050 public :
00051   // Type de données manipulés 
00052   typedef typename DataManipulator::Type         DataType;
00053   typedef typename DataManipulator::CorbaInType  CorbaInDataType;
00054 
00055   GenericUsesPort();
00056   virtual ~GenericUsesPort();
00057 
00058   virtual const char * get_repository_id();
00059   template <typename TimeType,typename TagType>
00060   void  put(CorbaInDataType data,  TimeType time, TagType tag); 
00061 
00062   virtual void uses_port_changed(Engines::DSC::uses_port * new_uses_port,
00063                                  const Engines::DSC::Message message);
00064 
00065 protected :
00066   Engines::DSC::uses_port * _my_ports;
00067 };
00068 
00069 
00070 template <typename DataManipulator,typename CorbaPortType, char * repositoryName, typename UsesPort > 
00071 GenericUsesPort< DataManipulator,CorbaPortType, repositoryName, UsesPort  >::GenericUsesPort() {
00072   _my_ports = NULL;
00073 }
00074 
00075 template <typename DataManipulator,typename CorbaPortType, char * repositoryName, typename UsesPort > 
00076 GenericUsesPort< DataManipulator,CorbaPortType, repositoryName, UsesPort  >::~GenericUsesPort() 
00077 {
00078   delete _my_ports;
00079 }
00080 
00081 template <typename DataManipulator,typename CorbaPortType, char * repositoryName, typename UsesPort > 
00082 const char *
00083 GenericUsesPort< DataManipulator,CorbaPortType, repositoryName, UsesPort  >::get_repository_id() {
00084   return repositoryName;
00085 }
00086 
00087 
00088 template <typename DataManipulator,typename CorbaPortType, char * repositoryName, typename UsesPort > 
00089 template <typename TimeType,typename TagType>
00090 void
00091 GenericUsesPort< DataManipulator,CorbaPortType, repositoryName, UsesPort  >::put( CorbaInDataType data, 
00092                                                                                   TimeType time, 
00093                                                                                   TagType tag) {
00094   typedef typename CorbaPortType::_var_type CorbaPortTypeVar;
00095   if (!_my_ports)
00096     throw DSC_Exception(LOC("There is no connected provides port to communicate with."));
00097 
00098   // OLD : PB1 : Cf remarque dans CalciumInterface, si on n'effectue pas de copie
00099   // OLD :       du buffer ! 
00100   // OLD : PB2 : Si les ports provides auquels on envoie data sont collocalisés
00101   // OLD : ils vont partagés le même buffer (à cause de notre optim ds get_data)
00102   // OLD : il faut alors effectuer une copie ici.
00103   // OLD : Pour l'instant on résoud PB2 en créant une copie de la donnée en cas
00104   // OLD : de connexions multiples. Il faudra tester la collocalisation.
00105   // OLD :  DataType copyOfData; // = data; PB1
00106   for(int i = 0; i < _my_ports->length(); i++) {
00107 
00108     CorbaPortTypeVar port = CorbaPortType::_narrow((*_my_ports)[i]);
00109     //if (i) { PB1
00110     //OLD :   copyOfData = DataManipulator::clone(data);
00111 #ifdef MYDEBUG
00112     std::cerr << "-------- GenericUsesPort::put -------- " << std::endl;
00113 #endif
00114     //} PB1
00115     try {
00116       port->put(data,time,tag);
00117       // OLD : port->put(*copyOfData,time,tag);
00118     } catch(const CORBA::SystemException& ex) {
00119       //OLD : DataManipulator::delete_data(copyOfData);
00120       throw DSC_Exception(LOC(OSS() << "Can't invoke put method on port number "
00121                               << i << "( i>=  0)"));
00122 
00123     }
00124     //if (i) PB1 
00125     // La séquence est détruite avec le buffer si on n'est pas collocalisé
00126     // La séquence est détruite sans son buffer sinon (cf comportement de get_data
00127     // appelée dans put (port provides)
00128     //OLD : DataManipulator::delete_data(copyOfData);
00129   }
00130 }
00131 
00132 
00133 template <typename DataManipulator, typename CorbaPortType, char * repositoryName, typename UsesPort>
00134 void 
00135 GenericUsesPort< DataManipulator, CorbaPortType, repositoryName, UsesPort  
00136                  >::uses_port_changed(Engines::DSC::uses_port * new_uses_port,
00137                                       const Engines::DSC::Message message)
00138 {
00139   if (_my_ports) delete _my_ports;
00140 
00141 #ifdef MYDEBUG
00142   std::cerr << "GenericUsesPort::uses_port_changed" << std::endl;
00143 #endif
00144   _my_ports = new_uses_port;
00145 }
00146 
00147 #endif