don't update model state from a DoDispose() method
authorTom Henderson <tomh@tomh.org>
Thu, 30 Dec 2010 12:17:00 -0800
changeset 6739 1b903a05007c
parent 6738 cca16b131d9b
child 6740 e22c8a30fb0e
don't update model state from a DoDispose() method
src/contrib/energy/model/basic-energy-source.cc
src/contrib/energy/test/basic-energy-model-test.cc
--- a/src/contrib/energy/model/basic-energy-source.cc	Thu Dec 30 11:16:35 2010 -0800
+++ b/src/contrib/energy/model/basic-energy-source.cc	Thu Dec 30 12:17:00 2010 -0800
@@ -174,8 +174,6 @@
 BasicEnergySource::DoDispose (void)
 {
   NS_LOG_FUNCTION (this);
-  // calculate remaining energy at the end of simulation
-  CalculateRemainingEnergy ();
   BreakDeviceEnergyModelRefCycle ();  // break reference cycle
 }
 
--- a/src/contrib/energy/test/basic-energy-model-test.cc	Thu Dec 30 11:16:35 2010 -0800
+++ b/src/contrib/energy/test/basic-energy-model-test.cc	Thu Dec 30 12:17:00 2010 -0800
@@ -152,10 +152,14 @@
   Simulator::Schedule (Seconds (m_timeS),
                        &WifiRadioEnergyModel::ChangeState, devModel, state);
 
-  // run simulation
-  Simulator::Stop (Seconds (m_timeS * 2));
+  // Calculate remaining energy at simulation stop time
+  Simulator::Schedule (Seconds (m_timeS * 2), 
+                       &BasicEnergySource::UpdateEnergySource, source);
+
+  double timeDelta = 0.000000001; // 1 nanosecond
+  // run simulation; stop just after last scheduled event
+  Simulator::Stop (Seconds (m_timeS * 2 + timeDelta));
   Simulator::Run ();
-  Simulator::Destroy ();
 
   // energy = current * voltage * time