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 private:
178  bool StringToUint32 (std::string str, uint32_t *value) const;
180  std::string m_element;
181 
182 }; // class ArrayMatcher
183 
184 
185 ArrayMatcher::ArrayMatcher (std::string element)
186  : m_element (element)
187 {
188  NS_LOG_FUNCTION (this << element);
189 }
190 bool
191 ArrayMatcher::Matches (std::size_t i) const
192 {
193  NS_LOG_FUNCTION (this << i);
194  if (m_element == "*")
195  {
196  NS_LOG_DEBUG ("Array "<<i<<" matches *");
197  return true;
198  }
199  std::string::size_type tmp;
200  tmp = m_element.find ("|");
201  if (tmp != std::string::npos)
202  {
203  std::string left = m_element.substr (0, tmp-0);
204  std::string right = m_element.substr (tmp+1, m_element.size () - (tmp + 1));
205  ArrayMatcher matcher = ArrayMatcher (left);
206  if (matcher.Matches (i))
207  {
208  NS_LOG_DEBUG ("Array "<<i<<" matches "<<left);
209  return true;
210  }
211  matcher = ArrayMatcher (right);
212  if (matcher.Matches (i))
213  {
214  NS_LOG_DEBUG ("Array "<<i<<" matches "<<right);
215  return true;
216  }
217  NS_LOG_DEBUG ("Array "<<i<<" does not match "<<m_element);
218  return false;
219  }
220  std::string::size_type leftBracket = m_element.find ("[");
221  std::string::size_type rightBracket = m_element.find ("]");
222  std::string::size_type dash = m_element.find ("-");
223  if (leftBracket == 0 && rightBracket == m_element.size () - 1 &&
224  dash > leftBracket && dash < rightBracket)
225  {
226  std::string lowerBound = m_element.substr (leftBracket + 1, dash - (leftBracket + 1));
227  std::string upperBound = m_element.substr (dash + 1, rightBracket - (dash + 1));
228  uint32_t min;
229  uint32_t max;
230  if (StringToUint32 (lowerBound, &min) &&
231  StringToUint32 (upperBound, &max) &&
232  i >= min && i <= max)
233  {
234  NS_LOG_DEBUG ("Array "<<i<<" matches "<<m_element);
235  return true;
236  }
237  else
238  {
239  NS_LOG_DEBUG ("Array "<<i<<" does not "<<m_element);
240  return false;
241  }
242  }
243  uint32_t value;
244  if (StringToUint32 (m_element, &value) &&
245  i == value)
246  {
247  NS_LOG_DEBUG ("Array "<<i<<" matches "<<m_element);
248  return true;
249  }
250  NS_LOG_DEBUG ("Array "<<i<<" does not match "<<m_element);
251  return false;
252 }
253 
254 bool
255 ArrayMatcher::StringToUint32 (std::string str, uint32_t *value) const
256 {
257  NS_LOG_FUNCTION (this << str << value);
258  std::istringstream iss;
259  iss.str (str);
260  iss >> (*value);
261  return !iss.bad () && !iss.fail ();
262 }
263 
268 class Resolver
269 {
270 public:
276  Resolver (std::string path);
278  virtual ~Resolver ();
279 
287  void Resolve (Ptr<Object> root);
288 
289 private:
291  void Canonicalize (void);
299  void DoResolve (std::string path, Ptr<Object> root);
306  void DoArrayResolve (std::string path, const ObjectPtrContainerValue &vector);
312  void DoResolveOne (Ptr<Object> object);
318  std::string GetResolvedPath (void) const;
325  virtual void DoOne (Ptr<Object> object, std::string path) = 0;
326 
328  std::vector<std::string> m_workStack;
330  std::string m_path;
331 
332 }; // class Resolver
333 
334 Resolver::Resolver (std::string path)
335  : m_path (path)
336 {
337  NS_LOG_FUNCTION (this << path);
338  Canonicalize ();
339 }
341 {
342  NS_LOG_FUNCTION (this);
343 }
344 void
346 {
347  NS_LOG_FUNCTION (this);
348 
349  // ensure that we start and end with a '/'
350  std::string::size_type tmp = m_path.find ("/");
351  if (tmp != 0)
352  {
353  // no slash at start
354  m_path = "/" + m_path;
355  }
356  tmp = m_path.find_last_of ("/");
357  if (tmp != (m_path.size () - 1))
358  {
359  // no slash at end
360  m_path = m_path + "/";
361  }
362 }
363 
364 void
366 {
367  NS_LOG_FUNCTION (this << root);
368 
369  DoResolve (m_path, root);
370 }
371 
372 std::string
374 {
375  NS_LOG_FUNCTION (this);
376 
377  std::string fullPath = "/";
378  for (std::vector<std::string>::const_iterator i = m_workStack.begin (); i != m_workStack.end (); i++)
379  {
380  fullPath += *i + "/";
381  }
382  return fullPath;
383 }
384 
385 void
387 {
388  NS_LOG_FUNCTION (this << object);
389 
390  NS_LOG_DEBUG ("resolved="<<GetResolvedPath ());
391  DoOne (object, GetResolvedPath ());
392 }
393 
394 void
395 Resolver::DoResolve (std::string path, Ptr<Object> root)
396 {
397  NS_LOG_FUNCTION (this << path << root);
398  NS_ASSERT ((path.find ("/")) == 0);
399  std::string::size_type next = path.find ("/", 1);
400 
401  if (next == std::string::npos)
402  {
403  //
404  // If root is zero, we're beginning to see if we can use the object name
405  // service to resolve this path. It is impossible to have a object name
406  // associated with the root of the object name service since that root
407  // is not an object. This path must be referring to something in another
408  // namespace and it will have been found already since the name service
409  // is always consulted last.
410  //
411  if (root)
412  {
413  DoResolveOne (root);
414  }
415  return;
416  }
417  std::string item = path.substr (1, next-1);
418  std::string pathLeft = path.substr (next, path.size ()-next);
419 
420  //
421  // If root is zero, we're beginning to see if we can use the object name
422  // service to resolve this path. In this case, we must see the name space
423  // "/Names" on the front of this path. There is no object associated with
424  // the root of the "/Names" namespace, so we just ignore it and move on to
425  // the next segment.
426  //
427  if (root == 0)
428  {
429  std::string::size_type offset = path.find ("/Names");
430  if (offset == 0)
431  {
432  m_workStack.push_back (item);
433  DoResolve (pathLeft, root);
434  m_workStack.pop_back ();
435  return;
436  }
437  }
438 
439  //
440  // We have an item (possibly a segment of a namespace path. Check to see if
441  // we can determine that this segment refers to a named object. If root is
442  // zero, this means to look in the root of the "/Names" name space, otherwise
443  // it refers to a name space context (level).
444  //
445  Ptr<Object> namedObject = Names::Find<Object> (root, item);
446  if (namedObject)
447  {
448  NS_LOG_DEBUG ("Name system resolved item = " << item << " to " << namedObject);
449  m_workStack.push_back (item);
450  DoResolve (pathLeft, namedObject);
451  m_workStack.pop_back ();
452  return;
453  }
454 
455  //
456  // We're done with the object name service hooks, so proceed down the path
457  // of types and attributes; but only if root is nonzero. If root is zero
458  // and we find ourselves here, we are trying to check in the namespace for
459  // a path that is not in the "/Names" namespace. We will have previously
460  // found any matches, so we just bail out.
461  //
462  if (root == 0)
463  {
464  return;
465  }
466  std::string::size_type dollarPos = item.find ("$");
467  if (dollarPos == 0)
468  {
469  // This is a call to GetObject
470  std::string tidString = item.substr (1, item.size () - 1);
471  NS_LOG_DEBUG ("GetObject="<<tidString<<" on path="<<GetResolvedPath ());
472  TypeId tid = TypeId::LookupByName (tidString);
473  Ptr<Object> object = root->GetObject<Object> (tid);
474  if (object == 0)
475  {
476  NS_LOG_DEBUG ("GetObject ("<<tidString<<") failed on path="<<GetResolvedPath ());
477  return;
478  }
479  m_workStack.push_back (item);
480  DoResolve (pathLeft, object);
481  m_workStack.pop_back ();
482  }
483  else
484  {
485  // this is a normal attribute.
486  TypeId tid;
487  TypeId nextTid = root->GetInstanceTypeId ();
488  bool foundMatch = false;
489 
490  do
491  {
492  tid = nextTid;
493 
494  for (uint32_t i = 0; i < tid.GetAttributeN(); i++)
495  {
496  struct TypeId::AttributeInformation info;
497  info = tid.GetAttribute(i);
498  if (info.name != item && item != "*")
499  {
500  continue;
501  }
502  // attempt to cast to a pointer checker.
503  const PointerChecker *pChecker = dynamic_cast<const PointerChecker *> (PeekPointer(info.checker));
504  if (pChecker != 0)
505  {
506  NS_LOG_DEBUG ("GetAttribute(ptr)="<<info.name<<" on path="<<GetResolvedPath ());
507  PointerValue pValue;
508  root->GetAttribute (info.name, pValue);
509  Ptr<Object> object = pValue.Get<Object> ();
510  if (object == 0)
511  {
512  NS_LOG_ERROR ("Requested object name=\""<<item<<
513  "\" exists on path=\""<<GetResolvedPath ()<<"\""
514  " but is null.");
515  continue;
516  }
517  foundMatch = true;
518  m_workStack.push_back (info.name);
519  DoResolve (pathLeft, object);
520  m_workStack.pop_back ();
521  }
522  // attempt to cast to an object vector.
523  const ObjectPtrContainerChecker *vectorChecker =
524  dynamic_cast<const ObjectPtrContainerChecker *> (PeekPointer (info.checker));
525  if (vectorChecker != 0)
526  {
527  NS_LOG_DEBUG ("GetAttribute(vector)="<<info.name<<" on path="<<GetResolvedPath () << pathLeft);
528  foundMatch = true;
530  root->GetAttribute (info.name, vector);
531  m_workStack.push_back (info.name);
532  DoArrayResolve (pathLeft, vector);
533  m_workStack.pop_back ();
534  }
535  // this could be anything else and we don't know what to do with it.
536  // So, we just ignore it.
537  }
538 
539  nextTid = tid.GetParent ();
540  } while (nextTid != tid);
541 
542  if (!foundMatch)
543  {
544  NS_LOG_DEBUG ("Requested item="<<item<<" does not exist on path="<<GetResolvedPath ());
545  return;
546  }
547  }
548 }
549 
550 void
551 Resolver::DoArrayResolve (std::string path, const ObjectPtrContainerValue &container)
552 {
553  NS_LOG_FUNCTION(this << path << &container);
554  NS_ASSERT (path != "");
555  NS_ASSERT ((path.find ("/")) == 0);
556  std::string::size_type next = path.find ("/", 1);
557  if (next == std::string::npos)
558  {
559  return;
560  }
561  std::string item = path.substr (1, next-1);
562  std::string pathLeft = path.substr (next, path.size ()-next);
563 
564  ArrayMatcher matcher = ArrayMatcher (item);
566  for (it = container.Begin (); it != container.End (); ++it)
567  {
568  if (matcher.Matches ((*it).first))
569  {
570  std::ostringstream oss;
571  oss << (*it).first;
572  m_workStack.push_back (oss.str ());
573  DoResolve (pathLeft, (*it).second);
574  m_workStack.pop_back ();
575  }
576  }
577 }
578 
583 class ConfigImpl : public Singleton<ConfigImpl>
584 {
585 public:
587  void Set (std::string path, const AttributeValue &value);
589  void ConnectWithoutContext (std::string path, const CallbackBase &cb);
591  void Connect (std::string path, const CallbackBase &cb);
593  void DisconnectWithoutContext (std::string path, const CallbackBase &cb);
595  void Disconnect (std::string path, const CallbackBase &cb);
597  MatchContainer LookupMatches (std::string path);
598 
603 
605  std::size_t GetRootNamespaceObjectN (void) const;
607  Ptr<Object> GetRootNamespaceObject (std::size_t i) const;
608 
609 private:
617  void ParsePath (std::string path, std::string *root, std::string *leaf) const;
618 
620  typedef std::vector<Ptr<Object> > Roots;
621 
624 
625 }; // class ConfigImpl
626 
627 void
628 ConfigImpl::ParsePath (std::string path, std::string *root, std::string *leaf) const
629 {
630  NS_LOG_FUNCTION (this << path << root << leaf);
631 
632  std::string::size_type slash = path.find_last_of ("/");
633  NS_ASSERT (slash != std::string::npos);
634  *root = path.substr (0, slash);
635  *leaf = path.substr (slash+1, path.size ()-(slash+1));
636  NS_LOG_FUNCTION (path << *root << *leaf);
637 }
638 
639 void
640 ConfigImpl::Set (std::string path, const AttributeValue &value)
641 {
642  NS_LOG_FUNCTION (this << path << &value);
643 
644  std::string root, leaf;
645  ParsePath (path, &root, &leaf);
646  MatchContainer container = LookupMatches (root);
647  container.Set (leaf, value);
648 }
649 void
650 ConfigImpl::ConnectWithoutContext (std::string path, const CallbackBase &cb)
651 {
652  NS_LOG_FUNCTION (this << path << &cb);
653  std::string root, leaf;
654  ParsePath (path, &root, &leaf);
655  MatchContainer container = LookupMatches (root);
656  if (container.GetN () == 0)
657  {
658  std::size_t lastFwdSlash = root.rfind ("/");
659  NS_LOG_WARN ("Failed to connect " << leaf
660  << ", the Requested object name = " << root.substr (lastFwdSlash + 1)
661  << " does not exits on path " << root.substr (0, lastFwdSlash));
662  }
663  container.ConnectWithoutContext (leaf, cb);
664 }
665 void
667 {
668  NS_LOG_FUNCTION (this << path << &cb);
669  std::string root, leaf;
670  ParsePath (path, &root, &leaf);
671  MatchContainer container = LookupMatches (root);
672  if (container.GetN () == 0)
673  {
674  std::size_t lastFwdSlash = root.rfind ("/");
675  NS_LOG_WARN ("Failed to disconnect " << leaf
676  << ", the Requested object name = " << root.substr (lastFwdSlash + 1)
677  << " does not exits on path " << root.substr (0, lastFwdSlash));
678  }
679  container.DisconnectWithoutContext (leaf, cb);
680 }
681 void
682 ConfigImpl::Connect (std::string path, const CallbackBase &cb)
683 {
684  NS_LOG_FUNCTION (this << path << &cb);
685 
686  std::string root, leaf;
687  ParsePath (path, &root, &leaf);
688  MatchContainer container = LookupMatches (root);
689  if (container.GetN () == 0)
690  {
691  std::size_t lastFwdSlash = root.rfind ("/");
692  NS_LOG_WARN ("Failed to connect " << leaf
693  << ", the Requested object name = " << root.substr (lastFwdSlash + 1)
694  << " does not exits on path " << root.substr (0, lastFwdSlash));
695  }
696  container.Connect (leaf, cb);
697 }
698 void
699 ConfigImpl::Disconnect (std::string path, const CallbackBase &cb)
700 {
701  NS_LOG_FUNCTION (this << path << &cb);
702 
703  std::string root, leaf;
704  ParsePath (path, &root, &leaf);
705  MatchContainer container = LookupMatches (root);
706  if (container.GetN () == 0)
707  {
708  std::size_t lastFwdSlash = root.rfind ("/");
709  NS_LOG_WARN ("Failed to disconnect " << leaf
710  << ", the Requested object name = " << root.substr (lastFwdSlash + 1)
711  << " does not exits on path " << root.substr (0, lastFwdSlash));
712  }
713  container.Disconnect (leaf, cb);
714 }
715 
717 ConfigImpl::LookupMatches (std::string path)
718 {
719  NS_LOG_FUNCTION (this << path);
720  class LookupMatchesResolver : public Resolver
721  {
722  public:
723  LookupMatchesResolver (std::string path)
724  : Resolver (path)
725  {}
726  virtual void DoOne (Ptr<Object> object, std::string path)
727  {
728  m_objects.push_back (object);
729  m_contexts.push_back (path);
730  }
731  std::vector<Ptr<Object> > m_objects;
732  std::vector<std::string> m_contexts;
733  } resolver = LookupMatchesResolver (path);
734  for (Roots::const_iterator i = m_roots.begin (); i != m_roots.end (); i++)
735  {
736  resolver.Resolve (*i);
737  }
738 
739  //
740  // See if we can do something with the object name service. Starting with
741  // the root pointer zeroed indicates to the resolver that it should start
742  // looking at the root of the "/Names" namespace during this go.
743  //
744  resolver.Resolve (0);
745 
746  return MatchContainer (resolver.m_objects, resolver.m_contexts, path);
747 }
748 
749 void
751 {
752  NS_LOG_FUNCTION (this << obj);
753  m_roots.push_back (obj);
754 }
755 
756 void
758 {
759  NS_LOG_FUNCTION (this << obj);
760 
761  for (std::vector<Ptr<Object> >::iterator i = m_roots.begin (); i != m_roots.end (); i++)
762  {
763  if (*i == obj)
764  {
765  m_roots.erase (i);
766  return;
767  }
768  }
769 }
770 
771 std::size_t
773 {
774  NS_LOG_FUNCTION (this);
775  return m_roots.size ();
776 }
779 {
780  NS_LOG_FUNCTION (this << i);
781  return m_roots[i];
782 }
783 
784 
785 void Reset (void)
786 {
788  // First, let's reset the initial value of every attribute
789  for (uint16_t i = 0; i < TypeId::GetRegisteredN (); i++)
790  {
791  TypeId tid = TypeId::GetRegistered (i);
792  for (uint32_t j = 0; j < tid.GetAttributeN (); j++)
793  {
794  struct TypeId::AttributeInformation info = tid.GetAttribute (j);
796  }
797  }
798  // now, let's reset the initial value of every global value.
800  {
801  (*i)->ResetInitialValue ();
802  }
803 }
804 
805 void Set (std::string path, const AttributeValue &value)
806 {
807  NS_LOG_FUNCTION (path << &value);
808  ConfigImpl::Get ()->Set (path, value);
809 }
810 void SetDefault (std::string name, const AttributeValue &value)
811 {
812  NS_LOG_FUNCTION (name << &value);
813  if (!SetDefaultFailSafe(name, value))
814  {
815  NS_FATAL_ERROR ("Could not set default value for " << name);
816  }
817 }
818 bool SetDefaultFailSafe (std::string fullName, const AttributeValue &value)
819 {
820  NS_LOG_FUNCTION (fullName << &value);
821  std::string::size_type pos = fullName.rfind ("::");
822  if (pos == std::string::npos)
823  {
824  return false;
825  }
826  std::string tidName = fullName.substr (0, pos);
827  std::string paramName = fullName.substr (pos+2, fullName.size () - (pos+2));
828  TypeId tid;
829  bool ok = TypeId::LookupByNameFailSafe (tidName, &tid);
830  if (!ok)
831  {
832  return false;
833  }
834  for (uint32_t j = 0; j < tid.GetAttributeN (); j++)
835  {
836  struct TypeId::AttributeInformation tmp = tid.GetAttribute(j);
837  if (tmp.name == paramName)
838  {
839  Ptr<AttributeValue> v = tmp.checker->CreateValidValue (value);
840  if (v == 0)
841  {
842  return false;
843  }
844  tid.SetAttributeInitialValue (j, v);
845  return true;
846  }
847  }
848  return false;
849 }
850 void SetGlobal (std::string name, const AttributeValue &value)
851 {
852  NS_LOG_FUNCTION (name << &value);
853  GlobalValue::Bind (name, value);
854 }
855 bool SetGlobalFailSafe (std::string name, const AttributeValue &value)
856 {
857  NS_LOG_FUNCTION (name << &value);
858  return GlobalValue::BindFailSafe (name, value);
859 }
860 void ConnectWithoutContext (std::string path, const CallbackBase &cb)
861 {
862  NS_LOG_FUNCTION (path << &cb);
863  ConfigImpl::Get ()->ConnectWithoutContext (path, cb);
864 }
865 void DisconnectWithoutContext (std::string path, const CallbackBase &cb)
866 {
867  NS_LOG_FUNCTION (path << &cb);
869 }
870 void
871 Connect (std::string path, const CallbackBase &cb)
872 {
873  NS_LOG_FUNCTION (path << &cb);
874  ConfigImpl::Get ()->Connect (path, cb);
875 }
876 void
877 Disconnect (std::string path, const CallbackBase &cb)
878 {
879  NS_LOG_FUNCTION (path << &cb);
880  ConfigImpl::Get ()->Disconnect (path, cb);
881 }
882 MatchContainer LookupMatches (std::string path)
883 {
884  NS_LOG_FUNCTION (path);
885  return ConfigImpl::Get ()->LookupMatches (path);
886 }
887 
889 {
890  NS_LOG_FUNCTION (obj);
892 }
893 
895 {
896  NS_LOG_FUNCTION (obj);
898 }
899 
900 std::size_t GetRootNamespaceObjectN (void)
901 {
904 }
905 
907 {
908  NS_LOG_FUNCTION (i);
910 }
911 
912 } // namespace Config
913 
914 } // 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:628
#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:818
std::vector< std::string > m_workStack
Current list of path tokens.
Definition: config.cc:328
Roots m_roots
The list of Config path roots.
Definition: config.cc:623
void Set(std::string path, const AttributeValue &value)
Definition: config.cc:805
bool SetGlobalFailSafe(std::string name, const AttributeValue &value)
Definition: config.cc:855
void UnregisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:894
Hold a value for an Attribute.
Definition: attribute.h:68
Ptr< const AttributeValue > originalInitialValue
Default initial value.
Definition: type-id.h:84
std::size_t GetRootNamespaceObjectN(void) const
Definition: config.cc:772
Helper to test if an array entry matches a config path specification.
Definition: config.cc:154
void RegisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:750
#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:564
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:204
void DoResolveOne(Ptr< Object > object)
Handle one object found on the path.
Definition: config.cc:386
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:1104
static TypeId GetRegistered(uint16_t i)
Get a TypeId by index.
Definition: type-id.cc:870
Config system implementation class.
Definition: config.cc:583
void Disconnect(std::string name, const CallbackBase &cb)
Definition: config.cc:127
void DisconnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:865
#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:832
Ptr< Object > GetRootNamespaceObject(std::size_t i) const
Definition: config.cc:778
void UnregisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:757
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:888
bool SetAttributeInitialValue(std::size_t i, Ptr< const AttributeValue > initialValue)
Set the initial value of an Attribute.
Definition: type-id.cc:1043
TypeId GetParent(void) const
Get the parent of this TypeId.
Definition: type-id.cc:936
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:255
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:185
std::string m_element
The Config path element.
Definition: config.cc:180
std::map< std::size_t, Ptr< Object > >::const_iterator Iterator
Iterator type for traversing this container.
MatchContainer LookupMatches(std::string path)
Definition: config.cc:717
Ptr< Object > GetRootNamespaceObject(uint32_t i)
Definition: config.cc:906
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:319
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:860
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:76
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:682
void Canonicalize(void)
Ensure the Config path starts and ends with a &#39;/&#39;.
Definition: config.cc:345
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:871
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
MatchContainer::Iterator Begin(void) const
Definition: config.cc:57
Ptr< const AttributeChecker > checker
Checker object.
Definition: type-id.h:90
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:293
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:78
void Set(std::string path, const AttributeValue &value)
Definition: config.cc:640
std::string GetResolvedPath(void) const
Get the current Config path.
Definition: config.cc:373
std::size_t GetRootNamespaceObjectN(void)
Definition: config.cc:900
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:365
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:785
std::vector< Ptr< Object > > Roots
Container type to hold the root Config path tokens.
Definition: config.cc:620
double max(double x, double y)
MatchContainer LookupMatches(std::string path)
Definition: config.cc:882
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:191
void DoArrayResolve(std::string path, const ObjectPtrContainerValue &vector)
Parse an index on the Config path.
Definition: config.cc:551
AttributeChecker implementation for PointerValue.
Definition: pointer.h:97
void DisconnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:666
void SetGlobal(std::string name, const AttributeValue &value)
Definition: config.cc:850
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:264
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:334
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:650
std::size_t GetAttributeN(void) const
Get the number of attributes.
Definition: type-id.cc:1069
void DoResolve(std::string path, Ptr< Object > root)
Parse the next element in the Config path.
Definition: config.cc:395
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:272
MatchContainer::Iterator End(void) const
Definition: config.cc:63
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:810
struct TypeId::AttributeInformation GetAttribute(std::size_t i) const
Get Attribute information by index.
Definition: type-id.cc:1076
Ptr< T > Get(void) const
Definition: pointer.h:194
void Disconnect(std::string path, const CallbackBase &cb)
Definition: config.cc:699
virtual ~Resolver()
Destructor.
Definition: config.cc:340
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:268
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:256
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:864
Debug message logging.
void Disconnect(std::string path, const CallbackBase &cb)
Definition: config.cc:877
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:185
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:330
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition: type-id.cc:824
std::string GetPath(void) const
Definition: config.cc:87