src/core/config.h
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Fri, 24 Oct 2008 12:35:28 +0200
changeset 3787 985324e2caaa
parent 3763 e46e361a4262
child 3999 7a1a377c3900
permissions -rw-r--r--
bug 284: cannot use config paths to get a handle on an object.
     1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     2 /*
     3  * Copyright (c) 2008 INRIA
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License version 2 as
     7  * published by the Free Software Foundation;
     8  *
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details.
    13  *
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program; if not, write to the Free Software
    16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    17  *
    18  * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
    19  */
    20 #ifndef CONFIG_H
    21 #define CONFIG_H
    22 
    23 #include "ptr.h"
    24 #include <string>
    25 #include <vector>
    26 
    27 namespace ns3 {
    28 
    29 class AttributeValue;
    30 class Object;
    31 class CallbackBase;
    32 
    33 /**
    34  * \brief Configuration of simulation parameters and tracing
    35  * \ingroup core
    36  */
    37 namespace Config {
    38 
    39 /**
    40  * \param path a path to match attributes.
    41  * \param value the value to set in all matching attributes.
    42  *
    43  * This function will attempt to find attributes which
    44  * match the input path and will then set their value to the input
    45  * value.
    46  */
    47 void Set (std::string path, const AttributeValue &value);
    48 /**
    49  * \param name the full name of the attribute
    50  * \param value the value to set.
    51  *
    52  * This method overrides the initial value of the 
    53  * matching attribute. This method cannot fail: it will
    54  * crash if the input attribute name or value is invalid.
    55  */
    56 void SetDefault (std::string name, const AttributeValue &value);
    57 /**
    58  * \param name the full name of the attribute
    59  * \param value the value to set.
    60  * \returns true if the value was set successfully, false otherwise.
    61  *
    62  * This method overrides the initial value of the 
    63  * matching attribute. 
    64  */
    65 bool SetDefaultFailSafe (std::string name, const AttributeValue &value);
    66 /**
    67  * \param name the name of the requested GlobalValue.
    68  * \param value the value to set
    69  *
    70  * This method is equivalent to GlobalValue::Bind
    71  */
    72 void SetGlobal (std::string name, const AttributeValue &value);
    73 /**
    74  * \param name the name of the requested GlobalValue.
    75  * \param value the value to set
    76  *
    77  * This method is equivalent to GlobalValue::BindFailSafe
    78  */
    79 bool SetGlobalFailSafe (std::string name, const AttributeValue &value);
    80 /**
    81  * \param path a path to match trace sources.
    82  * \param cb the callback to connect to the matching trace sources.
    83  *
    84  * This function will attempt to find all trace sources which
    85  * match the input path and will then connect the input callback
    86  * to them.
    87  */
    88 void ConnectWithoutContext (std::string path, const CallbackBase &cb);
    89 /**
    90  * \param path a path to match trace sources.
    91  * \param cb the callback to disconnect to the matching trace sources.
    92  *
    93  * This function undoes the work of Config::Connect.
    94  */
    95 void DisconnectWithoutContext (std::string path, const CallbackBase &cb);
    96 /**
    97  * \param path a path to match trace sources.
    98  * \param cb the callback to connect to the matching trace sources.
    99  *
   100  * This function will attempt to find all trace sources which
   101  * match the input path and will then connect the input callback
   102  * to them in such a way that the callback will receive an extra
   103  * context string upon trace event notification.
   104  */
   105 void Connect (std::string path, const CallbackBase &cb);
   106 /**
   107  * \param path a path to match trace sources.
   108  * \param cb the callback to connect to the matching trace sources.
   109  *
   110  * This function undoes the work of Config::ConnectWithContext.
   111  */
   112 void Disconnect (std::string path, const CallbackBase &cb);
   113 
   114 class MatchContainer
   115 {
   116 public:
   117   typedef std::vector<Ptr<Object> >::const_iterator Iterator;
   118   MatchContainer ();
   119   MatchContainer (const std::vector<Ptr<Object> > &objects, 
   120                   const std::vector<std::string> &contexts, 
   121                   std::string path);
   122 
   123   MatchContainer::Iterator Begin (void) const;
   124   MatchContainer::Iterator End (void) const;
   125   uint32_t GetN (void) const;
   126   Ptr<Object> Get (uint32_t i) const;
   127   std::string GetMatchedPath (uint32_t i) const;
   128   std::string GetPath (void) const;
   129 
   130   void Set (std::string name, const AttributeValue &value);
   131   void Connect (std::string name, const CallbackBase &cb);
   132   void ConnectWithoutContext (std::string name, const CallbackBase &cb);
   133   void Disconnect (std::string name, const CallbackBase &cb);
   134   void DisconnectWithoutContext (std::string name, const CallbackBase &cb);
   135 private:
   136   std::vector<Ptr<Object> > m_objects;
   137   std::vector<std::string> m_contexts;
   138   std::string m_path;
   139 };
   140 
   141 MatchContainer LookupMatches (std::string path);
   142 
   143 /**
   144  * \param obj a new root object
   145  *
   146  * Each root object is used during path matching as
   147  * the root of the path by Config::Connect, and Config::Set.
   148  */
   149 void RegisterRootNamespaceObject (Ptr<Object> obj);
   150 /**
   151  * \param obj a new root object
   152  *
   153  * This function undoes the work of Config::RegisterRootNamespaceObject.
   154  */
   155 void UnregisterRootNamespaceObject (Ptr<Object> obj);
   156 
   157 /**
   158  * \returns the number of registered root namespace objects.
   159  */
   160 uint32_t GetRootNamespaceObjectN (void);
   161 
   162 /**
   163  * \param i the index of the requested object.
   164  * \returns the requested root namespace object
   165  */
   166 Ptr<Object> GetRootNamespaceObject (uint32_t i);
   167 
   168 } // namespace Config
   169 
   170 } // namespace ns3
   171 
   172 #endif /* CONFIG_H */