![]() |
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_DELAYED_HPP 00029 #define WNS_LDK_DELAYED_HPP 00030 00031 #include <WNS/ldk/FunctionalUnit.hpp> 00032 #include <WNS/ldk/Receptor.hpp> 00033 00034 namespace wns { namespace ldk { 00035 00058 struct DelayedInterface : 00059 public virtual FunctionalUnit 00060 { 00067 virtual void processIncoming(const CompoundPtr& compound) = 0; 00068 00074 virtual void processOutgoing(const CompoundPtr&) = 0; 00075 00081 virtual bool hasCapacity() const = 0; 00082 00087 virtual const CompoundPtr hasSomethingToSend() const = 0; 00088 00096 virtual CompoundPtr getSomethingToSend() = 0; 00097 }; 00098 00099 00106 template <typename USER> 00107 class Delayed : 00108 public virtual FunctionalUnit, 00109 public virtual DelayedInterface 00110 { 00111 public: 00112 Delayed() 00113 : inWakeup(false) 00114 {} 00115 00116 00118 virtual void 00119 doSendData(const CompoundPtr& compound) 00120 { 00121 processOutgoing(compound); 00122 00123 tryToSend(); 00124 } // doSendData 00125 00126 00128 virtual void 00129 doOnData(const CompoundPtr& compound) 00130 { 00131 processIncoming(compound); 00132 00133 tryToSend(); 00134 } // doOnData 00135 00136 protected: 00146 void 00147 tryToSend() 00148 { 00149 // first, we try to send as many compounds from our internal memory as possible. if there 00150 // is no PDU left to send, we wake up all our upper layers. 00151 // waking up upper layers may result in doSendData calls to this layer, which ends up 00152 // in another call to this method. if functionalUnit capacities are high, recursion depth 00153 // may become an issue. 00154 while(tryToSendOnce()); 00155 00156 if(!inWakeup && hasCapacity()) { 00157 inWakeup = true; 00158 getReceptor()->wakeup(); 00159 inWakeup = false; 00160 } 00161 } // tryToSend 00162 00164 virtual bool 00165 doIsAccepting(const CompoundPtr& /* compound */) const 00166 { 00167 return hasCapacity(); 00168 } // isAccepting 00169 00170 00171 private: 00172 // 00173 // CompoundHandlerInterface implementation 00174 // 00175 00177 virtual void 00178 doWakeup() 00179 { 00180 tryToSend(); 00181 } // wakeup 00182 00183 bool 00184 tryToSendOnce() 00185 { 00186 const CompoundPtr compound = hasSomethingToSend(); 00187 if(compound == CompoundPtr()) 00188 return false; 00189 00190 if(!getConnector()->hasAcceptor(compound)) 00191 return false; 00192 00193 IConnectorReceptacle* target = getConnector()->getAcceptor(compound); 00194 target->sendData(getSomethingToSend()); 00195 00196 return true; 00197 } // tryToSendOnce 00198 00199 bool inWakeup; 00200 }; 00201 }} 00202 00203 00204 #endif // NOT defined WNS_LDK_DELAYED_HPP 00205 00206
1.5.5