User Manual, Developers Guide and API Documentation

QueueManager.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-2009
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 <WIMAC/services/QueueManager.hpp>
00029 #include <WIMAC/scheduler/Interface.hpp>
00030 
00031 
00032 using namespace wimac::service;
00033 
00034 STATIC_FACTORY_REGISTER_WITH_CREATOR(
00035     wimac::service::QueueManager,
00036     wns::ldk::ManagementServiceInterface,
00037     "wimac.services.QueueManager",
00038     wns::ldk::MSRConfigCreator);
00039             
00040 QueueManager::QueueManager(wns::ldk::ManagementServiceRegistry* msr, 
00041     const wns::pyconfig::View& config) :
00042     wns::scheduler::queue::IQueueManager(msr, config),
00043     connectionManagerServiceName_(config.get<std::string>("connectionManagerServiceName")),
00044     connectionManager_(NULL),
00045     logger_(config.get("logger"))
00046 {
00047     MESSAGE_BEGIN(NORMAL, logger_, m, "QueueManager");
00048     m << " Created QueueManager Service using ConnectionManagerService ";
00049     m << connectionManagerServiceName_;
00050     MESSAGE_END();
00051 }
00052 
00053 QueueManager::~QueueManager() 
00054 {
00055 }
00056 
00057 void
00058 QueueManager::onMSRCreated()
00059 {
00060     connectionManager_ =  
00061         getMSR()->getLayer()->getManagementService<service::ConnectionManager>(
00062             connectionManagerServiceName_);
00063     assure(connectionManager_ != NULL, "QueueManager needs a ConnectionManager");
00064 
00065     MESSAGE_BEGIN(NORMAL, logger_, m, "QueueManager");
00066     m << " Found valid ConnectionManagerService ";
00067     m << connectionManagerServiceName_;
00068     MESSAGE_END();
00069 
00070 }
00071 
00072 wns::scheduler::queue::QueueContainer
00073 QueueManager::getAllQueues()
00074 {
00075     wns::scheduler::queue::QueueContainer queues;
00076 
00077     ConnectionIdentifiers ci;
00078     ci = connectionManager_->getAllDataConnections(ConnectionIdentifier::Uplink);
00079     if(ci.empty())
00080         return queues;
00081 
00082     ConnectionIdentifiers::iterator it;
00083 
00084     for(it = ci.begin(); it != ci.end(); it++)
00085     {
00086         wns::scheduler::queue::QueueInterface* queue;
00087 
00088         if(cache_.find((*it)->cid_) != cache_.end())
00089         {
00090             queue = cache_[(*it)->cid_];
00091         }
00092         else
00093         {
00094            queue = getQueue((*it)->subscriberStation_, (*it)->cid_);
00095 
00096             if(queue != NULL)
00097             {            
00098                 MESSAGE_BEGIN(NORMAL, logger_, m, "QueueManager");
00099                 m << " Storing Queue pointer for CID ";
00100                 m << (*it)->cid_ << " in cache";
00101                 MESSAGE_END();
00102                 cache_[(*it)->cid_] = queue;
00103             }
00104         }
00105         if(queue != NULL)
00106             queues[(*it)->cid_] = queue;                
00107     }        
00108     return queues;
00109 }
00110 
00111 wns::scheduler::queue::QueueInterface*
00112 QueueManager::getQueue(wns::scheduler::ConnectionID cid)
00113 {
00114     wns::scheduler::queue::QueueInterface* queue;
00115     if(cache_.find(cid) != cache_.end())
00116     {
00117         queue = cache_[cid];
00118     }
00119     else
00120     {
00121         queue = getQueue(getStationID(cid), cid);
00122                  
00123         if(queue != NULL)
00124         {
00125             MESSAGE_BEGIN(NORMAL, logger_, m, "QueueManager");
00126             m << " Storing Queue pointer for CID ";
00127             m << cid << " in cache";
00128             MESSAGE_END();
00129             cache_[cid] = queue;
00130         }
00131     }
00132     return queue;
00133 }
00134 
00135 void
00136 QueueManager::startCollection(wns::scheduler::ConnectionID cid)
00137 {
00138     wimac::frame::DataCollector* dc;
00139 
00140     if(dcCache_.find(cid) != dcCache_.end())
00141         dc = dcCache_[cid];
00142     else
00143     {
00144         Component* peerComponent = dynamic_cast<wimac::Component*>(
00145             TheStationManager::getInstance()->getStationByID(getStationID(cid)) );
00146     
00147         wns::ldk::fun::Main* fun = peerComponent->getFUN();
00148         dc = fun->findFriend<wimac::frame::DataCollector*>("ulscheduler");
00149         dcCache_[cid] = dc;
00150     }
00151 
00152     MESSAGE_BEGIN(NORMAL, logger_, m, "QueueManager");
00153     m << " Starting data collection for CID ";
00154     m << cid;
00155     MESSAGE_END();
00156 
00157     assure(dc, "Cannot find DataCollector in FUN");
00158     dc->getTxScheduler()->startScheduling();
00159 }
00160 
00161 wns::scheduler::queue::QueueInterface*
00162 QueueManager::getQueue(ConnectionIdentifier::StationID peerStationId, wns::scheduler::ConnectionID cid)
00163 {
00164     if(peerStationId == -1)
00165         return NULL;
00166 
00167     wimac::frame::DataCollector* dc;
00168 
00169     if(dcCache_.find(cid) != dcCache_.end())
00170         dc = dcCache_[cid];
00171     else
00172     {
00173         Component* peerComponent = dynamic_cast<wimac::Component*>(
00174             TheStationManager::getInstance()->getStationByID(peerStationId) );
00175     
00176         wns::ldk::fun::Main* fun = peerComponent->getFUN();
00177         dc = fun->findFriend<wimac::frame::DataCollector*>("ulscheduler");
00178         dcCache_[cid] = dc;
00179     }
00180 
00181     assure(dc, "Cannot find DataCollector in FUN");
00182     return dc->getTxScheduler()->getQueue();
00183 }
00184 
00185 wimac::ConnectionIdentifier::StationID
00186 QueueManager::getStationID(wns::scheduler::ConnectionID cid)
00187 {
00188     ConnectionIdentifiers ci;
00189     ci = connectionManager_->getAllDataConnections(ConnectionIdentifier::Uplink);
00190     assure(!ci.empty(), "Tried to get StationID from CID but no CIDs are known yet");
00191 
00192     ConnectionIdentifiers::iterator it;
00193 
00194     for(it = ci.begin(); it != ci.end(); it++)
00195     {
00196         if((*it)->cid_ == cid)
00197             return (*it)->subscriberStation_;                
00198     }
00199     return -1;
00200     //assure(false, "Cannot find StationID for CID");
00201 }
00202 

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