A Discrete-Event Network Simulator
API
application.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2006 Georgia Tech Research Corporation
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: George F. Riley<riley@ece.gatech.edu>
18  */
19 
20 // Implementation for ns3 Application base class.
21 // George F. Riley, Georgia Tech, Fall 2006
22 
23 #include "application.h"
24 
25 #include "node.h"
26 
27 #include "ns3/log.h"
28 #include "ns3/nstime.h"
29 #include "ns3/simulator.h"
30 
31 namespace ns3
32 {
33 
34 NS_LOG_COMPONENT_DEFINE("Application");
35 
36 NS_OBJECT_ENSURE_REGISTERED(Application);
37 
38 // Application Methods
39 
40 TypeId
42 {
43  static TypeId tid = TypeId("ns3::Application")
44  .SetParent<Object>()
45  .SetGroupName("Network")
46  .AddAttribute("StartTime",
47  "Time at which the application will start",
48  TimeValue(Seconds(0.0)),
51  .AddAttribute("StopTime",
52  "Time at which the application will stop",
53  TimeValue(TimeStep(0)),
55  MakeTimeChecker());
56  return tid;
57 }
58 
59 // \brief Application Constructor
61 {
62  NS_LOG_FUNCTION(this);
63 }
64 
65 // \brief Application Destructor
67 {
68  NS_LOG_FUNCTION(this);
69 }
70 
71 void
73 {
74  NS_LOG_FUNCTION(this << start);
76 }
77 
78 void
80 {
81  NS_LOG_FUNCTION(this << stop);
82  m_stopTime = stop;
83 }
84 
85 void
87 {
88  NS_LOG_FUNCTION(this);
89  m_node = nullptr;
93 }
94 
95 void
97 {
98  NS_LOG_FUNCTION(this);
100  if (m_stopTime != TimeStep(0))
101  {
103  }
105 }
106 
107 Ptr<Node>
109 {
110  NS_LOG_FUNCTION(this);
111  return m_node;
112 }
113 
114 void
116 {
117  NS_LOG_FUNCTION(this);
118  m_node = node;
119 }
120 
121 // Protected methods
122 // StartApp and StopApp will likely be overridden by application subclasses
123 void
125 { // Provide null functionality in case subclass is not interested
126  NS_LOG_FUNCTION(this);
127 }
128 
129 void
131 { // Provide null functionality in case subclass is not interested
132  NS_LOG_FUNCTION(this);
133 }
134 
135 } // namespace ns3
EventId m_startEvent
The event that will fire at m_startTime to start the application.
Definition: application.h:152
void DoInitialize() override
Initialize() implementation.
Definition: application.cc:96
void SetNode(Ptr< Node > node)
Definition: application.cc:115
void DoDispose() override
Destructor implementation.
Definition: application.cc:86
Time m_startTime
The simulation time that the application will start.
Definition: application.h:150
Time m_stopTime
The simulation time that the application will end.
Definition: application.h:151
~Application() override
Definition: application.cc:66
void SetStopTime(Time stop)
Specify application stop time.
Definition: application.cc:79
virtual void StopApplication()
Application specific shutdown code.
Definition: application.cc:130
virtual void StartApplication()
Application specific startup code.
Definition: application.cc:124
void SetStartTime(Time start)
Specify application start time.
Definition: application.cc:72
EventId m_stopEvent
The event that will fire at m_stopTime to end the application.
Definition: application.h:153
static TypeId GetTypeId()
Get the type ID.
Definition: application.cc:41
Ptr< Node > GetNode() const
Definition: application.cc:108
Ptr< Node > m_node
The node that this application is installed on.
Definition: application.h:149
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:55
A base class which provides memory management and object aggregation.
Definition: object.h:89
virtual void DoInitialize()
Initialize() implementation.
Definition: object.cc:359
virtual void DoDispose()
Destructor implementation.
Definition: object.cc:352
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition: nstime.h:1414
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:533