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 #ifndef _GENERIC_USES_PORT_HXX_
00030 #define _GENERIC_USES_PORT_HXX_
00031
00032 #include "CorbaTypeManipulator.hxx"
00033
00034 #include "uses_port.hxx"
00035 #include "SALOME_Ports.hh"
00036
00037 #include "DSC_Exception.hxx"
00038
00039
00040
00041
00042
00043
00044
00045 template <typename DataManipulator, typename CorbaPortType, char * repositoryName,
00046 typename UsesPort=uses_port >
00047 class GenericUsesPort : public UsesPort
00048 {
00049 public :
00050
00051 typedef typename DataManipulator::Type DataType;
00052 typedef typename DataManipulator::CorbaInType CorbaInDataType;
00053
00054 GenericUsesPort();
00055 virtual ~GenericUsesPort();
00056
00057 virtual const char * get_repository_id();
00058 template <typename TimeType,typename TagType>
00059 void put(CorbaInDataType data, TimeType time, TagType tag);
00060
00061 virtual void uses_port_changed(Engines::DSC::uses_port * new_uses_port,
00062 const Engines::DSC::Message message);
00063
00064 protected :
00065 Engines::DSC::uses_port * _my_ports;
00066 };
00067
00068
00069 template <typename DataManipulator,typename CorbaPortType, char * repositoryName, typename UsesPort >
00070 GenericUsesPort< DataManipulator,CorbaPortType, repositoryName, UsesPort >::GenericUsesPort() {
00071 _my_ports = NULL;
00072 }
00073
00074 template <typename DataManipulator,typename CorbaPortType, char * repositoryName, typename UsesPort >
00075 GenericUsesPort< DataManipulator,CorbaPortType, repositoryName, UsesPort >::~GenericUsesPort()
00076 {
00077 delete _my_ports;
00078 }
00079
00080 template <typename DataManipulator,typename CorbaPortType, char * repositoryName, typename UsesPort >
00081 const char *
00082 GenericUsesPort< DataManipulator,CorbaPortType, repositoryName, UsesPort >::get_repository_id() {
00083 return repositoryName;
00084 }
00085
00086
00087 template <typename DataManipulator,typename CorbaPortType, char * repositoryName, typename UsesPort >
00088 template <typename TimeType,typename TagType>
00089 void
00090 GenericUsesPort< DataManipulator,CorbaPortType, repositoryName, UsesPort >::put( CorbaInDataType data,
00091 TimeType time,
00092 TagType tag) {
00093 typedef typename CorbaPortType::_var_type CorbaPortTypeVar;
00094 if (!_my_ports)
00095 throw DSC_Exception(LOC("There is no connected provides port to communicate with."));
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 for(int i = 0; i < _my_ports->length(); i++) {
00106
00107 CorbaPortTypeVar port = CorbaPortType::_narrow((*_my_ports)[i]);
00108
00109
00110 #ifdef MYDEBUG
00111 std::cerr << "-------- GenericUsesPort::put -------- " << std::endl;
00112 #endif
00113
00114 try {
00115 port->put(data,time,tag);
00116
00117 } catch(const CORBA::SystemException& ex) {
00118
00119 throw DSC_Exception(LOC(OSS() << "Can't invoke put method on port number "
00120 << i << "( i>= 0)"));
00121
00122 }
00123
00124
00125
00126
00127
00128 }
00129 }
00130
00131
00132 template <typename DataManipulator, typename CorbaPortType, char * repositoryName, typename UsesPort>
00133 void
00134 GenericUsesPort< DataManipulator, CorbaPortType, repositoryName, UsesPort
00135 >::uses_port_changed(Engines::DSC::uses_port * new_uses_port,
00136 const Engines::DSC::Message message)
00137 {
00138 if (_my_ports) delete _my_ports;
00139
00140 #ifdef MYDEBUG
00141 std::cerr << "GenericUsesPort::uses_port_changed" << std::endl;
00142 #endif
00143 _my_ports = new_uses_port;
00144 }
00145
00146 #endif