![]() |
User Manual, Developers Guide and API Documentation |
![]() |
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_CONTEXTPROVIDER_HPP 00029 #define WNS_PROBE_BUS_CONTEXTPROVIDER_HPP 00030 00031 #include <WNS/probe/bus/Context.hpp> 00032 00033 #include <WNS/StaticFactory.hpp> 00034 #include <WNS/PyConfigViewCreator.hpp> 00035 00036 #include <WNS/osi/PDU.hpp> 00037 #include <boost/function.hpp> 00038 00039 namespace wns { namespace probe { namespace bus { 00040 00045 class IContextProvider 00046 { 00047 public: 00052 virtual void 00053 visit(IContext&) const = 0; 00054 00060 virtual void 00061 visit(IContext&, const wns::osi::PDUPtr&) const = 0; 00062 00063 virtual ~IContextProvider() {} 00064 }; 00065 00070 template<typename T> 00071 class PDUContextProvider: 00072 public IContextProvider 00073 { 00074 public: 00075 00079 virtual void 00080 visit(IContext&) const{return;}; 00081 00087 virtual void 00088 visit(IContext& c, const wns::osi::PDUPtr& pdu) const 00089 { 00090 // Check if not NULL, return else 00091 if (!pdu) return; 00092 00093 // Check if of type T, return else 00094 if (NULL == dynamic_cast<T*>(pdu.getPtr())) return; 00095 00096 // Do the cast and dispatch 00097 const SmartPtr<T>& compound = wns::dynamicCast<T>(pdu); 00098 this->doVisit(c, compound); 00099 }; 00100 00101 private: 00102 virtual void 00103 doVisit(IContext&, const SmartPtr<T>&) const = 0; 00104 }; 00105 00110 class ContextProvider: 00111 public IContextProvider 00112 { 00113 public: 00114 virtual void 00115 visit(IContext& c) const 00116 { 00117 this->doVisit(c); 00118 }; 00119 00124 virtual void 00125 visit(IContext& c, const wns::osi::PDUPtr&) const 00126 { 00127 this->doVisit(c); 00128 }; 00129 00130 private: 00131 virtual void 00132 doVisit(IContext&) const = 0; 00133 }; 00134 00135 00136 typedef PyConfigViewCreator<IContextProvider> ContextProviderCreator; 00137 typedef wns::StaticFactory<ContextProviderCreator> ContextProviderFactory; 00138 00139 namespace contextprovider { 00140 00144 class Constant : 00145 public ContextProvider 00146 { 00147 public: 00148 Constant(const std::string& key, int value_); 00149 00150 explicit 00151 Constant(const pyconfig::View& config); 00152 00153 protected: 00154 const std::string key_; 00155 const int value_; 00156 00157 private: 00158 virtual void 00159 doVisit(IContext&) const; 00160 }; 00161 00172 class Variable : 00173 public ContextProvider 00174 { 00175 // prohibit use of copy constructor 00176 Variable(const Variable&) : ContextProvider(), key_(), value_() {} 00177 std::string key_; 00178 int value_; 00179 public: 00180 Variable(const std::string& key, int value_); 00181 00182 virtual void 00183 set(int value_); 00184 00185 virtual int 00186 get() const; 00187 private: 00188 virtual void 00189 doVisit(IContext&) const; 00190 00191 }; 00192 00198 class Container : 00199 public IContextProvider 00200 { 00201 IContextProvider* provider; 00202 public: 00203 Container(IContextProvider* p) : provider(p) {} 00204 00205 virtual void 00206 visit(IContext& context) const 00207 { 00208 provider->visit(context); 00209 } 00210 00211 virtual void 00212 visit(IContext& context, const wns::osi::PDUPtr& pdu) const 00213 { 00214 provider->visit(context, pdu); 00215 } 00216 00217 }; 00218 00234 class Callback : 00235 public ContextProvider 00236 { 00237 public: 00238 Callback(const std::string& key, 00239 boost::function0<int> callback): 00240 key_(key), 00241 callback_(callback) 00242 {} 00243 00244 private: 00245 virtual void 00246 doVisit(IContext& c) const 00247 { 00248 int value = callback_(); 00249 c.insertInt(key_, value); 00250 } 00251 00252 std::string key_; 00253 boost::function0<int> callback_; 00254 00255 }; 00256 } 00257 00258 }}} 00259 00260 00261 #endif // NOT defined WNS_PROBE_IDPROVIDER_HPP 00262 00263 /* 00264 Local Variables: 00265 mode: c++ 00266 fill-column: 80 00267 c-basic-offset: 8 00268 c-tab-always-indent: t 00269 indent-tabs-mode: t 00270 tab-width: 8 00271 End: 00272 */
1.5.5