![]() |
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. 5, 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 <APPLICATIONS/session/Session.hpp> 00029 #include <APPLICATIONS/session/server/TLListenerBinding.hpp> 00030 00031 #include <WNS/StaticFactory.hpp> 00032 #include <WNS/service/qos/QoSClasses.hpp> 00033 00034 using namespace applications::session::server; 00035 00036 STATIC_FACTORY_REGISTER_WITH_CREATOR(applications::session::server::TLListenerBinding, 00037 applications::session::Binding, 00038 "TLListenerBinding", wns::PyConfigViewCreator); 00039 00040 TLListenerBinding::TLListenerBinding(const wns::pyconfig::View& _pyco): 00041 pyco(_pyco), 00042 listenPort(_pyco.get<int>("listenPort")), 00043 destinationPort(_pyco.get<int>("destinationPort")), 00044 domainName(_pyco.get<std::string>("domainName")), 00045 destinationDomainName(_pyco.get<std::string>("destinationDomainName")), 00046 qosClass(_pyco.get<int>("qosClass")), 00047 logger(pyco.get("logger")), 00048 sessionIndex(0) 00049 { 00050 tlService = NULL; 00051 component = NULL; 00052 } 00053 00054 TLListenerBinding::~TLListenerBinding() 00055 { 00056 tlService = NULL; 00057 component = NULL; 00058 } 00059 00060 void 00061 TLListenerBinding::registerComponent(applications::node::component::Component* _component, int _sessionIndex) 00062 { 00063 component = _component; 00064 sessionIndex = _sessionIndex; 00065 00066 // Start listening! 00067 tlService = 00068 component->getService<wns::service::tl::Service*>(pyco.get<std::string>("tlService")); 00069 tlService->listenOnPort(listenPort, this); 00070 } 00071 00072 void 00073 TLListenerBinding::onConnectionEstablished(wns::service::nl::Address _address, wns::service::tl::Connection* _connection) 00074 { 00075 ownAddress = _address; 00076 00077 //create serversession 00078 wns::pyconfig::View sessionConfig = pyco.get("session"); 00079 std::string plugin = sessionConfig.get<std::string>("__plugin__"); 00080 00081 applications::session::Session::Creator* sessionCreator = 00082 applications::session::Session::Factory::creator(plugin); 00083 applications::session::Session* session = sessionCreator->create(sessionConfig); 00084 00085 // Set probe context 00086 session->registerComponent(component, sessionIndex); 00087 00088 // Connect session with its listener 00089 session->registerListener(this); 00090 00091 _connection->registerDataHandler(session); 00092 00093 session->onConnectionEstablished(_connection); 00094 00095 registerSession(sessionIndex, session); 00096 00097 ++sessionIndex; 00098 } 00099 00100 void 00101 TLListenerBinding::registerSession(int _i, applications::session::Session* _session) 00102 { 00103 sessionMap[_i] = _session; 00104 } 00105 00106 void 00107 TLListenerBinding::initBinding() 00108 { 00109 // Not needed. Client opened connection. 00110 } 00111 00112 void 00113 TLListenerBinding::releaseBinding(wns::service::tl::Connection* _connection) 00114 { 00115 tlService->closeConnection(_connection); 00116 } 00117 00118 void 00119 TLListenerBinding::onConnectionClosed(wns::service::tl::Connection*) 00120 { 00121 // no connection that can be closed 00122 // intentionally left empty 00123 } 00124 00125 void 00126 TLListenerBinding::onConnectionClosedByPeer(wns::service::tl::Connection*) 00127 { 00128 // no connection that can be closed 00129 // intentionally left empty 00130 } 00131 00132 void 00133 TLListenerBinding::onConnectionLost(wns::service::tl::Connection*) 00134 { 00135 // no connection that can be closed 00136 // intentionally left empty 00137 } 00138 00139 void 00140 TLListenerBinding::onShutdown() 00141 { 00142 for(mapType::const_iterator it = sessionMap.begin(); it != sessionMap.end(); ++it) 00143 { 00144 (it->second)->onShutdown(); 00145 } 00146 00147 for(mapType::const_iterator it = sessionMap.begin(); it != sessionMap.end(); ++it) 00148 { 00149 delete (it->second); 00150 } 00151 } 00152 00153 std::string 00154 TLListenerBinding::printAddress() const 00155 { 00156 std::ostringstream tmp; 00157 tmp << ownAddress << ":" << listenPort; 00158 return tmp.str(); 00159 } 00160 00161
1.5.5