![]() |
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 #include <WNS/ldk/Layer.hpp> 00029 #include <WNS/ldk/FunctionalUnit.hpp> 00030 #include <WNS/ldk/Command.hpp> 00031 #include <WNS/TypeInfo.hpp> 00032 00033 #include <WNS/Exception.hpp> 00034 00035 #include <sstream> 00036 00037 using namespace std; 00038 using namespace wns::ldk; 00039 00040 CommandPool::CommandPool(const CommandProxy* _proxy, 00041 const fun::FUN* _origin) : 00042 PCI(), 00043 path(), 00044 proxy(_proxy), 00045 commands(), 00046 origin(_origin), 00047 receiver(NULL) 00048 { 00049 } // CommandPool 00050 00051 00052 CommandPool::CommandPool(const CommandPool& that) : 00053 // RefCountable(), 00054 PCI(that), 00055 proxy(that.proxy), 00056 commands(), 00057 origin(that.origin), 00058 receiver(that.receiver) 00059 { 00060 proxy->copy(this, &that); 00061 } // CommandPool 00062 00063 00064 CommandPool::~CommandPool() 00065 { 00066 CommandContainer::const_iterator end = commands.end(); 00067 for (CommandContainer::const_iterator ii = commands.begin(); 00068 ii != end; 00069 ++ii) 00070 { 00071 Command* command = *ii; 00072 if (NULL != command) 00073 { 00074 delete command; 00075 } 00076 } 00077 } // ~CommandPool 00078 00079 00080 void 00081 CommandPool::calculateSizes( 00082 Bit& commandPoolSize, 00083 Bit& dataSize, 00084 const FunctionalUnit* questioner) const 00085 { 00086 proxy->calculateSizes(this, commandPoolSize, dataSize, questioner); 00087 } // calculateSizes 00088 00089 00090 void 00091 CommandPool::setSDUPtr(osi::PDUPtr& sdu) 00092 { 00093 if(sdu) { 00094 setPDULength(sdu->getLengthInBits()); 00095 } else { 00096 setPDULength(0); // only a valid branch during testing 00097 } 00098 00099 PCI::setSDU(sdu); 00100 } // setSDU 00101 00102 std::string 00103 CommandPool::dumpCommandTypes() const { 00104 std::stringstream str; 00105 CommandProxy::CommandIDType commandID = 0; 00106 for(CommandContainer::const_iterator iter = commands.begin(); 00107 iter != commands.end(); 00108 ++iter) 00109 { 00110 str << "Command ID: " << commandID << ", Type: "; 00111 if(*iter == NULL) 00112 { 00113 str << "NULL"; 00114 } 00115 else 00116 { 00117 str << TypeInfo::create(**iter); 00118 } 00119 str << "\n"; 00120 ++commandID; 00121 } 00122 return str.str(); 00123 } 00124 00125 bool 00126 CommandPool::knowsSameCommandsAs(const CommandPool& swimmingPool) const 00127 { 00128 bool isSame = true; 00129 CommandContainer::const_iterator iterMe = commands.begin(); 00130 CommandContainer::const_iterator iterSwimmingPool = swimmingPool.commands.begin(); 00131 while (isSame && (iterMe != commands.end()) && (iterSwimmingPool != swimmingPool.commands.end())) { 00132 isSame = ((*iterMe == NULL) && (*iterSwimmingPool == NULL) || 00133 (*iterMe != NULL) && (*iterSwimmingPool != NULL)); 00134 ++iterMe; 00135 ++iterSwimmingPool; 00136 } 00137 return isSame; 00138 } 00139 00140 void 00141 CommandPool::insert( 00142 const CommandProxy::CommandIDType& id, 00143 Command* command) 00144 { 00145 // if container is too small: resize and set new elements to NULL 00146 if (commands.size() <= id) 00147 { 00148 size_t oldSize = commands.size(); 00149 commands.resize(id+1); 00150 for(size_t ii = oldSize; ii < commands.size(); ++ii) 00151 { 00152 commands.at(ii) = NULL; 00153 } 00154 } 00155 if (NULL != commands.at(id)) 00156 { 00157 throw wns::Exception("You tried to insert a command which is already inserted!"); 00158 } 00159 00160 commands.at(id) = command; 00161 } 00162 00163 wns::ldk::Command* 00164 CommandPool::find(const CommandProxy::CommandIDType& id) const 00165 { 00166 return commands.at(id); 00167 } 00168 00169 bool 00170 CommandPool::knows(const CommandProxy::CommandIDType& id) const 00171 { 00172 if (commands.size() <= id) { 00173 return false; 00174 } else { 00175 return commands.at(id) != NULL; 00176 } 00177 } 00178 00179 #ifndef NDEBUG 00180 size_t 00181 CommandPool::calcObjSize() const 00182 { 00183 size_t sum = sizeof( *this ); 00184 for (size_t ii = 0; ii < commands.size(); ++ii) 00185 { 00186 if (commands.at(ii)!=NULL) 00187 { 00188 sum += proxy->getCommandObjSize(ii); 00189 } 00190 } 00191 return sum; 00192 } 00193 #endif 00194
1.5.5