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"
25#include "names.h"
26#include "pointer.h"
27#include "log.h"
28
29#include <sstream>
30
37namespace ns3 {
38
40
41namespace Config {
42
44{
45 NS_LOG_FUNCTION (this);
46}
47MatchContainer::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}
64{
65 NS_LOG_FUNCTION (this);
66 return m_objects.end ();
67}
68std::size_t
70{
71 NS_LOG_FUNCTION (this);
72 return m_objects.size ();
73}
75MatchContainer::Get (std::size_t i) const
76{
77 NS_LOG_FUNCTION (this << i);
78 return m_objects[i];
79}
80std::string
82{
83 NS_LOG_FUNCTION (this << i);
84 return m_contexts[i];
85}
86std::string
88{
89 NS_LOG_FUNCTION (this);
90 return m_path;
91}
92
93void
94MatchContainer::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}
104bool
105MatchContainer::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}
116void
117MatchContainer::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}
124bool
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}
138void
140{
141 if (!ConnectWithoutContextFailSafe (name, cb))
142 {
143 NS_FATAL_ERROR ("Could not connect callback to " << name);
144 }
145}
146bool
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}
158void
159MatchContainer::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}
170void
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{
188public:
194 ArrayMatcher (std::string element);
201 bool Matches (std::size_t i) const;
202
203private:
211 bool StringToUint32 (std::string str, uint32_t *value) const;
213 std::string m_element;
214
215}; // class ArrayMatcher
216
217
218ArrayMatcher::ArrayMatcher (std::string element)
219 : m_element (element)
220{
221 NS_LOG_FUNCTION (this << element);
222}
223bool
224ArrayMatcher::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));
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
287bool
288ArrayMatcher::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
302{
303public:
309 Resolver (std::string path);
311 virtual ~Resolver ();
312
320 void Resolve (Ptr<Object> root);
321
322private:
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
367Resolver::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}
377void
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
397void
399{
400 NS_LOG_FUNCTION (this << root);
401
402 DoResolve (m_path, root);
403}
404
405std::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
418void
420{
421 NS_LOG_FUNCTION (this << object);
422
423 NS_LOG_DEBUG ("resolved=" << GetResolvedPath ());
424 DoOne (object, GetResolvedPath ());
425}
426
427void
428Resolver::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 {
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
584void
585Resolver::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
617class ConfigImpl : public Singleton<ConfigImpl>
618{
619public:
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
647private:
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
665void
666ConfigImpl::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
677void
678ConfigImpl::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}
687bool
688ConfigImpl::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}
697bool
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}
706void
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}
722bool
723ConfigImpl::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}
732void
733ConfigImpl::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
752{
753 NS_LOG_FUNCTION (this << path);
754 class LookupMatchesResolver : public Resolver
755 {
756public:
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
784void
786{
787 NS_LOG_FUNCTION (this << obj);
788 m_roots.push_back (obj);
789}
790
791void
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
806std::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
820void 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 {
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}
839void Set (std::string path, const AttributeValue &value)
840{
841 NS_LOG_FUNCTION (path << &value);
842 ConfigImpl::Get ()->Set (path, value);
843}
844bool SetFailSafe (std::string path, const AttributeValue &value)
845{
846 NS_LOG_FUNCTION (path << &value);
847 return ConfigImpl::Get ()->SetFailSafe (path, value);
848}
849void 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}
857bool 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 }
874 tid.LookupAttributeByName(paramName, &info);
875 for (uint32_t j = 0; j < tid.GetAttributeN (); j++)
876 {
877 struct TypeId::AttributeInformation tmp = tid.GetAttribute (j);
878 if (tmp.name == paramName)
879 {
880 Ptr<AttributeValue> v = tmp.checker->CreateValidValue (value);
881 if (v == 0)
882 {
883 return false;
884 }
885 tid.SetAttributeInitialValue (j, v);
886 return true;
887 }
888 }
889 return false;
890}
891void SetGlobal (std::string name, const AttributeValue &value)
892{
893 NS_LOG_FUNCTION (name << &value);
894 GlobalValue::Bind (name, value);
895}
896bool SetGlobalFailSafe (std::string name, const AttributeValue &value)
897{
898 NS_LOG_FUNCTION (name << &value);
899 return GlobalValue::BindFailSafe (name, value);
900}
901void ConnectWithoutContext (std::string path, const CallbackBase &cb)
902{
903 NS_LOG_FUNCTION (path << &cb);
904 if (!ConnectWithoutContextFailSafe (path, cb))
905 {
906 NS_FATAL_ERROR ("Could not connect callback to " << path);
907 }
908}
909bool ConnectWithoutContextFailSafe (std::string path, const CallbackBase &cb)
910{
911 NS_LOG_FUNCTION (path << &cb);
913}
914void DisconnectWithoutContext (std::string path, const CallbackBase &cb)
915{
916 NS_LOG_FUNCTION (path << &cb);
918}
919void
920Connect (std::string path, const CallbackBase &cb)
921{
922 NS_LOG_FUNCTION (path << &cb);
923 if (!ConnectFailSafe (path, cb))
924 {
925 NS_FATAL_ERROR ("Could not connect callback to " << path);
926 }
927}
928bool
929ConnectFailSafe (std::string path, const CallbackBase &cb)
930{
931 NS_LOG_FUNCTION (path << &cb);
932 return ConfigImpl::Get ()->ConnectFailSafe (path, cb);
933}
934void
935Disconnect (std::string path, const CallbackBase &cb)
936{
937 NS_LOG_FUNCTION (path << &cb);
938 ConfigImpl::Get ()->Disconnect (path, cb);
939}
941{
942 NS_LOG_FUNCTION (path);
943 return ConfigImpl::Get ()->LookupMatches (path);
944}
945
947{
948 NS_LOG_FUNCTION (obj);
950}
951
953{
954 NS_LOG_FUNCTION (obj);
956}
957
958std::size_t GetRootNamespaceObjectN (void)
959{
962}
963
965{
966 NS_LOG_FUNCTION (i);
968}
969
970} // namespace Config
971
972} // namespace ns3
#define min(a, b)
Definition: 80211b.c:42
#define max(a, b)
Definition: 80211b.c:43
Hold a value for an Attribute.
Definition: attribute.h:69
Base class for Callback class.
Definition: callback.h:1196
Helper to test if an array entry matches a config path specification.
Definition: config.cc:187
ArrayMatcher(std::string element)
Construct from a Config path specification.
Definition: config.cc:218
bool StringToUint32(std::string str, uint32_t *value) const
Convert a string to an uint32_t.
Definition: config.cc:288
bool Matches(std::size_t i) const
Test if a specific index matches the Config Path.
Definition: config.cc:224
std::string m_element
The Config path element.
Definition: config.cc:213
Config system implementation class.
Definition: config.cc:618
void UnregisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:792
void DisconnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:707
Roots m_roots
The list of Config path roots.
Definition: config.cc:661
Ptr< Object > GetRootNamespaceObject(std::size_t i) const
Definition: config.cc:813
bool ConnectFailSafe(std::string path, const CallbackBase &cb)
Definition: config.cc:723
bool SetFailSafe(std::string path, const AttributeValue &value)
Definition: config.cc:688
std::size_t GetRootNamespaceObjectN(void) const
Definition: config.cc:807
void Set(std::string path, const AttributeValue &value)
Definition: config.cc:678
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
void Disconnect(std::string path, const CallbackBase &cb)
Definition: config.cc:733
std::vector< Ptr< Object > > Roots
Container type to hold the root Config path tokens.
Definition: config.cc:658
bool ConnectWithoutContextFailSafe(std::string path, const CallbackBase &cb)
Definition: config.cc:698
void RegisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:785
MatchContainer LookupMatches(std::string path)
Definition: config.cc:751
hold a set of objects which match a specific search string.
Definition: config.h:193
bool SetFailSafe(std::string name, const AttributeValue &value)
Definition: config.cc:105
void Connect(std::string name, const CallbackBase &cb)
Definition: config.cc:117
void DisconnectWithoutContext(std::string name, const CallbackBase &cb)
Definition: config.cc:171
void Set(std::string name, const AttributeValue &value)
Definition: config.cc:94
Ptr< Object > Get(std::size_t i) const
Definition: config.cc:75
void Disconnect(std::string name, const CallbackBase &cb)
Definition: config.cc:159
std::string GetPath(void) const
Definition: config.cc:87
MatchContainer::Iterator End(void) const
Definition: config.cc:63
std::string GetMatchedPath(uint32_t i) const
Definition: config.cc:81
bool ConnectFailSafe(std::string name, const CallbackBase &cb)
Definition: config.cc:125
std::size_t GetN(void) const
Definition: config.cc:69
bool ConnectWithoutContextFailSafe(std::string name, const CallbackBase &cb)
Definition: config.cc:147
std::string m_path
The path used to perform the object matching.
Definition: config.h:336
void ConnectWithoutContext(std::string name, const CallbackBase &cb)
Definition: config.cc:139
std::vector< Ptr< Object > >::const_iterator Iterator
Const iterator over the objects in this container.
Definition: config.h:196
std::vector< Ptr< Object > > m_objects
The list of objects in this container.
Definition: config.h:332
MatchContainer::Iterator Begin(void) const
Definition: config.cc:57
std::vector< std::string > m_contexts
The context for each object.
Definition: config.h:334
Abstract class to parse Config paths into object references.
Definition: config.cc:302
std::vector< std::string > m_workStack
Current list of path tokens.
Definition: config.cc:361
Resolver(std::string path)
Construct from a base Config path.
Definition: config.cc:367
void Resolve(Ptr< Object > root)
Parse the stored Config path into an object reference, beginning at the indicated root object.
Definition: config.cc:398
void Canonicalize(void)
Ensure the Config path starts and ends with a '/'.
Definition: config.cc:378
void DoResolveOne(Ptr< Object > object)
Handle one object found on the path.
Definition: config.cc:419
virtual void DoOne(Ptr< Object > object, std::string path)=0
Handle one found object.
std::string GetResolvedPath(void) const
Get the current Config path.
Definition: config.cc:406
void DoResolve(std::string path, Ptr< Object > root)
Parse the next element in the Config path.
Definition: config.cc:428
std::string m_path
The Config path.
Definition: config.cc:363
virtual ~Resolver()
Destructor.
Definition: config.cc:373
void DoArrayResolve(std::string path, const ObjectPtrContainerValue &vector)
Parse an index on the Config path.
Definition: config.cc:585
Vector::const_iterator Iterator
Iterator type for the list of all global values.
Definition: global-value.h:80
static Iterator End(void)
The End iterator.
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...
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...
static Iterator Begin(void)
The Begin iterator.
bool TraceConnectWithoutContext(std::string name, const CallbackBase &cb)
Connect a TraceSource to a Callback without a context.
Definition: object-base.cc:364
bool TraceDisconnectWithoutContext(std::string name, const CallbackBase &cb)
Disconnect from a TraceSource a Callback previously connected without a context.
Definition: object-base.cc:390
bool SetAttributeFailSafe(std::string name, const AttributeValue &value)
Set a single attribute without raising errors.
Definition: object-base.cc:276
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:256
void GetAttribute(std::string name, AttributeValue &value) const
Get the value of an attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:294
A base class which provides memory management and object aggregation.
Definition: object.h:88
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition: object.cc:79
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
AttributeChecker implementation for ObjectPtrContainerValue.
Container for a set of ns3::Object pointers.
Iterator Begin(void) const
Get an iterator to the first Object.
std::map< std::size_t, Ptr< Object > >::const_iterator Iterator
Iterator type for traversing this container.
Iterator End(void) const
Get an iterator to the past-the-end Object.
AttributeChecker implementation for PointerValue.
Definition: pointer.h:98
Hold objects of type Ptr<T>.
Definition: pointer.h:37
Ptr< T > Get(void) const
Definition: pointer.h:201
A template singleton.
Definition: singleton.h:61
static ConfigImpl * Get(void)
Get a pointer to the singleton instance.
Definition: singleton.h:100
a unique identifier for an interface.
Definition: type-id.h:59
bool SetAttributeInitialValue(std::size_t i, Ptr< const AttributeValue > initialValue)
Set the initial value of an Attribute.
Definition: type-id.cc:1050
static TypeId LookupByName(std::string name)
Get a TypeId by name.
Definition: type-id.cc:829
std::size_t GetAttributeN(void) const
Get the number of attributes.
Definition: type-id.cc:1076
static uint16_t GetRegisteredN(void)
Get the number of registered TypeIds.
Definition: type-id.cc:869
struct TypeId::AttributeInformation GetAttribute(std::size_t i) const
Get Attribute information by index.
Definition: type-id.cc:1083
static TypeId GetRegistered(uint16_t i)
Get a TypeId by index.
Definition: type-id.cc:875
TypeId GetParent(void) const
Get the parent of this TypeId.
Definition: type-id.cc:943
bool LookupAttributeByName(std::string name, struct AttributeInformation *info) const
Find an Attribute by name, retrieving the associated AttributeInformation.
Definition: type-id.cc:882
static bool LookupByNameFailSafe(std::string name, TypeId *tid)
Get a TypeId by name.
Definition: type-id.cc:837
Declaration of the various ns3::Config functions and classes.
ns3::GlobalValue declaration.
#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
void SetGlobal(std::string name, const AttributeValue &value)
Definition: config.cc:891
bool SetFailSafe(std::string path, const AttributeValue &value)
Definition: config.cc:844
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
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:849
void Disconnect(std::string path, const CallbackBase &cb)
Definition: config.cc:935
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:920
MatchContainer LookupMatches(std::string path)
Definition: config.cc:940
void DisconnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:914
void ConnectWithoutContext(std::string path, const CallbackBase &cb)
Definition: config.cc:901
bool ConnectFailSafe(std::string path, const CallbackBase &cb)
Definition: config.cc:929
void UnregisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:952
Ptr< Object > GetRootNamespaceObject(uint32_t i)
Definition: config.cc:964
bool SetGlobalFailSafe(std::string name, const AttributeValue &value)
Definition: config.cc:896
void Set(std::string path, const AttributeValue &value)
Definition: config.cc:839
void RegisterRootNamespaceObject(Ptr< Object > obj)
Definition: config.cc:946
std::size_t GetRootNamespaceObjectN(void)
Definition: config.cc:958
bool SetDefaultFailSafe(std::string fullName, const AttributeValue &value)
Definition: config.cc:857
bool ConnectWithoutContextFailSafe(std::string path, const CallbackBase &cb)
Definition: config.cc:909
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:257
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:265
Debug message logging.
Declaration of class ns3::Names.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
U * PeekPointer(const Ptr< U > &p)
Definition: ptr.h:415
ns3::ObjectPtrContainerValue attribute value declarations and template implementations.
ns3::Object class declaration, which is the root of the Object hierarchy and Aggregation.
ns3::PointerValue attribute value declarations and template implementations.
ns3::Singleton declaration and template implementation.
Attribute implementation.
Definition: type-id.h:78
Ptr< const AttributeValue > originalInitialValue
Default initial value.
Definition: type-id.h:86
std::string name
Attribute name.
Definition: type-id.h:80
Ptr< const AttributeChecker > checker
Checker object.
Definition: type-id.h:92