Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
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
00041
00042
00043
00044
00045
00046 template <typename DataManipulator, typename CorbaPortType, char * repositoryName,
00047 typename UsesPort=uses_port >
00048 class GenericUsesPort : public UsesPort
00049 {
00050 public :
00051
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
00099
00100
00101
00102
00103
00104
00105
00106 for(int i = 0; i < _my_ports->length(); i++) {
00107
00108 CorbaPortTypeVar port = CorbaPortType::_narrow((*_my_ports)[i]);
00109
00110
00111 #ifdef MYDEBUG
00112 std::cerr << "-------- GenericUsesPort::put -------- " << std::endl;
00113 #endif
00114
00115 try {
00116 port->put(data,time,tag);
00117
00118 } catch(const CORBA::SystemException& ex) {
00119
00120 throw DSC_Exception(LOC(OSS() << "Can't invoke put method on port number "
00121 << i << "( i>= 0)"));
00122
00123 }
00124
00125
00126
00127
00128
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