![]() |
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 <RISE/scenario/mobility/Component.hpp> 00029 #include <RISE/scenario/mobility/Mobility.hpp> 00030 00031 #include <WNS/probe/bus/ContextProvider.hpp> 00032 #include <boost/bind.hpp> 00033 #include <iomanip> 00034 00035 using namespace rise::scenario::mobility; 00036 00037 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00038 rise::scenario::mobility::Component, 00039 wns::node::component::Interface, 00040 "rise.mobility.Component", 00041 wns::node::component::ConfigCreator 00042 ); 00043 00044 Component::Component( 00045 wns::node::Interface* node, 00046 const wns::pyconfig::View& pyConfigView) : 00047 00048 wns::node::component::Component(node, pyConfigView), 00049 mobility(NULL), 00050 logger(pyConfigView.get("logger")) 00051 { 00052 // create mobility 00053 wns::pyconfig::View mobilityView = pyConfigView.get("mobility"); 00054 std::string plugin = mobilityView.get<std::string>("nameInMobilityFactory"); 00055 mobility = rise::scenario::mobility::MobilityFactory::creator(plugin)->create(mobilityView); 00056 00057 MESSAGE_SINGLE(NORMAL, logger, "Done creating rise::scenario::mobility::Component of type " << plugin); 00058 } 00059 00060 void 00061 Component::doStartup() 00062 { 00063 wns::probe::bus::ContextProviderCollection& cpc = getContextProviderCollection(); 00064 cpc.addProvider(wns::probe::bus::contextprovider::Callback( 00065 "rise.scenario.mobility.x", 00066 boost::bind(&Component::getX, this))); 00067 00068 cpc.addProvider(wns::probe::bus::contextprovider::Callback( 00069 "rise.scenario.mobility.y", 00070 boost::bind(&Component::getY, this))); 00071 00072 cpc.addProvider(wns::probe::bus::contextprovider::Callback( 00073 "rise.scenario.mobility.z", 00074 boost::bind(&Component::getZ, this))); 00075 00076 // register station as a PHY DataTransmissionService 00077 this->addService("mobility", mobility); 00078 00079 // register myself to Mobility 00080 this->startObserving(this->mobility); 00081 00082 positionContextCollectorX = wns::probe::bus::ContextCollectorPtr( 00083 new wns::probe::bus::ContextCollector(cpc, 00084 "rise.scenario.mobility.PositionX")); 00085 positionContextCollectorY = wns::probe::bus::ContextCollectorPtr( 00086 new wns::probe::bus::ContextCollector(cpc, 00087 "rise.scenario.mobility.PositionY")); 00088 positionContextCollectorZ = wns::probe::bus::ContextCollectorPtr( 00089 new wns::probe::bus::ContextCollector(cpc, 00090 "rise.scenario.mobility.PositionZ")); 00091 00092 MESSAGE_SINGLE(NORMAL, logger, "Done rise::scenario::mobility::Component::startup()"); 00093 } 00094 00095 Component::~Component() 00096 { 00097 delete mobility; 00098 } 00099 00100 void 00101 Component::onNodeCreated() 00102 { 00103 } 00104 00105 void 00106 Component::onWorldCreated() 00107 { 00108 } 00109 00110 void 00111 Component::onShutdown() 00112 { 00113 } 00114 00115 void 00116 Component::positionWillChange() 00117 { 00118 } 00119 00120 void 00121 Component::positionChanged() 00122 { 00123 positionContextCollectorX->put(mobility->getPosition().getX()); 00124 positionContextCollectorY->put(mobility->getPosition().getY()); 00125 positionContextCollectorZ->put(mobility->getPosition().getZ()); 00126 } 00127 00128 int 00129 Component::getX() 00130 { 00131 return (int)mobility->getPosition().getX(); 00132 } 00133 00134 int 00135 Component::getY() 00136 { 00137 return (int)mobility->getPosition().getY(); 00138 } 00139 00140 int 00141 Component::getZ() 00142 { 00143 return (int)mobility->getPosition().getZ(); 00144 } 00145 00146
1.5.5