![]() |
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/medium/Medium.hpp> 00029 #include <RISE/medium/PhysicalResource.hpp> 00030 #include <RISE/RISE.hpp> 00031 00032 #include <WNS/Exception.hpp> 00033 00034 #include <list> 00035 00036 using namespace rise; 00037 using namespace rise::medium; 00038 00039 Medium* Medium::getInstance() 00040 { 00041 if(!myself) { 00042 myself = new Medium; 00043 } 00044 return myself; 00045 } 00046 00047 void Medium::deleteInstance() 00048 { 00049 if(myself) delete myself; 00050 myself = NULL; 00051 } 00052 00053 void Medium::reset() 00054 { 00055 PhysicalResourceIterator i = prs.begin(); 00056 while( i != prs.end()) 00057 { 00058 PhysicalResource* p = *i; 00059 prs.erase(i); 00060 00061 MESSAGE_BEGIN(NORMAL, log, m, "Deleting PhysicalResource f: "); 00062 m << p->getFrequency() << " MHz, b: " << p->getBandwidth() << " MHz"; 00063 MESSAGE_END(); 00064 00065 delete p; 00066 i = prs.begin(); 00067 } 00068 } 00069 00070 PhysicalResource* Medium::getPhysicalResource(double f, double b) 00071 { 00072 PhysicalResourceIterator result; 00073 for(result = prs.begin(); result != prs.end(); ++result) { 00074 if((std::abs((*result)->getFrequency() - f)/f < 1.0e-6) && 00075 (std::abs((*result)->getBandwidth() - b)/b < 1.0e-6) ) 00076 break; 00077 } 00078 if(result==prs.end()) { 00079 PhysicalResource* pr = new PhysicalResource(f, b); 00080 MESSAGE_BEGIN(NORMAL, log, m, "Created and delivered new PhysicalResource f: "); 00081 m << pr->getFrequency() << " MHz, b: " << pr->getBandwidth() << " MHz"; 00082 MESSAGE_END(); 00083 if(checkForOverlap(pr)) { 00084 delete pr; 00085 throw wns::Exception("Overlapping PhysicalResources!"); 00086 } 00087 prs.push_back(pr); 00088 return pr; 00089 } else { 00090 MESSAGE_BEGIN(NORMAL, log, m, "Delivered new PhysicalResource f: "); 00091 m << (*result)->getFrequency() << " MHz, b: " << (*result)->getBandwidth() << " MHz"; 00092 MESSAGE_END(); 00093 return *result; 00094 } 00095 } 00096 00097 Medium::Medium() : 00098 prs(), 00099 log("Medium") 00100 { 00101 if(RISE::getPyConfigView().get<bool>("debug.medium")) { 00102 log.switchOn(); 00103 } else { 00104 log.switchOff(); 00105 } 00106 } 00107 00108 Medium::~Medium() 00109 { 00110 this->reset(); 00111 } 00112 00113 bool Medium::checkForOverlap(PhysicalResource* pr) const 00114 { 00115 bool overlapping=false; 00116 PhysicalResourceContainer::const_iterator itr, itrEnd; 00117 itrEnd = prs.end(); 00118 for(itr=prs.begin(); itr!=itrEnd; ++itr) { 00119 if( pr->getFrequencyRange().overlaps((*itr)->getFrequencyRange())) { 00120 overlapping = true; 00121 MESSAGE_BEGIN(NORMAL, log, m, ""); 00122 m << "WARNING: THESE PHYSICAL RESOURCES ARE OVERLAPPING:" 00123 << " New PR: Frequency=" << pr->getFrequency() 00124 << "MHz Bandwidth="<< pr->getBandwidth() 00125 << " Existing PR: Frequency=" << (*itr)->getFrequency() 00126 << "MHz Bandwidth="<< (*itr)->getBandwidth() 00127 << " INTERFRENCE BETWEEN THESE TWO PHYSICAL RESOURCES IS CURRENTLY" 00128 << " NOT TAKEN INTO ACCOUNT!!!"; 00129 MESSAGE_END(); 00130 } 00131 } 00132 return overlapping; 00133 /* Examples 00134 00135 Non Overlap example: 00136 00137 f1lb f1ub f2lb f2ub 00138 --|--------------------|-------|--------------------|------> f 00139 |<-PhysicalResource->| |<-PhysicalResource->| 00140 00141 00142 Overlap example: 00143 00144 f1lb f2lb f1ub f2ub 00145 --|-------------------|--------|--------------------|------> f 00146 |<-PhysicalResource--------->| | 00147 |<----------PhysicalResource->| 00148 */ 00149 } 00150 00151 Medium* Medium::myself = NULL; 00152 00153
1.5.5