A Discrete-Event Network Simulator
API
lr-wpan-interference-helper.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Fraunhofer FKIE
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author:
18  * Sascha Alexander Jopen <jopen@cs.uni-bonn.de>
19  */
21 
22 #include <ns3/log.h>
23 #include <ns3/spectrum-model.h>
24 #include <ns3/spectrum-value.h>
25 
26 namespace ns3
27 {
28 
29 NS_LOG_COMPONENT_DEFINE("LrWpanInterferenceHelper");
30 
32  : m_spectrumModel(spectrumModel),
33  m_dirty(false)
34 {
35  m_signal = Create<SpectrumValue>(m_spectrumModel);
36 }
37 
39 {
40  m_spectrumModel = nullptr;
41  m_signal = nullptr;
42  m_signals.clear();
43 }
44 
45 bool
47 {
48  NS_LOG_FUNCTION(this << signal);
49 
50  bool result = false;
51 
52  if (signal->GetSpectrumModel() == m_spectrumModel)
53  {
54  result = m_signals.insert(signal).second;
55  if (result && !m_dirty)
56  {
57  *m_signal += *signal;
58  }
59  }
60  return result;
61 }
62 
63 bool
65 {
66  NS_LOG_FUNCTION(this << signal);
67 
68  bool result = false;
69 
70  if (signal->GetSpectrumModel() == m_spectrumModel)
71  {
72  result = (m_signals.erase(signal) == 1);
73  if (result)
74  {
75  m_dirty = true;
76  }
77  }
78  return result;
79 }
80 
81 void
83 {
84  NS_LOG_FUNCTION(this);
85 
86  m_signals.clear();
87  m_dirty = true;
88 }
89 
92 {
93  NS_LOG_FUNCTION(this);
94 
95  if (m_dirty)
96  {
97  // Sum up the current interference PSD.
98  m_signal = Create<SpectrumValue>(m_spectrumModel);
99  for (auto 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 } // namespace ns3
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< SpectrumValue > GetSignalPsd() const
Get the sum of all accumulated signals.
void ClearSignals()
Remove all currently accumulated signals.
Ptr< const SpectrumModel > m_spectrumModel
The helpers SpectrumModel.
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:202
#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.