User Manual, Developers Guide and API Documentation

TcpBinding.cpp

Go to the documentation of this file.
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/TcpBinding.hpp>
00029 
00030 #include <WNS/StaticFactory.hpp>
00031 #include <WNS/service/nl/Address.hpp>
00032 #include <WNS/service/tl/PortPool.hpp>
00033 #include <WNS/service/qos/QoSClasses.hpp>
00034 #include <WNS/module/Base.hpp>
00035 
00036 using namespace constanze;
00037 
00038 STATIC_FACTORY_REGISTER_WITH_CREATOR(
00039     constanze::TcpBinding,
00040     constanze::Binding,
00041     "TcpBinding",
00042     wns::PyConfigViewCreator);
00043 
00044 TcpBinding::TcpBinding(const wns::pyconfig::View& _pyco):
00045     pyco(_pyco),
00046     domainName(_pyco.get<std::string>("domainName")),
00047     destinationDomainName(_pyco.get<std::string>("destinationDomainName")),
00048     destinationPort(_pyco.get<int>("destinationPort")),
00049     log(pyco.get("logger"))
00050 {
00051     startTrigger = NULL;
00052     stopTrigger = NULL;
00053     tcpService = NULL;
00054     connection = NULL;
00055     component = NULL;
00056 
00057     MESSAGE_BEGIN(NORMAL, log, m, "New TcpBinding created. Destination=");
00058     m << destinationDomainName << ":" << destinationPort;
00059     MESSAGE_END();
00060 }
00061 
00062 void TcpBinding::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 TcpBinding::registerComponent(wns::node::component::Component* _component)
00071 {
00072     component = _component;
00073     tcpService =
00074         component->getService<wns::service::tl::Service*>(pyco.get<std::string>("tcpService"));
00075 }
00076 
00077 void TcpBinding::onConnectionEstablished(wns::service::nl::Address, wns::service::tl::Connection* _connection)
00078 {
00079     connection = _connection;
00080     startTrigger->bindingReady();
00081 }
00082 
00083 void TcpBinding::initBinding(constanze::StartTrigger* _startTrigger)
00084 {
00085     startTrigger = _startTrigger;
00086     tcpService->openConnection( destinationPort, domainName, destinationDomainName, qosClass, this);
00087 }
00088 
00089 void TcpBinding::releaseBinding(constanze::StopTrigger* _stopTrigger)
00090 {
00091     stopTrigger = _stopTrigger;
00092     tcpService->closeConnection( connection );
00093     stopTrigger->bindingReady();
00094 }
00095 
00096 void TcpBinding::registerListener(constanze::Listener* )
00097 {
00098     // intentionally left empty
00099 }
00100 void TcpBinding::onConnectionClosed(wns::service::tl::Connection*)
00101 {
00102     // intentionally left empty
00103 }
00104 
00105 void TcpBinding::onConnectionClosedByPeer(wns::service::tl::Connection*)
00106 {
00107     // intentionally left empty
00108 }
00109 
00110 void TcpBinding::onConnectionLost(wns::service::tl::Connection*)
00111 {
00112     // intentionally left empty
00113 }
00114 
00115 std::string
00116 TcpBinding::printAddress() const
00117 {
00118         std::ostringstream tmp;
00119         tmp << destinationDomainName << ":" << destinationPort;
00120         return tmp.str();
00121 }
00122 
00123 
00124 
00125 

Generated on Sat May 26 03:32:14 2012 for openWNS by  doxygen 1.5.5