John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 1 | #ifndef AOS_NETWORK_TEAM_NUMBER_H_ |
| 2 | #define AOS_NETWORK_TEAM_NUMBER_H_ |
Brian Silverman | 431500a | 2013-10-28 19:50:15 -0700 | [diff] [blame] | 3 | |
| 4 | #include <stdint.h> |
| 5 | |
Brian Silverman | 3dfbfb1 | 2020-02-17 20:35:18 -0800 | [diff] [blame] | 6 | #include <optional> |
Austin Schuh | df5591e | 2015-12-19 22:36:50 -0800 | [diff] [blame] | 7 | #include <string> |
| 8 | |
Jim Ostrowski | 2192ddb | 2020-06-24 19:07:31 -0700 | [diff] [blame^] | 9 | #include "glog/logging.h" |
| 10 | |
| 11 | DECLARE_string(override_hostname); |
| 12 | |
Brian Silverman | 431500a | 2013-10-28 19:50:15 -0700 | [diff] [blame] | 13 | namespace aos { |
| 14 | namespace network { |
| 15 | |
| 16 | // Retrieves the current team number based off of the network address. |
| 17 | // This function will only do the complicated stuff once so it is cheap to call |
| 18 | // repeatedly. |
| 19 | uint16_t GetTeamNumber(); |
| 20 | |
Austin Schuh | 288479d | 2019-12-18 19:47:52 -0800 | [diff] [blame] | 21 | // Returns the current hostname. |
| 22 | ::std::string GetHostname(); |
| 23 | |
Brian Silverman | de0a53a | 2014-02-10 22:27:44 -0800 | [diff] [blame] | 24 | // Overrides the team number returned from GetTeamNumber(). Must be called |
| 25 | // before GetTeamNumber() is ever called. |
| 26 | // Overriding to team 0 won't work. |
| 27 | // Intended only for tests. |
Philipp Schrader | f75a8bf | 2015-02-02 05:30:16 +0000 | [diff] [blame] | 28 | // Guaranteed to be safe to call during static initialization time. |
Brian Silverman | de0a53a | 2014-02-10 22:27:44 -0800 | [diff] [blame] | 29 | void OverrideTeamNumber(uint16_t team); |
| 30 | |
Austin Schuh | 1f2996e | 2020-03-15 23:09:00 -0700 | [diff] [blame] | 31 | // Returns the pi number for a pi formated hostname. pi-team#-pi# (pi-971-5) |
| 32 | std::optional<uint16_t> ParsePiNumber(const std::string &hostname); |
| 33 | |
Brian Silverman | 3dfbfb1 | 2020-02-17 20:35:18 -0800 | [diff] [blame] | 34 | namespace team_number_internal { |
| 35 | |
| 36 | std::optional<uint16_t> ParseRoborioTeamNumber(const std::string &hostname); |
| 37 | |
Austin Schuh | 1f2996e | 2020-03-15 23:09:00 -0700 | [diff] [blame] | 38 | // Returns the team number for a pi formated hostname. pi-team#-pi# |
Brian Silverman | 5f06ed2 | 2020-02-17 21:49:42 -0800 | [diff] [blame] | 39 | std::optional<uint16_t> ParsePiTeamNumber(const std::string &hostname); |
| 40 | |
Brian Silverman | 3dfbfb1 | 2020-02-17 20:35:18 -0800 | [diff] [blame] | 41 | } // namespace team_number_internal |
Brian Silverman | 431500a | 2013-10-28 19:50:15 -0700 | [diff] [blame] | 42 | } // namespace network |
| 43 | } // namespace aos |
| 44 | |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 45 | #endif // AOS_NETWORK_TEAM_NUMBER_H_ |