blob: c2954b6d74690fcd71916ed29785b5052271a24e [file] [log] [blame]
John Park33858a32018-09-28 23:05:48 -07001#ifndef AOS_NETWORK_TEAM_NUMBER_H_
2#define AOS_NETWORK_TEAM_NUMBER_H_
Brian Silverman431500a2013-10-28 19:50:15 -07003
4#include <stdint.h>
5
Brian Silverman3dfbfb12020-02-17 20:35:18 -08006#include <optional>
Austin Schuhdf5591e2015-12-19 22:36:50 -08007#include <string>
8
Jim Ostrowski2192ddb2020-06-24 19:07:31 -07009#include "glog/logging.h"
10
11DECLARE_string(override_hostname);
12
Brian Silverman431500a2013-10-28 19:50:15 -070013namespace aos {
14namespace 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.
19uint16_t GetTeamNumber();
20
Austin Schuh288479d2019-12-18 19:47:52 -080021// Returns the current hostname.
22::std::string GetHostname();
23
Brian Silvermande0a53a2014-02-10 22:27:44 -080024// 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 Schraderf75a8bf2015-02-02 05:30:16 +000028// Guaranteed to be safe to call during static initialization time.
Brian Silvermande0a53a2014-02-10 22:27:44 -080029void OverrideTeamNumber(uint16_t team);
30
Austin Schuh1f2996e2020-03-15 23:09:00 -070031// Returns the pi number for a pi formated hostname. pi-team#-pi# (pi-971-5)
32std::optional<uint16_t> ParsePiNumber(const std::string &hostname);
33
Brian Silverman3dfbfb12020-02-17 20:35:18 -080034namespace team_number_internal {
35
36std::optional<uint16_t> ParseRoborioTeamNumber(const std::string &hostname);
37
Austin Schuh1f2996e2020-03-15 23:09:00 -070038// Returns the team number for a pi formated hostname. pi-team#-pi#
Brian Silverman5f06ed22020-02-17 21:49:42 -080039std::optional<uint16_t> ParsePiTeamNumber(const std::string &hostname);
40
Brian Silverman3dfbfb12020-02-17 20:35:18 -080041} // namespace team_number_internal
Brian Silverman431500a2013-10-28 19:50:15 -070042} // namespace network
43} // namespace aos
44
John Park33858a32018-09-28 23:05:48 -070045#endif // AOS_NETWORK_TEAM_NUMBER_H_