![]() |
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/node/component/client/Component.hpp> 00029 00030 using namespace applications::node::component::client; 00031 00032 STATIC_FACTORY_REGISTER_WITH_CREATOR(applications::node::component::client::Component, 00033 wns::node::component::Interface, 00034 "applications.component.Client", 00035 wns::node::component::ConfigCreator); 00036 00037 Component::Component(wns::node::Interface* _node, 00038 const wns::pyconfig::View& _pyco) : 00039 applications::node::component::Component(_node, _pyco), 00040 pyco(_pyco), 00041 logger(_pyco.get("logger")) 00042 { 00043 } 00044 00045 Component::~Component() 00046 { 00047 } 00048 00049 void 00050 Component::onNodeCreated() 00051 { 00052 // Create client sessions which are configured 00053 for(int i = 0; i < pyco.len("sessions"); ++i) 00054 { 00055 // create all sessions 00056 wns::pyconfig::View sessionConfig = pyco.get("sessions", i); 00057 std::string plugin = sessionConfig.get<std::string>("__plugin__"); 00058 applications::session::Session::Creator* sessionCreator = 00059 applications::session::Session::Factory::creator(plugin); 00060 applications::session::Session* session = sessionCreator->create(sessionConfig); 00061 00062 // create the session's binding, either TCP or UDP 00063 wns::pyconfig::View bindingConfig = pyco.get("bindings", i); 00064 plugin = bindingConfig.get<std::string>("__plugin__"); 00065 applications::session::Binding::Creator* bindingCreator = 00066 applications::session::Binding::Factory::creator(plugin); 00067 applications::session::BindingPtr binding(bindingCreator->create(bindingConfig)); 00068 00069 // Connect session with its binding 00070 session->registerBinding(binding); 00071 00072 // Set probe context 00073 session->registerComponent(this, i); 00074 00075 binding->registerSession(i, session); 00076 00077 binding->registerComponent(this, i); 00078 00079 registerSessions(i, session); 00080 } 00081 } 00082 00083 00084 void 00085 Component::onShutdown() 00086 { 00087 for(mapType::const_iterator it = sessionMap.begin(); it != sessionMap.end(); ++it) 00088 { 00089 (it->second)->onShutdown(); 00090 } 00091 00092 for(mapType::const_iterator it = sessionMap.begin(); it != sessionMap.end(); ++it) 00093 { 00094 delete (it->second); 00095 } 00096 } 00097 00098 void 00099 Component::registerSessions(int _i, applications::session::Session* _session) 00100 { 00101 sessionMap[_i] = _session; 00102 }
1.5.5