A Discrete-Event Network Simulator
API
application-container.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18  */
19 
20 #include "application-container.h"
21 
22 #include "ns3/log.h"
23 #include "ns3/names.h"
24 
25 namespace ns3
26 {
27 
28 NS_LOG_COMPONENT_DEFINE("ApplicationContainer");
29 
31 {
32 }
33 
35 {
36  m_applications.push_back(app);
37 }
38 
40 {
41  Ptr<Application> app = Names::Find<Application>(name);
42  m_applications.push_back(app);
43 }
44 
47 {
48  return m_applications.begin();
49 }
50 
53 {
54  return m_applications.end();
55 }
56 
57 uint32_t
59 {
60  return m_applications.size();
61 }
62 
64 ApplicationContainer::Get(uint32_t i) const
65 {
66  return m_applications[i];
67 }
68 
69 void
71 {
72  for (auto i = other.Begin(); i != other.End(); i++)
73  {
74  m_applications.push_back(*i);
75  }
76 }
77 
78 void
80 {
81  m_applications.push_back(application);
82 }
83 
84 void
85 ApplicationContainer::Add(std::string name)
86 {
87  Ptr<Application> application = Names::Find<Application>(name);
88  m_applications.push_back(application);
89 }
90 
91 void
93 {
94  for (auto i = Begin(); i != End(); ++i)
95  {
96  Ptr<Application> app = *i;
97  app->SetStartTime(start);
98  }
99 }
100 
101 void
103 {
104  for (auto i = Begin(); i != End(); ++i)
105  {
106  Ptr<Application> app = *i;
107  double value = rv->GetValue();
108  NS_LOG_DEBUG("Start application at time " << start.GetSeconds() + value << "s");
109  app->SetStartTime(start + Seconds(value));
110  }
111 }
112 
113 void
115 {
116  for (auto i = Begin(); i != End(); ++i)
117  {
118  Ptr<Application> app = *i;
119  app->SetStopTime(stop);
120  }
121 }
122 
123 } // namespace ns3
holds a vector of ns3::Application pointers.
std::vector< Ptr< Application > > m_applications
Applications smart pointers.
Iterator Begin() const
Get an iterator which refers to the first Application in the container.
Iterator End() const
Get an iterator which indicates past-the-last Application in the container.
void Start(Time start) const
Start all of the Applications in this container at the start time given as a parameter.
void StartWithJitter(Time start, Ptr< RandomVariableStream > rv) const
Start all of the Applications in this container at the start time given as a parameter,...
std::vector< Ptr< Application > >::const_iterator Iterator
Application container iterator.
ApplicationContainer()
Create an empty ApplicationContainer.
Ptr< Application > Get(uint32_t i) const
Get the Ptr<Application> stored in this container at a given index.
void Stop(Time stop) const
Arrange for all of the Applications in this container to Stop() at the Time given as a parameter.
uint32_t GetN() const
Get the number of Ptr<Application> stored in this container.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
virtual double GetValue()=0
Get the next random value drawn from the distribution.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
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.