User Manual, Developers Guide and API Documentation

utils.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/utils.hpp>
00029 
00030 using namespace wns;
00031 using namespace wns::ldk;
00032 
00033 
00034 FunctionalUnit*
00035 wns::ldk::configuredFunctionalUnit(fun::FUN* fuNet, const pyconfig::View& config)
00036 {
00037     std::string pluginName = config.get<std::string>("__plugin__");
00038 
00039     wns::pyconfig::View view = config;
00040 
00041     FunctionalUnit* functionalUnit = FunctionalUnitFactory::creator(pluginName)
00042         ->create(fuNet, view);
00043 
00044     return functionalUnit;
00045 } // configuredFunctionalUnit
00046 
00047 
00048 void
00049 wns::ldk::configureFUN(fun::FUN* fuNet, const pyconfig::View& config)
00050 {
00051     int nFunctionalUnits = config.len("functionalUnit");
00052     for(int ii = 0; ii < nFunctionalUnits; ++ii) {
00053         pyconfig::View nodeConfig(config, "functionalUnit", ii);
00054         std::string commandName = nodeConfig.get<std::string>("commandName");
00055         std::string functionalUnitName;
00056         if (!nodeConfig.isNone("functionalUnitName"))
00057             functionalUnitName = nodeConfig.get<std::string>("functionalUnitName");
00058         else
00059             functionalUnitName = commandName;
00060         if (nodeConfig.knows("config")){
00061             // Old-school config using wns.FUN.Node
00062             fuNet->addFunctionalUnit(commandName,
00063                                      functionalUnitName,
00064                                      configuredFunctionalUnit(fuNet, nodeConfig.get("config")));
00065         } else {
00066             // new config using FU config derived from wns.FUN.FunctionalUnit
00067             fuNet->addFunctionalUnit(commandName,
00068                                      functionalUnitName,
00069                                      configuredFunctionalUnit(fuNet, nodeConfig));
00070         }
00071     }
00072 
00073     // this is part of the connect order preserving quick hack.
00074     // order of connects should not matter, but here it was the simplest
00075     // way to get Dispatcher/FrameDispatcher running.
00076     int nConnections = config.len("connects");
00077     for(int ii = 0; ii < nConnections; ++ii) {
00078         pyconfig::View connection(config, "connects", ii);
00079 
00080         int type = connection.get<int>("type");
00081         std::string src;
00082         if (!connection.isNone("src.functionalUnitName"))
00083             src = connection.get<std::string>("src.functionalUnitName");
00084         else
00085             src = connection.get<std::string>("src.commandName");
00086 
00087         std::string srcPort = connection.get<std::string>("srcPort.name");
00088 
00089         std::string dst;
00090         if (!connection.isNone("dst.functionalUnitName"))
00091             dst = connection.get<std::string>("dst.functionalUnitName");
00092         else
00093             dst = connection.get<std::string>("dst.commandName");
00094 
00095         std::string dstPort = connection.get<std::string>("dstPort.name");
00096 
00097         switch(type) {
00098         case 0:
00099             fuNet->connectFunctionalUnit(src, dst, srcPort, dstPort);
00100             break;
00101         case 1:
00102             fuNet->downConnectFunctionalUnit(src, dst, srcPort, dstPort);
00103             break;
00104         case 2:
00105             fuNet->upConnectFunctionalUnit(src, dst, srcPort, dstPort);
00106             break;
00107         default:
00108             assure(false, "invalid connection type");
00109             break;
00110         }
00111     }
00112 } // configureFUN
00113 

Generated on Sun May 27 03:31:48 2012 for openWNS by  doxygen 1.5.5