User Manual, Developers Guide and API Documentation

FUN.hpp

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 #ifndef WNS_LDK_FUN_HPP
00029 #define WNS_LDK_FUN_HPP
00030 
00031 #include <WNS/ldk/Compound.hpp>
00032 #include <WNS/osi/PDU.hpp>
00033 
00034 #include <WNS/pyconfig/View.hpp>
00035 #include <WNS/node/Interface.hpp>
00036 #include <WNS/TypeInfo.hpp>
00037 #include <WNS/Exception.hpp>
00038 
00039 #include <map>
00040 #include <string>
00041 
00042 
00043 namespace wns { namespace ldk {
00044     class ILayer;
00045     class FunctionalUnit;
00046     class CommandProxy;
00047     class CommandPool;
00048     class CommandTypeSpecifierInterface;
00049     class LinkHandlerInterface;
00050 }}
00051 
00052 namespace wns { namespace ldk { namespace fun {
00053 
00054     class FindFriendException :
00055         public wns::Exception
00056     {
00057     public:
00058         FindFriendException(const std::string& e) :
00059             wns::Exception(e)
00060         {}
00061         ~FindFriendException() throw() {}
00062     };
00063 
00070     class FUN
00071     {
00072     public:
00073         typedef std::map<std::string, FunctionalUnit*> FunctionalUnitMap;
00074         virtual ~FUN() {}
00075 
00076         //
00077         // FUN construction
00078         //
00079 
00084         virtual void addFunctionalUnit(const std::string& commandName,
00085                            const std::string& functionalUnitName,
00086                            FunctionalUnit* functionalUnit) = 0;
00087 
00091         virtual void addFunctionalUnit(const std::string& name, FunctionalUnit* functionalUnit) = 0;
00092 
00096         virtual void removeFunctionalUnit(const std::string& name) = 0;
00097 
00101         virtual void connectFunctionalUnit(
00102                     const std::string& upperName, const std::string& lowerName,
00103                     const std::string& srcPort = "SinglePort", const std::string& dstPort = "SinglePort") = 0;
00104 
00108         virtual void upConnectFunctionalUnit(
00109                     const std::string& upperName, const std::string& lowerName,
00110                     const std::string& srcPort = "SinglePort", const std::string& dstPort = "SinglePort") = 0;
00111 
00115         virtual void downConnectFunctionalUnit(
00116                     const std::string& upperName, const std::string& lowerName,
00117                     const std::string& srcPort = "SinglePort", const std::string& dstPort = "SinglePort") = 0;
00118 
00123             //      virtual void reconfigureFUN(const wns::pyconfig::View& reconfig) = 0;
00124 
00125         //
00126         // FU access
00127         //
00131         virtual FunctionalUnit* getFunctionalUnit(const std::string& name) const = 0;
00132 
00136         virtual bool knowsFunctionalUnit(const std::string& name) const = 0;
00137 
00140         virtual CommandProxy* getProxy() const = 0;
00141         virtual ILayer* getLayer() const = 0;
00142 
00143         template <typename LAYERTYPE>
00144         LAYERTYPE
00145         getLayer() const
00146         {
00147             ILayer* aLayer = getLayer();
00148             assureType(aLayer, LAYERTYPE);
00149             // we can't use C-Style downcasts here!
00150             return dynamic_cast<LAYERTYPE>(aLayer);
00151         }
00152 
00153         virtual std::string getName() const = 0;
00154         virtual LinkHandlerInterface* getLinkHandler() const = 0;
00155         virtual CommandReaderInterface* getCommandReader(const std::string& commandName) const = 0;
00157 
00169         template <typename T>
00170         T findFriend(const std::string& name) const
00171         {
00172             FunctionalUnit* functionalUnit = this->getFunctionalUnit(name);
00173             T t = dynamic_cast<T>(functionalUnit);
00174 
00175             if (!t)
00176             {
00177                 std::stringstream ss;
00178 
00179                 ss << "FindFriend call failed. Friend FU " << name << " is not of required type "
00180                    << wns::TypeInfo::create<T>() << ". " << "FU " << name << " is of type "
00181                    << wns::TypeInfo::create(*functionalUnit) << "." << std::endl;
00182 
00183                 throw FindFriendException(ss.str());
00184             }
00185 
00186             return t;
00187         } // findFriend
00188 
00189         //
00190         // forwarding to meet the LawOfDemeter
00191         //
00192         void
00193         calculateSizes(const CommandPool* commandPool,
00194                        Bit& commandPoolSize, Bit& sduSize,
00195                        const CommandTypeSpecifierInterface* questioner = NULL) const
00196         {
00197             getProxy()->calculateSizes(commandPool, commandPoolSize, sduSize,
00198                                        questioner);
00199         } // calculateSizes
00200 
00201         CommandPool*
00202         createCommandPool()
00203         {
00204             return getProxy()->createCommandPool(this);
00205         } // createCommandPool
00206 
00207         //
00208         // shortcut
00209         //
00210         CompoundPtr
00211         createCompound(osi::PDUPtr sdu = osi::PDUPtr())
00212         {
00213             return CompoundPtr(new Compound(createCommandPool(), sdu));
00214         } // createCompound
00215     };
00216 
00217 }}}
00218 
00219 
00220 
00221 #endif // NOT defined WNS_LDK_FUN_HPP
00222 
00223 

Generated on Wed May 23 03:31:39 2012 for openWNS by  doxygen 1.5.5