User Manual, Developers Guide and API Documentation

CommandTypeSpecifier.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_COMMANDTYPESPECIFIER_HPP
00029 #define WNS_LDK_COMMANDTYPESPECIFIER_HPP
00030 
00031 #include <WNS/ldk/fun/FUN.hpp>
00032 #include <WNS/ldk/Command.hpp>
00033 #include <WNS/ldk/FunctionalUnit.hpp>
00034 #include <WNS/ldk/Connector.hpp>
00035 #include <WNS/ldk/CommandReaderInterface.hpp>
00036 
00037 #include <WNS/Assure.hpp>
00038 
00039 #include <WNS/osi/PCI.hpp>
00040 
00041 #include <vector>
00042 #include <cstdlib>              // NULL, size_t
00043 #include <limits>
00044 
00045 
00046 namespace wns { namespace ldk {
00047     class CommandPool;
00048 
00061     template <typename T = EmptyCommand>
00062     class CommandTypeSpecifier :
00063         public virtual CommandTypeSpecifierInterface
00064     {
00065     public:
00066         typedef T COMMANDTYPE;
00067 
00068         CommandTypeSpecifier(fun::FUN* _fun) :
00069                 fuNet(_fun)
00070         {
00071             assure(fuNet, "No fuNet, my friend. No fuNet.");
00072             // assure, that every Command contains the following entries
00073             int satisfyCompiler;
00074             satisfyCompiler = sizeof(&COMMANDTYPE::local);
00075             satisfyCompiler = sizeof(&COMMANDTYPE::peer);
00076             satisfyCompiler = sizeof(&COMMANDTYPE::magic);
00077         }
00078 
00079         virtual ~CommandTypeSpecifier()
00080         {}
00081 
00082         CommandTypeSpecifier(const CommandTypeSpecifier& other) :
00083             CommandTypeSpecifierInterface(),
00084             fuNet(other.fuNet)
00085         {
00086         }
00087 
00088         CommandTypeSpecifier&
00089         operator=(const CommandTypeSpecifier& other)
00090         {
00091             assure(fuNet == other.fuNet, "Assignment is only supported within the same fun");
00092             fuNet = other.fuNet;
00093         }
00094 
00106         COMMANDTYPE* getCommand(const CommandPool* commandPool) const
00107         {
00108             assure(commandPool != NULL, "Invalid argument.");
00109 
00110             Command* command = getFUN()->getProxy()->getCommand(commandPool, this);
00111 
00112             assureType(command, COMMANDTYPE*);
00113             return static_cast<COMMANDTYPE*>(command);
00114         }
00115 
00120         COMMANDTYPE* getCommand(const CompoundPtr& compound) const
00121         {
00122             assure(compound != CompoundPtr(), "Invalid argument.");
00123             return this->getCommand(compound->getCommandPool());
00124         }
00125 
00140         COMMANDTYPE* activateCommand(CommandPool* commandPool) const
00141         {
00142             assure(commandPool != NULL, "Invalid argument.");
00143             Command* command = getFUN()->getProxy()->activateCommand(commandPool, this);
00144             assureType(command, COMMANDTYPE*);
00145             return static_cast<COMMANDTYPE*>(command);
00146         }
00147 
00162         void commitSizes(CommandPool* commandPool) const
00163         {
00164             assure(commandPool, "Invalid argument.");
00165             getFUN()->getProxy()->commitSizes(commandPool, this);
00166         }
00167     public:
00173         virtual CommandPool*
00174         createReply(const CommandPool* original) const
00175         {
00176             return getFUN()->getProxy()->createReply(original, this);
00177         } // createReply
00178 
00186         virtual void
00187         calculateSizes(const CommandPool* commandPool, Bit& commandPoolSize, Bit& dataSize) const
00188         {
00189             getFUN()->getProxy()->calculateSizes(commandPool, commandPoolSize, dataSize, this);
00190             Command* command = getFUN()->getProxy()->getCommand(commandPool, this);
00191 
00192             commandPoolSize += command->getSize();
00193         } // calculateSizes
00194 
00195         virtual Bit
00196         getLengthInBits(const CompoundPtr& compound) const
00197         {
00198             Bit commandPoolSize;
00199             Bit sduSize;
00200 
00201             getFUN()->getProxy()->calculateSizes(compound->getCommandPool(), commandPoolSize, sduSize, this);
00202             return commandPoolSize + sduSize;
00203         } // getLengthInBits
00204 
00205         virtual fun::FUN*
00206         getFUN() const
00207         {
00208             return fuNet;
00209         } // getFUN
00210 
00211         virtual CopyCommandInterface*
00212         getCopyCommandInterface() const
00213         {
00214             return new CopyCommand<COMMANDTYPE>;
00215         }
00216 
00217 #ifndef NDEBUG
00218         virtual size_t
00219         getCommandObjSize() const
00220         {
00221             return sizeof( COMMANDTYPE );
00222         }
00223 #endif
00224 
00225     private:
00226         COMMANDTYPE*
00227         createCommand() const
00228         {
00229             return new COMMANDTYPE();
00230         } // createCommand
00231 
00232         COMMANDTYPE*
00233         copyCommand(const Command* src) const
00234         {
00235             CopyCommand<COMMANDTYPE> f;
00236             return f.copy(src);
00237         } // copyCommand
00238 
00239 
00240         template<typename COMMAND>
00241         class CopyCommand :
00242             virtual public CopyCommandInterface
00243         {
00244         public:
00245             virtual
00246             ~CopyCommand(){}
00247 
00248             virtual COMMAND*
00249             copy(const Command* src) const
00250             {
00251                 assureType(src, const COMMAND*);
00252                 return new COMMAND(*(dynamic_cast<const COMMAND*>(src)));
00253             }
00254         };
00255 
00256         class CommandReader :
00257             virtual public CommandReaderInterface
00258         {
00259             const unsigned long int id;
00260             CommandProxy* proxy;
00261 
00262             virtual CommandProxy*
00263             getProxy() const
00264             {
00265                 return proxy;
00266             }
00267 
00268             virtual const unsigned long int
00269             getPCIID() const
00270             {
00271                 return id;
00272             }
00273 
00274         public:
00275             CommandReader(const unsigned long int _id, CommandProxy* _proxy) :
00276                 id(_id),
00277                 proxy(_proxy)
00278             {}
00279 
00280             virtual
00281             ~CommandReader(){}
00282 
00283             virtual bool
00284             commandIsActivated(const CommandPool* commandPool) const
00285             {
00286                 assure(commandPool != NULL, "Invalid argument.");
00287                 return proxy->commandIsActivated(commandPool, id);
00288             }
00289 
00290         };
00291 
00292         virtual CommandReaderInterface*
00293         getCommandReader(CommandProxy* proxy)
00294         {
00295             return new CommandReader(this->getPCIID(), proxy);
00296         }
00297 
00302         fun::FUN* fuNet;
00303     };
00304 
00305 } // ldk
00306 } // wns
00307 
00308 #endif // NOT defined WNS_LDK_COMMANDTYPESPECIFIER_HPP
00309 
00310 

Generated on Tue May 22 03:31:37 2012 for openWNS by  doxygen 1.5.5