TraveSim Adapters  0.1
Protobuf adapters for TraveSim project
teams_configurer.cpp
Go to the documentation of this file.
1 /**
2  * @file teams_configurer.cpp
3  *
4  * @author Lucas Haug <lucas.haug@thuneratz.org>
5  *
6  * @brief Configurer for the teams
7  *
8  * @date 06/2021
9  *
10  * @copyright MIT License - Copyright (c) 2021 ThundeRatz
11  *
12  */
13 
16 
17 /*****************************************
18  * Private Constants
19  *****************************************/
20 
21 #define TEAMS_CONFIGURER_NAMESPACE BASE_CONFIGURER_NAMESPACE "teams"
22 
23 namespace travesim {
24 /*****************************************
25  * Public Methods Bodies Definitions
26  *****************************************/
27 
28 TeamsConfigurer::TeamsConfigurer(void) : AdapterConfigurer<travesim_adapters::TeamsConfig>::AdapterConfigurer(
30 }
31 
33  boost::recursive_mutex::scoped_lock scoped_lock(this->mutex);
34 
35  std::string address;
36 
37  if (color == TeamColor::YELLOW) {
38  address = this->config.yellow_team_address;
39  } else {
40  address = this->config.blue_team_address;
41  }
42 
44 
45  if (validation == IPValidation::VALID) {
46  return address;
47  } else {
48  ROS_ERROR_STREAM(get_error_msg(validation));
49 
50  return INVALID_ADDRESS;
51  }
52 }
53 
55  boost::recursive_mutex::scoped_lock scoped_lock(this->mutex);
56 
57  if (color == TeamColor::YELLOW) {
58  return this->config.yellow_team_port;
59  } else {
60  return this->config.blue_team_port;
61  }
62 }
63 
65  boost::recursive_mutex::scoped_lock scoped_lock(this->mutex);
66  return this->config.specific_source;
67 }
68 
69 std::ostream& operator <<(std::ostream& output, const TeamsConfigurer& teams_conf) {
70  output << "Yellow Team Endpoint: " << teams_conf.config.yellow_team_address;
71  output << ":" << teams_conf.config.yellow_team_port << std::endl;
72  output << "Blue Team Endpoint: " << teams_conf.config.blue_team_address;
73  output << ":" << teams_conf.config.blue_team_port << std::endl;
74  output << "Specific Source: " << (teams_conf.config.specific_source ? "True" : "False") << std::endl;
75  output << "Reset: " << ((teams_conf.config.reset || teams_conf.reconfigured) ? "True" : "False") << std::endl;
76 
77  return output;
78 }
79 }
bool get_specific_source(void)
Get the specific_source config.
IPValidation
Type used to validate a IP string.
TeamsConfigurer(void)
Construct a new TeamsConfigurer object.
#define TEAMS_CONFIGURER_NAMESPACE
uint16_t get_port(TeamColor color)
Get the configured port of a team.
Configurer for the teams.
TeamsConfigurer class definition.
std::string get_error_msg(IPValidation error)
Get the error msg based on the validation type.
IPValidation check_valid_ip(std::string ip, std::string min_ip, std::string max_ip)
Checks if a IP is valid and is in the specified range.
Configurers utilitary funtions.
#define MIN_UNICAST_ADDRESS
TeamColor
Team color enumeration type.
std::ostream & operator<<(std::ostream &output, const ReplacerConfigurer &repl_conf)
std::string get_address(TeamColor color)
Get the configured address of a team.
#define MAX_UNICAST_ADDRESS
#define INVALID_ADDRESS