User Manual, Developers Guide and API Documentation

FlowControl.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/command/FlowControl.hpp>
00029 
00030 #include <WNS/ldk/fun/FUN.hpp>
00031 
00032 #include <iostream>
00033 
00034 using namespace wns::ldk;
00035 using namespace wns::ldk::command;
00036 
00037 STATIC_FACTORY_REGISTER_WITH_CREATOR(FlowControl, FunctionalUnit, "wns.command.FlowControl", FUNConfigCreator);
00038 
00039 FlowControl::FlowControl(fun::FUN* fuNet, const wns::pyconfig::View& _config) :
00040         CommandTypeSpecifier<FlowControlCommand>(fuNet),
00041         HasReceptor<>(),
00042         HasConnector<>(),
00043         HasDeliverer<>(),
00044         Delayed<FlowControl>(),
00045         Cloneable<FlowControl>(),
00046 
00047         config(_config),
00048         toSend(CompoundPtr()),
00049         logger("WNS", config.get<std::string>("name"))
00050 {
00051     friends.gate = 0;
00052 } // FlowControl
00053 
00054 
00055 void
00056 FlowControl::open()
00057 {
00058     MESSAGE_BEGIN(NORMAL, logger, m, getFUN()->getName());
00059     m << " open";
00060     MESSAGE_END();
00061 
00062     friends.gate->setOutgoingState(tools::GateInterface::OPEN);
00063     send(FlowControlCommand::START);
00064 } // open
00065 
00066 
00067 void
00068 FlowControl::close()
00069 {
00070     MESSAGE_BEGIN(NORMAL, logger, m, getFUN()->getName());
00071     m << " close";
00072     MESSAGE_END();
00073 
00074     friends.gate->setOutgoingState(tools::GateInterface::CLOSED);
00075     send(FlowControlCommand::STOP);
00076 } // close
00077 
00078 
00079 bool
00080 FlowControl::hasCapacity() const
00081 {
00082     return false;
00083 } // hasCapacity
00084 
00085 
00086 void
00087 FlowControl::processOutgoing(const CompoundPtr& /* compound */)
00088 {
00089     assure(false, "command::FlowControl never accepts compounds.");
00090 } // processOutgoing
00091 
00092 
00093 void
00094 FlowControl::processIncoming(const CompoundPtr& compound)
00095 {
00096     FlowControlCommand* command = getCommand(compound->getCommandPool());
00097 
00098     switch(command->peer.type) {
00099     case FlowControlCommand::START:
00100         MESSAGE_BEGIN(NORMAL, logger, m, getFUN()->getName());
00101         m << " received START";
00102         MESSAGE_END();
00103 
00104         friends.gate->setOutgoingState(tools::GateInterface::OPEN);
00105         break;
00106 
00107     case FlowControlCommand::STOP:
00108         MESSAGE_BEGIN(NORMAL, logger, m, getFUN()->getName());
00109         m << " received STOP";
00110         MESSAGE_END();
00111 
00112         friends.gate->setOutgoingState(tools::GateInterface::CLOSED);
00113         break;
00114     }
00115 } // doOnData
00116 
00117 
00118 const CompoundPtr
00119 FlowControl::hasSomethingToSend() const
00120 {
00121     return toSend;
00122 } // hasSomethingToSend
00123 
00124 
00125 CompoundPtr
00126 FlowControl::getSomethingToSend()
00127 {
00128     CompoundPtr it = toSend;
00129     toSend = CompoundPtr();
00130     return it;
00131 } // getSomethingToSend
00132 
00133 
00134 void
00135 FlowControl::send(FlowControlCommand::FrameType type)
00136 {
00137     toSend = CompoundPtr(getFUN()->createCompound());
00138 
00139     FlowControlCommand* command = activateCommand(toSend->getCommandPool());
00140     command->peer.type = type;
00141 
00142     tryToSend();
00143 } // send
00144 
00145 
00146 void
00147 FlowControl::onFUNCreated()
00148 {
00149     std::string gateName = config.get<std::string>("gateName");
00150     friends.gate = getFUN()->findFriend<tools::GateInterface*>(gateName);
00151 } // onFUNCreated
00152 
00153 
00154 void
00155 FlowControl::calculateSizes(const CommandPool* commandPool, Bit& commandPoolSize, Bit& dataSize) const
00156 {
00157     getFUN()->calculateSizes(commandPool, commandPoolSize, dataSize, this);
00158 
00159     commandPoolSize += 1;               // START / STOP bit
00160 } // calculateSizes
00161 
00162 
00163 CommandPool*
00164 FlowControl::createReply(const CommandPool* /* original */) const
00165 {
00166     MESSAGE_BEGIN(NORMAL, logger, m, "createReply");
00167     MESSAGE_END();
00168 
00169     CommandPool* commandPool = getFUN()->createCommandPool();
00170 
00171     return commandPool;
00172 } // createReply
00173 
00174 
00175 

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