EmulatedWirelessInterface.cci
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
14 /** \file
15  \brief EmulatedWirelessInterface inline non-template implementation */
16 
17 // Custom includes
18 
19 #define prefix_ inline
20 //-/////////////////////////////////////////////////////////////////////////////////////////////////
21 
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
23 // senf::emu::detail::EmulatedWirelessInterfaceTransmitFilter
24 
25 prefix_
26 senf::emu::detail::EmulatedWirelessInterfaceTransmitFilter::
27 EmulatedWirelessInterfaceTransmitFilter(EmulatedWirelessTransmitter & iface)
28  : iface_ (iface)
29 {
30  route(input,output);
31  input.onRequest(&EmulatedWirelessInterfaceTransmitFilter::request);
32 }
33 
34 //-/////////////////////////////////////////////////////////////////////////////////////////////////
35 // senf::emu::detail::EmulatedWirelessInterfaceReceiveFilter
36 
37 prefix_
38 senf::emu::detail::EmulatedWirelessInterfaceReceiveFilter::
39 EmulatedWirelessInterfaceReceiveFilter(EmulatedWirelessReceiver & iface)
40  : iface_ (iface)
41 {
42  route(input,output);
43  input.onRequest(&EmulatedWirelessInterfaceReceiveFilter::request);
44 }
45 
46 //-/////////////////////////////////////////////////////////////////////////////////////////////////
47 // senf::emu::EmulatedFrequencyRegistry::Entry
48 
49 prefix_ senf::emu::EmulatedFrequencyRegistry::Entry::Entry()
50  : frequency (), bandwidth (), address (), nUsers (), ownerNodeId ()
51 {}
52 
53 prefix_ senf::emu::EmulatedFrequencyRegistry::Entry::Entry(unsigned frequency_,
54  unsigned bandwidth_)
55  : frequency (frequency_), bandwidth (bandwidth_), address (), nUsers (), ownerNodeId ()
56 {}
57 
58 prefix_ senf::emu::EmulatedFrequencyRegistry::Entry::Entry(unsigned frequency_,
59  unsigned bandwidth_,
60  UDPClientHandle::Address address_,
61  unsigned nUsers_,
62  unsigned ownerNodeId_)
63  : frequency (frequency_), bandwidth (bandwidth_), address (address_), nUsers (nUsers_),
64  ownerNodeId (ownerNodeId_)
65 {}
66 
67 //-/////////////////////////////////////////////////////////////////////////////////////////////////
68 // senf::emu::EmulatedFrequencyRegistry::User
69 
70 prefix_ senf::emu::EmulatedFrequencyRegistry::User::User()
71  : entry(), interfaceId(), callback()
72 {}
73 
74 prefix_ senf::emu::EmulatedFrequencyRegistry::User::
75 User(Entries::index_iterator<ByFrequency>::type entry_, unsigned interfaceId_, UserCallback callback_)
76  : entry(entry_), interfaceId(interfaceId_), callback(callback_)
77 {}
78 
79 //-/////////////////////////////////////////////////////////////////////////////////////////////////
80 // senf::emu::EmulatedFrequencyRegistry::AddrCompare
81 
82 prefix_ bool senf::emu::EmulatedFrequencyRegistry::AddrCompare::
83 operator()(Entries::index_iterator<ByFrequency>::type a,
84  Entries::index_iterator<ByFrequency>::type b)
85  const
86 {
87  return &*a < &*b;
88 }
89 
90 prefix_ bool senf::emu::EmulatedFrequencyRegistry::AddrCompare::
91 operator()(Entries::index_iterator<ByFrequency>::type a, Entry const * b)
92  const
93 {
94  return &*a < b;
95 }
96 
97 prefix_ bool senf::emu::EmulatedFrequencyRegistry::AddrCompare::
98 operator()(Entry const * a, Entries::index_iterator<ByFrequency>::type b)
99  const
100 {
101  return a < &*b;
102 }
103 
104 //-/////////////////////////////////////////////////////////////////////////////////////////////////
105 // senf::emu::EmulatedFrequencyRegistry
106 
107 prefix_ senf::emu::UDPClientHandle::Address senf::emu::EmulatedFrequencyRegistry::consoleGroup()
108  const
109 {
110  return group_;
111 }
112 
113 prefix_ void
114 senf::emu::EmulatedFrequencyRegistry::consoleGroup(UDPClientHandle::Address const & group)
115 {
116  group_ = group;
117  /// FIXME: How to change the group address after entering the scheduler ??
118  /// (need to change the address of a running socket)
119 }
120 
121 prefix_ std::pair<senf::INet4Network, unsigned> senf::emu::EmulatedFrequencyRegistry::addressRange()
122  const
123 {
124  return std::make_pair(channelGroupRange_, portbase_);
125 }
126 
127 prefix_ void senf::emu::EmulatedFrequencyRegistry::addressRange(INet4Network const & range,
128  unsigned portbase)
129 {
130  channelGroupRange_ = range;
131  portbase_ = portbase;
132 }
133 
134 prefix_ void senf::emu::EmulatedFrequencyRegistry::nextAddress(unsigned index)
135 {
136  lastAddress_ = index-1;
137 }
138 
139 prefix_ void senf::emu::EmulatedFrequencyRegistry::collisionCallback(CollisionCallback cb)
140 {
141  cb_ = cb;
142 }
143 
144 prefix_ senf::emu::EmulatedFrequencyRegistry::EntriesRange
145 senf::emu::EmulatedFrequencyRegistry::entries()
146  const
147 {
148  return boost::make_iterator_range(
149  entries_.get<ByFrequency>().begin(), entries_.get<ByFrequency>().end());
150 }
151 
152 prefix_ senf::emu::EmulatedFrequencyRegistry::UsersRange
153 senf::emu::EmulatedFrequencyRegistry::users(EntriesRange::iterator i)
154  const
155 {
156  return senf::make_transform_range(users_.get<ByEntry>().equal_range(i), GetInterfaceId());
157 }
158 
159 //-/////////////////////////////////////////////////////////////////////////////////////////////////
160 // senf::emu::EmulatedWirelessInterface
161 
162 prefix_ void senf::emu::EmulatedWirelessInterface::registerFrequency(unsigned frequency,
163  unsigned bandwidth)
164 {
165  interface().registerFrequency(frequency, bandwidth);
166 }
167 
168 prefix_ void senf::emu::EmulatedWirelessInterface::registerFrequency(unsigned frequencyLower,
169  unsigned frequencyUpper,
170  unsigned bandwidthLower,
171  unsigned bandwidthUpper)
172 {
173  interface().registerFrequency(frequencyLower, frequencyUpper, bandwidthLower, bandwidthUpper);
174 }
175 
176 prefix_ senf::emu::EmulatedWirelessInterface::EmulatedWirelessInterface()
177  : frequency_ (0u), bandwidth_ (0u), index_ (0u), distanceCallback_()
178 {}
179 
180 prefix_ unsigned senf::emu::EmulatedWirelessInterface::emulatedFrequency()
181  const
182 {
183  return frequency_;
184 }
185 
186 prefix_ unsigned senf::emu::EmulatedWirelessInterface::emulatedBandwidth()
187  const
188 {
189  return bandwidth_;
190 }
191 
192 prefix_ void senf::emu::EmulatedWirelessInterface::distanceCallback(DistanceCallback cb)
193 {
194  distanceCallback_ = cb;
195 }
196 //-/////////////////////////////////////////////////////////////////////////////////////////////////
197 // senf::emu::EmulatedWirelessReceiver
198 
199 prefix_ senf::emu::EmulatedWirelessReceiver::EmulatedWirelessReceiver()
200  : receiverJack(filter_.output), filter_ (*this),
201  rssiRandomnessRange_(0), noiseRandomnessRange_(0)
202 {
203  ppi::connect(EmulatedReceiver::receiverJack, filter_);
204 }
205 //-/////////////////////////////////////////////////////////////////////////////////////////////////
206 // senf::emu::EmulatedWirelessTransmitter
207 
208 prefix_ void senf::emu::EmulatedWirelessTransmitter::registerTxPower(int power)
209 {
210  basei::interface().transmitter().registerTxPower(power);
211 }
212 
213 prefix_ void senf::emu::EmulatedWirelessTransmitter::registerTxPower(int powerLow,
214  int powerHigh)
215 {
216  basei::interface().transmitter().registerTxPower(powerLow, powerHigh);
217 }
218 
219 prefix_ senf::emu::EmulatedWirelessTransmitter::EmulatedWirelessTransmitter()
220  : transmitterJack(filter_.input), filter_ (*this)
221 {
222  ppi::connect(filter_, EmulatedTransmitter::transmitterJack);
223 }
224 
225 //-/////////////////////////////////////////////////////////////////////////////////////////////////
226 
227 prefix_ senf::emu::EmulatedFrequencyRegistry & senf::emu::emulatedFrequencyRegistry()
228 {
229  return EmulatedFrequencyRegistry::instance();
230 }
231 
232 //-/////////////////////////////////////////////////////////////////////////////////////////////////
233 #undef prefix_
234 
235 
236 // Local Variables:
237 // mode: c++
238 // fill-column: 100
239 // comment-column: 40
240 // c-file-style: "senf"
241 // indent-tabs-mode: nil
242 // ispell-local-dictionary: "american"
243 // compile-command: "scons -u test"
244 // End: