Version: 8.3.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
GenericUsesPort.hxx
1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 
23 // File : GenericUsesPort.hxx
24 // Author : Eric Fayolle (EDF)
25 // Module : KERNEL
26 // Modified by : $LastChangedBy$
27 // Date : $LastChangedDate: 2007-02-28 15:26:32 +0100 (mer, 28 fév 2007) $
28 // Id : $Id$
29 //
30 #ifndef _GENERIC_USES_PORT_HXX_
31 #define _GENERIC_USES_PORT_HXX_
32 
33 #include "CorbaTypeManipulator.hxx"
34 
35 #include "uses_port.hxx"
36 #include "SALOME_Ports.hh"
37 
38 #include "DSC_Exception.hxx"
39 
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;
43 
44 //ex : GENERATE_USES_PORT(Ports::Data_Short_Port,data_short_port);
45 
46 template <typename DataManipulator, typename CorbaPortType, char * repositoryName,
47  typename UsesPort=uses_port >
48 class GenericUsesPort : public UsesPort
49 {
50 public :
51  // Type de données manipulés
52  typedef typename DataManipulator::Type DataType;
53  typedef typename DataManipulator::CorbaInType CorbaInDataType;
54 
56  virtual ~GenericUsesPort();
57 
58  virtual const char * get_repository_id();
59  template <typename TimeType,typename TagType>
60  void put(CorbaInDataType data, TimeType time, TagType tag);
61 
62  virtual void uses_port_changed(Engines::DSC::uses_port * new_uses_port,
63  const Engines::DSC::Message message);
64 
65 protected :
66  Engines::DSC::uses_port * _my_ports;
67 };
68 
69 
70 template <typename DataManipulator,typename CorbaPortType, char * repositoryName, typename UsesPort >
72  _my_ports = NULL;
73 }
74 
75 template <typename DataManipulator,typename CorbaPortType, char * repositoryName, typename UsesPort >
77 {
78  delete _my_ports;
79 }
80 
81 template <typename DataManipulator,typename CorbaPortType, char * repositoryName, typename UsesPort >
82 const char *
84  return repositoryName;
85 }
86 
87 
88 template <typename DataManipulator,typename CorbaPortType, char * repositoryName, typename UsesPort >
89 template <typename TimeType,typename TagType>
90 void
92  TimeType time,
93  TagType tag) {
94  typedef typename CorbaPortType::_var_type CorbaPortTypeVar;
95  if (!_my_ports)
96  throw DSC_Exception(LOC("There is no connected provides port to communicate with."));
97 
98  // OLD : PB1 : Cf remarque dans CalciumInterface, si on n'effectue pas de copie
99  // OLD : du buffer !
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++) {
107 
108  CorbaPortTypeVar port = CorbaPortType::_narrow((*_my_ports)[i]);
109  //if (i) { PB1
110  //OLD : copyOfData = DataManipulator::clone(data);
111 #ifdef MYDEBUG
112  std::cerr << "-------- GenericUsesPort::put -------- " << std::endl;
113 #endif
114  //} PB1
115  try {
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)"));
122 
123  }
124  //if (i) PB1
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);
129  }
130 }
131 
132 
133 template <typename DataManipulator, typename CorbaPortType, char * repositoryName, typename UsesPort>
134 void
135 GenericUsesPort< DataManipulator, CorbaPortType, repositoryName, UsesPort
136  >::uses_port_changed(Engines::DSC::uses_port * new_uses_port,
137  const Engines::DSC::Message message)
138 {
139  if (_my_ports) delete _my_ports;
140 
141 #ifdef MYDEBUG
142  std::cerr << "GenericUsesPort::uses_port_changed" << std::endl;
143 #endif
144  _my_ports = new_uses_port;
145 }
146 
147 #endif