![]() |
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 <WNS/node/NodeSimulationModel.hpp> 00029 #include <WNS/node/Node.hpp> 00030 #include <WNS/osi/PDU.hpp> 00031 00032 using namespace wns::node; 00033 00034 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00035 NodeSimulationModel, 00036 wns::simulator::ISimulationModel, 00037 "wns.Node.NodeSimulationModel", 00038 wns::PyConfigViewCreator); 00039 00040 NodeSimulationModel::NodeSimulationModel(const wns::pyconfig::View& config) : 00041 registry_(), 00042 logger_(config.get("logger")), 00043 config_(config) 00044 { 00045 } 00046 00047 NodeSimulationModel::~NodeSimulationModel() 00048 { 00049 // Shut down the final part of the logger 00050 #ifndef NDEBUG 00051 long int pdusAvailableBeforeNodesDeletd = wns::osi::PDU::getExistingPDUs(); 00052 #endif 00053 00054 MESSAGE_SINGLE(NORMAL, logger_, "Deleting all nodes"); 00055 while(!registry_.empty()) 00056 { 00057 wns::node::Interface* doomed = registry_.begin()->second; 00058 MESSAGE_SINGLE(NORMAL, logger_, "Deleting: " << doomed->getName()); 00059 delete doomed; 00060 registry_.erase(registry_.begin()->first); 00061 } 00062 00063 // Some final debug stuff 00064 #ifndef NDEBUG 00065 std::cout << "\n"; 00066 std::cout << "PDUs available before Nodes deleted: " << pdusAvailableBeforeNodesDeletd << "\n"; 00067 std::cout << "PDUs available after Nodes deleted: " << wns::osi::PDU::getExistingPDUs() << "\n"; 00068 std::cout << "Maximum number of PDUs available: " << wns::osi::PDU::getMaxExistingPDUs() << "\n"; 00069 #endif 00070 } 00071 00072 void 00073 NodeSimulationModel::doStartup() 00074 { 00075 // Construct Nodes 00076 for (int ii = 0; ii < config_.len("nodes"); ++ii) 00077 { 00078 wns::pyconfig::View nodeView = 00079 config_.get<wns::pyconfig::View>("nodes",ii); 00080 00081 wns::node::Node* currentNode = new wns::node::Node(®istry_, nodeView); 00082 currentNode->startup(); 00083 } 00084 00085 // World created -> call onWorldCreated for each node 00086 for(wns::node::Registry::const_iterator itr = registry_.begin(); 00087 itr != this->registry_.end(); 00088 ++itr) 00089 { 00090 itr->second->onWorldCreated(); 00091 } 00092 } 00093 00094 void 00095 NodeSimulationModel::doShutdown() 00096 { 00097 MESSAGE_SINGLE(NORMAL, logger_, "Calling onShutdown for all nodes"); 00098 for(wns::node::Registry::const_iterator itr = registry_.begin(); 00099 itr != registry_.end(); 00100 ++itr) 00101 { 00102 itr->second->onShutdown(); 00103 } 00104 }
1.5.5