User Manual, Developers Guide and API Documentation

ProbeBusRegistry.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. 16, 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/probe/bus/ProbeBusRegistry.hpp>
00029 #include <WNS/probe/bus/PassThroughProbeBus.hpp>
00030 
00031 using namespace wns::probe::bus;
00032 
00033 ProbeBusRegistry::ProbeBusRegistry(const wns::pyconfig::View& pyco):
00034     pyco_(pyco),
00035     registry_(),
00036     logger_(pyco.get("logger"))
00037 {
00038 }
00039 
00040 ProbeBusRegistry::ProbeBusRegistry(const wns::pyconfig::View& pyco, wns::logger::Master* ml):
00041     pyco_(pyco),
00042     registry_(),
00043     logger_(pyco.get("logger"), ml)
00044 {
00045 }
00046 
00047 ProbeBusRegistry::~ProbeBusRegistry()
00048 {
00049     reset();
00050 }
00051 
00052 void
00053 ProbeBusRegistry::reset()
00054 {
00055     // Delete all busses
00056     for (CreatedProbeBussesContainer::iterator it = createdProbeBusses_.begin();
00057          it != createdProbeBusses_.end();
00058          ++it)
00059     {
00060         delete *it;
00061     }
00062     registry_ = ProbeBusRegistryContainer();
00063     createdProbeBusses_ = CreatedProbeBussesContainer();
00064 }
00065 
00066 void
00067 ProbeBusRegistry::startup()
00068 {
00069     this->spawnProbeBusses(pyco_);
00070 
00071     if (registry_.size() > 0)
00072     {
00073         MESSAGE_BEGIN(NORMAL, logger_, m, "");
00074         m << registry_;
00075         MESSAGE_END();
00076     }
00077 }
00078 
00079 void
00080 ProbeBusRegistry::spawnProbeBusses(const wns::pyconfig::View& config)
00081 {
00082     for(int ii=0 ; ii < config.len("measurementSources.keys()"); ++ii)
00083     {
00084         wns::pyconfig::View subpyco = config.get("measurementSources.values()",ii);
00085 
00086         std::string probeBusID = config.get<std::string>("measurementSources.keys()",ii);
00087 
00088         ProbeBus* pb = registry_.find(probeBusID);
00089 
00090         this->spawnObservers(pb, subpyco);
00091     }
00092 }
00093 
00094 void
00095 ProbeBusRegistry::spawnObservers(ProbeBus* subject, const wns::pyconfig::View& config)
00096 {
00097     for(int ii=0 ; ii < config.len("observers"); ++ii)
00098     {
00099         wns::pyconfig::View subpyco = config.get("observers", ii);
00100 
00101         std::string nameInFactory = subpyco.get<std::string>("nameInFactory");
00102 
00103         wns::probe::bus::ProbeBusCreator* c =
00104             wns::probe::bus::ProbeBusFactory::creator(nameInFactory);
00105 
00106         wns::probe::bus::ProbeBus* pb = c->create(subpyco);
00107 
00108         createdProbeBusses_.push_back(pb);
00109 
00110         pb->startObserving(subject);
00111 
00112         this->spawnObservers(pb, subpyco);
00113     }  
00114 }
00115 
00116 ProbeBus*
00117 ProbeBusRegistry::getMeasurementSource(const std::string& probeBusID)
00118 {
00119     if (!registry_.knows(probeBusID))
00120     {
00121         registry_.insert(probeBusID, new PassThroughProbeBus());
00122     }
00123     return registry_.find(probeBusID);
00124 }
00125 
00126 void
00127 ProbeBusRegistry::forwardOutput()
00128 {
00129     for (ProbeBusRegistryContainer::const_iterator it = registry_.begin();
00130          it != registry_.end();
00131          ++it)
00132     {
00133         it->second->forwardOutput();
00134     }
00135 }
00136 
00137 std::string
00138 ProbeBusRegistry::doToString() const
00139 {
00140     return registry_.toString();
00141 }

Generated on Fri May 25 03:31:50 2012 for openWNS by  doxygen 1.5.5