User Manual, Developers Guide and API Documentation

VirtualCapabilityInformationBase.hpp

Go to the documentation of this file.
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 #ifndef WIFIMAC_MANAGEMENT_VIRTUALCAPABILITYINFORMATIONBASE_HPP
00030 #define WIFIMAC_MANAGEMENT_VIRTUALCAPABILITYINFORMATIONBASE_HPP
00031 
00032 #include <DLL/UpperConvergence.hpp>
00033 
00034 #include <WNS/container/Registry.hpp>
00035 #include <WNS/container/UntypedRegistry.hpp>
00036 #include <WNS/ldk/fun/Main.hpp>
00037 #include <WNS/ldk/Layer.hpp>
00038 #include <WNS/node/component/Component.hpp>
00039 #include <WNS/logger/Logger.hpp>
00040 #include <WNS/Singleton.hpp>
00041 
00042 
00043 namespace wifimac { namespace management {
00044 
00045 
00046     typedef wns::container::UntypedRegistry<std::string> InformationBase;
00047     typedef wns::container::Registry<wns::service::dll::UnicastAddress, InformationBase*> NodeBase;
00048 
00066     class VirtualCapabilityInformationBase:
00067         virtual public wns::ldk::Layer,
00068         public wns::node::component::Component
00069     {
00070     public:
00071         VirtualCapabilityInformationBase(
00072             wns::node::Interface* _node,
00073             const wns::pyconfig::View& _config);
00074 
00075         virtual void
00076         doStartup()
00077             {};
00078 
00079         virtual ~VirtualCapabilityInformationBase()
00080         {
00081             delete nodeInformationBase;
00082             delete defaultValues;
00083         };
00084 
00085         virtual void
00086         onNodeCreated()
00087             {};
00088 
00089         virtual void
00090         onWorldCreated()
00091             {};
00092 
00093         virtual void
00094         onShutdown()
00095             {};
00096 
00097         bool
00098         knows(const wns::service::dll::UnicastAddress adr, const std::string& key) const;
00099 
00100         bool
00101         knows(const wns::service::dll::UnicastAddress adr) const;
00102 
00103         template <typename T>
00104         T
00105         get(const wns::service::dll::UnicastAddress adr, const std::string& key) const
00106         {
00107             assure(this->knows(adr, key), "Cannot get unknown information of node " << adr << " with key " << key);
00108 
00109             InformationBase* myIB;
00110             if(nodeInformationBase->knows(adr))
00111             {
00112                 myIB = nodeInformationBase->find(adr);
00113                 if(not myIB->knows(key))
00114                 {
00115                     myIB = this->defaultValues;
00116                 }
00117             }
00118             else
00119             {
00120                 myIB = this->defaultValues;
00121             }
00122 
00123             MESSAGE_SINGLE(NORMAL, logger, "Query for node " << adr << ", key " << key << " --> " << myIB->find<T>(key));
00124 
00125             return(myIB->find<T>(key));
00126         } // get
00127 
00128         InformationBase*
00129         getAll(const wns::service::dll::UnicastAddress adr) const;
00130 
00131         template <typename T>
00132         void
00133         set(const wns::service::dll::UnicastAddress adr, const std::string& key, const T value)
00134         {
00135             if(not nodeInformationBase->knows(adr))
00136             {
00137                 // first time information about this node is added
00138                 nodeInformationBase->insert(adr, new InformationBase());
00139             }
00140 
00141             if(nodeInformationBase->find(adr)->knows(key))
00142             {
00143                 throw wns::Exception("Cannot set the same information twice");
00144             }
00145 
00146             InformationBase* i = nodeInformationBase->find(adr);
00147         i->insert<T>(key, value);
00148 
00149             MESSAGE_SINGLE(NORMAL, logger, "Node " << adr << " inserted key " << key << " with value " << value);
00150         } // set
00151 
00152     private:
00156         wns::logger::Logger logger;
00157 
00161         NodeBase* nodeInformationBase;
00162 
00166         InformationBase* defaultValues;
00167     };
00168 
00169     class VirtualCapabilityInformationBaseService {
00170     public:
00171         VirtualCapabilityInformationBaseService();
00172 
00173         VirtualCapabilityInformationBase*
00174         getVCIB();
00175 
00176         void
00177         setVCIB(VirtualCapabilityInformationBase* _vcib);
00178 
00179     private:
00180         wns::logger::Logger logger;
00181         VirtualCapabilityInformationBase* vcib;
00182     };
00183 
00184     typedef wns::SingletonHolder<VirtualCapabilityInformationBaseService> TheVCIBService;
00185 
00186 } // management
00187 } // wifimac
00188 
00189 #endif

Generated on Sat May 26 03:32:09 2012 for openWNS by  doxygen 1.5.5