User Manual, Developers Guide and API Documentation

Gate.cpp

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 #include <WNS/ldk/tools/Gate.hpp>
00029 
00030 using namespace wns::ldk;
00031 using namespace wns::ldk::tools;
00032 
00033 STATIC_FACTORY_REGISTER_WITH_CREATOR(Gate, FunctionalUnit, "wns.tools.Gate", FUNConfigCreator);
00034 
00035 Gate::Gate(fun::FUN* fuNet, const wns::pyconfig::View& config) :
00036         CommandTypeSpecifier<>(fuNet),
00037         HasReceptor<>(),
00038         HasConnector<>(),
00039         HasDeliverer<>(),
00040         Cloneable<Gate>(),
00041 
00042         logger("WNS", config.get<std::string>("name")),
00043 
00044         incomingState(OPEN),
00045         outgoingState(OPEN)
00046 {
00047 } // Gate
00048 
00049 
00050 void
00051 Gate::setIncomingState(State state)
00052 {
00053     incomingState = state;
00054 } // setIncomingState
00055 
00056 
00057 void
00058 Gate::setOutgoingState(State state)
00059 {
00060     outgoingState = state;
00061 
00062     wakeup();
00063 } // setOutgoingState
00064 
00065 
00066 bool
00067 Gate::doIsAccepting(const CompoundPtr& compound) const
00068 {
00069     if(outgoingState == CLOSED) {
00070         MESSAGE_BEGIN(NORMAL, logger, m, getFUN()->getName());
00071         m << " isAccepting -> false";
00072         MESSAGE_END();
00073 
00074         return false;
00075     }
00076 
00077     return getConnector()->hasAcceptor(compound);
00078 } // isAccepting
00079 
00080 
00081 void
00082 Gate::doSendData(const CompoundPtr& compound)
00083 {
00084     assure(isAccepting(compound), "sendData called although the FunctionalUnit is not accepting!");
00085 
00086     activateCommand(compound->getCommandPool());
00087 
00088     getConnector()->getAcceptor(compound)->sendData(compound);
00089 } // doSendData
00090 
00091 
00092 void
00093 Gate::doOnData(const CompoundPtr& compound)
00094 {
00095     if(incomingState == CLOSED) {
00096         MESSAGE_BEGIN(NORMAL, logger, m, getFUN()->getName());
00097         m << " dropping incoming PDU";
00098         MESSAGE_END();
00099     } else {
00100         getDeliverer()->getAcceptor(compound)->onData(compound);
00101     }
00102 } // doOnData
00103 
00104 
00105 void
00106 Gate::doWakeup()
00107 {
00108     if(outgoingState == CLOSED)
00109         return;
00110 
00111     getReceptor()->wakeup();
00112 } // wakeup
00113 
00114 
00115 

Generated on Thu May 24 03:31:44 2012 for openWNS by  doxygen 1.5.5