milind-u | 086d726 | 2022-01-19 20:44:18 -0800 | [diff] [blame^] | 1 | #include "y2022/constants.h" |
| 2 | |
| 3 | #include <cinttypes> |
| 4 | #include <map> |
| 5 | |
| 6 | #if __has_feature(address_sanitizer) |
| 7 | #include "sanitizer/lsan_interface.h" |
| 8 | #endif |
| 9 | |
| 10 | #include "absl/base/call_once.h" |
| 11 | #include "aos/mutex/mutex.h" |
| 12 | #include "aos/network/team_number.h" |
| 13 | #include "glog/logging.h" |
| 14 | |
| 15 | namespace y2022 { |
| 16 | namespace constants { |
| 17 | |
| 18 | const int Values::kZeroingSampleSize; |
| 19 | |
| 20 | namespace { |
| 21 | |
| 22 | const uint16_t kCompTeamNumber = 971; |
| 23 | const uint16_t kPracticeTeamNumber = 9971; |
| 24 | const uint16_t kCodingRobotTeamNumber = 7971; |
| 25 | |
| 26 | const Values *DoGetValuesForTeam(uint16_t team) { |
| 27 | Values *const r = new Values(); |
| 28 | |
| 29 | switch (team) { |
| 30 | // A set of constants for tests. |
| 31 | case 1: |
| 32 | break; |
| 33 | |
| 34 | case kCompTeamNumber: |
| 35 | break; |
| 36 | |
| 37 | case kPracticeTeamNumber: |
| 38 | break; |
| 39 | |
| 40 | case kCodingRobotTeamNumber: |
| 41 | break; |
| 42 | |
| 43 | default: |
| 44 | LOG(FATAL) << "unknown team: " << team; |
| 45 | } |
| 46 | |
| 47 | return r; |
| 48 | } |
| 49 | |
| 50 | const Values *values = nullptr; |
| 51 | |
| 52 | void DoGetValues() { |
| 53 | uint16_t team = ::aos::network::GetTeamNumber(); |
| 54 | LOG(INFO) << "creating a Constants for team: " << team; |
| 55 | values = DoGetValuesForTeam(team); |
| 56 | } |
| 57 | |
| 58 | } // namespace |
| 59 | |
| 60 | void InitValues() { |
| 61 | static absl::once_flag once; |
| 62 | absl::call_once(once, DoGetValues); |
| 63 | } |
| 64 | |
| 65 | const Values &GetValues() { |
| 66 | CHECK(values) |
| 67 | << "Values are uninitialized. Call InitValues before accessing them."; |
| 68 | return *values; |
| 69 | } |
| 70 | |
| 71 | } // namespace constants |
| 72 | } // namespace y2022 |