1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  *
18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #include "ns3/names.h"
22 #include "ns3/log.h"
23 #include "application-container.h"
24 
25 namespace ns3 {
26 
27 NS_LOG_COMPONENT_DEFINE ("ApplicationContainer");
28 
ApplicationContainer()29 ApplicationContainer::ApplicationContainer ()
30 {
31 }
32 
ApplicationContainer(Ptr<Application> app)33 ApplicationContainer::ApplicationContainer (Ptr<Application> app)
34 {
35   m_applications.push_back (app);
36 }
37 
ApplicationContainer(std::string name)38 ApplicationContainer::ApplicationContainer (std::string name)
39 {
40   Ptr<Application> app = Names::Find<Application> (name);
41   m_applications.push_back (app);
42 }
43 
44 
45 ApplicationContainer::Iterator
Begin(void) const46 ApplicationContainer::Begin (void) const
47 {
48   return m_applications.begin ();
49 }
50 ApplicationContainer::Iterator
End(void) const51 ApplicationContainer::End (void) const
52 {
53   return m_applications.end ();
54 }
55 
56 uint32_t
GetN(void) const57 ApplicationContainer::GetN (void) const
58 {
59   return m_applications.size ();
60 }
61 Ptr<Application>
Get(uint32_t i) const62 ApplicationContainer::Get (uint32_t i) const
63 {
64   return m_applications[i];
65 }
66 void
Add(ApplicationContainer other)67 ApplicationContainer::Add (ApplicationContainer other)
68 {
69   for (Iterator i = other.Begin (); i != other.End (); i++)
70     {
71       m_applications.push_back (*i);
72     }
73 }
74 void
Add(Ptr<Application> application)75 ApplicationContainer::Add (Ptr<Application> application)
76 {
77   m_applications.push_back (application);
78 }
79 void
Add(std::string name)80 ApplicationContainer::Add (std::string name)
81 {
82   Ptr<Application> application = Names::Find<Application> (name);
83   m_applications.push_back (application);
84 }
85 
86 void
Start(Time start)87 ApplicationContainer::Start (Time start)
88 {
89   for (Iterator i = Begin (); i != End (); ++i)
90     {
91       Ptr<Application> app = *i;
92       app->SetStartTime (start);
93     }
94 }
95 void
StartWithJitter(Time start,Ptr<RandomVariableStream> rv)96 ApplicationContainer::StartWithJitter (Time start, Ptr<RandomVariableStream> rv)
97 {
98   for (Iterator i = Begin (); i != End (); ++i)
99     {
100       Ptr<Application> app = *i;
101       double value = rv->GetValue ();
102       NS_LOG_DEBUG ("Start application at time " << start.GetSeconds () + value << "s");
103       app->SetStartTime (start + Seconds (value));
104     }
105 }
106 void
Stop(Time stop)107 ApplicationContainer::Stop (Time stop)
108 {
109   for (Iterator i = Begin (); i != End (); ++i)
110     {
111       Ptr<Application> app = *i;
112       app->SetStopTime (stop);
113     }
114 }
115 
116 
117 } // namespace ns3
118