User Manual, Developers Guide and API Documentation

IInnerCopyQueue.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 <WNS/scheduler/queue/detail/IInnerCopyQueue.hpp>
00029 
00030 using namespace wns::scheduler::queue::detail;
00031 
00032 SimpleInnerCopyQueue::SimpleInnerCopyQueue()
00033 {
00034 }
00035 
00036 SimpleInnerCopyQueue::~SimpleInnerCopyQueue()
00037 {
00038 }
00039 
00040 bool
00041 SimpleInnerCopyQueue::knowsCID(ConnectionID cid)
00042 {
00043     return queue_.find(cid) != queue_.end();
00044 }
00045 
00046 bool
00047 SimpleInnerCopyQueue::isEmpty(ConnectionID cid)
00048 {
00049     assure(queue_.find(cid) != queue_.end(), "Unknown CID");
00050     return  queue_[cid].empty();
00051 }
00052 
00053 wns::ldk::CompoundPtr
00054 SimpleInnerCopyQueue::getPDU(ConnectionID cid, Bit)
00055 {
00056     assure(queue_.find(cid) != queue_.end(), "Unknown CID");
00057     assure(!queue_[cid].empty(), "Called getPDU for empty queue");
00058 
00059     wns::ldk::CompoundPtr c = queue_[cid].front();
00060 
00061     queueSize_[cid] -= getHeadofLinePDUBit(cid);
00062     assure(queueSize_[cid] > 0, "Queue size is below 0");
00063 
00064     queue_[cid].pop();
00065 
00066     return  c;
00067 }
00068     
00069 Bit
00070 SimpleInnerCopyQueue::getHeadofLinePDUBit(ConnectionID cid)
00071 {
00072     assure(queue_.find(cid) != queue_.end(), "Unknown CID");
00073     assure(!queue_[cid].empty(), "Called getHeadofLinePDUBit for empty queue");
00074 
00075     return queue_[cid].front()->getLengthInBits();
00076 }
00077     
00078 
00079 void
00080 SimpleInnerCopyQueue::reset(ConnectionID cid)
00081 {
00082     assure(queue_.find(cid) != queue_.end(), "Unknown CID");
00083     queue_[cid] = std::queue<wns::ldk::CompoundPtr>();
00084     queueSize_[cid] = 0;
00085 }
00086     
00087 int
00088 SimpleInnerCopyQueue::getSize(ConnectionID cid)
00089 {
00090     assure(queue_.find(cid) != queue_.end(), "Unknown CID");
00091     return queue_[cid].size();
00092 }
00093     
00094 int
00095 SimpleInnerCopyQueue::getSizeInBit(ConnectionID cid)
00096 {
00097     assure(queue_.find(cid) != queue_.end(), "Unknown CID");
00098     assure(queueSize_.find(cid) != queueSize_.end(), "Unknown CID");
00099 
00100     return queueSize_[cid];
00101 }
00102     
00103 void
00104 SimpleInnerCopyQueue::setQueue(ConnectionID cid, std::queue<wns::ldk::CompoundPtr> queue)
00105 {
00106     if(queue_.find(cid) != queue_.end())
00107         queue_[cid] = std::queue<wns::ldk::CompoundPtr>();
00108 
00109     queueSize_[cid] = 0;
00110 
00111     wns::ldk::CompoundPtr compound;
00112 
00113     int s = queue.size();
00114     for(int i = 0; i < s; i++)
00115     {
00116         compound = queue.front();
00117         queue_[cid].push(compound);
00118         queueSize_[cid] += compound->getLengthInBits();
00119     }
00120 }
00121 
00122 // SegmentingInnerCopyQueue:
00123 
00124 SegmentingInnerCopyQueue::SegmentingInnerCopyQueue(const wns::pyconfig::View& _config) :
00125     fixedHeaderSize_(_config.get<Bit>("fixedHeaderSize")),
00126     minimumSegmentSize_(_config.get<unsigned long int>("minimumSegmentSize")),
00127     extensionHeaderSize_(_config.get<Bit>("extensionHeaderSize")),
00128     usePadding_(_config.get<bool>("usePadding")),
00129     byteAlignHeader_(_config.get<bool>("byteAlignHeader")),
00130     segmentHeaderCommandName_(_config.get<std::string>("segmentHeaderCommandName"))
00131 {
00132 }
00133 
00134 SegmentingInnerCopyQueue::~SegmentingInnerCopyQueue()
00135 {
00136 }
00137 
00138 void
00139 SegmentingInnerCopyQueue::setFUN(wns::ldk::fun::FUN* fun)
00140 {
00141     assure(fun != NULL, "FUN pointer  cannot be NULL");
00142 
00143     segmentHeaderReader_ = fun->getCommandReader(segmentHeaderCommandName_);
00144     assure(segmentHeaderReader_, "No reader for the Segment Header (" << segmentHeaderCommandName_ << ") available!");
00145 }
00146     
00147 bool
00148 SegmentingInnerCopyQueue::knowsCID(ConnectionID cid)
00149 {
00150     return queue_.find(cid) != queue_.end();
00151 }
00152 
00153 bool
00154 SegmentingInnerCopyQueue::isEmpty(ConnectionID cid)
00155 {
00156     assure(queue_.find(cid) != queue_.end(), "Unknown CID");
00157     return  queue_[cid].empty();
00158 }
00159 
00160 wns::ldk::CompoundPtr
00161 SegmentingInnerCopyQueue::getPDU(ConnectionID cid, Bit requestedBits)
00162 {
00163     assure(queue_.find(cid) != queue_.end(), "Unknown CID");
00164     assure(!queue_[cid].empty(), "Called getHeadofLinePDU for empty queue");
00165     assure(segmentHeaderReader_ != NULL, "No valid segmentHeaderReader set! You need to call setFUN() first.");
00166 
00167     wns::ldk::CompoundPtr segment;
00168     try {
00169         segment = queue_[cid].retrieve(requestedBits, fixedHeaderSize_, extensionHeaderSize_, usePadding_, byteAlignHeader_, segmentHeaderReader_);
00170 
00171         segmentHeaderReader_->commitSizes(segment->getCommandPool());
00172 
00173     } catch (detail::InnerQueue::RequestBelowMinimumSize e)
00174     {
00175         return wns::ldk::CompoundPtr();
00176     }
00177 
00178     return  segment;
00179 }
00180     
00181 Bit
00182 SegmentingInnerCopyQueue::getHeadofLinePDUBit(ConnectionID cid)
00183 {
00184     assure(queue_.find(cid) != queue_.end(), "Unknown CID");
00185     assure(!queue_[cid].empty(), "Called getHeadofLinePDUBit for empty queue");
00186 
00187     return queue_[cid].queuedBruttoBits(fixedHeaderSize_, extensionHeaderSize_, byteAlignHeader_);
00188 }
00189     
00190 
00191 void
00192 SegmentingInnerCopyQueue::reset(ConnectionID cid)
00193 {
00194     assure(queue_.find(cid) != queue_.end(), "Unknown CID");
00195     queue_.erase(cid);
00196 }
00197     
00198 int
00199 SegmentingInnerCopyQueue::getSize(ConnectionID cid)
00200 {
00201     assure(queue_.find(cid) != queue_.end(), "Unknown CID");
00202     return queue_[cid].queuedCompounds();
00203 }
00204 
00205 int
00206 SegmentingInnerCopyQueue::getSizeInBit(ConnectionID cid)
00207 {
00208     assure(queue_.find(cid) != queue_.end(), "Unknown CID");
00209     return queue_[cid].queuedBruttoBits(fixedHeaderSize_, extensionHeaderSize_, byteAlignHeader_);
00210 }
00211     
00212 void
00213 SegmentingInnerCopyQueue::setQueue(ConnectionID cid, std::queue<wns::ldk::CompoundPtr> queue)
00214 {
00215     if(queue_.find(cid) != queue_.end())
00216         queue_[cid] = InnerQueue();
00217 
00218     int s = queue.size();
00219     for(int i = 0; i < s; i++)
00220         queue_[cid].put(queue.front());
00221 }
00222 
00223 unsigned long int 
00224 SegmentingInnerCopyQueue::getMinimumSegmentSize()
00225 {
00226     return minimumSegmentSize_;
00227 }

Generated on Thu May 24 03:31:49 2012 for openWNS by  doxygen 1.5.5