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
acoustic-modem-energy-model-helper.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2010 Andrea Sacco
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: Author: Andrea Sacco <andrea.sacco85@gmail.com>
19
*/
20
21
#include "
acoustic-modem-energy-model-helper.h
"
22
#include "ns3/basic-energy-source-helper.h"
23
#include "ns3/uan-phy.h"
24
#include "ns3/uan-net-device.h"
25
#include "ns3/config.h"
26
#include "ns3/names.h"
27
28
namespace
ns3 {
29
30
AcousticModemEnergyModelHelper::AcousticModemEnergyModelHelper
()
31
{
32
m_modemEnergy
.
SetTypeId
(
"ns3::AcousticModemEnergyModel"
);
33
m_depletionCallback
.
Nullify
();
34
}
35
36
AcousticModemEnergyModelHelper::~AcousticModemEnergyModelHelper
()
37
{
38
}
39
40
void
41
AcousticModemEnergyModelHelper::Set
(std::string name,
const
AttributeValue
&v)
42
{
43
m_modemEnergy
.
Set
(name, v);
44
}
45
46
void
47
AcousticModemEnergyModelHelper::SetDepletionCallback
(
48
AcousticModemEnergyModel::AcousticModemEnergyDepletionCallback
callback)
49
{
50
m_depletionCallback
= callback;
51
}
52
53
/*
54
* Private function starts here.
55
*/
56
57
Ptr<DeviceEnergyModel>
58
AcousticModemEnergyModelHelper::DoInstall
(
Ptr<NetDevice>
device,
59
Ptr<EnergySource>
source)
const
60
{
61
NS_ASSERT
(device != NULL);
62
NS_ASSERT
(source != NULL);
63
// check if device is UanNetDevice
64
std::string deviceName = device->
GetInstanceTypeId
().
GetName
();
65
if
(deviceName.compare (
"ns3::UanNetDevice"
) != 0)
66
{
67
NS_FATAL_ERROR
(
"NetDevice type is not UanNetDevice!"
);
68
}
69
Ptr<Node>
node = device->
GetNode
();
70
Ptr<AcousticModemEnergyModel>
model =
m_modemEnergy
.
Create
<
AcousticModemEnergyModel
> ();
71
NS_ASSERT
(model != NULL);
72
// set node pointer
73
model->SetNode (node);
74
// set energy source pointer
75
model->SetEnergySource (source);
76
// get phy layer
77
Ptr<UanNetDevice>
uanDevice = DynamicCast<UanNetDevice> (device);
78
Ptr<UanPhy>
uanPhy = uanDevice->
GetPhy
();
79
// set energy depletion callback
80
model->SetEnergyDepletionCallback (
m_depletionCallback
);
81
// add model to device model list in energy source
82
source->
AppendDeviceEnergyModel
(model);
83
// set node pointer
84
source->
SetNode
(node);
85
// create and install energy model callback
86
DeviceEnergyModel::ChangeStateCallback
cb;
87
cb =
MakeCallback
(&
DeviceEnergyModel::ChangeState
, model);
88
uanPhy->SetEnergyModelCallback (cb);
89
90
return
model;
91
}
92
93
}
// namespace ns3
src
uan
helper
acoustic-modem-energy-model-helper.cc
Generated on Tue Oct 9 2012 16:45:47 for ns-3 by
1.8.1.2