1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : GenericUsesPort.hxx
23 // Author : Eric Fayolle (EDF)
25 // Modified by : $LastChangedBy$
26 // Date : $LastChangedDate: 2007-02-28 15:26:32 +0100 (mer, 28 fév 2007) $
29 #ifndef _GENERIC_USES_PORT_HXX_
30 #define _GENERIC_USES_PORT_HXX_
32 #include "CorbaTypeManipulator.hxx"
34 #include "uses_port.hxx"
35 #include "SALOME_Ports.hh"
37 #include "DSC_Exception.hxx"
39 // #define GENERATE_USES_PORT(dataManip,portType,portName) \
40 // const char * _repository_##portType##_name_ = "IDL:Ports/##portType##:1.0"; \
41 // GenericUsesPort< dataManip, portType, _repository_##portType##_name_ > portName;
43 //ex : GENERATE_USES_PORT(Ports::Data_Short_Port,data_short_port);
45 template <typename DataManipulator, typename CorbaPortType, char * repositoryName,
46 typename UsesPort=uses_port >
47 class GenericUsesPort : public UsesPort
50 // Type de données manipulés
51 typedef typename DataManipulator::Type DataType;
52 typedef typename DataManipulator::CorbaInType CorbaInDataType;
55 virtual ~GenericUsesPort();
57 virtual const char * get_repository_id();
58 template <typename TimeType,typename TagType>
59 void put(CorbaInDataType data, TimeType time, TagType tag);
61 virtual void uses_port_changed(Engines::DSC::uses_port * new_uses_port,
62 const Engines::DSC::Message message);
65 Engines::DSC::uses_port * _my_ports;
69 template <typename DataManipulator,typename CorbaPortType, char * repositoryName, typename UsesPort >
70 GenericUsesPort< DataManipulator,CorbaPortType, repositoryName, UsesPort >::GenericUsesPort() {
74 template <typename DataManipulator,typename CorbaPortType, char * repositoryName, typename UsesPort >
75 GenericUsesPort< DataManipulator,CorbaPortType, repositoryName, UsesPort >::~GenericUsesPort()
80 template <typename DataManipulator,typename CorbaPortType, char * repositoryName, typename UsesPort >
82 GenericUsesPort< DataManipulator,CorbaPortType, repositoryName, UsesPort >::get_repository_id() {
83 return repositoryName;
87 template <typename DataManipulator,typename CorbaPortType, char * repositoryName, typename UsesPort >
88 template <typename TimeType,typename TagType>
90 GenericUsesPort< DataManipulator,CorbaPortType, repositoryName, UsesPort >::put( CorbaInDataType data,
93 typedef typename CorbaPortType::_var_type CorbaPortTypeVar;
95 throw DSC_Exception(LOC("There is no connected provides port to communicate with."));
97 // OLD : PB1 : Cf remarque dans CalciumInterface, si on n'effectue pas de copie
99 // OLD : PB2 : Si les ports provides auquels on envoie data sont collocalisés
100 // OLD : ils vont partagés le même buffer (à cause de notre optim ds get_data)
101 // OLD : il faut alors effectuer une copie ici.
102 // OLD : Pour l'instant on résoud PB2 en créant une copie de la donnée en cas
103 // OLD : de connexions multiples. Il faudra tester la collocalisation.
104 // OLD : DataType copyOfData; // = data; PB1
105 for(int i = 0; i < _my_ports->length(); i++) {
107 CorbaPortTypeVar port = CorbaPortType::_narrow((*_my_ports)[i]);
109 //OLD : copyOfData = DataManipulator::clone(data);
110 MESSAGE("-------- GenericUsesPort::put -------- " );
113 port->put(data,time,tag);
114 // OLD : port->put(*copyOfData,time,tag);
115 } catch(const CORBA::SystemException& ex) {
116 //OLD : DataManipulator::delete_data(copyOfData);
117 throw DSC_Exception(LOC(OSS() << "Can't invoke put method on port number "
118 << i << "( i>= 0)"));
122 // La séquence est détruite avec le buffer si on n'est pas collocalisé
123 // La séquence est détruite sans son buffer sinon (cf comportement de get_data
124 // appelée dans put (port provides)
125 //OLD : DataManipulator::delete_data(copyOfData);
130 template <typename DataManipulator, typename CorbaPortType, char * repositoryName, typename UsesPort>
132 GenericUsesPort< DataManipulator, CorbaPortType, repositoryName, UsesPort
133 >::uses_port_changed(Engines::DSC::uses_port * new_uses_port,
134 const Engines::DSC::Message message)
136 if (_my_ports) delete _my_ports;
138 MESSAGE("GenericUsesPort::uses_port_changed");
139 _my_ports = new_uses_port;