User Manual, Developers Guide and API Documentation

ContextCollector.hpp

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 #ifndef WNS_PROBE_BUS_PUTDECORATOR_HPP
00029 #define WNS_PROBE_BUS_PUTDECORATOR_HPP
00030 
00031 #include <WNS/probe/bus/ContextProvider.hpp>
00032 #include <WNS/probe/bus/ContextProviderCollection.hpp>
00033 #include <WNS/probe/bus/ProbeBusRegistry.hpp>
00034 #include <WNS/probe/bus/ProbeBus.hpp>
00035 #include <WNS/simulator/ISimulator.hpp>
00036 
00037 #include <WNS/osi/PDU.hpp>
00038 
00039 #include <WNS/RefCountable.hpp>
00040 #include <WNS/SmartPtr.hpp>
00041 
00042 #include <boost/tuple/tuple.hpp>
00043 
00044 #include <vector>
00045 
00046 namespace wns { namespace probe { namespace bus {
00047 
00059     class ContextCollector :
00060         virtual public wns::RefCountable
00061     {
00062         ContextProviderCollection contextProviders_;
00064         wns::probe::bus::ProbeBus* probeBus_;
00065 
00066         template <typename Tuple, int keyIndex, int valueIndex>
00067         struct detail
00068         {
00069             static void fillContext(Context& c, const Tuple& tuple)
00070                 {
00071                     std::string k = boost::tuples::get<keyIndex>(tuple);
00072 
00073                     c.insert(k, boost::tuples::get<valueIndex>(tuple));
00074 
00075                     detail<Tuple, keyIndex-2, valueIndex-2>::fillContext(c, tuple);
00076                 }
00077         };
00078 
00079         template <typename Tuple>
00080         struct detail<Tuple, 0, 1>
00081         {
00082             static void fillContext(Context& c, const Tuple& tuple)
00083                 {
00084                     std::string k = boost::tuples::get<0>(tuple);
00085 
00086                     c.insert(k, boost::tuples::get<1>(tuple));
00087                 }
00088         };
00089 
00090     public:
00091 
00092         ContextCollector(std::string probeBusId);
00093 
00098         ContextCollector(ContextProviderCollection contextProviders,
00099                          std::string probeBusId);
00100 
00101         ~ContextCollector()
00102         {};
00103 
00104         bool
00105         hasObservers() const;
00106 
00107         void
00108         put(double value) const;
00109 
00117         template<typename Tuple>
00118         void
00119         put(double value, const Tuple& contextentries) const
00120             {
00121                 // early return if no one is listening
00122                 if (!probeBus_->hasObservers())
00123                 {
00124                     return;
00125                 }
00126                 // Create vanilla Context object
00127                 Context c;
00128 
00129                 contextProviders_.fillContext(c);
00130 
00131                 ContextCollector::detail<Tuple, boost::tuples::length<Tuple>::value-2, boost::tuples::length<Tuple>::value-1>::fillContext(c, contextentries);
00132 
00133                 // determine simTime
00134                 wns::simulator::Time t = wns::simulator::getEventScheduler()->getTime();
00135                 probeBus_->forwardMeasurement(t, value, c);
00136             }
00137 
00138         void
00139         put(const wns::osi::PDUPtr&, double value) const;
00140 
00141         template<typename Tuple>
00142         void
00143         put(const wns::osi::PDUPtr& compound, double value, const Tuple& contextentries) const
00144             {
00145                 // early return if no one is listening
00146                 if (!probeBus_->hasObservers())
00147                 {
00148                     return;
00149                 }
00150                 // Create vanilla Context object
00151                 Context c;
00152 
00153                 contextProviders_.fillContext(c, compound);
00154 
00155                 ContextCollector::detail<Tuple, boost::tuples::length<Tuple>::value-2, boost::tuples::length<Tuple>::value-1>::fillContext(c, contextentries);
00156 
00157                 // determine simTime
00158                 wns::simulator::Time t = wns::simulator::getEventScheduler()->getTime();
00159                 probeBus_->forwardMeasurement(t, value, c);
00160             }
00161     };
00162 
00163     typedef wns::SmartPtr<ContextCollector> ContextCollectorPtr;
00164 
00165 }}}
00166 
00298 #endif // NOT defined WNS_PROBE_PUTDECORATOR_HPP

Generated on Tue May 22 03:31:46 2012 for openWNS by  doxygen 1.5.5