Skip to content
Snippets Groups Projects
Commit 236f7bff authored by Philipp Spilger's avatar Philipp Spilger
Browse files

Add default constructor to SimConnection with enviroment port extraction

* remove mandatory command-line options of simtests

Change-Id: I4de943a230e3636b1fdee7fb56c78e314e20250f
parent e3754797
No related branches found
No related tags found
No related merge requests found
......@@ -30,6 +30,18 @@ public:
*/
SimulatorClient(ip_t ip, port_t port);
/**
* Create and start connection to simulation server.
* Automatically extract RCF port from environment, the simulation server is expected to run on
* the same host.
*/
SimulatorClient();
/**
* Copy constructor.
*/
SimulatorClient(SimulatorClient const& other);
/**
* Close connection to simulator.
*/
......
......@@ -56,6 +56,13 @@ public:
*/
SimConnection(ip_t ip, port_t port);
/**
* Create and start connection to simulation server.
* The RCF port is automatically extracted from the enviroment, the simulation server is
* expected to run on the same host.
*/
SimConnection();
/**
* Copy constructor (deleted because no two instances with the same simulator allocation can
* coexist).
......@@ -177,7 +184,7 @@ private:
constexpr static size_t receive_buffer_size = 100000;
DoubleBuffer<Packet<subpacket_type, receive_buffer_size>> m_receive_buffer;
void work_fill_receive_buffer(ip_t ip, port_t port);
void work_fill_receive_buffer();
std::thread m_worker_fill_receive_buffer;
void work_decode_messages();
......
......@@ -14,7 +14,30 @@ SimConnection<ConnectionParameter>::SimConnection(ip_t ip, port_t port) :
m_run_receive(true),
m_receive_buffer(m_run_receive),
m_worker_fill_receive_buffer(
&SimConnection<ConnectionParameter>::work_fill_receive_buffer, this, ip, port),
&SimConnection<ConnectionParameter>::work_fill_receive_buffer, this),
m_worker_decode_messages(&SimConnection<ConnectionParameter>::work_decode_messages, this),
m_runnable_mutex(),
m_terminate_on_destruction(false),
m_logger(log4cxx::Logger::getLogger("hxcomm.SimConnection"))
{
HXCOMM_LOG_TRACE(m_logger, "SimConnection(): Sim connection started.");
// reset synplify wrapper to align behavior to ARQ FPGA reset of ARQConnection.
m_sim.issue_reset();
}
template <typename ConnectionParameter>
SimConnection<ConnectionParameter>::SimConnection() :
m_sim(),
m_send_queue(),
m_encoder(m_send_queue),
m_receive_queue(),
m_listener_halt(),
m_decoder(m_receive_queue, m_listener_halt),
m_run_receive(true),
m_receive_buffer(m_run_receive),
m_worker_fill_receive_buffer(
&SimConnection<ConnectionParameter>::work_fill_receive_buffer, this),
m_worker_decode_messages(&SimConnection<ConnectionParameter>::work_decode_messages, this),
m_runnable_mutex(),
m_terminate_on_destruction(false),
......@@ -85,9 +108,9 @@ bool SimConnection<ConnectionParameter>::try_receive(receive_message_type& messa
}
template <typename ConnectionParameter>
void SimConnection<ConnectionParameter>::work_fill_receive_buffer(ip_t ip, port_t port)
void SimConnection<ConnectionParameter>::work_fill_receive_buffer()
{
thread_local decltype(m_sim) local_sim(ip, port);
thread_local decltype(m_sim) local_sim(m_sim);
while (true) {
auto const write_pointer = m_receive_buffer.start_write();
......
......@@ -21,6 +21,19 @@ struct SimulatorClient::Impl
SimulatorClient::SimulatorClient(ip_t ip, port_t port) : m_impl(std::make_unique<Impl>(ip, port)) {}
SimulatorClient::SimulatorClient() : m_impl()
{
char const* env_port = std::getenv("FLANGE_SIMULATION_RCF_PORT");
if (env_port == nullptr) {
throw std::runtime_error("No port to simulator found in environment.");
}
m_impl = std::make_unique<Impl>("127.0.0.1", static_cast<port_t>(std::atoi(env_port)));
}
SimulatorClient::SimulatorClient(SimulatorClient const& other) :
m_impl(std::make_unique<Impl>(*(other.m_impl)))
{}
SimulatorClient::~SimulatorClient()
{}
......
......@@ -7,18 +7,9 @@
// logger include directory structure omits prefix
#include "logging_ctrl.h"
#ifndef HXCOMM_TEST_ARQ_CONNECTION
std::string simulation_ip;
unsigned int simulation_port;
#endif
TestConnection generate_test_connection()
{
#ifdef HXCOMM_TEST_ARQ_CONNECTION
return TestConnection();
#else
return TestConnection(simulation_ip, simulation_port);
#endif
}
int main(int argc, char* argv[])
......@@ -29,10 +20,6 @@ int main(int argc, char* argv[])
namespace bpo = boost::program_options;
bpo::options_description desc("Options");
// clang-format off
#ifndef HXCOMM_TEST_ARQ_CONNECTION
desc.add_options()("simulation_ip", bpo::value<std::string>(&simulation_ip)->default_value("127.0.0.1"));
desc.add_options()("simulation_port", bpo::value<unsigned int>(&simulation_port)->required());
#endif
desc.add_options()("loglevel", bpo::value<std::string>(&loglevel)->default_value("trace"));
// clang-format on
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment