1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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
23 // File : GenericUsesPort.hxx
24 // Author : Eric Fayolle (EDF)
26 // Modified by : $LastChangedBy$
27 // Date : $LastChangedDate: 2007-02-28 15:26:32 +0100 (mer, 28 fév 2007) $
30 #ifndef _GENERIC_USES_PORT_HXX_
31 #define _GENERIC_USES_PORT_HXX_
33 #include "CorbaTypeManipulator.hxx"
35 #include "uses_port.hxx"
36 #include "SALOME_Ports.hh"
38 #include "DSC_Exception.hxx"
40 // #define GENERATE_USES_PORT(dataManip,portType,portName) \
41 // const char * _repository_##portType##_name_ = "IDL:Ports/##portType##:1.0"; \
42 // GenericUsesPort< dataManip, portType, _repository_##portType##_name_ > portName;
44 //ex : GENERATE_USES_PORT(Ports::Data_Short_Port,data_short_port);
46 template <typename DataManipulator, typename CorbaPortType, char * repositoryName,
47 typename UsesPort=uses_port >
48 class GenericUsesPort : public UsesPort
51 // Type de données manipulés
52 typedef typename DataManipulator::Type DataType;
53 typedef typename DataManipulator::CorbaInType CorbaInDataType;
56 virtual ~GenericUsesPort();
58 virtual const char * get_repository_id();
59 template <typename TimeType,typename TagType>
60 void put(CorbaInDataType data, TimeType time, TagType tag);
62 virtual void uses_port_changed(Engines::DSC::uses_port * new_uses_port,
63 const Engines::DSC::Message message);
66 Engines::DSC::uses_port * _my_ports;
70 template <typename DataManipulator,typename CorbaPortType, char * repositoryName, typename UsesPort >
71 GenericUsesPort< DataManipulator,CorbaPortType, repositoryName, UsesPort >::GenericUsesPort() {
75 template <typename DataManipulator,typename CorbaPortType, char * repositoryName, typename UsesPort >
76 GenericUsesPort< DataManipulator,CorbaPortType, repositoryName, UsesPort >::~GenericUsesPort()
81 template <typename DataManipulator,typename CorbaPortType, char * repositoryName, typename UsesPort >
83 GenericUsesPort< DataManipulator,CorbaPortType, repositoryName, UsesPort >::get_repository_id() {
84 return repositoryName;
88 template <typename DataManipulator,typename CorbaPortType, char * repositoryName, typename UsesPort >
89 template <typename TimeType,typename TagType>
91 GenericUsesPort< DataManipulator,CorbaPortType, repositoryName, UsesPort >::put( CorbaInDataType data,
94 typedef typename CorbaPortType::_var_type CorbaPortTypeVar;
96 throw DSC_Exception(LOC("There is no connected provides port to communicate with."));
98 // OLD : PB1 : Cf remarque dans CalciumInterface, si on n'effectue pas de copie
100 // OLD : PB2 : Si les ports provides auquels on envoie data sont collocalisés
101 // OLD : ils vont partagés le même buffer (à cause de notre optim ds get_data)
102 // OLD : il faut alors effectuer une copie ici.
103 // OLD : Pour l'instant on résoud PB2 en créant une copie de la donnée en cas
104 // OLD : de connexions multiples. Il faudra tester la collocalisation.
105 // OLD : DataType copyOfData; // = data; PB1
106 for(int i = 0; i < _my_ports->length(); i++) {
108 CorbaPortTypeVar port = CorbaPortType::_narrow((*_my_ports)[i]);
110 //OLD : copyOfData = DataManipulator::clone(data);
112 std::cerr << "-------- GenericUsesPort::put -------- " << std::endl;
116 port->put(data,time,tag);
117 // OLD : port->put(*copyOfData,time,tag);
118 } catch(const CORBA::SystemException& ex) {
119 //OLD : DataManipulator::delete_data(copyOfData);
120 throw DSC_Exception(LOC(OSS() << "Can't invoke put method on port number "
121 << i << "( i>= 0)"));
125 // La séquence est détruite avec le buffer si on n'est pas collocalisé
126 // La séquence est détruite sans son buffer sinon (cf comportement de get_data
127 // appelée dans put (port provides)
128 //OLD : DataManipulator::delete_data(copyOfData);
133 template <typename DataManipulator, typename CorbaPortType, char * repositoryName, typename UsesPort>
135 GenericUsesPort< DataManipulator, CorbaPortType, repositoryName, UsesPort
136 >::uses_port_changed(Engines::DSC::uses_port * new_uses_port,
137 const Engines::DSC::Message message)
139 if (_my_ports) delete _my_ports;
142 std::cerr << "GenericUsesPort::uses_port_changed" << std::endl;
144 _my_ports = new_uses_port;