00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2008 INRIA 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> 00019 */ 00020 #ifndef CONFIG_H 00021 #define CONFIG_H 00022 00023 #include "ptr.h" 00024 #include <string> 00025 #include <vector> 00026 00027 namespace ns3 { 00028 00029 class AttributeValue; 00030 class Object; 00031 class CallbackBase; 00032 00033 /** 00034 * \brief Configuration of simulation parameters and tracing 00035 * \ingroup core 00036 */ 00037 namespace Config { 00038 00039 /** 00040 * \param path a path to match attributes. 00041 * \param value the value to set in all matching attributes. 00042 * 00043 * This function will attempt to find attributes which 00044 * match the input path and will then set their value to the input 00045 * value. 00046 */ 00047 void Set (std::string path, const AttributeValue &value); 00048 /** 00049 * \param name the full name of the attribute 00050 * \param value the value to set. 00051 * 00052 * This method overrides the initial value of the 00053 * matching attribute. This method cannot fail: it will 00054 * crash if the input attribute name or value is invalid. 00055 */ 00056 void SetDefault (std::string name, const AttributeValue &value); 00057 /** 00058 * \param name the full name of the attribute 00059 * \param value the value to set. 00060 * \returns true if the value was set successfully, false otherwise. 00061 * 00062 * This method overrides the initial value of the 00063 * matching attribute. 00064 */ 00065 bool SetDefaultFailSafe (std::string name, const AttributeValue &value); 00066 /** 00067 * \param name the name of the requested GlobalValue. 00068 * \param value the value to set 00069 * 00070 * This method is equivalent to GlobalValue::Bind 00071 */ 00072 void SetGlobal (std::string name, const AttributeValue &value); 00073 /** 00074 * \param name the name of the requested GlobalValue. 00075 * \param value the value to set 00076 * 00077 * This method is equivalent to GlobalValue::BindFailSafe 00078 */ 00079 bool SetGlobalFailSafe (std::string name, const AttributeValue &value); 00080 /** 00081 * \param path a path to match trace sources. 00082 * \param cb the callback to connect to the matching trace sources. 00083 * 00084 * This function will attempt to find all trace sources which 00085 * match the input path and will then connect the input callback 00086 * to them. 00087 */ 00088 void ConnectWithoutContext (std::string path, const CallbackBase &cb); 00089 /** 00090 * \param path a path to match trace sources. 00091 * \param cb the callback to disconnect to the matching trace sources. 00092 * 00093 * This function undoes the work of Config::Connect. 00094 */ 00095 void DisconnectWithoutContext (std::string path, const CallbackBase &cb); 00096 /** 00097 * \param path a path to match trace sources. 00098 * \param cb the callback to connect to the matching trace sources. 00099 * 00100 * This function will attempt to find all trace sources which 00101 * match the input path and will then connect the input callback 00102 * to them in such a way that the callback will receive an extra 00103 * context string upon trace event notification. 00104 */ 00105 void Connect (std::string path, const CallbackBase &cb); 00106 /** 00107 * \param path a path to match trace sources. 00108 * \param cb the callback to connect to the matching trace sources. 00109 * 00110 * This function undoes the work of Config::ConnectWithContext. 00111 */ 00112 void Disconnect (std::string path, const CallbackBase &cb); 00113 00114 /** 00115 * \brief hold a set of objects which match a specific search string. 00116 * 00117 * This class also allows you to perform a set of configuration operations 00118 * on the set of matching objects stored in the container. Specifically, 00119 * it is possible to perform bulk Connects and Sets. 00120 */ 00121 class MatchContainer 00122 { 00123 public: 00124 typedef std::vector<Ptr<Object> >::const_iterator Iterator; 00125 MatchContainer (); 00126 // constructor used only by implementation. 00127 MatchContainer (const std::vector<Ptr<Object> > &objects, 00128 const std::vector<std::string> &contexts, 00129 std::string path); 00130 00131 /** 00132 * \returns an iterator which points to the first item in the container 00133 */ 00134 MatchContainer::Iterator Begin (void) const; 00135 /** 00136 * \returns an iterator which points to the last item in the container 00137 */ 00138 MatchContainer::Iterator End (void) const; 00139 /** 00140 * \returns the number of items in the container 00141 */ 00142 uint32_t GetN (void) const; 00143 /** 00144 * \param i index of item to lookup ([0,n[) 00145 * \returns the item requested. 00146 */ 00147 Ptr<Object> Get (uint32_t i) const; 00148 /** 00149 * \param i index of item to lookup ([0,n[) 00150 * \returns the fully-qualified matching path associated 00151 * to the requested item. 00152 * 00153 * The matching patch uniquely identifies the requested object. 00154 */ 00155 std::string GetMatchedPath (uint32_t i) const; 00156 /** 00157 * \returns the path used to perform the object matching. 00158 */ 00159 std::string GetPath (void) const; 00160 00161 /** 00162 * \param name name of attribute to set 00163 * \param value value to set to the attribute 00164 * 00165 * Set the specified attribute value to all the objects stored in this 00166 * container. 00167 * \sa ns3::Config::Set 00168 */ 00169 void Set (std::string name, const AttributeValue &value); 00170 /** 00171 * \param name the name of the trace source to connect to 00172 * \param cb the sink to connect to the trace source 00173 * 00174 * Connect the specified sink to all the objects stored in this 00175 * container. 00176 * \sa ns3::Config::Connect 00177 */ 00178 void Connect (std::string name, const CallbackBase &cb); 00179 /** 00180 * \param name the name of the trace source to connect to 00181 * \param cb the sink to connect to the trace source 00182 * 00183 * Connect the specified sink to all the objects stored in this 00184 * container. 00185 * \sa ns3::Config::ConnectWithoutContext 00186 */ 00187 void ConnectWithoutContext (std::string name, const CallbackBase &cb); 00188 /** 00189 * \param name the name of the trace source to disconnect from 00190 * \param cb the sink to disconnect from the trace source 00191 * 00192 * Disconnect the specified sink from all the objects stored in this 00193 * container. 00194 * \sa ns3::Config::Disconnect 00195 */ 00196 void Disconnect (std::string name, const CallbackBase &cb); 00197 /** 00198 * \param name the name of the trace source to disconnect from 00199 * \param cb the sink to disconnect from the trace source 00200 * 00201 * Disconnect the specified sink from all the objects stored in this 00202 * container. 00203 * \sa ns3::Config::DisconnectWithoutContext 00204 */ 00205 void DisconnectWithoutContext (std::string name, const CallbackBase &cb); 00206 private: 00207 std::vector<Ptr<Object> > m_objects; 00208 std::vector<std::string> m_contexts; 00209 std::string m_path; 00210 }; 00211 00212 /** 00213 * \param path the path to perform a match against 00214 * \returns a container which contains all the objects which match the input 00215 * path. 00216 */ 00217 MatchContainer LookupMatches (std::string path); 00218 00219 /** 00220 * \param obj a new root object 00221 * 00222 * Each root object is used during path matching as 00223 * the root of the path by Config::Connect, and Config::Set. 00224 */ 00225 void RegisterRootNamespaceObject (Ptr<Object> obj); 00226 /** 00227 * \param obj a new root object 00228 * 00229 * This function undoes the work of Config::RegisterRootNamespaceObject. 00230 */ 00231 void UnregisterRootNamespaceObject (Ptr<Object> obj); 00232 00233 /** 00234 * \returns the number of registered root namespace objects. 00235 */ 00236 uint32_t GetRootNamespaceObjectN (void); 00237 00238 /** 00239 * \param i the index of the requested object. 00240 * \returns the requested root namespace object 00241 */ 00242 Ptr<Object> GetRootNamespaceObject (uint32_t i); 00243 00244 } // namespace Config 00245 00246 } // namespace ns3 00247 00248 #endif /* CONFIG_H */