6429
|
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
|
|
31 |
EnergySource::GetTypeId (void)
|
|
32 |
{
|
|
33 |
static TypeId tid = TypeId ("ns3::EnergySource")
|
|
34 |
.SetParent<Object> ()
|
|
35 |
;
|
|
36 |
return tid;
|
|
37 |
}
|
|
38 |
|
|
39 |
EnergySource::EnergySource ()
|
|
40 |
{
|
|
41 |
}
|
|
42 |
|
|
43 |
EnergySource::~EnergySource ()
|
|
44 |
{
|
|
45 |
}
|
|
46 |
|
|
47 |
double
|
|
48 |
EnergySource::GetInitialEnergy (void) const
|
|
49 |
{
|
|
50 |
return DoGetInitialEnergy ();
|
|
51 |
}
|
|
52 |
|
|
53 |
double
|
|
54 |
EnergySource::GetRemainingEnergy (void) const
|
|
55 |
{
|
|
56 |
return DoGetRemainingEnergy ();
|
|
57 |
}
|
|
58 |
|
|
59 |
void
|
|
60 |
EnergySource::DecreaseRemainingEnergy (double energyJ)
|
|
61 |
{
|
|
62 |
DoDecreaseRemainingEnergy (energyJ);
|
|
63 |
}
|
|
64 |
|
|
65 |
void
|
|
66 |
EnergySource::IncreaseRemainingEnergy (double energyJ)
|
|
67 |
{
|
|
68 |
DoIncreaseRemainingEnergy (energyJ);
|
|
69 |
}
|
|
70 |
|
|
71 |
double
|
|
72 |
EnergySource::GetEnergyFraction (void) const
|
|
73 |
{
|
|
74 |
return DoGetEnergyFraction ();
|
|
75 |
}
|
|
76 |
|
|
77 |
void
|
|
78 |
EnergySource::AppendDeviceEnergyModel (
|
|
79 |
Ptr<DeviceEnergyModel> deviceEnergyModelPtr)
|
|
80 |
{
|
|
81 |
NS_LOG_FUNCTION (this << deviceEnergyModelPtr);
|
|
82 |
NS_ASSERT (deviceEnergyModelPtr != NULL); // model must exist
|
|
83 |
m_deviceEnergyModelList.push_back (deviceEnergyModelPtr);
|
|
84 |
}
|
|
85 |
|
|
86 |
EnergySource::DeviceEnergyModelList
|
|
87 |
EnergySource::FindDeviceEnergyModels (TypeId tid)
|
|
88 |
{
|
|
89 |
NS_LOG_FUNCTION (this << tid);
|
|
90 |
DeviceEnergyModelList list;
|
|
91 |
DeviceEnergyModelList::iterator listItr;
|
|
92 |
for (listItr = m_deviceEnergyModelList.begin ();
|
|
93 |
listItr != m_deviceEnergyModelList.end (); listItr++)
|
|
94 |
{
|
|
95 |
if ((*listItr)->GetInstanceTypeId () == tid)
|
|
96 |
{
|
|
97 |
list.push_back (*listItr);
|
|
98 |
}
|
|
99 |
}
|
|
100 |
return list;
|
|
101 |
}
|
|
102 |
|
|
103 |
EnergySource::DeviceEnergyModelList
|
|
104 |
EnergySource::FindDeviceEnergyModels (std::string name)
|
|
105 |
{
|
|
106 |
NS_LOG_FUNCTION (this << name);
|
|
107 |
DeviceEnergyModelList list;
|
|
108 |
DeviceEnergyModelList::iterator listItr;
|
|
109 |
for (listItr = m_deviceEnergyModelList.begin ();
|
|
110 |
listItr != m_deviceEnergyModelList.end (); listItr++)
|
|
111 |
{
|
|
112 |
if ((*listItr)->GetInstanceTypeId ().GetName ().compare (name) == 0)
|
|
113 |
{
|
|
114 |
list.push_back (*listItr);
|
|
115 |
}
|
|
116 |
}
|
|
117 |
return list;
|
|
118 |
}
|
|
119 |
|
|
120 |
/*
|
|
121 |
* Private function starts here.
|
|
122 |
*/
|
|
123 |
|
|
124 |
void
|
|
125 |
EnergySource::DoDispose (void)
|
|
126 |
{
|
|
127 |
NS_LOG_FUNCTION (this);
|
|
128 |
m_deviceEnergyModelList.clear (); // break reference cycle
|
|
129 |
}
|
|
130 |
|
|
131 |
/*
|
|
132 |
* Protected functions start here.
|
|
133 |
*/
|
|
134 |
|
|
135 |
void
|
|
136 |
EnergySource::NotifyEnergyDrained (void)
|
|
137 |
{
|
|
138 |
NS_LOG_FUNCTION (this);
|
|
139 |
// notify all device energy models installed on node
|
|
140 |
DeviceEnergyModelList::iterator listItr;
|
|
141 |
for (listItr = m_deviceEnergyModelList.begin ();
|
|
142 |
listItr != m_deviceEnergyModelList.end (); listItr++)
|
|
143 |
{
|
|
144 |
NS_LOG_DEBUG ("BasicEnergySource:Notifying device energy model: "
|
|
145 |
<< (*listItr)->GetInstanceTypeId ());
|
|
146 |
(*listItr)->HandleEnergyDepletion ();
|
|
147 |
}
|
|
148 |
}
|
|
149 |
|
|
150 |
void
|
|
151 |
EnergySource::BreakDeviceEnergyModelRefCycle (void)
|
|
152 |
{
|
|
153 |
NS_LOG_FUNCTION (this);
|
|
154 |
m_deviceEnergyModelList.clear (); // break reference cycle
|
|
155 |
}
|
|
156 |
|
|
157 |
} // namespace ns3
|