fix the doxygen comments and simplify the implementation
This commit is contained in:
@@ -35,9 +35,7 @@ namespace ns3 {
|
||||
|
||||
// \brief Application Constructor
|
||||
Application::Application(Ptr<Node> n)
|
||||
: m_node (n),
|
||||
m_startVar(0), m_stopVar(0),
|
||||
m_start(false), m_stop(false)
|
||||
: m_node (n)
|
||||
{
|
||||
m_node->AddApplication (this);
|
||||
}
|
||||
@@ -50,57 +48,33 @@ void
|
||||
Application::DoDispose (void)
|
||||
{
|
||||
m_node = 0;
|
||||
if (m_start)
|
||||
{
|
||||
Simulator::Cancel(m_startEvent);
|
||||
m_start = false;
|
||||
}
|
||||
if (m_stop)
|
||||
{
|
||||
Simulator::Cancel(m_stopEvent);
|
||||
m_stop = false;
|
||||
}
|
||||
delete m_startVar;
|
||||
m_startVar = 0;
|
||||
delete m_stopVar;
|
||||
m_stopVar = 0;
|
||||
Simulator::Cancel(m_startEvent);
|
||||
Simulator::Cancel(m_stopEvent);
|
||||
}
|
||||
|
||||
// \brief Specify application start time
|
||||
// The virtual method STartApp will be called at the time
|
||||
// specified by startTime.
|
||||
// \param Time to start application (absolute time, from start of simulation)
|
||||
void Application::Start(const Time& startTime)
|
||||
{
|
||||
delete m_startVar;
|
||||
m_startVar = new ConstantVariable(startTime.GetSeconds());
|
||||
ScheduleStart();
|
||||
ScheduleStart (startTime);
|
||||
}
|
||||
|
||||
void Application::Start(const RandomVariable& startVar)
|
||||
{ // Start at random time
|
||||
delete m_startVar;
|
||||
m_startVar = startVar.Copy();
|
||||
ScheduleStart();
|
||||
{
|
||||
RandomVariable *v = startVar.Copy ();
|
||||
ScheduleStart (Seconds (v->GetValue ()));
|
||||
delete v;
|
||||
}
|
||||
|
||||
|
||||
// \brief Specify application stop time
|
||||
// The virtual method StopApp will be called at the time
|
||||
// specified by stopTime.
|
||||
// \param Time to stop application (absolute time, from start of simulation)
|
||||
void Application::Stop(const Time& stopTime)
|
||||
{
|
||||
delete m_stopVar;
|
||||
m_stopVar = new ConstantVariable(stopTime.GetSeconds());
|
||||
ScheduleStop();
|
||||
ScheduleStop (stopTime);
|
||||
}
|
||||
|
||||
void Application::Stop(const RandomVariable& stopVar)
|
||||
{ // Stop at random time
|
||||
delete m_stopVar;
|
||||
m_stopVar = stopVar.Copy();
|
||||
ScheduleStop();
|
||||
{
|
||||
RandomVariable *v = stopVar.Copy ();
|
||||
ScheduleStop (Seconds (v->GetValue ()));
|
||||
delete v;
|
||||
}
|
||||
|
||||
Ptr<Node> Application::GetNode() const
|
||||
@@ -120,20 +94,18 @@ void Application::StopApplication()
|
||||
|
||||
|
||||
// Private helpers
|
||||
void Application::ScheduleStart()
|
||||
void Application::ScheduleStart (const Time &startTime)
|
||||
{
|
||||
m_startEvent = Simulator::Schedule(Seconds(m_startVar->GetValue()) -
|
||||
m_startEvent = Simulator::Schedule(startTime -
|
||||
Simulator::Now(),
|
||||
&Application::StartApplication, this);
|
||||
m_start = true;
|
||||
}
|
||||
|
||||
void Application::ScheduleStop()
|
||||
void Application::ScheduleStop (const Time &stopTime)
|
||||
{
|
||||
m_stopEvent = Simulator::Schedule(Seconds(m_stopVar->GetValue()) -
|
||||
Simulator::Now(),
|
||||
&Application::StopApplication, this);
|
||||
m_stop = true;
|
||||
m_stopEvent = Simulator::Schedule(stopTime -
|
||||
Simulator::Now(),
|
||||
&Application::StopApplication, this);
|
||||
}
|
||||
|
||||
} //namespace ns3
|
||||
|
||||
@@ -57,77 +57,92 @@ namespace ns3 {
|
||||
|
||||
class Node;
|
||||
class RandomVariable;
|
||||
|
||||
|
||||
/**
|
||||
* \brief a model for userspace applications.
|
||||
*/
|
||||
class Application : public Object
|
||||
{
|
||||
public:
|
||||
Application(Ptr<Node>);
|
||||
virtual ~Application();
|
||||
|
||||
// \brief Specify application start time
|
||||
// Applications start at various times in the simulation scenario.
|
||||
// The Start method specifies when the application should be
|
||||
// started. The application subclasses should override the
|
||||
// private "StartApplication" method defined below, which is called at the
|
||||
// time specified, to cause the application to begin.
|
||||
// \param Start time for this application, relative to the
|
||||
// current simulation time.
|
||||
void Start(const Time&);
|
||||
/**
|
||||
* \brief Specify application start time
|
||||
* Applications start at various times in the simulation scenario.
|
||||
* The Start method specifies when the application should be
|
||||
* started. The application subclasses should override the
|
||||
* private "StartApplication" method defined below, which is called at the
|
||||
* time specified, to cause the application to begin.
|
||||
* \param startTime Start time for this application, absolute time,
|
||||
* relative to the start of the simulation.
|
||||
*/
|
||||
void Start(const Time& startTime);
|
||||
|
||||
// \brief Same as above, but uses a random variable for start time
|
||||
// The random variable returns the desired start time in units of
|
||||
// Seconds.
|
||||
/**
|
||||
* \brief Same as above, but uses a random variable for start time
|
||||
* The random variable returns the desired start time in units of
|
||||
* Seconds.
|
||||
* \param startVariable the random variable to use to pick
|
||||
* the real start time as an absolute time, relative to
|
||||
* the start of the simulation.
|
||||
*/
|
||||
void Start(const RandomVariable& startVariable);
|
||||
|
||||
void Start(const RandomVariable&);
|
||||
|
||||
// \brief Specify application stop time
|
||||
// Once an application has started, it is sometimes useful
|
||||
// to stop the application. The Stop method specifies when an
|
||||
// application is to stop. The application subclasses should override
|
||||
// the private StopApplication method defined below, to cause the application
|
||||
// to stop.
|
||||
// \param Stop time for this application, relative to the
|
||||
// current simulation time.
|
||||
void Stop(const Time&);
|
||||
/**
|
||||
* \brief Specify application stop time
|
||||
* Once an application has started, it is sometimes useful
|
||||
* to stop the application. The Stop method specifies when an
|
||||
* application is to stop. The application subclasses should override
|
||||
* the private StopApplication method defined below, to cause the application
|
||||
* to stop.
|
||||
* \param stopTime Stop time for this application, relative to the
|
||||
* start of the simulation.
|
||||
*/
|
||||
void Stop(const Time& stopTime);
|
||||
|
||||
// \brief Same as above, but uses a random variable for stop time
|
||||
// The random variable returns the desired stop time in units of
|
||||
// Seconds.
|
||||
void Stop(const RandomVariable&);
|
||||
|
||||
// \brief Attaches an application to a specific node
|
||||
// Specifies which node object this application is associated with.
|
||||
// \param Node object to associate with this application.
|
||||
// \brief Returns the pointer to the attached node.
|
||||
/**
|
||||
* \brief Same as above, but uses a random variable for stop time
|
||||
* The random variable returns the desired stop time in units of
|
||||
* Seconds.
|
||||
* \param stopVariable the random variable to use to pick
|
||||
* the real stop time, relative to the start of the simulation.
|
||||
*/
|
||||
void Stop(const RandomVariable& stopVariable);
|
||||
|
||||
/**
|
||||
* \returns the Node to which this Application object is attached.
|
||||
*/
|
||||
Ptr<Node> GetNode() const;
|
||||
|
||||
private:
|
||||
// Members
|
||||
Ptr<Node> m_node; // All applications have an associated node
|
||||
RandomVariable* m_startVar; // Random variable for start time
|
||||
RandomVariable* m_stopVar; // Random variable for stop time
|
||||
EventId m_startEvent;// Event identifier for start event
|
||||
EventId m_stopEvent; // Event identifier for the stop event
|
||||
bool m_start; // True if start event scheduled
|
||||
bool m_stop; // True if stop event scheduled
|
||||
|
||||
|
||||
private:
|
||||
/**
|
||||
* \brief Application specific startup code
|
||||
* The StartApplication method is called at the start time specifed by Start
|
||||
* This method should be overridden by all or most application
|
||||
* subclasses.
|
||||
*/
|
||||
virtual void StartApplication (void);
|
||||
|
||||
/**
|
||||
* \brief Application specific shutdown code
|
||||
* The StopApplication method is called at the stop time specifed by Stop
|
||||
* This method should be overridden by all or most application
|
||||
* subclasses.
|
||||
*/
|
||||
virtual void StopApplication (void);
|
||||
protected:
|
||||
// \brief Application specific startup code
|
||||
// The StartApplication method is called at the start time specifed by Start
|
||||
// This method should be overridden by all or most application
|
||||
// subclasses.
|
||||
virtual void StartApplication();
|
||||
|
||||
// \brief Application specific shutdown code
|
||||
// The StopApplication method is called at the stop time specifed by Stop
|
||||
// This method should be overridden by all or most application
|
||||
// subclasses.
|
||||
virtual void StopApplication();
|
||||
|
||||
virtual void DoDispose (void);
|
||||
private:
|
||||
// Helpers
|
||||
void ScheduleStart();
|
||||
void ScheduleStop();
|
||||
void ScheduleStart (const Time &time);
|
||||
void ScheduleStop (const Time &time);
|
||||
};
|
||||
|
||||
} //namespace ns3
|
||||
|
||||
Reference in New Issue
Block a user