![]() |
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 #ifndef WNS_LDK_COMMANDPROXY_HPP 00029 #define WNS_LDK_COMMANDPROXY_HPP 00030 00031 #include <WNS/container/Registry.hpp> 00032 #include <WNS/Singleton.hpp> 00033 #include <WNS/logger/Logger.hpp> 00034 00035 #include <WNS/osi/PCI.hpp> 00036 00037 #include <vector> 00038 #include <cstdlib> 00039 00040 namespace wns { namespace ldk { 00041 00042 class Command; 00043 class CommandPool; 00044 class CommandTypeSpecifierInterface; 00045 class CopyCommandInterface; 00046 class CommandReaderInterface; 00047 00048 namespace fun { 00049 class FUN; 00050 } 00051 00063 class CommandProxy 00064 { 00065 public: 00066 typedef unsigned long int CommandIDType; 00067 private: 00068 00069 // During registration, each FunctionalUnit will be tagged with 00070 // the position within the CommandPool using 00071 // CommandTypeSpecifierInterface::setPCIID(). 00072 // 00073 // Later on, each FunctionalUnit can be queried for its Command 00074 // position within the commandPool by calling 00075 // CommandTypeSpecifierInterface::getPCIID(). 00076 00077 friend class CommandReaderInterface; 00078 friend class CommandPool; 00079 00083 typedef std::vector<CommandTypeSpecifierInterface*> 00084 CommandTypeSpecifierContainer; 00085 00089 typedef std::vector<bool> 00090 BoolContainer; 00091 00095 typedef wns::container::Registry<std::string, CommandIDType> 00096 CommandIDRegistry; 00097 00101 typedef wns::container::Registry<CommandIDType, CommandReaderInterface*, wns::container::registry::DeleteOnErase> 00102 CommandReaderRegistry; 00103 00107 typedef wns::container::Registry<CommandIDType, CopyCommandInterface*, wns::container::registry::DeleteOnErase> 00108 CopyCommandInterfaceRegistry; 00109 00110 wns::logger::Logger logger; 00111 00112 public: 00113 CommandProxy() : 00114 logger("default","default"), 00115 commandTypeSpecifiers(), 00116 commandTypeSpecifierCloned() 00117 { 00118 wns::simulator::getResetSignal()->connect(&wns::ldk::CommandProxy::clearRegistries); 00119 } 00120 00121 CommandProxy(const wns::pyconfig::View& config); 00122 00123 ~CommandProxy(); 00124 00133 void 00134 addFunctionalUnit( 00135 const std::string& commandName, 00136 CommandTypeSpecifierInterface* functionalUnit); 00137 00144 void 00145 removeFunctionalUnit(const std::string& commandName); 00146 00156 CommandPool* 00157 createCommandPool(const fun::FUN* origin = NULL) const; 00158 00186 CommandPool* 00187 createReply( 00188 const CommandPool* original, 00189 const CommandTypeSpecifierInterface* questioner) const; 00190 00216 void 00217 calculateSizes( 00218 const CommandPool* commandPool, 00219 Bit& commandPoolSize, Bit& sduSize, 00220 const CommandTypeSpecifierInterface* questioner = NULL) const; 00221 00225 void 00226 commitSizes(CommandPool* commandPool, 00227 const CommandTypeSpecifierInterface* commiter = NULL) const; 00228 00232 void 00233 commitSizes(CommandPool* commandPool, 00234 const CommandIDType& id) const; 00235 00242 Command* 00243 getCommand( 00244 const CommandPool* commandPool, 00245 const CommandTypeSpecifierInterface* kind) const; 00246 00250 Command* 00251 getCommand(const CommandPool* commandPool, CommandIDType n) const; 00252 00259 template <typename COMMANDTYPE> 00260 COMMANDTYPE* 00261 getCommand(const CommandPool* commandPool, const std::string& role) const 00262 { 00263 assure(this->getCommandIDRegistry().knows(role), "Argument for unknown role="<<role<<" requested."); 00264 Command* theCommand = this->getCommand(commandPool, this->getCommandIDRegistry().find(role)); 00265 assureType(theCommand, COMMANDTYPE*); 00266 return dynamic_cast<COMMANDTYPE*>(theCommand); 00267 } // getCommand 00268 00273 CommandReaderInterface* 00274 getCommandReader(const std::string& role) const; 00275 00282 static Command* 00283 activateCommand( 00284 CommandPool* commandPool, 00285 const CommandTypeSpecifierInterface* kind); 00286 00293 Command* 00294 activateCommand( 00295 CommandPool* commandPool, 00296 const CommandIDType& id); 00297 00306 bool 00307 commandIsActivated( 00308 const CommandPool* commandPool, 00309 const CommandTypeSpecifierInterface* kind) const; 00310 00312 bool 00313 commandIsActivated( 00314 const CommandPool* commandPool, 00315 const CommandIDType& id) const; 00316 00320 void 00321 copy(CommandPool* dst, const CommandPool* src) const; 00322 00343 void 00344 partialCopy( 00345 const CommandTypeSpecifierInterface* initiator, 00346 CommandPool* dst, const CommandPool* src) const; 00347 00356 static void 00357 clearRegistries(); 00358 00362 std::string 00363 printCommandIDRegistryKeys() 00364 { 00365 return dumpCommandIDRegistry(); 00366 } 00367 00368 #ifndef NDEBUG 00369 size_t 00370 getCommandObjSize(const CommandIDType& id) const; 00371 #endif 00372 private: 00376 void 00377 cleanup(CommandPool* commandPool) const; 00378 00380 wns::ldk::Command* 00381 commit(CommandPool* commandPool, 00382 const CommandTypeSpecifierInterface* commiter = NULL) const; 00383 00387 const CommandTypeSpecifierInterface* 00388 getCommandTypeSpecifier(CommandIDType id) const; 00389 00393 const CommandTypeSpecifierInterface* 00394 getNext( 00395 const CommandPool* commandPool, 00396 const CommandTypeSpecifierInterface* questioner) const; 00397 00398 CommandTypeSpecifierContainer commandTypeSpecifiers; 00399 00400 BoolContainer commandTypeSpecifierCloned; 00401 00402 static CommandIDType serial; 00403 00404 static CommandIDRegistry& 00405 getCommandIDRegistry(); 00406 00407 static std::string 00408 dumpCommandIDRegistry(); 00409 00410 static CopyCommandInterfaceRegistry& 00411 getCopyCommandRegistry(); 00412 00413 static CommandReaderRegistry& 00414 getCommandReaderRegistry(); 00415 00416 }; 00417 00418 } // ldk 00419 } // wns 00420 00421 #endif // NOT defined WNS_LDK_COMMANDPROXY_HPP 00422 00423
1.5.5