![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /****************************************************************************** 00002 * UDP ClientBinding * 00003 * __________________________________________________________________________ * 00004 * * 00005 * Copyright (C) 2005 * 00006 * Lehrstuhl fuer Kommunikationsnetze (ComNets) * 00007 * Kopernikusstr. 16, D-52074 Aachen, Germany * 00008 * phone: ++49-241-80-27910 (phone), fax: ++49-241-80-22242 * 00009 * email: wns@comnetsrwth-aachen.de, www: http://wns.comnets.rwth-aachen.de/ * 00010 *****************************************************************************/ 00011 00012 #include <CONSTANZE/UdpClientBinding.hpp> 00013 #include <CONSTANZE/UdpClientListenerBinding.hpp> 00014 #include <CONSTANZE/Listener.hpp> 00015 00016 #include <WNS/StaticFactory.hpp> 00017 #include <WNS/service/nl/Address.hpp> 00018 #include <WNS/service/tl/PortPool.hpp> 00019 #include <WNS/module/Base.hpp> 00020 00021 using namespace constanze; 00022 00023 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00024 constanze::UdpClientBinding, 00025 constanze::Binding, 00026 "UdpClientBinding", 00027 wns::PyConfigViewCreator); 00028 00029 UdpClientBinding::UdpClientBinding(const wns::pyconfig::View& _pyco): 00030 pyco(_pyco), 00031 dns(NULL), 00032 domainName(_pyco.get<std::string>("domainName")), 00033 destinationDomainName(_pyco.get<std::string>("destinationDomainName")), 00034 destinationPort(_pyco.get<int>("destinationPort")), 00035 qosClass(_pyco.get<int>("qosClass")), // aoz does not support this solution. aoz wanted the qosClass to be a parameter of the generator 00036 log(pyco.get("logger")), 00037 listener(0), 00038 packetCounter(0), 00039 bitCounter(0), 00040 nodeID(0) 00041 { 00042 startTrigger = NULL; 00043 stopTrigger = NULL; 00044 udpService = NULL; 00045 connection = NULL; 00046 component = NULL; 00047 00048 listener = NULL; 00049 00050 MESSAGE_BEGIN(NORMAL, log, m, "New UdpClientBinding created. Destination="); 00051 m << destinationDomainName << ":" << destinationPort; 00052 if (qosClass != 0) { // UNDEFINED == 0 00053 m << ", QoSClass="<<qosClass; 00054 } 00055 MESSAGE_END(); 00056 } 00057 00058 UdpClientBinding::~UdpClientBinding() 00059 { 00060 MESSAGE_BEGIN(NORMAL, log, m, "Received a total of "); 00061 m << packetCounter << " packets with " << bitCounter << " bits"; 00062 MESSAGE_END(); 00063 } 00064 00065 00066 void 00067 UdpClientBinding::sendData(const wns::osi::PDUPtr& _data) 00068 { 00069 assure(connection, "No connection available."); 00070 00071 //MESSAGE_SINGLE(NORMAL, log, "sendData to destination: " << destinationDomainName << ":" << destinationPort); 00072 MESSAGE_SINGLE(NORMAL, log, "sendData to destination: " << peerAddress << ":" << destinationPort); 00073 connection->sendData(_data); 00074 } 00075 00076 void 00077 UdpClientBinding::registerComponent(wns::node::component::Component* _component) 00078 { 00079 component = _component; 00080 udpService = 00081 component->getService<wns::service::tl::Service*>(pyco.get<std::string>("udpService")); 00082 dns = component->getService<wns::service::nl::DNSService*>(pyco.get<std::string>("dnsService")); 00083 00084 00085 wns::pyconfig::View listenerView = pyco.get("listener"); 00086 listener = new Listener(listenerView, component); 00087 00088 nodeID = component->getNode()->getNodeID(); 00089 } 00090 00091 void 00092 UdpClientBinding::onConnectionEstablished(wns::service::nl::Address, wns::service::tl::Connection* _connection) 00093 { 00094 connection = _connection; 00095 startTrigger->bindingReady(); 00096 connection->registerDataHandler(this); 00097 } 00098 00099 void 00100 UdpClientBinding::onData(const wns::osi::PDUPtr& _pdu) 00101 { 00102 assure(_pdu , "data is empty."); 00103 //assureType(_pdu.getPtr(), ConstanzePDU*); 00104 int bits = _pdu->getLengthInBits(); 00105 packetCounter ++; 00106 bitCounter += bits; 00107 00108 MESSAGE_SINGLE(NORMAL, log, "Received " << _pdu->getLengthInBits()/8 << " bytes"); 00109 listener->onData(_pdu); 00110 } 00111 00112 void 00113 UdpClientBinding::initBinding(constanze::StartTrigger* _startTrigger) 00114 { 00115 startTrigger = _startTrigger; 00116 udpService->openConnection( destinationPort, domainName, destinationDomainName, qosClass, this); 00117 assure(dns!=NULL,"dns needed"); 00118 wns::service::nl::Address peerAddress = dns->lookup(destinationDomainName); 00119 } 00120 00121 void 00122 UdpClientBinding::releaseBinding(constanze::StopTrigger* _stopTrigger) 00123 { 00124 stopTrigger = _stopTrigger; 00125 udpService->closeConnection( connection ); 00126 stopTrigger->bindingReady(); 00127 } 00128 00129 void 00130 UdpClientBinding::registerListener(constanze::Listener*) 00131 { 00132 // intentionally left empty 00133 } 00134 void 00135 UdpClientBinding::onConnectionClosed(wns::service::tl::Connection*) 00136 { 00137 // intentionally left empty 00138 } 00139 00140 void 00141 UdpClientBinding::onConnectionClosedByPeer(wns::service::tl::Connection*) 00142 { 00143 // intentionally left empty 00144 } 00145 00146 void 00147 UdpClientBinding::onConnectionLost(wns::service::tl::Connection*) 00148 { 00149 // intentionally left empty 00150 } 00151 00152 std::string 00153 UdpClientBinding::printAddress() const 00154 { 00155 std::ostringstream tmp; 00156 //tmp << destinationDomainName << ":" << destinationPort; 00157 tmp << peerAddress << ":" << destinationPort; 00158 return tmp.str(); 00159 } 00160 00161 00162 00163
1.5.5