User Manual, Developers Guide and API Documentation

TcpListenerBinding.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/TcpListenerBinding.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::TcpListenerBinding,
00039     constanze::Binding,
00040     "TcpListenerBinding",
00041     wns::PyConfigViewCreator);
00042 
00043 TcpListenerBinding::TcpListenerBinding(const wns::pyconfig::View& _pyco):
00044     pyco(_pyco),
00045     listenPort(_pyco.get<int>("listenPort")),
00046     //log("CONST","TcpListenerBinding",wns::module::Base::getService<wns::logger::Master>("W-NS-MSG"))
00047     log(pyco.get("logger"))
00048 {
00049     MESSAGE_BEGIN(NORMAL, log, m, "New TcpListenerBinding created on my socket=");
00050     m << ownAddress << ":" << listenPort;
00051     MESSAGE_END();
00052 }
00053 
00054 void TcpListenerBinding::sendData(const wns::osi::PDUPtr&)
00055 {
00056     // intentionally left empty
00057 }
00058 
00059 void TcpListenerBinding::registerComponent(wns::node::component::Component* _component)
00060 {
00061     component = _component;
00062     tcpService =
00063         component->getService<wns::service::tl::Service*>(
00064             pyco.get<std::string>("tcpService"));
00065     tcpService->listenOnPort(listenPort, this);
00066 }
00067 
00068 void TcpListenerBinding::onConnectionEstablished(wns::service::nl::Address _address, wns::service::tl::Connection* _connection)
00069 {
00070     ownAddress = _address;
00071     _connection->registerDataHandler(this);
00072 }
00073 
00074 void TcpListenerBinding::onData(const wns::osi::PDUPtr& _data)
00075 {
00076     assure(listener, "No listener set.");
00077     MESSAGE_BEGIN(NORMAL, log, m, "Received " << _data->getLengthInBits()/8 << " bytes"); // "from ?"
00078     m << " on my socket=" << ownAddress << ":" << listenPort;
00079     MESSAGE_END();
00080     listener->onData(_data);
00081 }
00082 
00083 void TcpListenerBinding::registerListener(constanze::Listener* _listener)
00084 {
00085     listener = _listener;
00086 }
00087 
00088 void TcpListenerBinding::initBinding(constanze::StartTrigger* )
00089 {
00090     // intentionally left empty
00091 }
00092 
00093 void TcpListenerBinding::releaseBinding(constanze::StopTrigger*)
00094 {
00096 }
00097 
00098 void TcpListenerBinding::onConnectionClosed(wns::service::tl::Connection*)
00099 {
00100     // TCP has no connection that can be closed
00101     // intentionally left empty
00102 }
00103 
00104 void TcpListenerBinding::onConnectionClosedByPeer(wns::service::tl::Connection*)
00105 {
00106     // TCP has no connection that can be closed
00107     // intentionally left empty
00108 }
00109 
00110 void TcpListenerBinding::onConnectionLost(wns::service::tl::Connection*)
00111 {
00112     // TCP has no connection that can be closed
00113     // intentionally left empty
00114 }
00115 
00116 std::string
00117 TcpListenerBinding::printAddress() const
00118 {
00119     std::ostringstream tmp;
00120     tmp << ownAddress << ":" << listenPort;
00121     return tmp.str();
00122 }
00123 
00124 

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