A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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
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
void
48
EnergySource::SetNode
(
Ptr<Node>
node)
49
{
50
NS_ASSERT
(node != NULL);
51
m_node
= node;
52
}
53
54
Ptr<Node>
55
EnergySource::GetNode
(
void
)
const
56
{
57
return
m_node
;
58
}
59
60
void
61
EnergySource::AppendDeviceEnergyModel
(
Ptr<DeviceEnergyModel>
deviceEnergyModelPtr)
62
{
63
NS_LOG_FUNCTION
(
this
<< deviceEnergyModelPtr);
64
NS_ASSERT
(deviceEnergyModelPtr != NULL);
// model must exist
65
m_models
.
Add
(deviceEnergyModelPtr);
66
}
67
68
DeviceEnergyModelContainer
69
EnergySource::FindDeviceEnergyModels
(
TypeId
tid)
70
{
71
NS_LOG_FUNCTION
(
this
<< tid);
72
DeviceEnergyModelContainer
container;
73
DeviceEnergyModelContainer::Iterator
i;
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
84
DeviceEnergyModelContainer
85
EnergySource::FindDeviceEnergyModels
(std::string name)
86
{
87
NS_LOG_FUNCTION
(
this
<< name);
88
DeviceEnergyModelContainer
container;
89
DeviceEnergyModelContainer::Iterator
i;
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
101
EnergySource::StartDeviceModels
(
void
)
102
{
103
/*
104
* Device models are not aggregated to the node, hence we have to manually
105
* call dispose method here.
106
*/
107
DeviceEnergyModelContainer::Iterator
i;
108
for
(i =
m_models
.
Begin
(); i !=
m_models
.
End
(); i++)
109
{
110
(*i)->Start ();
111
}
112
}
113
114
void
115
EnergySource::DisposeDeviceModels
(
void
)
116
{
117
/*
118
* Device models are not aggregated to the node, hence we have to manually
119
* call dispose method here.
120
*/
121
DeviceEnergyModelContainer::Iterator
i;
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
133
EnergySource::DoDispose
(
void
)
134
{
135
NS_LOG_FUNCTION
(
this
);
136
BreakDeviceEnergyModelRefCycle
();
137
}
138
139
/*
140
* Protected functions start here.
141
*/
142
143
double
144
EnergySource::CalculateTotalCurrent
(
void
)
145
{
146
NS_LOG_FUNCTION
(
this
);
147
double
totalCurrentA = 0.0;
148
DeviceEnergyModelContainer::Iterator
i;
149
for
(i =
m_models
.
Begin
(); i !=
m_models
.
End
(); i++)
150
{
151
totalCurrentA += (*i)->GetCurrentA ();
152
}
153
return
totalCurrentA;
154
}
155
156
void
157
EnergySource::NotifyEnergyDrained
(
void
)
158
{
159
NS_LOG_FUNCTION
(
this
);
160
// notify all device energy models installed on node
161
DeviceEnergyModelContainer::Iterator
i;
162
for
(i =
m_models
.
Begin
(); i !=
m_models
.
End
(); i++)
163
{
164
(*i)->HandleEnergyDepletion ();
165
}
166
}
167
168
void
169
EnergySource::BreakDeviceEnergyModelRefCycle
(
void
)
170
{
171
NS_LOG_FUNCTION
(
this
);
172
m_models
.
Clear
();
173
m_node
= NULL;
174
}
175
176
}
// namespace ns3
src
energy
model
energy-source.cc
Generated on Tue Oct 9 2012 16:45:37 for ns-3 by
1.8.1.2