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 
31 TypeId
33 {
34  static TypeId tid = TypeId ("ns3::EnergySource")
35  .SetParent<Object> ()
36  ;
37  return tid;
38 }
39 
41 {
42  NS_LOG_FUNCTION (this);
43 }
44 
46 {
47  NS_LOG_FUNCTION (this);
48 }
49 
50 void
52 {
53  NS_LOG_FUNCTION (this);
54  NS_ASSERT (node != NULL);
55  m_node = node;
56 }
57 
60 {
61  NS_LOG_FUNCTION (this);
62  return m_node;
63 }
64 
65 void
67 {
68  NS_LOG_FUNCTION (this << deviceEnergyModelPtr);
69  NS_ASSERT (deviceEnergyModelPtr != NULL); // model must exist
70  m_models.Add (deviceEnergyModelPtr);
71 }
72 
75 {
76  NS_LOG_FUNCTION (this << tid);
79  for (i = m_models.Begin (); i != m_models.End (); i++)
80  {
81  if ((*i)->GetInstanceTypeId () == tid)
82  {
83  container.Add (*i);
84  }
85  }
86  return container;
87 }
88 
91 {
92  NS_LOG_FUNCTION (this << name);
95  for (i = m_models.Begin (); i != m_models.End (); i++)
96  {
97  if ((*i)->GetInstanceTypeId ().GetName ().compare (name) == 0)
98  {
99  container.Add (*i);
100  }
101  }
102  return container;
103 }
104 
105 void
107 {
108  NS_LOG_FUNCTION (this);
109  /*
110  * Device models are not aggregated to the node, hence we have to manually
111  * call dispose method here.
112  */
114  for (i = m_models.Begin (); i != m_models.End (); i++)
115  {
116  (*i)->Initialize ();
117  }
118 }
119 
120 void
122 {
123  NS_LOG_FUNCTION (this);
124  /*
125  * Device models are not aggregated to the node, hence we have to manually
126  * call dispose method here.
127  */
129  for (i = m_models.Begin (); i != m_models.End (); i++)
130  {
131  (*i)->Dispose ();
132  }
133 }
134 
135 /*
136  * Private function starts here.
137  */
138 
139 void
141 {
142  NS_LOG_FUNCTION (this);
144 }
145 
146 /*
147  * Protected functions start here.
148  */
149 
150 double
152 {
153  NS_LOG_FUNCTION (this);
154  double totalCurrentA = 0.0;
156  for (i = m_models.Begin (); i != m_models.End (); i++)
157  {
158  totalCurrentA += (*i)->GetCurrentA ();
159  }
160  return totalCurrentA;
161 }
162 
163 void
165 {
166  NS_LOG_FUNCTION (this);
167  // notify all device energy models installed on node
169  for (i = m_models.Begin (); i != m_models.End (); i++)
170  {
171  (*i)->HandleEnergyDepletion ();
172  }
173 }
174 
175 void
177 {
178  NS_LOG_FUNCTION (this);
179  m_models.Clear ();
180  m_node = NULL;
181 }
182 
183 } // namespace ns3
std::vector< Ptr< DeviceEnergyModel > >::const_iterator Iterator
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
Ptr< Node > GetNode(void) const
#define NS_ASSERT(condition)
Definition: assert.h:64
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
NS_LOG_COMPONENT_DEFINE("EnergySource")
void Add(DeviceEnergyModelContainer container)
Holds a vector of ns3::DeviceEnergyModel pointers.
void BreakDeviceEnergyModelRefCycle(void)
This function is called to break reference cycle between EnergySource and DeviceEnergyModel.
virtual void DoDispose(void)
All child's implementation must call BreakDeviceEnergyModelRefCycle to ensure reference cycles to Dev...
static TypeId GetTypeId(void)
double CalculateTotalCurrent(void)
Iterator Begin(void) const
Get an iterator which refers to the first DeviceEnergyModel pointer in the container.
void InitializeDeviceModels(void)
Calls Start () method of the device energy models.
void AppendDeviceEnergyModel(Ptr< DeviceEnergyModel > deviceEnergyModelPtr)
virtual ~EnergySource()
Ptr< Node > m_node
Pointer to node containing this EnergySource.
void NotifyEnergyDrained(void)
This function notifies all DeviceEnergyModel of energy depletion event.
Iterator End(void) const
Get an iterator which refers to the last DeviceEnergyModel pointer in the container.
DeviceEnergyModelContainer m_models
List of device energy models installed on the same node.
void DisposeDeviceModels(void)
Calls Dispose () method of the device energy models.
DeviceEnergyModelContainer FindDeviceEnergyModels(TypeId tid)
a base class which provides memory management and object aggregation
Definition: object.h:63
void SetNode(Ptr< Node > node)
Sets pointer to node containing this EnergySource.
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
void Clear(void)
Removes all elements in the container.