A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
energy-source.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
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: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
19  */
20 
21 #include "energy-source.h"
22 #include "ns3/log.h"
23 
24 NS_LOG_COMPONENT_DEFINE ("EnergySource");
25 
26 namespace ns3 {
27 
28 NS_OBJECT_ENSURE_REGISTERED (EnergySource);
29 
30 TypeId
32 {
33  static TypeId tid = TypeId ("ns3::EnergySource")
34  .SetParent<Object> ()
35  ;
36  return tid;
37 }
38 
40 {
41 }
42 
44 {
45 }
46 
47 void
49 {
50  NS_ASSERT (node != NULL);
51  m_node = node;
52 }
53 
56 {
57  return m_node;
58 }
59 
60 void
62 {
63  NS_LOG_FUNCTION (this << deviceEnergyModelPtr);
64  NS_ASSERT (deviceEnergyModelPtr != NULL); // model must exist
65  m_models.Add (deviceEnergyModelPtr);
66 }
67 
70 {
71  NS_LOG_FUNCTION (this << tid);
74  for (i = m_models.Begin (); i != m_models.End (); i++)
75  {
76  if ((*i)->GetInstanceTypeId () == tid)
77  {
78  container.Add (*i);
79  }
80  }
81  return container;
82 }
83 
86 {
87  NS_LOG_FUNCTION (this << name);
90  for (i = m_models.Begin (); i != m_models.End (); i++)
91  {
92  if ((*i)->GetInstanceTypeId ().GetName ().compare (name) == 0)
93  {
94  container.Add (*i);
95  }
96  }
97  return container;
98 }
99 
100 void
102 {
103  /*
104  * Device models are not aggregated to the node, hence we have to manually
105  * call dispose method here.
106  */
108  for (i = m_models.Begin (); i != m_models.End (); i++)
109  {
110  (*i)->Start ();
111  }
112 }
113 
114 void
116 {
117  /*
118  * Device models are not aggregated to the node, hence we have to manually
119  * call dispose method here.
120  */
122  for (i = m_models.Begin (); i != m_models.End (); i++)
123  {
124  (*i)->Dispose ();
125  }
126 }
127 
128 /*
129  * Private function starts here.
130  */
131 
132 void
134 {
135  NS_LOG_FUNCTION (this);
137 }
138 
139 /*
140  * Protected functions start here.
141  */
142 
143 double
145 {
146  NS_LOG_FUNCTION (this);
147  double totalCurrentA = 0.0;
149  for (i = m_models.Begin (); i != m_models.End (); i++)
150  {
151  totalCurrentA += (*i)->GetCurrentA ();
152  }
153  return totalCurrentA;
154 }
155 
156 void
158 {
159  NS_LOG_FUNCTION (this);
160  // notify all device energy models installed on node
162  for (i = m_models.Begin (); i != m_models.End (); i++)
163  {
164  (*i)->HandleEnergyDepletion ();
165  }
166 }
167 
168 void
170 {
171  NS_LOG_FUNCTION (this);
172  m_models.Clear ();
173  m_node = NULL;
174 }
175 
176 } // namespace ns3