![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /****************************************************************************** 00002 * WiFiMac * 00003 * This file is part of openWNS (open Wireless Network Simulator) 00004 * _____________________________________________________________________________ 00005 * 00006 * Copyright (C) 2004-2007 00007 * Chair of Communication Networks (ComNets) 00008 * Kopernikusstr. 16, D-52074 Aachen, Germany 00009 * phone: ++49-241-80-27910, 00010 * fax: ++49-241-80-22242 00011 * email: info@openwns.org 00012 * www: http://www.openwns.org 00013 * _____________________________________________________________________________ 00014 * 00015 * openWNS is free software; you can redistribute it and/or modify it under the 00016 * terms of the GNU Lesser General Public License version 2 as published by the 00017 * Free Software Foundation; 00018 * 00019 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00020 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00021 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00022 * details. 00023 * 00024 * You should have received a copy of the GNU Lesser General Public License 00025 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00026 * 00027 ******************************************************************************/ 00028 00029 #include <WIFIMAC/management/VirtualCapabilityInformationBase.hpp> 00030 00031 #include <WNS/Exception.hpp> 00032 #include <WNS/pyconfig/Sequence.hpp> 00033 #include <WNS/Ttos.hpp> 00034 00035 using namespace wifimac::management; 00036 00037 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00038 wifimac::management::VirtualCapabilityInformationBase, 00039 wns::node::component::Interface, 00040 "wifimac.management.VirtualCapabilityInformationBase", 00041 wns::node::component::ConfigCreator); 00042 00043 00044 VirtualCapabilityInformationBaseService::VirtualCapabilityInformationBaseService(): 00045 logger("WIFIMAC", "VCIB", wns::simulator::getMasterLogger()), 00046 vcib(NULL) 00047 { 00048 MESSAGE_SINGLE(NORMAL, logger, "Starting VCIB Service."); 00049 } 00050 00051 void 00052 VirtualCapabilityInformationBaseService::setVCIB(VirtualCapabilityInformationBase* _vcib) 00053 { 00054 assure(vcib == NULL, "setVCIB already called, cannot call twice"); 00055 this->vcib = _vcib; 00056 } 00057 00058 VirtualCapabilityInformationBase* 00059 VirtualCapabilityInformationBaseService::getVCIB() 00060 { 00061 assureNotNull(this->vcib); 00062 return(this->vcib); 00063 } 00064 00065 VirtualCapabilityInformationBase::VirtualCapabilityInformationBase(wns::node::Interface* _node, const wns::pyconfig::View& _config) : 00066 wns::node::component::Component(_node, _config), 00067 logger(_config.get("logger")), 00068 nodeInformationBase(new NodeBase), 00069 defaultValues(new InformationBase) 00070 { 00071 TheVCIBService::Instance().setVCIB(this); 00072 MESSAGE_SINGLE(NORMAL, logger, "Starting Virtual Capability Information Base."); 00073 00074 // currently, default information must have type int 00075 for (int i=0; i< _config.get<int>("defaultValues.size()"); ++i) 00076 { 00077 std::string s = "defaultValues.get("+ wns::Ttos(i) + ")"; 00078 wns::pyconfig::Sequence entry = _config.getSequence(s); 00079 assure(entry.size() == 2, "Entry has wrong size"); 00080 00081 std::string key = entry.at<std::string>(0); 00082 int value = entry.at<int>(1); 00083 00084 defaultValues->insert<int>(key, value); 00085 00086 MESSAGE_SINGLE(NORMAL, logger, "Inserted key " << key << " with value " << value << " into default information base"); 00087 } 00088 } 00089 00090 bool 00091 VirtualCapabilityInformationBase::knows(const wns::service::dll::UnicastAddress adr, const std::string& key) const 00092 { 00093 if(defaultValues->knows(key)) 00094 { 00095 // at least default information is available 00096 return true; 00097 } 00098 00099 if(not nodeInformationBase->knows(adr)) 00100 { 00101 // address is not known 00102 return false; 00103 } 00104 00105 if(not nodeInformationBase->find(adr)->knows(key)) 00106 { 00107 // address is known, but no information about the capability 00108 return false; 00109 } 00110 00111 return true; 00112 } // VirtualCapabilityInformationBase::knows 00113 00114 bool 00115 VirtualCapabilityInformationBase::knows(const wns::service::dll::UnicastAddress adr) const 00116 { 00117 if(nodeInformationBase->knows(adr)) 00118 { 00119 // address is not known 00120 return true; 00121 } 00122 else 00123 { 00124 return false; 00125 } 00126 } 00127 00128 00129 InformationBase* 00130 VirtualCapabilityInformationBase::getAll(const wns::service::dll::UnicastAddress adr) const 00131 { 00132 assure(nodeInformationBase->knows(adr), "Address " << adr << "not stored in capability information base"); 00133 00134 InformationBase* myIB = nodeInformationBase->find(adr); 00135 00136 return(myIB); 00137 }
1.5.5