![]() |
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. 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/ConstanzeComponent.hpp> 00029 #include <CONSTANZE/Generator.hpp> 00030 #include <CONSTANZE/Binding.hpp> 00031 #include <CONSTANZE/Listener.hpp> 00032 00033 #include <WNS/module/Base.hpp> 00034 #include <WNS/pyconfig/helper/Functions.hpp> 00035 #include <WNS/node/Node.hpp> 00036 00037 using namespace constanze; 00038 00039 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00040 ConstanzeComponent, 00041 wns::node::component::Interface, 00042 "Constanze", 00043 wns::node::component::ConfigCreator); 00044 00045 ConstanzeComponent::ConstanzeComponent( 00046 wns::node::Interface* _node, 00047 const wns::pyconfig::View& _pyco) : 00048 00049 Component(_node, _pyco), 00050 pyco(_pyco), 00051 log(pyco.get("logger")) 00052 { 00053 MESSAGE_SINGLE(NORMAL, log, "New Component created."); 00054 } 00055 00056 void 00057 ConstanzeComponent::doStartup() 00058 { 00059 MESSAGE_SINGLE(VERBOSE, log, "Component::doStartup() called."); 00060 } 00061 00062 ConstanzeComponent::~ConstanzeComponent() 00063 { 00064 while(!listOfGenerators.empty()) 00065 { 00066 delete *(listOfGenerators.begin()); 00067 listOfGenerators.erase(listOfGenerators.begin()); 00068 } 00069 while(!listOfGeneratorBindings.empty()) 00070 { 00071 delete *(listOfGeneratorBindings.begin()); 00072 listOfGeneratorBindings.erase(listOfGeneratorBindings.begin()); 00073 } 00074 while(!listOfListeners.empty()) 00075 { 00076 delete *(listOfListeners.begin()); 00077 listOfListeners.erase(listOfListeners.begin()); 00078 } 00079 while(!listOfListenerBindings.empty()) 00080 { 00081 delete *(listOfListenerBindings.begin()); 00082 listOfListenerBindings.erase(listOfListenerBindings.begin()); 00083 } 00084 } 00085 00086 void 00087 ConstanzeComponent::onNodeCreated() 00088 { 00089 int numgen=pyco.len("generators"); 00090 int numlis=pyco.len("listeners"); 00091 MESSAGE_SINGLE(NORMAL, log, "onNodeCreated(): initializing " << numgen << " generators, " << numlis << " listeners."); 00092 00093 // data source (Generators) 00094 for (int ii=0; ii < numgen ; ++ii) 00095 { 00096 // create generator 00097 wns::pyconfig::View generatorView = pyco.get("generators", ii); 00098 std::string generatorPlugin = generatorView.get<std::string>("__plugin__"); 00099 MESSAGE_SINGLE(NORMAL, log, "source "<<ii<<": generator plugin="<<generatorPlugin); 00100 // generatorPlugin can be "PointProcess","MMPP","MMBP", todo: "ARMA" 00101 // OLD: GeneratorBase* generator = new Generator(generatorView); 00102 GeneratorBase::Creator* generatorCreator; 00103 generatorCreator = GeneratorBase::Factory::creator(generatorPlugin); 00104 GeneratorBase* generator = generatorCreator->create(generatorView); 00105 listOfGenerators.push_back(generator); 00106 00107 // create binding 00108 wns::pyconfig::View bindingView = pyco.get("generatorBindings", ii); 00109 std::string bindingName = bindingView.get<std::string>("nameInBindingFactory"); 00110 Binding::Creator* bindingCreator; 00111 bindingCreator = Binding::Factory::creator(bindingName); 00112 Binding* generatorBinding = bindingCreator->create(bindingView); 00113 MESSAGE_SINGLE(VERBOSE, log, "source "<<ii<<": generatorBinding created"); 00114 listOfGeneratorBindings.push_back(generatorBinding); 00115 assure(generator, "No generator exists to register binding."); 00116 generator->registerBinding(generatorBinding); 00117 assure(generatorBinding, "No generator binding exists to register component."); 00123 generatorBinding->registerComponent(this); 00124 } 00125 00126 // data sink (Listeners) 00127 for (int ii=0; ii < numlis; ++ii) 00128 { 00129 wns::pyconfig::View listenerView = pyco.get("listeners", ii); 00130 Listener* listener = new Listener(listenerView, this); 00131 listOfListeners.push_back(listener); 00132 00133 // create binding 00134 wns::pyconfig::View bindingView = pyco.get("listenerBindings", ii); 00135 std::string bindingName = bindingView.get<std::string>("nameInBindingFactory"); 00136 Binding::Creator* bindingCreator = Binding::Factory::creator(bindingName); 00137 Binding* listenerBinding = bindingCreator->create(bindingView); 00138 MESSAGE_SINGLE(VERBOSE, log, "sink " << ii << ": listenerBinding created"); 00139 listOfListenerBindings.push_back(listenerBinding); 00140 assure(listener, "No listener exists to register binding."); 00141 listener->registerBinding(listenerBinding); 00142 assure(listenerBinding, "No listener binding exists to register component."); 00143 listenerBinding->registerComponent(this); 00144 } 00145 MESSAGE_SINGLE(VERBOSE, log, "onNodeCreated() ready"); 00146 } 00147 00148 void 00149 ConstanzeComponent::onWorldCreated() 00150 { 00151 00152 } 00153 00154 void 00155 ConstanzeComponent::onShutdown() 00156 { 00157 00158 } 00159
1.5.5