User Manual, Developers Guide and API Documentation

MACg.cpp

Go to the documentation of this file.
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 <LTE/macg/MACg.hpp>
00029 #include <LTE/main/Layer2.hpp>
00030 #include <LTE/macg/modeselection/Strategy.hpp>
00031 
00032 #include <WNS/ldk/fun/FUN.hpp>
00033 #include <sstream>
00034 
00035 using namespace lte::macg;
00036 using namespace wns::ldk;
00037 
00038 MACgScheduler::~MACgScheduler()
00039 {
00040     delete strategy;
00041     delete logger;
00042 }
00043 
00044 unsigned long int
00045 MACgScheduler::size() const
00046 {
00047     return layers.size();
00048 } // size
00049 
00050 void
00051 MACgScheduler::setMACg(MACg* _macg)
00052 {
00053     macg = _macg;
00054 }
00055 
00056 void
00057 MACgScheduler::setStrategy(lte::macg::modeselection::Strategy* _strategy)
00058 {
00059     strategy = _strategy;
00060 }
00061 
00062 void
00063 MACgScheduler::add(wns::ldk::IConnectorReceptacle* it)
00064 {
00065     layers.push_back(it);
00066 }
00067 
00068 void
00069 MACgScheduler::addDestination(lte::macr::ScorerInterface* scorer)
00070 {
00071     scorers.push_back(scorer);
00072 }
00073 
00074 lte::helper::Route
00075 MACgScheduler::getRoute(const wns::ldk::CompoundPtr& compound)
00076 {
00077     lte::helper::Route route = strategy->getRoute(compound, layers, scorers);
00078     return  route;
00079 }
00080 
00081 void
00082 MACgScheduler::setLogger(const wns::pyconfig::View& config)
00083 {
00084     assure(!logger, "MACgScheduler: Logger already set!");
00085     logger = new wns::logger::Logger(config);
00086 }
00087 
00088 MACg::MACg(wns::ldk::fun::FUN* _fun, const wns::pyconfig::View& _config) :
00089     CommandTypeSpecifier<MACgCommand>(_fun),
00090     fun(_fun),
00091     config(_config),
00092     logger(_config.get("logger"))
00093 {}
00094 
00095 void
00096 MACg::onFUNCreated()
00097 {
00098     // I can find all my scorer friends from a dict in my config
00099     int numModes = config.len("modes");
00100     std::string separator = config.get<std::string>("separator");
00101     std::string taskName = config.get<std::string>("task");
00102     for(int i=0; i<numModes; i++)
00103     {
00104     wns::pyconfig::View modeView = config.getView("modes",i);
00105 
00106     std::string modeName   = modeView.get<std::string>("modeName");
00107     std::string suffixName = modeView.get<std::string>("scorerSuffix");
00108 
00109     std::ostringstream scorerName;
00110     scorerName << modeName;
00111     if (taskName!="")
00112         scorerName << separator << taskName;
00113     scorerName << separator << suffixName;
00114 
00115     lte::macr::ScorerInterface* scorer =
00116         fun->findFriend<lte::macr::ScorerInterface*>(scorerName.str());
00117 
00118     assureType(getConnector(), lte::macg::MACgScheduler*);
00119     //add them to the container "macrs"
00120     static_cast<lte::macg::MACgScheduler*>(getConnector())->addDestination(scorer);
00121     }
00122     std::string plugin  = config.get<std::string>("strategy.__plugin__");
00123     modeselection::StrategyCreator* creator = modeselection::StrategyFactory::creator(plugin);
00124     modeselection::Strategy* strategy = creator->create();
00125 
00126     assureType(getConnector(), lte::macg::MACgScheduler*);
00127     static_cast<lte::macg::MACgScheduler*>(getConnector())->setStrategy(strategy);
00128 } // onFUNCreated
00129 
00130 
00131 wns::ldk::CommandPool*
00132 MACg::createReply(const wns::ldk::CommandPool* original) const
00133 {
00134     wns::ldk::CommandPool* reply = this->fun->createCommandPool();
00135 
00136     MACgCommand* originalCommand = getCommand(original);
00137     MACgCommand* replyCommand = activateCommand(reply);
00138 
00139     // set source MACg Identification
00140     assureType(this->fun->getLayer(), lte::main::Layer2*);
00141     lte::main::Layer2* layer2 = dynamic_cast<lte::main::Layer2*>(this->fun->getLayer());
00142     // set source
00143     replyCommand->peer.source = layer2->getDLLAddress();
00144     // copy dest from original source
00145     replyCommand->peer.dest = originalCommand->peer.source;
00146     // copy mode
00147     replyCommand->local.modeID  = originalCommand->local.modeID;
00148 
00149     return reply;
00150 } // createReply
00151 
00152 

Generated on Fri May 25 03:32:05 2012 for openWNS by  doxygen 1.5.5