A Discrete-Event Network Simulator
API
config.cc
Go to the documentation of this file.
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 #include "config.h"
21 #include "singleton.h"
22 #include "object.h"
23 #include "global-value.h"
24 #include "object-ptr-container.h"
25 #include "names.h"
26 #include "pointer.h"
27 #include "log.h"
28 
29 #include <sstream>
30 
37 namespace ns3 {
38 
39 NS_LOG_COMPONENT_DEFINE ("Config");
40 
41 namespace Config {
42 
44 {
45  NS_LOG_FUNCTION (this);
46 }
47 MatchContainer::MatchContainer (const std::vector<Ptr<Object> > &objects,
48  const std::vector<std::string> &contexts,
49  std::string path)
50  : m_objects (objects),
51  m_contexts (contexts),
52  m_path (path)
53 {
54  NS_LOG_FUNCTION (this << &objects << &contexts << path);
55 }
58 {
59  NS_LOG_FUNCTION (this);
60  return m_objects.begin ();
61 }
63 MatchContainer::End (void) const
64 {
65  NS_LOG_FUNCTION (this);
66  return m_objects.end ();
67 }
68 std::size_t
70 {
71  NS_LOG_FUNCTION (this);
72  return m_objects.size ();
73 }
75 MatchContainer::Get (std::size_t i) const
76 {
77  NS_LOG_FUNCTION (this << i);
78  return m_objects[i];
79 }
80 std::string
82 {
83  NS_LOG_FUNCTION (this << i);
84  return m_contexts[i];
85 }
86 std::string
88 {
89  NS_LOG_FUNCTION (this);
90  return m_path;
91 }
92 
93 void
94 MatchContainer::Set (std::string name, const AttributeValue &value)
95 {
96  NS_LOG_FUNCTION (this << name << &value);
97  for (Iterator tmp = Begin (); tmp != End (); ++tmp)
98  {
99  Ptr<Object> object = *tmp;
100  object->SetAttribute (name, value);
101  }
102 }
103 void
104 MatchContainer::Connect (std::string name, const CallbackBase &cb)
105 {
106  NS_LOG_FUNCTION (this << name << &cb);
107  NS_ASSERT (m_objects.size () == m_contexts.size ());
108  for (uint32_t i = 0; i < m_objects.size (); ++i)
109  {
110  Ptr<Object> object = m_objects[i];
111  std::string ctx = m_contexts[i] + name;
112  object->TraceConnect (name, ctx, cb);
113  }
114 }
115 void
117 {
118  NS_LOG_FUNCTION (this << name << &cb);
119 
120  for (Iterator tmp = Begin (); tmp != End (); ++tmp)
121  {
122  Ptr<Object> object = *tmp;
123  object->TraceConnectWithoutContext (name, cb);
124  }
125 }
126 void
127 MatchContainer::Disconnect (std::string name, const CallbackBase &cb)
128 {
129  NS_LOG_FUNCTION (this << name << &cb);
130  NS_ASSERT (m_objects.size () == m_contexts.size ());
131  for (uint32_t i = 0; i < m_objects.size (); ++i)
132  {
133  Ptr<Object> object = m_objects[i];
134  std::string ctx = m_contexts[i] + name;
135  object->TraceDisconnect (name, ctx, cb);
136  }
137 }
138 void
140 {
141  NS_LOG_FUNCTION (this << name << &cb);
142  for (Iterator tmp = Begin (); tmp != End (); ++tmp)
143  {
144  Ptr<Object> object = *tmp;
145  object->TraceDisconnectWithoutContext (name, cb);
146  }
147 }
148 
149 
155 {
156 public:
162  ArrayMatcher (std::string element);
169  bool Matches (std::size_t i) const;
170 
171 private:
179  bool StringToUint32 (std::string str, uint32_t *value) const;
181  std::string m_element;
182 
183 }; // class ArrayMatcher
184 
185 
186 ArrayMatcher::ArrayMatcher (std::string element)
187  : m_element (element)
188 {
189  NS_LOG_FUNCTION (this << element);
190 }
191 bool
192 ArrayMatcher::Matches (std::size_t i) const
193 {
194  NS_LOG_FUNCTION (this << i);
195  if (m_element == "*")
196  {
197  NS_LOG_DEBUG ("Array " << i << " matches *");
198  return true;
199  }
200  std::string::size_type tmp;
201  tmp = m_element.find ("|");
202  if (tmp != std::string::npos)
203  {
204  std::string left = m_element.substr (0, tmp - 0);
205  std::string right = m_element.substr (tmp + 1, m_element.size () - (tmp + 1));
206  ArrayMatcher matcher = ArrayMatcher (left);
207  if (matcher.Matches (i))
208  {
209  NS_LOG_DEBUG ("Array " << i << " matches " << left);
210  return true;
211  }
212  matcher = ArrayMatcher (right);
213  if (matcher.Matches (i))
214  {
215  NS_LOG_DEBUG ("Array " << i << " matches " << right);
216  return true;
217  }
218  NS_LOG_DEBUG ("Array " << i << " does not match " << m_element);
219  return false;
220  }
221  std::string::size_type leftBracket = m_element.find ("[");
222  std::string::size_type rightBracket = m_element.find ("]");
223  std::string::size_type dash = m_element.find ("-");
224  if (leftBracket == 0 && rightBracket == m_element.size () - 1
225  && dash > leftBracket && dash < rightBracket)
226  {
227  std::string lowerBound = m_element.substr (leftBracket + 1, dash - (leftBracket + 1));
228  std::string upperBound = m_element.substr (dash + 1, rightBracket - (dash + 1));
229  uint32_t min;
230  uint32_t max;
231  if (StringToUint32 (lowerBound, &min)
232  && StringToUint32 (upperBound, &max)
233  && i >= min && i <= max)
234  {
235  NS_LOG_DEBUG ("Array " << i << " matches " << m_element);
236  return true;
237  }
238  else
239  {
240  NS_LOG_DEBUG ("Array " << i << " does not " << m_element);
241  return false;
242  }
243  }
244  uint32_t value;
245  if (StringToUint32 (m_element, &value)
246  && i == value)
247  {
248  NS_LOG_DEBUG ("Array " << i << " matches " << m_element);
249  return true;
250  }
251  NS_LOG_DEBUG ("Array " << i << " does not match " << m_element);
252  return false;
253 }
254 
255 bool
256 ArrayMatcher::StringToUint32 (std::string str, uint32_t *value) const
257 {
258  NS_LOG_FUNCTION (this << str << value);
259  std::istringstream iss;
260  iss.str (str);
261  iss >> (*value);
262  return !iss.bad () && !iss.fail ();
263 }
264 
269 class Resolver
270 {
271 public:
277  Resolver (std::string path);
279  virtual ~Resolver ();
280 
288  void Resolve (Ptr<Object> root);
289 
290 private:
292  void Canonicalize (void);
300  void DoResolve (std::string path, Ptr<Object> root);
307  void DoArrayResolve (std::string path, const ObjectPtrContainerValue &vector);
313  void DoResolveOne (Ptr<Object> object);
319  std::string GetResolvedPath (void) const;
326  virtual void DoOne (Ptr<Object> object, std::string path) = 0;
327 
329  std::vector<std::string> m_workStack;
331  std::string m_path;
332 
333 }; // class Resolver
334 
335 Resolver::Resolver (std::string path)
336  : m_path (path)
337 {
338  NS_LOG_FUNCTION (this << path);
339  Canonicalize ();
340 }
342 {
343  NS_LOG_FUNCTION (this);
344 }
345 void
347 {
348  NS_LOG_FUNCTION (this);
349 
350  // ensure that we start and end with a '/'
351  std::string::size_type tmp = m_path.find ("/");
352  if (tmp != 0)
353  {
354  // no slash at start
355  m_path = "/" + m_path;
356  }
357  tmp = m_path.find_last_of ("/");
358  if (tmp != (m_path.size () - 1))
359  {
360  // no slash at end
361  m_path = m_path + "/";
362  }
363 }
364 
365 void
367 {
368  NS_LOG_FUNCTION (this << root);
369 
370  DoResolve (m_path, root);
371 }
372 
373 std::string
375 {
376  NS_LOG_FUNCTION (this);
377 
378  std::string fullPath = "/";
379  for (std::vector<std::string>::const_iterator i = m_workStack.begin (); i != m_workStack.end (); i++)
380  {
381  fullPath += *i + "/";
382  }
383  return fullPath;
384 }
385 
386 void
388 {
389  NS_LOG_FUNCTION (this << object);
390 
391  NS_LOG_DEBUG ("resolved=" << GetResolvedPath ());
392  DoOne (object, GetResolvedPath ());
393 }
394 
395 void
396 Resolver::DoResolve (std::string path, Ptr<Object> root)
397 {
398  NS_LOG_FUNCTION (this << path << root);
399  NS_ASSERT ((path.find ("/")) == 0);
400  std::string::size_type next = path.find ("/", 1);
401 
402  if (next == std::string::npos)
403  {
404  //
405  // If root is zero, we're beginning to see if we can use the object name
406  // service to resolve this path. It is impossible to have a object name
407  // associated with the root of the object name service since that root
408  // is not an object. This path must be referring to something in another
409  // namespace and it will have been found already since the name service
410  // is always consulted last.
411  //
412  if (root)
413  {
414  DoResolveOne (root);
415  }
416  return;
417  }
418  std::string item = path.substr (1, next - 1);
419  std::string pathLeft = path.substr (next, path.size () - next);
420 
421  //
422  // If root is zero, we're beginning to see if we can use the object name
423  // service to resolve this path. In this case, we must see the name space
424  // "/Names" on the front of this path. There is no object associated with
425  // the root of the "/Names" namespace, so we just ignore it and move on to
426  // the next segment.
427  //
428  if (root == 0)
429  {
430  std::string::size_type offset = path.find ("/Names");
431  if (offset == 0)
432  {
433  m_workStack.push_back (item);
434  DoResolve (pathLeft, root);
435  m_workStack.pop_back ();
436  return;
437  }
438  }
439 
440  //
441  // We have an item (possibly a segment of a namespace path. Check to see if
442  // we can determine that this segment refers to a named object. If root is
443  // zero, this means to look in the root of the "/Names" name space, otherwise
444  // it refers to a name space context (level).
445  //
446  Ptr<Object> namedObject = Names::Find<Object> (root, item);
447  if (namedObject)
448  {
449  NS_LOG_DEBUG ("Name system resolved item = " << item << " to " << namedObject);
450  m_workStack.push_back (item);
451  DoResolve (pathLeft, namedObject);
452  m_workStack.pop_back ();
453  return;
454  }
455 
456  //
457  // We're done with the object name service hooks, so proceed down the path
458  // of types and attributes; but only if root is nonzero. If root is zero
459  // and we find ourselves here, we are trying to check in the namespace for
460  // a path that is not in the "/Names" namespace. We will have previously
461  // found any matches, so we just bail out.
462  //
463  if (root == 0)
464  {
465  return;
466  }
467  std::string::size_type dollarPos = item.find ("$");
468  if (dollarPos == 0)
469  {
470  // This is a call to GetObject
471  std::string tidString = item.substr (1, item.size () - 1);
472  NS_LOG_DEBUG ("GetObject=" << tidString << " on path=" << GetResolvedPath ());
473  TypeId tid = TypeId::LookupByName (tidString);
474  Ptr<Object> object = root->GetObject<Object> (tid);
475  if (object == 0)
476  {
477  NS_LOG_DEBUG ("GetObject (" << tidString << ") failed on path=" << GetResolvedPath ());
478  return;
479  }
480  m_workStack.push_back (item);
481  DoResolve (pathLeft, object);
482  m_workStack.pop_back ();
483  }
484  else
485  {
486  // this is a normal attribute.
487  TypeId tid;
488  TypeId nextTid = root->GetInstanceTypeId ();
489  bool foundMatch = false;
490 
491  do
492  {
493  tid = nextTid;
494 
495  for (uint32_t i = 0; i < tid.GetAttributeN (); i++)
496  {
497  struct TypeId::AttributeInformation info;
498  info = tid.GetAttribute (i);
499  if (info.name != item && item != "*")
500  {
501  continue;
502  }
503  // attempt to cast to a pointer checker.
504  const PointerChecker *pChecker = dynamic_cast<const PointerChecker *> (PeekPointer (info.checker));
505  if (pChecker != 0)
506  {
507  NS_LOG_DEBUG ("GetAttribute(ptr)=" << info.name << " on path=" << GetResolvedPath ());
508  PointerValue pValue;
509  root->GetAttribute (info.name, pValue);
510  Ptr<Object> object = pValue.Get<Object> ();
511  if (object == 0)
512  {
513  NS_LOG_ERROR ("Requested object name=\"" << item <<
514  "\" exists on path=\"" << GetResolvedPath () << "\""
515  " but is null.");
516  continue;
517  }
518  foundMatch = true;
519  m_workStack.push_back (info.name);
520  DoResolve (pathLeft, object);
521  m_workStack.pop_back ();
522  }
523  // attempt to cast to an object vector.
524  const ObjectPtrContainerChecker *vectorChecker =
525  dynamic_cast<const ObjectPtrContainerChecker *> (PeekPointer (info.checker));
526  if (vectorChecker != 0)
527  {
528  NS_LOG_DEBUG ("GetAttribute(vector)=" << info.name << " on path=" << GetResolvedPath () << pathLeft);
529  foundMatch = true;
531  root->GetAttribute (info.name, vector);
532  m_workStack.push_back (info.name);
533  DoArrayResolve (pathLeft, vector);
534  m_workStack.pop_back ();
535  }
536  // this could be anything else and we don't know what to do with it.
537  // So, we just ignore it.
538  }
539 
540  nextTid = tid.GetParent ();
541  }
542  while (nextTid != tid);
543 
544  if (!foundMatch)
545  {
546  NS_LOG_DEBUG ("Requested item=" << item << " does not exist on path=" << GetResolvedPath ());
547  return;
548  }
549  }
550 }
551 
552 void
553 Resolver::DoArrayResolve (std::string path, const ObjectPtrContainerValue &container)
554 {
555  NS_LOG_FUNCTION (this << path << &container);
556  NS_ASSERT (path != "");
557  NS_ASSERT ((path.find ("/")) == 0);
558  std::string::size_type next = path.find ("/", 1);
559  if (next == std::string::npos)
560  {
561  return;
562  }
563  std::string item = path.substr (1, next - 1);
564  std::string pathLeft = path.substr (next, path.size () - next);
565 
566  ArrayMatcher matcher = ArrayMatcher (item);
568  for (it = container.Begin (); it != container.End (); ++it)
569  {
570  if (matcher.Matches ((*it).first))
571  {
572  std::ostringstream oss;
573  oss << (*it).first;
574  m_workStack.push_back (oss.str ());
575  DoResolve (pathLeft, (*it).second);
576  m_workStack.pop_back ();
577  }
578  }
579 }
580 
585 class ConfigImpl : public Singleton<ConfigImpl>
586 {
587 public:
589  void Set (std::string path, const AttributeValue &value);
591  void ConnectWithoutContext (std::string path, const CallbackBase &cb);
593  void Connect (std::string path, const CallbackBase &cb);
595  void DisconnectWithoutContext (std::string path, const CallbackBase &cb);
597  void Disconnect (std::string path, const CallbackBase &cb);
599  MatchContainer LookupMatches (std::string path);
600 
605 
607  std::size_t GetRootNamespaceObjectN (void) const;
609  Ptr<Object> GetRootNamespaceObject (std::size_t i) const;
610 
611 private:
619  void ParsePath (std::string path, std::string *root, std::string *leaf) const;
620 
622  typedef std::vector<Ptr<Object> > Roots;
623 
626 
627 }; // class ConfigImpl
628 
629 void
630 ConfigImpl::ParsePath (std::string path, std::string *root, std::string *leaf) const
631 {
632  NS_LOG_FUNCTION (this << path << root << leaf);
633 
634  std::string::size_type slash = path.find_last_of ("/");
635  NS_ASSERT (slash != std::string::npos);
636  *root = path.substr (0, slash);
637  *leaf = path.substr (slash + 1, path.size () - (slash + 1));
638  NS_LOG_FUNCTION (path << *root << *leaf);
639 }
640 
641 void
642 ConfigImpl::Set (std::string path, const AttributeValue &value)
643 {
644  NS_LOG_FUNCTION (this << path << &value);
645 
646  std::string root, leaf;
647  ParsePath (path, &root, &leaf);
648  MatchContainer container = LookupMatches (root);
649  container.Set (leaf, value);
650 }
651 void
652 ConfigImpl::ConnectWithoutContext (std::string path, const CallbackBase &cb)
653 {
654  NS_LOG_FUNCTION (this << path << &cb);
655  std::string root, leaf;
656  ParsePath (path, &root, &leaf);
657  MatchContainer container = LookupMatches (root);
658  if (container.GetN () == 0)
659  {
660  std::size_t lastFwdSlash = root.rfind ("/");
661  NS_LOG_WARN ("Failed to connect " << leaf <<
662  ", the Requested object name = " << root.substr (lastFwdSlash + 1) <<
663  " does not exits on path " << root.substr (0, lastFwdSlash));
664  }
665  container.ConnectWithoutContext (leaf, cb);
666 }
667 void
669 {
670  NS_LOG_FUNCTION (this << path << &cb);
671  std::string root, leaf;
672  ParsePath (path, &root, &leaf);
673  MatchContainer container = LookupMatches (root);
674  if (container.GetN () == 0)
675  {
676  std::size_t lastFwdSlash = root.rfind ("/");
677  NS_LOG_WARN ("Failed to disconnect " << leaf <<
678  ", the Requested object name = " << root.substr (lastFwdSlash + 1) <<
679  " does not exits on path " << root.substr (0, lastFwdSlash));
680  }
681  container.DisconnectWithoutContext (leaf, cb);
682 }
683 void
684 ConfigImpl::Connect (std::string path, const CallbackBase &cb)
685 {
686  NS_LOG_FUNCTION (this << path << &cb);
687 
688  std::string root, leaf;
689  ParsePath (path, &root, &leaf);
690  MatchContainer container = LookupMatches (root);
691  if (container.GetN () == 0)
692  {
693  std::size_t lastFwdSlash = root.rfind ("/");
694  NS_LOG_WARN ("Failed to connect " << leaf <<
695  ", the Requested object name = " << root.substr (lastFwdSlash + 1) <<
696  " does not exits on path " << root.substr (0, lastFwdSlash));
697  }
698  container.Connect (leaf, cb);
699 }
700 void
701 ConfigImpl::Disconnect (std::string path, const CallbackBase &cb)
702 {
703  NS_LOG_FUNCTION (this << path << &cb);
704 
705  std::string root, leaf;
706  ParsePath (path, &root, &leaf);
707  MatchContainer container = LookupMatches (root);
708  if (container.GetN () == 0)
709  {
710  std::size_t lastFwdSlash = root.rfind ("/");
711  NS_LOG_WARN ("Failed to disconnect " << leaf <<
712  ", the Requested object name = " << root.substr (lastFwdSlash + 1) <<
713  " does not exits on path " << root.substr (0, lastFwdSlash));
714  }
715  container.Disconnect (leaf, cb);
716 }
717 
719 ConfigImpl::LookupMatches (std::string path)
720 {
721  NS_LOG_FUNCTION (this << path);
722  class LookupMatchesResolver : public Resolver
723  {
724  public:
725  LookupMatchesResolver (std::string path)
726  : Resolver (path)
727  {}
728  virtual void DoOne (Ptr<Object> object, std::string path)
729  {
730  m_objects.push_back (object);
731  m_contexts.push_back (path);
732  }
733  std::vector<Ptr<Object> > m_objects;
734  std::vector<std::string> m_contexts;
735  } resolver = LookupMatchesResolver (path);
736  for (Roots::const_iterator i = m_roots.begin (); i != m_roots.end (); i++)
737  {
738  resolver.Resolve (*i);
739  }
740 
741  //
742  // See if we can do something with the object name service. Starting with
743  // the root pointer zeroed indicates to the resolver that it should start
744  // looking at the root of the "/Names" namespace during this go.
745  //
746  resolver.Resolve (0);
747 
748  return MatchContainer (resolver.m_objects, resolver.m_contexts, path);
749 }
750 
751 void
753 {
754  NS_LOG_FUNCTION (this << obj);
755  m_roots.push_back (obj);
756 }
757 
758 void
760 {
761  NS_LOG_FUNCTION (this << obj);
762 
763  for (std::vector<Ptr<Object> >::iterator i = m_roots.begin (); i != m_roots.end (); i++)
764  {
765  if (*i == obj)
766  {
767  m_roots.erase (i);
768  return;
769  }
770  }
771 }
772 
773 std::size_t
775 {
776  NS_LOG_FUNCTION (this);
777  return m_roots.size ();
778 }
781 {
782  NS_LOG_FUNCTION (this << i);
783  return m_roots[i];
784 }
785 
786 
787 void Reset (void)
788 {
790  // First, let's reset the initial value of every attribute
791  for (uint16_t i = 0; i < TypeId::GetRegisteredN (); i++)
792  {
793  TypeId tid = TypeId::GetRegistered (i);
794  for (uint32_t j = 0; j < tid.GetAttributeN (); j++)
795  {
796  struct TypeId::AttributeInformation info = tid.GetAttribute (j);
798  }
799  }
800  // now, let's reset the initial value of every global value.
802  {
803  (*i)->ResetInitialValue ();
804  }
805 }
806 
807 void Set (std::string path, const AttributeValue &value)
808 {
809  NS_LOG_FUNCTION (path << &value);
810  ConfigImpl::Get ()->Set (path, value);
811 }
812 void SetDefault (std::string name, const AttributeValue &value)
813 {
814  NS_LOG_FUNCTION (name << &value);
815  if (!SetDefaultFailSafe (name, value))
816  {
817  NS_FATAL_ERROR ("Could not set default value for " << name);
818  }
819 }
820 bool SetDefaultFailSafe (std::string fullName, const AttributeValue &value)
821 {
822  NS_LOG_FUNCTION (fullName << &value);
823  std::string::size_type pos = fullName.rfind ("::");
824  if (pos == std::string::npos)
825  {
826  return false;
827  }
828  std::string tidName = fullName.substr (0, pos);
829  std::string paramName = fullName.substr (pos + 2, fullName.size () - (pos + 2));
830  TypeId tid;
831  bool ok = TypeId::LookupByNameFailSafe (tidName, &tid);
832  if (!ok)
833  {
834  return false;
835  }
836  for (uint32_t j = 0; j < tid.GetAttributeN (); j++)
837  {
838  struct TypeId::AttributeInformation tmp = tid.GetAttribute (j);
839  if (tmp.name == paramName)
840  {
841  Ptr<AttributeValue> v = tmp.checker->CreateValidValue (value);
842  if (v == 0)
843  {
844  return false;
845  }
846  tid.SetAttributeInitialValue (j, v);
847  return true;
848  }
849  }
850  return false;
851 }
852 void SetGlobal (std::string name, const AttributeValue &value)
853 {
854  NS_LOG_FUNCTION (name << &value);
855  GlobalValue::Bind (name, value);
856 }
857 bool SetGlobalFailSafe (std::string name, const AttributeValue &value)
858 {
859  NS_LOG_FUNCTION (name << &value);
860  return GlobalValue::BindFailSafe (name, value);
861 }
862 void ConnectWithoutContext (std::string path, const CallbackBase &cb)
863 {
864  NS_LOG_FUNCTION (path << &cb);
865  ConfigImpl::Get ()->ConnectWithoutContext (path, cb);
866 }
867 void DisconnectWithoutContext (std::string path, const CallbackBase &cb)
868 {
869  NS_LOG_FUNCTION (path << &cb);
871 }
872 void
873 Connect (std::string path, const CallbackBase &cb)
874 {
875  NS_LOG_FUNCTION (path << &cb);
876  ConfigImpl::Get ()->Connect (path, cb);
877 }
878 void
879 Disconnect (std::string path, const CallbackBase &cb)
880 {
881  NS_LOG_FUNCTION (path << &cb);
882  ConfigImpl::Get ()->Disconnect (path, cb);
883 }
884 MatchContainer LookupMatches (std::string path)
885 {
886  NS_LOG_FUNCTION (path);
887  return ConfigImpl::Get ()->LookupMatches (path);
888 }
889 
891 {
892  NS_LOG_FUNCTION (obj);
894 }
895 
897 {
898  NS_LOG_FUNCTION (obj);
900 }
901 
902 std::size_t GetRootNamespaceObjectN (void)
903 {
906 }
907 
909 {
910  NS_LOG_FUNCTION (i);
912 }
913 
914 } // namespace Config
915 
916 } // namespace ns3
std::string GetMatchedPath(uint32_t i) const
Definition: config.cc:81
void ParsePath(std::string path, std::string *root, std::string *leaf) const
Break a Config path into the leading path and the last leaf token.
Definition: config.cc:630
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
ns3::Singleton declaration and template implementation.
bool SetDefaultFailSafe(std::string fullName, const AttributeValue &value)
Definition: config.cc:820
std::vector< std::string > m_workStack
Current list of path tokens.
Definition: config.cc:329
Roots m_roots
The list of Config path roots.
Definition: config.cc:625
void Set(std::string path, const AttributeValue &value)
Definition: config.cc:807
bool SetGlobalFailSafe(std::string name, const AttributeValue &value)
Definition: config.cc:857
void UnregisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:896
Hold a value for an Attribute.
Definition: attribute.h:68
Ptr< const AttributeValue > originalInitialValue
Default initial value.
Definition: type-id.h:86
std::size_t GetRootNamespaceObjectN(void) const
Definition: config.cc:774
Helper to test if an array entry matches a config path specification.
Definition: config.cc:154
void RegisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:752
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
U * PeekPointer(const Ptr< U > &p)
Definition: ptr.h:566
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
void DoResolveOne(Ptr< Object > object)
Handle one object found on the path.
Definition: config.cc:387
Vector::const_iterator Iterator
Iterator type for the list of all global values.
Definition: global-value.h:80
Base class for Callback class.
Definition: callback.h:1194
static TypeId GetRegistered(uint16_t i)
Get a TypeId by index.
Definition: type-id.cc:875
Config system implementation class.
Definition: config.cc:585
void Disconnect(std::string name, const CallbackBase &cb)
Definition: config.cc:127
void DisconnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:867
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
static bool LookupByNameFailSafe(std::string name, TypeId *tid)
Get a TypeId by name.
Definition: type-id.cc:837
Ptr< Object > GetRootNamespaceObject(std::size_t i) const
Definition: config.cc:780
void UnregisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:759
Ptr< Object > Get(std::size_t i) const
Definition: config.cc:75
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
std::size_t GetN(void) const
Definition: config.cc:69
Declaration of the various ns3::Config functions and classes.
static ConfigImpl * Get(void)
Get a pointer to the singleton instance.
Definition: singleton.h:89
void RegisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:890
bool SetAttributeInitialValue(std::size_t i, Ptr< const AttributeValue > initialValue)
Set the initial value of an Attribute.
Definition: type-id.cc:1050
TypeId GetParent(void) const
Get the parent of this TypeId.
Definition: type-id.cc:943
A template singleton.
Definition: singleton.h:63
void ConnectWithoutContext(std::string name, const CallbackBase &cb)
Definition: config.cc:116
ns3::ObjectPtrContainerValue attribute value declarations and template implementations.
bool StringToUint32(std::string str, uint32_t *value) const
Convert a string to an uint32_t.
Definition: config.cc:256
static Iterator Begin(void)
The Begin iterator.
Iterator Begin(void) const
Get an iterator to the first Object.
ArrayMatcher(std::string element)
Construct from a Config path specification.
Definition: config.cc:186
std::string m_element
The Config path element.
Definition: config.cc:181
std::map< std::size_t, Ptr< Object > >::const_iterator Iterator
Iterator type for traversing this container.
MatchContainer LookupMatches(std::string path)
Definition: config.cc:719
Ptr< Object > GetRootNamespaceObject(uint32_t i)
Definition: config.cc:908
AttributeChecker implementation for ObjectPtrContainerValue.
Iterator End(void) const
Get an iterator to the past-the-end Object.
bool TraceDisconnectWithoutContext(std::string name, const CallbackBase &cb)
Disconnect from a TraceSource a Callback previously connected without a context.
Definition: object-base.cc:321
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:862
static void Bind(std::string name, const AttributeValue &value)
Iterate over the set of GlobalValues until a matching name is found and then set its value with Globa...
Attribute implementation.
Definition: type-id.h:77
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:684
void Canonicalize(void)
Ensure the Config path starts and ends with a &#39;/&#39;.
Definition: config.cc:346
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:873
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:461
MatchContainer::Iterator Begin(void) const
Definition: config.cc:57
Ptr< const AttributeChecker > checker
Checker object.
Definition: type-id.h:92
std::string m_path
The path used to perform the object matching.
Definition: config.h:250
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:295
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Hold objects of type Ptr<T>.
Definition: pointer.h:36
std::string name
Attribute name.
Definition: type-id.h:80
void Set(std::string path, const AttributeValue &value)
Definition: config.cc:642
std::string GetResolvedPath(void) const
Get the current Config path.
Definition: config.cc:374
std::size_t GetRootNamespaceObjectN(void)
Definition: config.cc:902
ns3::GlobalValue declaration.
void Resolve(Ptr< Object > root)
Parse the stored Config path into an object reference, beginning at the indicated root object...
Definition: config.cc:366
hold a set of objects which match a specific search string.
Definition: config.h:151
std::vector< Ptr< Object > > m_objects
The list of objects in this container.
Definition: config.h:246
void Connect(std::string name, const CallbackBase &cb)
Definition: config.cc:104
void Reset(void)
Reset the initial value of every attribute as well as the value of every global to what they were bef...
Definition: config.cc:787
std::vector< Ptr< Object > > Roots
Container type to hold the root Config path tokens.
Definition: config.cc:622
double max(double x, double y)
MatchContainer LookupMatches(std::string path)
Definition: config.cc:884
ns3::Object class declaration, which is the root of the Object hierarchy and Aggregation.
void DisconnectWithoutContext(std::string name, const CallbackBase &cb)
Definition: config.cc:139
virtual void DoOne(Ptr< Object > object, std::string path)=0
Handle one found object.
bool Matches(std::size_t i) const
Test if a specific index matches the Config Path.
Definition: config.cc:192
void DoArrayResolve(std::string path, const ObjectPtrContainerValue &vector)
Parse an index on the Config path.
Definition: config.cc:553
AttributeChecker implementation for PointerValue.
Definition: pointer.h:97
void DisconnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:668
void SetGlobal(std::string name, const AttributeValue &value)
Definition: config.cc:852
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:265
std::vector< std::string > m_contexts
The context for each object.
Definition: config.h:248
Resolver(std::string path)
Construct from a base Config path.
Definition: config.cc:335
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:652
std::size_t GetAttributeN(void) const
Get the number of attributes.
Definition: type-id.cc:1076
void DoResolve(std::string path, Ptr< Object > root)
Parse the next element in the Config path.
Definition: config.cc:396
static Iterator End(void)
The End iterator.
static bool BindFailSafe(std::string name, const AttributeValue &value)
Iterate over the set of GlobalValues until a matching name is found and then set its value with Globa...
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
MatchContainer::Iterator End(void) const
Definition: config.cc:63
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:812
struct TypeId::AttributeInformation GetAttribute(std::size_t i) const
Get Attribute information by index.
Definition: type-id.cc:1083
Ptr< T > Get(void) const
Definition: pointer.h:201
void Disconnect(std::string path, const CallbackBase &cb)
Definition: config.cc:701
virtual ~Resolver()
Destructor.
Definition: config.cc:341
Declaration of class ns3::Names.
double min(double x, double y)
std::vector< Ptr< Object > >::const_iterator Iterator
Const iterator over the objects in this container.
Definition: config.h:155
Abstract class to parse Config paths into object references.
Definition: config.cc:269
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:257
void Set(std::string name, const AttributeValue &value)
Definition: config.cc:94
A base class which provides memory management and object aggregation.
Definition: object.h:87
Container for a set of ns3::Object pointers.
static uint16_t GetRegisteredN(void)
Get the number of registered TypeIds.
Definition: type-id.cc:869
Debug message logging.
void Disconnect(std::string path, const CallbackBase &cb)
Definition: config.cc:879
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:187
ns3::PointerValue attribute value declarations and template implementations.
a unique identifier for an interface.
Definition: type-id.h:58
std::string m_path
The Config path.
Definition: config.cc:331
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition: type-id.cc:829
std::string GetPath(void) const
Definition: config.cc:87