Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
Emulator.cpp
1 /*
2  * The MIT License (MIT)
3  *
4  * Copyright (c) 2016 The SKA organisation
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #include "cheetah/emulator/Emulator.h"
25 #include "cheetah/emulator/Config.h"
26 #include "panda/Log.h"
27 #include <cassert>
28 
29 
30 namespace ska {
31 namespace cheetah {
32 namespace emulator {
33 
34 
35 template<typename StreamType, typename T>
36 template<typename... StreamConstructorArgs>
37 Emulator<StreamType, T>::Emulator(Config const& config
38  , generators::TimeFrequencyGenerator<T>* model
39  , StreamConstructorArgs&&... args)
40  : _model(model)
41  , _stream(*_model, std::forward<StreamConstructorArgs>(args)...)
42  , _connection(new ConnectionType(config.engine()))
43  , _emulator_app(_stream, config.engine())
44  , _server(config.server_config(), _emulator_app)
45 {
46  assert(_model != nullptr);
47  _connection->set_remote_end_point(config.fixed_end_point());
48  _emulator_app.add_fixed_client(_connection);
49 }
50 
51 template<typename StreamType, typename T>
52 Emulator<StreamType, T>::~Emulator()
53 {
54  PANDA_LOG << "mean send rate: " << _connection->monitor().mean();
55  delete _model;
56 }
57 
58 template<typename StreamType, typename T>
59 int Emulator<StreamType, T>::run()
60 {
61  _connection->socket().set_option(boost::asio::ip::udp::socket::reuse_address(true));
62  return _server.run();
63 }
64 
65 template<typename StreamType, typename T>
66 void Emulator<StreamType, T>::stop()
67 {
68  _server.stop();
69 }
70 
71 template<typename StreamType, typename T>
72 bool Emulator<StreamType, T>::is_running() const
73 {
74  return _server.is_running();
75 }
76 
77 template<typename StreamType, typename T>
78 boost::asio::ip::udp::endpoint const Emulator<StreamType, T>::end_point() const
79 {
80  return _connection->remote_end_point();
81 }
82 
83 template<typename StreamType, typename T>
84 boost::asio::ip::udp::endpoint const Emulator<StreamType, T>::subscriber_end_point() const
85 {
86  return _server.end_point();
87 }
88 
89 template<typename StreamType, typename T>
91 {
92  return *_model;
93 }
94 
95 } // namespace emulator
96 } // namespace cheetah
97 } // namespace ska
boost::asio::ip::udp::endpoint const end_point() const
the port to where the udp data stream is being directed
Definition: Emulator.cpp:78
Emulator(Config const &, ModelType *model, StreamConstructorArgs &&...)
Construct an Emulator utilisiing the provided model.
Some limits and constants for FLDO.
Definition: Brdz.h:35
Emulate UDP stream using a data madel generator.
Definition: Emulator.h:49