A Discrete-Event Network Simulator
API
lr-wpan-interference-helper.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 Fraunhofer FKIE
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:
19  * Sascha Alexander Jopen <jopen@cs.uni-bonn.de>
20  */
22 #include <ns3/spectrum-value.h>
23 #include <ns3/spectrum-model.h>
24 #include <ns3/log.h>
25 
26 namespace ns3 {
27 
28 NS_LOG_COMPONENT_DEFINE ("LrWpanInterferenceHelper");
29 
31  : m_spectrumModel (spectrumModel),
32  m_dirty (false)
33 {
34  m_signal = Create<SpectrumValue> (m_spectrumModel);
35 }
36 
38 {
39  m_spectrumModel = 0;
40  m_signal = 0;
41  m_signals.clear ();
42 }
43 
44 bool
46 {
47  NS_LOG_FUNCTION (this << signal);
48 
49  bool result = false;
50 
51  if (signal->GetSpectrumModel () == m_spectrumModel)
52  {
53  result = m_signals.insert (signal).second;
54  if (result && !m_dirty)
55  {
56  *m_signal += *signal;
57  }
58  }
59  return result;
60 }
61 
62 bool
64 {
65  NS_LOG_FUNCTION (this << signal);
66 
67  bool result = false;
68 
69  if (signal->GetSpectrumModel () == m_spectrumModel)
70  {
71  result = (m_signals.erase (signal) == 1);
72  if (result)
73  {
74  m_dirty = true;
75  }
76  }
77  return result;
78 }
79 
80 void
82 {
83  NS_LOG_FUNCTION (this);
84 
85  m_signals.clear ();
86  m_dirty = true;
87 }
88 
91 {
92  NS_LOG_FUNCTION (this);
93 
94  if (m_dirty)
95  {
96  // Sum up the current interference PSD.
97  std::set<Ptr<const SpectrumValue> >::const_iterator it;
98  m_signal = Create<SpectrumValue> (m_spectrumModel);
99  for (it = m_signals.begin (); it != m_signals.end (); ++it)
100  {
101  *m_signal += *(*it);
102  }
103  m_dirty = false;
104  }
105 
106  return m_signal->Copy ();
107 }
108 
109 }
bool RemoveSignal(Ptr< const SpectrumValue > signal)
Remove the given signal to the set of accumulated signals.
std::set< Ptr< const SpectrumValue > > m_signals
The set of accumulated signals.
Ptr< const SpectrumModel > m_spectrumModel
The helpers SpectrumModel.
Ptr< SpectrumValue > GetSignalPsd(void) const
Get the sum of all accumulated signals.
void ClearSignals(void)
Remove all currently accumulated signals.
bool m_dirty
Mark m_signal as dirty, whenever a signal is added or removed.
LrWpanInterferenceHelper(Ptr< const SpectrumModel > spectrumModel)
Create a new interference helper for the given SpectrumModel.
Ptr< SpectrumValue > m_signal
The precomputed sum of all accumulated signals.
bool AddSignal(Ptr< const SpectrumValue > signal)
Add the given signal to the set of accumulated signals.
Ptr< SpectrumValue > Copy() const
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.