User Manual, Developers Guide and API Documentation

CRCFilter.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/crc/CRCFilter.hpp>
00029 #include <WNS/ldk/crc/CRC.hpp>
00030 #include <WNS/ldk/fun/FUN.hpp>
00031 
00032 using namespace wns::ldk::crc;
00033 using namespace wns::ldk;
00034 
00035 STATIC_FACTORY_REGISTER_WITH_CREATOR(CRCFilter,
00036                      FunctionalUnit,
00037                      "wns.crc.CRCFilter",
00038                      FUNConfigCreator);
00039 
00040 
00041 CRCFilter::CRCFilter(fun::FUN* fuNet, const wns::pyconfig::View& _config) :
00042     fu::Plain<CRCFilter>(fuNet),
00043     SuspendSupport(fuNet, _config),
00044     friends(),
00045     fus(),
00046     config(_config),
00047     logger(_config.get("logger"))
00048 {
00049     friends.crc = NULL;
00050 } // CRCFilter
00051 
00052 
00053 void
00054 CRCFilter::onFUNCreated()
00055 {
00056     friends.crc = getFUN()->findFriend<CRC*>(config.get<std::string>("crc"));
00057     if (!friends.crc->isMarking())
00058         throw wns::Exception("CRC FU (friend) has to be set to mode MARKING");
00059     for (int i = 0; i < config.len("fus"); ++i)
00060         fus.push_back(getFUN()->findFriend<FunctionalUnit*>(config.get<std::string>("fus", i)));
00061 }  // onFUNCreated
00062 
00063 
00064 void
00065 CRCFilter::doOnData(const CompoundPtr& compound)
00066 {
00067     Command* command = getFUN()->getProxy()->getCommand(compound->getCommandPool(), friends.crc);
00068     assureType(command, CRCCommand*);
00069     CRCCommand* crcCommand = dynamic_cast<CRCCommand*>(command);
00070 
00071     if (crcCommand->local.checkOK)
00072     {
00073         MESSAGE_SINGLE(NORMAL, logger, "CRCheck - success");
00074         getDeliverer()->getAcceptor(compound)->onData(compound);
00075         return;
00076     }
00077     else
00078     {
00079         CommandPool* commandPool = compound->getCommandPool();
00080 
00081         for (unsigned int i = 0; i < fus.size(); ++i)
00082         {
00083             if (getFUN()->getProxy()->commandIsActivated(commandPool, fus.at(i)))
00084             {
00085                 MESSAGE_SINGLE(NORMAL, logger, "CRCheck - failed, but compound contains at least one activated command of listed FUs\n"
00086                            "Hence, forwarding compound to upper FU anyway");
00087                 crcCommand->local.checkOK = true;
00088                 getDeliverer()->getAcceptor(compound)->onData(compound);
00089                 return;
00090             }
00091         }
00092     }
00093 
00094     MESSAGE_SINGLE(NORMAL, logger, "CRCheck - failed - dropping compound");
00095 } // doOnData
00096 
00097 
00098 

Generated on Mon May 21 03:31:45 2012 for openWNS by  doxygen 1.5.5