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  // Let ObjectBase::SetAttribute raise any errors
101  object->SetAttribute (name, value);
102  }
103 }
104 bool
105 MatchContainer::SetFailSafe (std::string name, const AttributeValue &value)
106 {
107  NS_LOG_FUNCTION (this << name << &value);
108  bool ok = false;
109  for (Iterator tmp = Begin (); tmp != End (); ++tmp)
110  {
111  Ptr<Object> object = *tmp;
112  ok |= object->SetAttributeFailSafe (name, value);
113  }
114  return ok;
115 }
116 void
117 MatchContainer::Connect (std::string name, const CallbackBase &cb)
118 {
119  if (!ConnectFailSafe (name, cb))
120  {
121  NS_FATAL_ERROR ("Cound not connect callback to " << name);
122  }
123 }
124 bool
125 MatchContainer::ConnectFailSafe (std::string name, const CallbackBase &cb)
126 {
127  NS_LOG_FUNCTION (this << name << &cb);
128  NS_ASSERT (m_objects.size () == m_contexts.size ());
129  bool ok = false;
130  for (uint32_t i = 0; i < m_objects.size (); ++i)
131  {
132  Ptr<Object> object = m_objects[i];
133  std::string ctx = m_contexts[i] + name;
134  ok |= object->TraceConnect (name, ctx, cb);
135  }
136  return ok;
137 }
138 void
140 {
141  if (!ConnectWithoutContextFailSafe (name, cb))
142  {
143  NS_FATAL_ERROR ("Could not connect callback to " << name);
144  }
145 }
146 bool
148 {
149  NS_LOG_FUNCTION (this << name << &cb);
150  bool ok = false;
151  for (Iterator tmp = Begin (); tmp != End (); ++tmp)
152  {
153  Ptr<Object> object = *tmp;
154  ok |= object->TraceConnectWithoutContext (name, cb);
155  }
156  return ok;
157 }
158 void
159 MatchContainer::Disconnect (std::string name, const CallbackBase &cb)
160 {
161  NS_LOG_FUNCTION (this << name << &cb);
162  NS_ASSERT (m_objects.size () == m_contexts.size ());
163  for (uint32_t i = 0; i < m_objects.size (); ++i)
164  {
165  Ptr<Object> object = m_objects[i];
166  std::string ctx = m_contexts[i] + name;
167  object->TraceDisconnect (name, ctx, cb);
168  }
169 }
170 void
172 {
173  NS_LOG_FUNCTION (this << name << &cb);
174  for (Iterator tmp = Begin (); tmp != End (); ++tmp)
175  {
176  Ptr<Object> object = *tmp;
177  object->TraceDisconnectWithoutContext (name, cb);
178  }
179 }
180 
181 
187 {
188 public:
194  ArrayMatcher (std::string element);
201  bool Matches (std::size_t i) const;
202 
203 private:
211  bool StringToUint32 (std::string str, uint32_t *value) const;
213  std::string m_element;
214 
215 }; // class ArrayMatcher
216 
217 
218 ArrayMatcher::ArrayMatcher (std::string element)
219  : m_element (element)
220 {
221  NS_LOG_FUNCTION (this << element);
222 }
223 bool
224 ArrayMatcher::Matches (std::size_t i) const
225 {
226  NS_LOG_FUNCTION (this << i);
227  if (m_element == "*")
228  {
229  NS_LOG_DEBUG ("Array " << i << " matches *");
230  return true;
231  }
232  std::string::size_type tmp;
233  tmp = m_element.find ("|");
234  if (tmp != std::string::npos)
235  {
236  std::string left = m_element.substr (0, tmp - 0);
237  std::string right = m_element.substr (tmp + 1, m_element.size () - (tmp + 1));
238  ArrayMatcher matcher = ArrayMatcher (left);
239  if (matcher.Matches (i))
240  {
241  NS_LOG_DEBUG ("Array " << i << " matches " << left);
242  return true;
243  }
244  matcher = ArrayMatcher (right);
245  if (matcher.Matches (i))
246  {
247  NS_LOG_DEBUG ("Array " << i << " matches " << right);
248  return true;
249  }
250  NS_LOG_DEBUG ("Array " << i << " does not match " << m_element);
251  return false;
252  }
253  std::string::size_type leftBracket = m_element.find ("[");
254  std::string::size_type rightBracket = m_element.find ("]");
255  std::string::size_type dash = m_element.find ("-");
256  if (leftBracket == 0 && rightBracket == m_element.size () - 1
257  && dash > leftBracket && dash < rightBracket)
258  {
259  std::string lowerBound = m_element.substr (leftBracket + 1, dash - (leftBracket + 1));
260  std::string upperBound = m_element.substr (dash + 1, rightBracket - (dash + 1));
261  uint32_t min;
262  uint32_t max;
263  if (StringToUint32 (lowerBound, &min)
264  && StringToUint32 (upperBound, &max)
265  && i >= min && i <= max)
266  {
267  NS_LOG_DEBUG ("Array " << i << " matches " << m_element);
268  return true;
269  }
270  else
271  {
272  NS_LOG_DEBUG ("Array " << i << " does not " << m_element);
273  return false;
274  }
275  }
276  uint32_t value;
277  if (StringToUint32 (m_element, &value)
278  && i == value)
279  {
280  NS_LOG_DEBUG ("Array " << i << " matches " << m_element);
281  return true;
282  }
283  NS_LOG_DEBUG ("Array " << i << " does not match " << m_element);
284  return false;
285 }
286 
287 bool
288 ArrayMatcher::StringToUint32 (std::string str, uint32_t *value) const
289 {
290  NS_LOG_FUNCTION (this << str << value);
291  std::istringstream iss;
292  iss.str (str);
293  iss >> (*value);
294  return !iss.bad () && !iss.fail ();
295 }
296 
301 class Resolver
302 {
303 public:
309  Resolver (std::string path);
311  virtual ~Resolver ();
312 
320  void Resolve (Ptr<Object> root);
321 
322 private:
324  void Canonicalize (void);
332  void DoResolve (std::string path, Ptr<Object> root);
339  void DoArrayResolve (std::string path, const ObjectPtrContainerValue &vector);
345  void DoResolveOne (Ptr<Object> object);
351  std::string GetResolvedPath (void) const;
358  virtual void DoOne (Ptr<Object> object, std::string path) = 0;
359 
361  std::vector<std::string> m_workStack;
363  std::string m_path;
364 
365 }; // class Resolver
366 
367 Resolver::Resolver (std::string path)
368  : m_path (path)
369 {
370  NS_LOG_FUNCTION (this << path);
371  Canonicalize ();
372 }
374 {
375  NS_LOG_FUNCTION (this);
376 }
377 void
379 {
380  NS_LOG_FUNCTION (this);
381 
382  // ensure that we start and end with a '/'
383  std::string::size_type tmp = m_path.find ("/");
384  if (tmp != 0)
385  {
386  // no slash at start
387  m_path = "/" + m_path;
388  }
389  tmp = m_path.find_last_of ("/");
390  if (tmp != (m_path.size () - 1))
391  {
392  // no slash at end
393  m_path = m_path + "/";
394  }
395 }
396 
397 void
399 {
400  NS_LOG_FUNCTION (this << root);
401 
402  DoResolve (m_path, root);
403 }
404 
405 std::string
407 {
408  NS_LOG_FUNCTION (this);
409 
410  std::string fullPath = "/";
411  for (std::vector<std::string>::const_iterator i = m_workStack.begin (); i != m_workStack.end (); i++)
412  {
413  fullPath += *i + "/";
414  }
415  return fullPath;
416 }
417 
418 void
420 {
421  NS_LOG_FUNCTION (this << object);
422 
423  NS_LOG_DEBUG ("resolved=" << GetResolvedPath ());
424  DoOne (object, GetResolvedPath ());
425 }
426 
427 void
428 Resolver::DoResolve (std::string path, Ptr<Object> root)
429 {
430  NS_LOG_FUNCTION (this << path << root);
431  NS_ASSERT ((path.find ("/")) == 0);
432  std::string::size_type next = path.find ("/", 1);
433 
434  if (next == std::string::npos)
435  {
436  //
437  // If root is zero, we're beginning to see if we can use the object name
438  // service to resolve this path. It is impossible to have a object name
439  // associated with the root of the object name service since that root
440  // is not an object. This path must be referring to something in another
441  // namespace and it will have been found already since the name service
442  // is always consulted last.
443  //
444  if (root)
445  {
446  DoResolveOne (root);
447  }
448  return;
449  }
450  std::string item = path.substr (1, next - 1);
451  std::string pathLeft = path.substr (next, path.size () - next);
452 
453  //
454  // If root is zero, we're beginning to see if we can use the object name
455  // service to resolve this path. In this case, we must see the name space
456  // "/Names" on the front of this path. There is no object associated with
457  // the root of the "/Names" namespace, so we just ignore it and move on to
458  // the next segment.
459  //
460  if (root == 0)
461  {
462  std::string::size_type offset = path.find ("/Names");
463  if (offset == 0)
464  {
465  m_workStack.push_back (item);
466  DoResolve (pathLeft, root);
467  m_workStack.pop_back ();
468  return;
469  }
470  }
471 
472  //
473  // We have an item (possibly a segment of a namespace path. Check to see if
474  // we can determine that this segment refers to a named object. If root is
475  // zero, this means to look in the root of the "/Names" name space, otherwise
476  // it refers to a name space context (level).
477  //
478  Ptr<Object> namedObject = Names::Find<Object> (root, item);
479  if (namedObject)
480  {
481  NS_LOG_DEBUG ("Name system resolved item = " << item << " to " << namedObject);
482  m_workStack.push_back (item);
483  DoResolve (pathLeft, namedObject);
484  m_workStack.pop_back ();
485  return;
486  }
487 
488  //
489  // We're done with the object name service hooks, so proceed down the path
490  // of types and attributes; but only if root is nonzero. If root is zero
491  // and we find ourselves here, we are trying to check in the namespace for
492  // a path that is not in the "/Names" namespace. We will have previously
493  // found any matches, so we just bail out.
494  //
495  if (root == 0)
496  {
497  return;
498  }
499  std::string::size_type dollarPos = item.find ("$");
500  if (dollarPos == 0)
501  {
502  // This is a call to GetObject
503  std::string tidString = item.substr (1, item.size () - 1);
504  NS_LOG_DEBUG ("GetObject=" << tidString << " on path=" << GetResolvedPath ());
505  TypeId tid = TypeId::LookupByName (tidString);
506  Ptr<Object> object = root->GetObject<Object> (tid);
507  if (object == 0)
508  {
509  NS_LOG_DEBUG ("GetObject (" << tidString << ") failed on path=" << GetResolvedPath ());
510  return;
511  }
512  m_workStack.push_back (item);
513  DoResolve (pathLeft, object);
514  m_workStack.pop_back ();
515  }
516  else
517  {
518  // this is a normal attribute.
519  TypeId tid;
520  TypeId nextTid = root->GetInstanceTypeId ();
521  bool foundMatch = false;
522 
523  do
524  {
525  tid = nextTid;
526 
527  for (uint32_t i = 0; i < tid.GetAttributeN (); i++)
528  {
529  struct TypeId::AttributeInformation info;
530  info = tid.GetAttribute (i);
531  if (info.name != item && item != "*")
532  {
533  continue;
534  }
535  // attempt to cast to a pointer checker.
536  const PointerChecker *pChecker = dynamic_cast<const PointerChecker *> (PeekPointer (info.checker));
537  if (pChecker != 0)
538  {
539  NS_LOG_DEBUG ("GetAttribute(ptr)=" << info.name << " on path=" << GetResolvedPath ());
540  PointerValue pValue;
541  root->GetAttribute (info.name, pValue);
542  Ptr<Object> object = pValue.Get<Object> ();
543  if (object == 0)
544  {
545  NS_LOG_ERROR ("Requested object name=\"" << item <<
546  "\" exists on path=\"" << GetResolvedPath () << "\""
547  " but is null.");
548  continue;
549  }
550  foundMatch = true;
551  m_workStack.push_back (info.name);
552  DoResolve (pathLeft, object);
553  m_workStack.pop_back ();
554  }
555  // attempt to cast to an object vector.
556  const ObjectPtrContainerChecker *vectorChecker =
557  dynamic_cast<const ObjectPtrContainerChecker *> (PeekPointer (info.checker));
558  if (vectorChecker != 0)
559  {
560  NS_LOG_DEBUG ("GetAttribute(vector)=" << info.name << " on path=" << GetResolvedPath () << pathLeft);
561  foundMatch = true;
563  root->GetAttribute (info.name, vector);
564  m_workStack.push_back (info.name);
565  DoArrayResolve (pathLeft, vector);
566  m_workStack.pop_back ();
567  }
568  // this could be anything else and we don't know what to do with it.
569  // So, we just ignore it.
570  }
571 
572  nextTid = tid.GetParent ();
573  }
574  while (nextTid != tid);
575 
576  if (!foundMatch)
577  {
578  NS_LOG_DEBUG ("Requested item=" << item << " does not exist on path=" << GetResolvedPath ());
579  return;
580  }
581  }
582 }
583 
584 void
585 Resolver::DoArrayResolve (std::string path, const ObjectPtrContainerValue &container)
586 {
587  NS_LOG_FUNCTION (this << path << &container);
588  NS_ASSERT (path != "");
589  NS_ASSERT ((path.find ("/")) == 0);
590  std::string::size_type next = path.find ("/", 1);
591  if (next == std::string::npos)
592  {
593  return;
594  }
595  std::string item = path.substr (1, next - 1);
596  std::string pathLeft = path.substr (next, path.size () - next);
597 
598  ArrayMatcher matcher = ArrayMatcher (item);
600  for (it = container.Begin (); it != container.End (); ++it)
601  {
602  if (matcher.Matches ((*it).first))
603  {
604  std::ostringstream oss;
605  oss << (*it).first;
606  m_workStack.push_back (oss.str ());
607  DoResolve (pathLeft, (*it).second);
608  m_workStack.pop_back ();
609  }
610  }
611 }
612 
617 class ConfigImpl : public Singleton<ConfigImpl>
618 {
619 public:
620  // Keep Set and SetFailSafe since their errors are triggered
621  // by the underlying ObjecBase functions.
623  void Set (std::string path, const AttributeValue &value);
625  bool SetFailSafe (std::string path, const AttributeValue &value);
627  bool ConnectWithoutContextFailSafe (std::string path, const CallbackBase &cb);
629  bool ConnectFailSafe (std::string path, const CallbackBase &cb);
631  void DisconnectWithoutContext (std::string path, const CallbackBase &cb);
633  void Disconnect (std::string path, const CallbackBase &cb);
635  MatchContainer LookupMatches (std::string path);
636 
641 
643  std::size_t GetRootNamespaceObjectN (void) const;
645  Ptr<Object> GetRootNamespaceObject (std::size_t i) const;
646 
647 private:
655  void ParsePath (std::string path, std::string *root, std::string *leaf) const;
656 
658  typedef std::vector<Ptr<Object> > Roots;
659 
662 
663 }; // class ConfigImpl
664 
665 void
666 ConfigImpl::ParsePath (std::string path, std::string *root, std::string *leaf) const
667 {
668  NS_LOG_FUNCTION (this << path << root << leaf);
669 
670  std::string::size_type slash = path.find_last_of ("/");
671  NS_ASSERT (slash != std::string::npos);
672  *root = path.substr (0, slash);
673  *leaf = path.substr (slash + 1, path.size () - (slash + 1));
674  NS_LOG_FUNCTION (path << *root << *leaf);
675 }
676 
677 void
678 ConfigImpl::Set (std::string path, const AttributeValue &value)
679 {
680  NS_LOG_FUNCTION (this << path << &value);
681 
682  std::string root, leaf;
683  ParsePath (path, &root, &leaf);
684  MatchContainer container = LookupMatches (root);
685  container.Set (leaf, value);
686 }
687 bool
688 ConfigImpl::SetFailSafe (std::string path, const AttributeValue &value)
689 {
690  NS_LOG_FUNCTION (this << path << &value);
691 
692  std::string root, leaf;
693  ParsePath (path, &root, &leaf);
694  MatchContainer container = LookupMatches (root);
695  return container.SetFailSafe (leaf, value);
696 }
697 bool
699 {
700  NS_LOG_FUNCTION (this << path << &cb);
701  std::string root, leaf;
702  ParsePath (path, &root, &leaf);
703  MatchContainer container = LookupMatches (root);
704  return container.ConnectWithoutContextFailSafe (leaf, cb);
705 }
706 void
708 {
709  NS_LOG_FUNCTION (this << path << &cb);
710  std::string root, leaf;
711  ParsePath (path, &root, &leaf);
712  MatchContainer container = LookupMatches (root);
713  if (container.GetN () == 0)
714  {
715  std::size_t lastFwdSlash = root.rfind ("/");
716  NS_LOG_WARN ("Failed to disconnect " << leaf
717  << ", the Requested object name = " << root.substr (lastFwdSlash + 1)
718  << " does not exits on path " << root.substr (0, lastFwdSlash));
719  }
720  container.DisconnectWithoutContext (leaf, cb);
721 }
722 bool
723 ConfigImpl::ConnectFailSafe (std::string path, const CallbackBase &cb)
724 {
725  NS_LOG_FUNCTION (this << path << &cb);
726 
727  std::string root, leaf;
728  ParsePath (path, &root, &leaf);
729  MatchContainer container = LookupMatches (root);
730  return container.ConnectFailSafe (leaf, cb);
731 }
732 void
733 ConfigImpl::Disconnect (std::string path, const CallbackBase &cb)
734 {
735  NS_LOG_FUNCTION (this << path << &cb);
736 
737  std::string root, leaf;
738  ParsePath (path, &root, &leaf);
739  MatchContainer container = LookupMatches (root);
740  if (container.GetN () == 0)
741  {
742  std::size_t lastFwdSlash = root.rfind ("/");
743  NS_LOG_WARN ("Failed to disconnect " << leaf
744  << ", the Requested object name = " << root.substr (lastFwdSlash + 1)
745  << " does not exits on path " << root.substr (0, lastFwdSlash));
746  }
747  container.Disconnect (leaf, cb);
748 }
749 
751 ConfigImpl::LookupMatches (std::string path)
752 {
753  NS_LOG_FUNCTION (this << path);
754  class LookupMatchesResolver : public Resolver
755  {
756 public:
757  LookupMatchesResolver (std::string path)
758  : Resolver (path)
759  {
760  }
761  virtual void DoOne (Ptr<Object> object, std::string path)
762  {
763  m_objects.push_back (object);
764  m_contexts.push_back (path);
765  }
766  std::vector<Ptr<Object> > m_objects;
767  std::vector<std::string> m_contexts;
768  } resolver = LookupMatchesResolver (path);
769  for (Roots::const_iterator i = m_roots.begin (); i != m_roots.end (); i++)
770  {
771  resolver.Resolve (*i);
772  }
773 
774  //
775  // See if we can do something with the object name service. Starting with
776  // the root pointer zeroed indicates to the resolver that it should start
777  // looking at the root of the "/Names" namespace during this go.
778  //
779  resolver.Resolve (0);
780 
781  return MatchContainer (resolver.m_objects, resolver.m_contexts, path);
782 }
783 
784 void
786 {
787  NS_LOG_FUNCTION (this << obj);
788  m_roots.push_back (obj);
789 }
790 
791 void
793 {
794  NS_LOG_FUNCTION (this << obj);
795 
796  for (std::vector<Ptr<Object> >::iterator i = m_roots.begin (); i != m_roots.end (); i++)
797  {
798  if (*i == obj)
799  {
800  m_roots.erase (i);
801  return;
802  }
803  }
804 }
805 
806 std::size_t
808 {
809  NS_LOG_FUNCTION (this);
810  return m_roots.size ();
811 }
814 {
815  NS_LOG_FUNCTION (this << i);
816  return m_roots[i];
817 }
818 
819 
820 void Reset (void)
821 {
823  // First, let's reset the initial value of every attribute
824  for (uint16_t i = 0; i < TypeId::GetRegisteredN (); i++)
825  {
826  TypeId tid = TypeId::GetRegistered (i);
827  for (uint32_t j = 0; j < tid.GetAttributeN (); j++)
828  {
829  struct TypeId::AttributeInformation info = tid.GetAttribute (j);
831  }
832  }
833  // now, let's reset the initial value of every global value.
835  {
836  (*i)->ResetInitialValue ();
837  }
838 }
839 void Set (std::string path, const AttributeValue &value)
840 {
841  NS_LOG_FUNCTION (path << &value);
842  ConfigImpl::Get ()->Set (path, value);
843 }
844 bool SetFailSafe (std::string path, const AttributeValue &value)
845 {
846  NS_LOG_FUNCTION (path << &value);
847  return ConfigImpl::Get ()->SetFailSafe (path, value);
848 }
849 void SetDefault (std::string name, const AttributeValue &value)
850 {
851  NS_LOG_FUNCTION (name << &value);
852  if (!SetDefaultFailSafe (name, value))
853  {
854  NS_FATAL_ERROR ("Could not set default value for " << name);
855  }
856 }
857 bool SetDefaultFailSafe (std::string fullName, const AttributeValue &value)
858 {
859  NS_LOG_FUNCTION (fullName << &value);
860  std::string::size_type pos = fullName.rfind ("::");
861  if (pos == std::string::npos)
862  {
863  return false;
864  }
865  std::string tidName = fullName.substr (0, pos);
866  std::string paramName = fullName.substr (pos + 2, fullName.size () - (pos + 2));
867  TypeId tid;
868  bool ok = TypeId::LookupByNameFailSafe (tidName, &tid);
869  if (!ok)
870  {
871  return false;
872  }
873  for (uint32_t j = 0; j < tid.GetAttributeN (); j++)
874  {
875  struct TypeId::AttributeInformation tmp = tid.GetAttribute (j);
876  if (tmp.name == paramName)
877  {
878  Ptr<AttributeValue> v = tmp.checker->CreateValidValue (value);
879  if (v == 0)
880  {
881  return false;
882  }
883  tid.SetAttributeInitialValue (j, v);
884  return true;
885  }
886  }
887  return false;
888 }
889 void SetGlobal (std::string name, const AttributeValue &value)
890 {
891  NS_LOG_FUNCTION (name << &value);
892  GlobalValue::Bind (name, value);
893 }
894 bool SetGlobalFailSafe (std::string name, const AttributeValue &value)
895 {
896  NS_LOG_FUNCTION (name << &value);
897  return GlobalValue::BindFailSafe (name, value);
898 }
899 void ConnectWithoutContext (std::string path, const CallbackBase &cb)
900 {
901  NS_LOG_FUNCTION (path << &cb);
902  if (!ConnectWithoutContextFailSafe (path, cb))
903  {
904  NS_FATAL_ERROR ("Could not connect callback to " << path);
905  }
906 }
907 bool ConnectWithoutContextFailSafe (std::string path, const CallbackBase &cb)
908 {
909  NS_LOG_FUNCTION (path << &cb);
910  return ConfigImpl::Get ()->ConnectWithoutContextFailSafe (path, cb);
911 }
912 void DisconnectWithoutContext (std::string path, const CallbackBase &cb)
913 {
914  NS_LOG_FUNCTION (path << &cb);
916 }
917 void
918 Connect (std::string path, const CallbackBase &cb)
919 {
920  NS_LOG_FUNCTION (path << &cb);
921  if (!ConnectFailSafe (path, cb))
922  {
923  NS_FATAL_ERROR ("Could not connect callback to " << path);
924  }
925 }
926 bool
927 ConnectFailSafe (std::string path, const CallbackBase &cb)
928 {
929  NS_LOG_FUNCTION (path << &cb);
930  return ConfigImpl::Get ()->ConnectFailSafe (path, cb);
931 }
932 void
933 Disconnect (std::string path, const CallbackBase &cb)
934 {
935  NS_LOG_FUNCTION (path << &cb);
936  ConfigImpl::Get ()->Disconnect (path, cb);
937 }
938 MatchContainer LookupMatches (std::string path)
939 {
940  NS_LOG_FUNCTION (path);
941  return ConfigImpl::Get ()->LookupMatches (path);
942 }
943 
945 {
946  NS_LOG_FUNCTION (obj);
948 }
949 
951 {
952  NS_LOG_FUNCTION (obj);
954 }
955 
956 std::size_t GetRootNamespaceObjectN (void)
957 {
960 }
961 
963 {
964  NS_LOG_FUNCTION (i);
966 }
967 
968 } // namespace Config
969 
970 } // 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:666
bool ConnectWithoutContextFailSafe(std::string name, const CallbackBase &cb)
Connect the specified sink to all the objects stored in this container.
Definition: config.cc:147
#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:857
std::vector< std::string > m_workStack
Current list of path tokens.
Definition: config.cc:361
Ptr< T > Get(void) const
Definition: pointer.h:201
bool SetFailSafe(std::string path, const AttributeValue &value)
This function will attempt to find attributes which match the input path and will then set their valu...
Definition: config.cc:844
Roots m_roots
The list of Config path roots.
Definition: config.cc:661
void Set(std::string path, const AttributeValue &value)
Definition: config.cc:839
bool SetGlobalFailSafe(std::string name, const AttributeValue &value)
Definition: config.cc:894
void UnregisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:950
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:807
Helper to test if an array entry matches a config path specification.
Definition: config.cc:186
void RegisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:785
#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:411
#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:419
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:1195
static TypeId GetRegistered(uint16_t i)
Get a TypeId by index.
Definition: type-id.cc:876
Config system implementation class.
Definition: config.cc:617
bool SetAttributeFailSafe(std::string name, const AttributeValue &value)
Set a single attribute without raising errors.
Definition: object-base.cc:205
void Disconnect(std::string name, const CallbackBase &cb)
Definition: config.cc:159
void DisconnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:912
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
static bool LookupByNameFailSafe(std::string name, TypeId *tid)
Get a TypeId by name.
Definition: type-id.cc:838
Ptr< Object > GetRootNamespaceObject(std::size_t i) const
Definition: config.cc:813
void UnregisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:792
Ptr< Object > Get(std::size_t i) const
Definition: config.cc:75
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
bool ConnectFailSafe(std::string path, const CallbackBase &cb)
This function will attempt to find all trace sources which match the input path and will then connect...
Definition: config.cc:723
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:944
bool SetAttributeInitialValue(std::size_t i, Ptr< const AttributeValue > initialValue)
Set the initial value of an Attribute.
Definition: type-id.cc:1051
TypeId GetParent(void) const
Get the parent of this TypeId.
Definition: type-id.cc:944
bool ConnectFailSafe(std::string name, const CallbackBase &cb)
Connect the specified sink to all the objects stored in this container.
Definition: config.cc:125
bool ConnectWithoutContextFailSafe(std::string path, const CallbackBase &cb)
This function will attempt to find all trace sources which match the input path and will then connect...
Definition: config.cc:698
A template singleton.
Definition: singleton.h:63
void ConnectWithoutContext(std::string name, const CallbackBase &cb)
Definition: config.cc:139
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:288
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:218
std::string m_element
The Config path element.
Definition: config.cc:213
std::map< std::size_t, Ptr< Object > >::const_iterator Iterator
Iterator type for traversing this container.
MatchContainer LookupMatches(std::string path)
Definition: config.cc:751
Ptr< Object > GetRootNamespaceObject(uint32_t i)
Definition: config.cc:962
AttributeChecker implementation for ObjectPtrContainerValue.
Iterator End(void) const
Get an iterator to the past-the-end Object.
bool SetFailSafe(std::string path, const AttributeValue &value)
This function will attempt to find attributes which match the input path and will then set their valu...
Definition: config.cc:688
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:899
bool SetFailSafe(std::string name, const AttributeValue &value)
Set the specified attribute value to all the objects stored in this container.
Definition: config.cc:105
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 Canonicalize(void)
Ensure the Config path starts and ends with a &#39;/&#39;.
Definition: config.cc:378
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:918
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
MatchContainer::Iterator Begin(void) const
Definition: config.cc:57
Ptr< const AttributeChecker > checker
Checker object.
Definition: type-id.h:92
bool ConnectWithoutContextFailSafe(std::string path, const CallbackBase &cb)
This function will attempt to find all trace sources which match the input path and will then connect...
Definition: config.cc:907
std::string m_path
The path used to perform the object matching.
Definition: config.h:306
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:80
void Set(std::string path, const AttributeValue &value)
Definition: config.cc:678
std::string GetResolvedPath(void) const
Get the current Config path.
Definition: config.cc:406
std::size_t GetRootNamespaceObjectN(void)
Definition: config.cc:956
bool ConnectFailSafe(std::string path, const CallbackBase &cb)
This function will attempt to find all trace sources which match the input path and will then connect...
Definition: config.cc:927
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:398
hold a set of objects which match a specific search string.
Definition: config.h:180
std::vector< Ptr< Object > > m_objects
The list of objects in this container.
Definition: config.h:302
void Connect(std::string name, const CallbackBase &cb)
Definition: config.cc:117
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:820
std::vector< Ptr< Object > > Roots
Container type to hold the root Config path tokens.
Definition: config.cc:658
double max(double x, double y)
MatchContainer LookupMatches(std::string path)
Definition: config.cc:938
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:171
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:224
void DoArrayResolve(std::string path, const ObjectPtrContainerValue &vector)
Parse an index on the Config path.
Definition: config.cc:585
AttributeChecker implementation for PointerValue.
Definition: pointer.h:97
void DisconnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:707
void SetGlobal(std::string name, const AttributeValue &value)
Definition: config.cc:889
#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:304
Resolver(std::string path)
Construct from a base Config path.
Definition: config.cc:367
std::size_t GetAttributeN(void) const
Get the number of attributes.
Definition: type-id.cc:1077
void DoResolve(std::string path, Ptr< Object > root)
Parse the next element in the Config path.
Definition: config.cc:428
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:849
struct TypeId::AttributeInformation GetAttribute(std::size_t i) const
Get Attribute information by index.
Definition: type-id.cc:1084
void Disconnect(std::string path, const CallbackBase &cb)
Definition: config.cc:733
virtual ~Resolver()
Destructor.
Definition: config.cc:373
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:184
Abstract class to parse Config paths into object references.
Definition: config.cc:301
#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:870
Debug message logging.
void Disconnect(std::string path, const CallbackBase &cb)
Definition: config.cc:933
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:363
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition: type-id.cc:830
std::string GetPath(void) const
Definition: config.cc:87