User Manual, Developers Guide and API Documentation

IpListenerBinding.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/IpListenerBinding.hpp>
00029 
00030 #include <WNS/StaticFactory.hpp>
00031 #include <WNS/module/Base.hpp>
00032 #include <WNS/service/nl/Address.hpp>
00033 
00034 using namespace constanze;
00035 
00036 STATIC_FACTORY_REGISTER_WITH_CREATOR(
00037     constanze::IpListenerBinding,
00038     constanze::Binding,
00039     "IpListenerBinding",
00040     wns::PyConfigViewCreator);
00041 
00042 IpListenerBinding::IpListenerBinding(const wns::pyconfig::View& _pyco):
00043     pyco(_pyco),
00044     component(NULL),
00045     ipNotification(NULL),
00046     listener(NULL),
00047     listenDomainName(pyco.get<std::string>("listenDomainName")),
00048     log(pyco.get("logger"))
00049 {
00050     MESSAGE_BEGIN(NORMAL, log, m, "New IpListenerBinding created for own IP=");
00051     m << listenDomainName; // own IP address
00052     MESSAGE_END();
00053 }
00054 
00055 void IpListenerBinding::sendData(const wns::osi::PDUPtr&)
00056 {
00057     // intentionally left empty
00058 }
00059 
00060 void IpListenerBinding::registerComponent(wns::node::component::Component* _component)
00061 {
00062     component = _component;
00063     ipNotification =
00064         component->getService<wns::service::nl::Notification*>(
00065             pyco.get<std::string>("ipNotification"));
00066     ipNotification->registerHandler(wns::service::nl::Constanze, this);
00067 }
00068 
00069 void IpListenerBinding::onData(wns::service::nl::Address
00070 #ifndef WNS_NO_LOGGING
00071                                _address
00072 #endif
00073                                , const wns::osi::PDUPtr& _data)
00074 {
00075     assure(listener, "No listener set.");
00076     MESSAGE_BEGIN(NORMAL, log, m, "Received " << _data->getLengthInBits()/8 << " bytes from IP=" << _address);
00077     MESSAGE_END();
00078     listener->onData(_data);
00079 }
00080 
00081 void IpListenerBinding::registerListener(constanze::Listener* _listener)
00082 {
00083     listener = _listener;
00084 }
00085 
00086 void IpListenerBinding::initBinding(constanze::StartTrigger* _trigger)
00087 {
00088     _trigger->bindingReady();
00089 }
00090 
00091 void IpListenerBinding::releaseBinding(constanze::StopTrigger* _trigger)
00092 {
00093     _trigger->bindingReady();
00094 }
00095 
00096 std::string IpListenerBinding::printAddress() const
00097 {
00098     std::ostringstream tmp;
00099     tmp << listenDomainName;
00100     return tmp.str();
00101 }
00102 

Generated on Thu May 24 03:32:15 2012 for openWNS by  doxygen 1.5.5