src/core/config.cc
changeset 2504 da3ec9cc3ba3
parent 2479 7d1d80aea47b
child 2531 b451b5fc8b57
--- a/src/core/config.cc	Wed Feb 27 22:19:39 2008 +0100
+++ b/src/core/config.cc	Thu Feb 28 04:28:34 2008 +0100
@@ -398,6 +398,9 @@
 
 #include "test.h"
 #include "integer.h"
+#include "traced-value.h"
+#include "trace-source-accessor.h"
+#include "callback.h"
 
 namespace ns3 {
 
@@ -422,6 +425,7 @@
   Ptr<MyNode> m_nodeB;
   int8_t m_a;
   int8_t m_b;
+  TracedValue<int16_t> m_trace;
 };
 
 TypeId MyNode::GetTypeId (void)
@@ -452,6 +456,12 @@
 		   Integer (9),
 		   MakeIntegerAccessor (&MyNode::m_b),
 		   MakeIntegerChecker<int8_t> ())
+    .AddAttribute ("Source", "XX",
+		   Integer (-1),
+		   MakeIntegerAccessor (&MyNode::m_trace),
+		   MakeIntegerChecker<int16_t> ())
+    .AddTraceSource ("Source", "XX",
+		     MakeTraceSourceAccessor (&MyNode::m_trace))
     ;
   return tid;
 }
@@ -493,6 +503,9 @@
 public:
   ConfigTest ();
   virtual bool RunTests (void);
+private:
+  void ChangeNotification (int16_t old, int16_t newValue);
+  int16_t m_traceNotification;
 };
 
 static ConfigTest g_configTestUnique;
@@ -501,6 +514,12 @@
   : Test ("Config")
 {}
 
+void
+ConfigTest::ChangeNotification (int16_t oldValue, int16_t newValue)
+{
+  m_traceNotification = newValue;
+}
+
 bool
 ConfigTest::RunTests (void)
 {
@@ -603,6 +622,24 @@
   NS_TEST_ASSERT_EQUAL (v.Get (), -16);
 
 
+  Config::Connect ("/NodeA/NodeB/NodesB/[0-1]|3/Source", 
+		   MakeCallback (&ConfigTest::ChangeNotification, this));
+  m_traceNotification = 0;
+  // this should trigger no notification
+  d2->SetAttribute ("Source", Integer (-2));
+  NS_TEST_ASSERT_EQUAL (m_traceNotification, 0);
+  m_traceNotification = 0;
+  // this should trigger a notification
+  d1->SetAttribute ("Source", Integer (-3));
+  NS_TEST_ASSERT_EQUAL (m_traceNotification, -3);
+  Config::Disconnect ("/NodeA/NodeB/NodesB/[0-1]|3/Source", 
+		      MakeCallback (&ConfigTest::ChangeNotification, this));
+  m_traceNotification = 0;
+  // this should _not_ trigger a notification
+  d1->SetAttribute ("Source", Integer (-4));
+  NS_TEST_ASSERT_EQUAL (m_traceNotification, 0);
+
+
 
   return result;
 }