Skip to content

Commit

Permalink
check_connection now fails is server is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
maiconkist committed Apr 3, 2019
1 parent 2364677 commit e710fc5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
6 changes: 5 additions & 1 deletion grc_blocks/lib/hydra_gr_client_sink_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ hydra_gr_client_sink_impl::hydra_gr_client_sink_impl(
g_host = s_host;
client = std::make_unique<hydra_client>(g_host, u_port, u_id, true);

client->check_connection();
if (client->check_connection(3) == std::string(""))
{
std::cout << "Could not connect to server. Aborting" << std::endl;
assert (1 == 0);
}
}

hydra_gr_client_sink_impl::~hydra_gr_client_sink_impl()
Expand Down
7 changes: 6 additions & 1 deletion grc_blocks/lib/hydra_gr_client_source_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ hydra_gr_client_source_impl::hydra_gr_client_source_impl(unsigned int u_id,
gr::io_signature::make(1, 1, sizeof(gr_complex)))
{
client = std::make_unique<hydra_client>(c_host, u_port, u_id, true);
client->check_connection();

if (client->check_connection(3) == std::string(""))
{
std::cout << "Could not connect to server. Aborting" << std::endl;
assert(1 == 0);
}
}

hydra_gr_client_source_impl::~hydra_gr_client_source_impl()
Expand Down
18 changes: 12 additions & 6 deletions lib/hydra_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ namespace hydra {
hydra_client::hydra_client(std::string client_ip,
unsigned int u_port,
unsigned int u_client_id,
bool b_debug)
bool b_debug):
s_server_host(""),
s_client_host(client_ip),
u_id(u_client_id),
b_debug_flag(b_debug)
{
s_client_host = client_ip;
s_server_port = std::to_string(u_port);
u_id = u_client_id;
b_debug_flag = b_debug;

std::cout << boost::format("s_client_host: %s - s_server_host: %s") % s_client_host % s_server_host << std::endl;
}
Expand All @@ -28,9 +29,10 @@ int
hydra_client::request_rx_resources(rx_configuration &rx_conf)
{
// If ill defined one of the parameters
if (not bool(rx_conf.center_freq) or not bool(rx_conf.bandwidth))
if (not bool(rx_conf.center_freq) or not bool(rx_conf.bandwidth) or s_server_host == "")
{
std::cerr << "Missing RX information!" << std::endl;
return -1;
}

// Set message type
Expand Down Expand Up @@ -101,9 +103,10 @@ int
hydra_client::request_tx_resources(rx_configuration &tx_conf)
{
// If ill defined one of the parameters
if (not bool(tx_conf.center_freq) or not bool(tx_conf.bandwidth))
if (not bool(tx_conf.center_freq) or not bool(tx_conf.bandwidth) or s_server_host == "")
{
std::cerr << "Missing TX information!" << std::endl;
return -1;
}

// Set message type
Expand Down Expand Up @@ -177,6 +180,9 @@ hydra_client::query_resources()
std::string
hydra_client::free_resources()
{
if (s_server_host == "")
return "";

// Set message type
std::string message = "{\"xvl_fre\":{\"id\":" + std::to_string(u_id) + "}}";
// Send message and return acknowledgement
Expand Down

0 comments on commit e710fc5

Please sign in to comment.