Version: 9.12.0
GenericUsesPort.hxx
Go to the documentation of this file.
1 // Copyright (C) 2007-2023 CEA, EDF, 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 :
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 < (int)_my_ports->length(); i++) { //TODO: mismatch signed/unsigned
107 
108  CorbaPortTypeVar port = CorbaPortType::_narrow((*_my_ports)[i]);
109  //if (i) { PB1
110  //OLD : copyOfData = DataManipulator::clone(data);
112  std::cerr << "-------- GenericUsesPort::put -------- " << std::endl;
113  //} PB1
114  try {
115  port->put(data,time,tag);
116  // OLD : port->put(*copyOfData,time,tag);
117  } catch(const CORBA::SystemException& ex) {
118  //OLD : DataManipulator::delete_data(copyOfData);
119  throw DSC_Exception(LOC(OSS() << "Can't invoke put method on port number "
120  << i << "( i>= 0)"));
121 
122  }
123  //if (i) PB1
124  // La séquence est détruite avec le buffer si on n'est pas collocalisé // La séquence est détruite sans son buffer sinon (cf comportement de get_data // appelée dans put (port provides) //OLD : DataManipulator::delete_data(copyOfData); } } template <typename DataManipulator, typename CorbaPortType, char * repositoryName, typename UsesPort> void GenericUsesPort< DataManipulator, CorbaPortType, repositoryName, UsesPort >::uses_port_changed(Engines::DSC::uses_port * new_uses_port, const Engines::DSC::Message /*message*/) { if (_my_ports) delete _my_ports; if (SALOME::VerbosityActivated()) std::cerr << "GenericUsesPort::uses_port_changed" << std::endl; _my_ports = new_uses_port; } #endif
125  // La séquence est détruite sans son buffer sinon (cf comportement de get_data
126  // appelée dans put (port provides)
127  //OLD : DataManipulator::delete_data(copyOfData);
128  }
129 }
130 
131 
132 template <typename DataManipulator, typename CorbaPortType, char * repositoryName, typename UsesPort>
133 void
134 GenericUsesPort< DataManipulator, CorbaPortType, repositoryName, UsesPort
135  >::uses_port_changed(Engines::DSC::uses_port * new_uses_port,
136  const Engines::DSC::Message /*message*/)
137 {
138  if (_my_ports) delete _my_ports;
139 
141  std::cerr << "GenericUsesPort::uses_port_changed" << std::endl;
142 
143  _my_ports = new_uses_port;
144 }
145 
146 #endif
#define LOC(message)
Definition: DSC_Exception.hxx:55
Definition: GenericUsesPort.hxx:49
virtual ~GenericUsesPort()
Definition: GenericUsesPort.hxx:76
GenericUsesPort()
Definition: GenericUsesPort.hxx:71
void put(CorbaInDataType data, TimeType time, TagType tag)
Definition: GenericUsesPort.hxx:91
virtual const char * get_repository_id()
This is used by the component to get the CORBA repository id of the uses port.
Definition: GenericUsesPort.hxx:83
DataManipulator::CorbaInType CorbaInDataType
Definition: GenericUsesPort.hxx:53
virtual void uses_port_changed(Engines::DSC::uses_port *new_uses_port, const Engines::DSC::Message message)
This method is the uses port's callback to be aware of connections states.
Definition: GenericUsesPort.hxx:135
Engines::DSC::uses_port * _my_ports
Definition: GenericUsesPort.hxx:66
DataManipulator::Type DataType
Definition: GenericUsesPort.hxx:52
Class OSS is useful when streaming data through a function that expect a string as parameter.
Definition: DSC_Exception.hxx:65
This class implements a DSC_User uses C++ port.
Definition: uses_port.hxx:44
Message
This enumeration is used when the connection of a port (uses or provides) is changed.
Definition: DSC_Engines.idl:79
sequence< Ports::Port > uses_port
a uses port
Definition: DSC_Engines.idl:73
bool VerbosityActivated()
Called by any log message macros to decide about log output in Release and Debug mode dynamically rel...
Definition: libSALOMELog.cxx:48
port
Definition: salome_instance.py:114
Definition: DSC_Exception.hxx:94
double TagType
Definition: testAdjacentPredicate.cxx:53
int TimeType
Definition: testAdjacentPredicate.cxx:52