![]() |
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. 16, 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/osi/PDU.hpp> 00029 #include <WNS/osi/PCI.hpp> 00030 00031 #include <sstream> 00032 00033 00034 using namespace wns::osi; 00035 00036 #ifndef NDEBUG 00037 long int PDU::existingPDUs = 0; 00038 long int PDU::maxExistingPDUs = 0; 00039 #endif 00040 00041 PDU::PDU(PCI* aPCIPtr, PDU* anSDUPtr) : 00042 p_pciPtr(PCIPtr()), 00043 p_userDataPtr(PDUPtr()) 00044 { 00045 if(aPCIPtr != NULL) 00046 p_pciPtr = PCIPtr(aPCIPtr); 00047 00048 if(anSDUPtr != NULL) 00049 p_userDataPtr = PDUPtr(anSDUPtr); 00050 00051 if(p_pciPtr != NULL) 00052 p_pciPtr->setSDU(p_userDataPtr); 00053 00054 #ifndef NDEBUG 00055 ++existingPDUs; 00056 maxExistingPDUs = std::max(maxExistingPDUs, existingPDUs); 00057 #endif // NDEBUG 00058 } 00059 00060 PDU::PDU(const PDU& aPDURef) : 00061 //wns::RefCountable(), 00062 wns::IOutputStreamable(), 00063 p_pciPtr(aPDURef.p_pciPtr), 00064 p_userDataPtr(aPDURef.p_userDataPtr) 00065 { 00066 #ifndef NDEBUG 00067 ++existingPDUs; 00068 maxExistingPDUs = std::max(maxExistingPDUs, existingPDUs); 00069 #endif // NDEBUG 00070 } 00071 00072 PDU::~PDU() 00073 { 00074 #ifndef NDEBUG 00075 --existingPDUs; 00076 #endif // NDEBUG 00077 } 00078 00079 void PDU::print(std::ostream& aStreamRef) const 00080 { 00081 aStreamRef << "p_pciPtr = " << p_pciPtr << std::endl 00082 << "p_userDataPtr = " << p_userDataPtr << std::endl; 00083 } 00084 00085 std::string 00086 PDU::doToString() const 00087 { 00088 std::stringstream ss; 00089 ss << "p_pciPtr = " << p_pciPtr << std::endl; 00090 ss << "p_userDataPtr = " << p_userDataPtr << std::endl; 00091 return ss.str(); 00092 } 00093 00094 void PDU::setPCI(PCI* aPCIPtr) 00095 { 00096 p_pciPtr = PCIPtr(aPCIPtr); 00097 if(p_pciPtr != NULL) 00098 p_pciPtr->setSDU(p_userDataPtr); 00099 } 00100 00101 PCI* PDU::getPCI() const 00102 { 00103 return p_pciPtr.getPtr(); 00104 } 00105 00106 void PDU::setUserData(PDU* aUserDataPtr) 00107 { 00108 if(aUserDataPtr != NULL) 00109 p_userDataPtr = PDUPtr(aUserDataPtr); 00110 else 00111 p_userDataPtr = PDUPtr(); 00112 00113 if(p_pciPtr != NULL) 00114 p_pciPtr->setSDU(p_userDataPtr); 00115 } 00116 00117 PDU* PDU::getUserData() const 00118 { 00119 return p_userDataPtr.getPtr(); 00120 } 00121 00122 void PDU::setPDUType(pduType aPDUType) 00123 { 00124 assure(p_pciPtr != NULL, "Can't set type of PDU without PCI!"); 00125 p_pciPtr->setPDUType(aPDUType); 00126 } 00127 00128 pduType PDU::getPDUType() const 00129 { 00130 assure(p_pciPtr != NULL, "Can't get type of PDU without PCI!"); 00131 return p_pciPtr->getPDUType(); 00132 } 00133 00134 unsigned long int PDU::getPDUId() const 00135 { 00136 assure(p_pciPtr != NULL, "Can't get id of PDU without PCI!"); 00137 return p_pciPtr->getPDUId(); 00138 } 00139 00140 PDU* PDU::clone() 00141 { 00142 return new PDU(*this); 00143 } 00144 00145 Bit 00146 PDU::getLengthInBits() const 00147 { 00148 assure(doGetLengthInBits() >= 0, "Length must be greater than zero"); 00149 return doGetLengthInBits(); 00150 } // getSize 00151 00152 Bit 00153 PDU::doGetLengthInBits() const 00154 { 00155 assure(false, "doGetLengthInBits not implementted! Implement in derived class!"); 00156 return 0; 00157 } 00158 00159 #ifndef NDEBUG 00160 00161 long int PDU::getExistingPDUs() 00162 { 00163 return existingPDUs; 00164 } 00165 00166 long int PDU::getMaxExistingPDUs() 00167 { 00168 return maxExistingPDUs; 00169 } 00170 00171 size_t 00172 PDU::calcObjSize() const 00173 { 00174 // Init with container size 00175 size_t sum = sizeof( *this ); 00176 if (p_pciPtr != NULL) 00177 // add PCI size 00178 sum += p_pciPtr->calcObjSize(); 00179 if (p_userDataPtr != NULL) 00180 // add SDU size 00181 sum += p_userDataPtr->calcObjSize(); 00182 return sum; 00183 } 00184 00185 #endif // not defined NDEBUG 00186 00187 /* 00188 Local Variables: 00189 mode: c++ 00190 folded-file: t 00191 End: 00192 */ 00193
1.5.5