User Manual, Developers Guide and API Documentation

Routing.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  * Glue                                                                       *
00003  * __________________________________________________________________________ *
00004  *                                                                            *
00005  * Copyright (C) 2005-2006                                                    *
00006  * Lehrstuhl fuer Kommunikationsnetze (ComNets)                               *
00007  * Kopernikusstr. 16, D-52074 Aachen, Germany                                 *
00008  * phone: ++49-241-80-27910 (phone), fax: ++49-241-80-22242                   *
00009  * email: wns@comnets.rwth-aachen.de                                          *
00010  * www: http://wns.comnets.rwth-aachen.de                                     *
00011  ******************************************************************************/
00012 
00013 #include <GLUE/Routing.hpp>
00014 #include <GLUE/convergence/Upper.hpp>
00015 
00016 using namespace glue;
00017 using namespace wns::ldk;
00018 
00019 STATIC_FACTORY_REGISTER_WITH_CREATOR(Routing,
00020                      wns::ldk::FunctionalUnit,
00021                      "glue.Routing",
00022                      wns::ldk::FUNConfigCreator);
00023 
00024 
00025 Routing::Routing(wns::ldk::fun::FUN* fun, const wns::pyconfig::View& _config) :
00026     wns::ldk::CommandTypeSpecifier<RoutingCommand>(fun),
00027     wns::ldk::HasReceptor<>(),
00028     wns::ldk::HasConnector<>(),
00029     wns::ldk::HasDeliverer<>(),
00030     wns::Cloneable<Routing>(),
00031 
00032     allowRouteChange(_config.get<bool>("allowRouteChange")),
00033     routingCommandPool(NULL),
00034     config(_config),
00035     logger(_config.get<wns::pyconfig::View>("logger"))
00036 {
00037     friends.addressProviderFU = NULL;
00038 } // Routing
00039 
00040 
00041 Routing::~Routing()
00042 {
00043 } // ~Routing
00044 
00045 
00046 void
00047 Routing::onFUNCreated()
00048 {
00049     friends.addressProviderFU = getFUN()->findFriend<FunctionalUnit*>(config.get<std::string>("addressProvider"));
00050 } // onFUNCreated
00051 
00052 
00053 void
00054 Routing::doSendData(const wns::ldk::CompoundPtr& compound)
00055 {
00056     assure(isAccepting(compound), "sendData called although not accepting!");
00057 
00058     if (!getFUN()->getProxy()->commandIsActivated(compound->getCommandPool(),
00059                               friends.addressProviderFU))
00060     {
00061         if (!routingCommandPool)
00062         {
00063             MESSAGE_BEGIN(NORMAL, logger, m, getFUN()->getName());
00064             m << ": Routing information not (yet) available. Discarding compound...";
00065             MESSAGE_END();
00066 
00067             return;
00068         }
00069         else
00070         {
00071             getFUN()->getProxy()->copy(compound->getCommandPool(), routingCommandPool);
00072 
00073             MESSAGE_BEGIN(NORMAL, logger, m, getFUN()->getName());
00074             m << ": Routing information to compound added";
00075             MESSAGE_END();
00076         }
00077     }
00078 
00079     activateCommand(compound->getCommandPool());
00080 
00081     getConnector()->getAcceptor(compound)->sendData(compound);
00082 } // doSendData
00083 
00084 
00085 void
00086 Routing::doOnData(const wns::ldk::CompoundPtr& compound)
00087 {
00088     if (!routingCommandPool)
00089     {
00090         routingCommandPool = createReply(compound->getCommandPool());
00091 
00092         MESSAGE_BEGIN(NORMAL, logger, m, getFUN()->getName());
00093         m << ": Setting routing information";
00094         MESSAGE_END();
00095     }
00096     else if (allowRouteChange)
00097     {
00098         if (routingCommandPool)
00099             delete routingCommandPool;
00100         routingCommandPool = createReply(compound->getCommandPool());
00101 
00102         MESSAGE_BEGIN(NORMAL, logger, m, getFUN()->getName());
00103         m << ": Setting new routing information";
00104         MESSAGE_END();
00105     }
00106 
00107     getDeliverer()->getAcceptor(compound)->onData(compound);
00108 } // doOnData
00109 
00110 
00111 bool
00112 Routing::doIsAccepting(const wns::ldk::CompoundPtr& compound) const
00113 {
00114     if (getFUN()->getProxy()->commandIsActivated(compound->getCommandPool(),
00115                              friends.addressProviderFU))
00116     {
00117         return getConnector()->hasAcceptor(compound);
00118     }
00119     else
00120     {
00121         if (routingCommandPool)
00122         {
00123             CompoundPtr compoundCopy = compound->copy();
00124             getFUN()->getProxy()->copy(compoundCopy->getCommandPool(), routingCommandPool);
00125             return getConnector()->hasAcceptor(compoundCopy);
00126         }
00127     }
00128 
00129     return false;
00130 } // doIsAccepting
00131 
00132 
00133 

Generated on Sun May 27 03:32:17 2012 for openWNS by  doxygen 1.5.5