![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /******************************************************************************* 00002 * This file is part of openWNS (open Wireless Network Simulator) 00003 * _____________________________________________________________________________ 00004 * 00005 * Copyright (C) 2004-2007 00006 * Chair of Communication Networks (ComNets) 00007 * Kopernikusstr. 16, D-52074 Aachen, Germany 00008 * phone: ++49-241-80-27910, 00009 * fax: ++49-241-80-22242 00010 * email: info@openwns.org 00011 * www: http://www.openwns.org 00012 * _____________________________________________________________________________ 00013 * 00014 * openWNS is free software; you can redistribute it and/or modify it under the 00015 * terms of the GNU Lesser General Public License version 2 as published by the 00016 * Free Software Foundation; 00017 * 00018 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00019 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00020 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00021 * details. 00022 * 00023 * You should have received a copy of the GNU Lesser General Public License 00024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00025 * 00026 ******************************************************************************/ 00027 00028 #include <CONSTANZE/UdpBinding.hpp> 00029 00030 #include <WNS/StaticFactory.hpp> 00031 #include <WNS/service/nl/Address.hpp> 00032 #include <WNS/service/tl/PortPool.hpp> 00033 #include <WNS/module/Base.hpp> 00034 00035 using namespace constanze; 00036 00037 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00038 constanze::UdpBinding, 00039 constanze::Binding, 00040 "UdpBinding", 00041 wns::PyConfigViewCreator); 00042 00043 UdpBinding::UdpBinding(const wns::pyconfig::View& _pyco): 00044 pyco(_pyco), 00045 domainName(_pyco.get<std::string>("domainName")), 00046 destinationDomainName(_pyco.get<std::string>("destinationDomainName")), 00047 destinationPort(_pyco.get<int>("destinationPort")), 00048 qosClass(_pyco.get<int>("qosClass")), // aoz does not support this solution. aoz wanted the qosClass to be a parameter of the generator 00049 log(pyco.get("logger")) 00050 { 00051 startTrigger = NULL; 00052 stopTrigger = NULL; 00053 udpService = NULL; 00054 connection = NULL; 00055 component = NULL; 00056 00057 MESSAGE_BEGIN(NORMAL, log, m, "New UdpBinding created. Destination="); 00058 m << destinationDomainName << ":" << destinationPort; 00059 MESSAGE_END(); 00060 } 00061 00062 void UdpBinding::sendData(const wns::osi::PDUPtr& _data) 00063 { 00064 assure(connection, "No connection available."); 00065 MESSAGE_SINGLE(NORMAL, log, "sendData to destination : " << destinationDomainName << ":" << destinationPort); 00066 connection->sendData(_data); 00067 00068 } 00069 00070 void UdpBinding::registerComponent(wns::node::component::Component* _component) 00071 { 00072 component = _component; 00073 udpService = 00074 component->getService<wns::service::tl::Service*>(pyco.get<std::string>("udpService")); 00075 } 00076 00077 void UdpBinding::onConnectionEstablished(wns::service::nl::Address, wns::service::tl::Connection* _connection) 00078 { 00079 connection = _connection; 00080 startTrigger->bindingReady(); 00081 } 00082 00083 void UdpBinding::initBinding(constanze::StartTrigger* _startTrigger) 00084 { 00085 startTrigger = _startTrigger; 00086 MESSAGE_SINGLE(NORMAL, log, "initBinding(): Opening UDP connection to " << destinationDomainName << ":" << destinationPort << " from " << domainName); 00087 udpService->openConnection( destinationPort, domainName, destinationDomainName, qosClass, this); 00088 } 00089 00090 void UdpBinding::releaseBinding(constanze::StopTrigger* _stopTrigger) 00091 { 00092 stopTrigger = _stopTrigger; 00093 MESSAGE_SINGLE(NORMAL, log, "releaseBinding(): Closing UDP connection."); 00094 udpService->closeConnection( connection ); 00095 stopTrigger->bindingReady(); 00096 } 00097 00098 void UdpBinding::registerListener(constanze::Listener* ) 00099 { 00100 // intentionally left empty 00101 } 00102 void UdpBinding::onConnectionClosed(wns::service::tl::Connection*) 00103 { 00104 // intentionally left empty 00105 } 00106 00107 void UdpBinding::onConnectionClosedByPeer(wns::service::tl::Connection*) 00108 { 00109 // intentionally left empty 00110 } 00111 00112 void UdpBinding::onConnectionLost(wns::service::tl::Connection*) 00113 { 00114 // intentionally left empty 00115 } 00116 00117 std::string UdpBinding::printAddress() const 00118 { 00119 std::ostringstream tmp; 00120 tmp << destinationDomainName << ":" << destinationPort; 00121 return tmp.str(); 00122 } 00123 00124 00125 00126
1.5.5