SearchMsgBookkeeping.cc

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 //
00018 
00024 #include "SearchMsgBookkeeping.h"
00025 
00026 
00027 SearchMsgBookkeeping::~SearchMsgBookkeeping()
00028 {
00029     // virtual dectructor
00030 }
00031 
00032 uint32_t SearchMsgBookkeeping::getSize() const
00033 {
00034     return messages.size();
00035 }
00036 
00037 void SearchMsgBookkeeping::addMessage(const OverlayKey& searchKey)
00038 {
00039     SearchMessageItem item;
00040     item.searchKey = searchKey;
00041     item.creationTime = simTime();
00042     item.minDelay = 0;
00043     item.maxDelay = 0;
00044     item.minHopCount = 0;
00045     item.maxHopCount = 0;
00046     item.responseCount = 0;
00047     messages[searchKey] = item;
00048 }
00049 
00050 void SearchMsgBookkeeping::removeMessage(const OverlayKey& searchKey)
00051 {
00052     SearchBookkeepingListIterator it = messages.find(searchKey);
00053 
00054     if(it->first == searchKey)
00055         messages.erase(it);
00056 }
00057 
00058 bool SearchMsgBookkeeping::contains(const OverlayKey& searchKey) const
00059 {
00060     SearchBookkeepingListConstIterator it = messages.find(searchKey);
00061     return (it != messages.end());
00062 }
00063 
00064 void SearchMsgBookkeeping::updateItem(const OverlayKey& searchKey,
00065                                       uint32_t hopCount)
00066 {
00067     SearchBookkeepingListIterator it = messages.find(searchKey);
00068     SearchMessageItem currentItem;
00069 
00070     if(it->first == searchKey) {
00071         currentItem = it->second;
00072         simtime_t currentTime = simTime();
00073 
00074         simtime_t delay = currentTime - currentItem.creationTime;
00075 
00076         // initialize first minDelay
00077         if (currentItem.minDelay == 0)
00078             currentItem.minDelay = delay;
00079         // initialize first minHopCount
00080         if (currentItem.minHopCount == 0)
00081             currentItem.minHopCount = hopCount;
00082 
00083         if (delay < currentItem.minDelay)
00084             currentItem.minDelay = delay;
00085         if (delay > currentItem.maxDelay)
00086             currentItem.maxDelay = delay;
00087 
00088         if (hopCount < currentItem.minHopCount)
00089             currentItem.minHopCount = hopCount;
00090         if (hopCount > currentItem.maxHopCount)
00091             currentItem.maxHopCount = hopCount;
00092 
00093         currentItem.responseCount++;
00094 
00095         it->second = currentItem;
00096     }
00097 }
00098 
00099 GiaSearchStats SearchMsgBookkeeping::getStatisticalData() const
00100 {
00101     SearchMessageItem currentItem;
00102     GiaSearchStats temp = {0, 0, 0, 0, 0};
00103 
00104     uint32_t size = messages.size();
00105 
00106     if (size == 0) return temp;
00107 
00108     for(SearchBookkeepingListConstIterator it = messages.begin();
00109                                            it != messages.end(); it++) {
00110         currentItem = it->second;
00111         temp.minDelay += (float)SIMTIME_DBL(currentItem.minDelay);
00112         temp.maxDelay += (float)SIMTIME_DBL(currentItem.maxDelay);
00113         temp.minHopCount += currentItem.minHopCount;
00114         temp.maxHopCount += currentItem.maxHopCount;
00115         temp.responseCount += currentItem.responseCount;
00116     }
00117 
00118     temp.minDelay /= size;
00119     temp.maxDelay /= size;
00120     temp.minHopCount /= size;
00121     temp.maxHopCount /= size;
00122     temp.responseCount /= size;
00123 
00124     return temp;
00125 }
Generated on Wed May 26 16:21:15 2010 for OverSim by  doxygen 1.6.3