move methods from Collector to DataCollectionObject. Fix TimeDrivenCollector and its sub-classes
--- a/src/stats/model/data-collection-object.cc Tue Mar 03 00:08:57 2015 -0500
+++ b/src/stats/model/data-collection-object.cc Tue Mar 03 00:25:59 2015 -0500
@@ -21,6 +21,7 @@
#include "ns3/log.h"
#include "ns3/string.h"
#include "ns3/boolean.h"
+#include "ns3/nstime.h"
#include "data-collection-object.h"
@@ -93,4 +94,24 @@
m_enabled = false;
}
+void
+DataCollectionObject::SetEnabledPeriod(Time startTime, Time endTime)
+{
+ NS_LOG_FUNCTION(this);
+ m_startTime = startTime;
+ m_endTime = endTime;
+ isEnabledPeriodSet = true;
+ // automatically enable the collector in order for TimeDrivenCollector
+ // to shedule the first event. This line will do nothing to
+ // EventDrivenCollector
+ Enable();
+}
+
+void
+DataCollectionObject::UnsetEnabledPeriod(void)
+{
+ isEnabledPeriodSet = false;
+}
+
+
} // namespace ns3
--- a/src/stats/model/data-collection-object.h Tue Mar 03 00:08:57 2015 -0500
+++ b/src/stats/model/data-collection-object.h Tue Mar 03 00:25:59 2015 -0500
@@ -23,6 +23,7 @@
#include <string>
#include "ns3/object.h"
+#include "ns3/nstime.h"
namespace ns3 {
@@ -60,6 +61,27 @@
/// Set the object's name. All spaces are replaced by underscores.
void SetName (std::string name);
+ // set the time period in which the collector will be enabled. Note that
+ // once this method is called, you do not need to explicitly call
+ // Collector::Enable() or Collector::Disable() again. The Collector class
+ // will take care of everything for you. Note that when using
+ // TimeDrivenCollector, do not call Disable() after calling
+ // SetEnabledPeriod(); otherwise TimeDrivenCollector will not run.
+ //
+ // A good pratice will be that after calling SetEnabledPeriod(), do not
+ // mess around with Enable() and Disable() anymore. This function takes
+ // care of everything for you.
+ void SetEnabledPeriod(Time startTime, Time endTime);
+
+ // disable the enabled period so that you can control the collector
+ // manually with Enable() and Disable()
+ void UnsetEnabledPeriod(void);
+
+ Time GetStartTime(void) {return m_startTime;}
+ Time GetEndTime(void) {return m_endTime;}
+
+ bool IsEnabledPeriodSet(void) {return isEnabledPeriodSet;}
+
protected:
/// Object's activation state.
@@ -70,6 +92,10 @@
/// Report Data to downstream objects
void ReportData (void);
+
+ Time m_startTime;
+ Time m_endTime;
+ bool isEnabledPeriodSet;
};
} // namespace ns3
--- a/src/stats/model/double-time-driven-collector.h Tue Mar 03 00:08:57 2015 -0500
+++ b/src/stats/model/double-time-driven-collector.h Tue Mar 03 00:25:59 2015 -0500
@@ -45,12 +45,13 @@
void TraceSinkUinteger8(uint8_t oldValue, uint8_t newValue);
protected:
- virtual void DoReportData(void);
-
TracedCallback<double, double> m_output;
// keep track of the double value received by the trace sink
double m_doubleValue;
+private:
+ void DoReportData(void);
+
};
} // namespace ns3
--- a/src/stats/model/time-driven-collector.cc Tue Mar 03 00:08:57 2015 -0500
+++ b/src/stats/model/time-driven-collector.cc Tue Mar 03 00:25:59 2015 -0500
@@ -32,7 +32,7 @@
TimeDrivenCollector::GetTypeId(void)
{
static TypeId tid = TypeId("ns3::TimeDrivenCollector")
- .SetParent<Collector> ();
+ .SetParent<DataCollectionObject> ();
return tid;
}
--- a/src/stats/model/time-driven-collector.h Tue Mar 03 00:08:57 2015 -0500
+++ b/src/stats/model/time-driven-collector.h Tue Mar 03 00:25:59 2015 -0500
@@ -21,7 +21,7 @@
#define TIME_DRIVEN_COLLECTOR_H
#include "ns3/object.h"
-#include "ns3/collector.h"
+#include "ns3/data-collection-object.h"
#include "ns3/event-id.h"
#include "ns3/type-id.h"
#include "ns3/nstime.h"
@@ -45,7 +45,7 @@
* For a simple example, please look at the DoubleTimeDrivenCollector class.
*/
-class TimeDrivenCollector : public Collector
+class TimeDrivenCollector : public DataCollectionObject
{
public:
static TypeId GetTypeId(void);
@@ -60,6 +60,7 @@
protected:
void ReportData(void);
+ virtual void DoReportData(void) = 0;
Time m_period;
EventId m_reportEventId;
bool m_hasReportBeenScheduled;