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