| 47 | } |
| 48 | |
| 49 | void SpeedCameraManager::OnLocationPositionChanged(location::GpsInfo const & info) |
| 50 | { |
| 51 | CHECK_THREAD_CHECKER(m_threadChecker, ()); |
| 52 | CHECK(!m_route.expired(), ()); |
| 53 | |
| 54 | auto const passedDistanceMeters = m_route.lock()->GetCurrentDistanceFromBeginMeters(); |
| 55 | |
| 56 | // Step 1. Find new cameras and cache them. |
| 57 | FindCamerasOnRouteAndCache(passedDistanceMeters); |
| 58 | |
| 59 | double distFromCurrentPosAndClosestCam = -1.0; |
| 60 | m_speedLimitExceeded = false; |
| 61 | if (m_closestCamera.IsValid()) |
| 62 | { |
| 63 | distFromCurrentPosAndClosestCam = m_closestCamera.m_distFromBeginMeters - passedDistanceMeters; |
| 64 | if (distFromCurrentPosAndClosestCam < -kInfluenceZoneMeters) |
| 65 | { |
| 66 | m_closestCamera.Invalidate(); |
| 67 | m_speedCamClearCallback(); |
| 68 | } |
| 69 | else if (!m_closestCamera.NoSpeed()) |
| 70 | { |
| 71 | m_speedLimitExceeded = IsSpeedHigh(distFromCurrentPosAndClosestCam, info.m_speed, m_closestCamera); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | // Step 2. Check cached cameras. Do it only after pass through closest camera. |
| 76 | if (!m_cachedSpeedCameras.empty() && distFromCurrentPosAndClosestCam < 0) |
| 77 | { |
| 78 | // Do not use reference here, because ProcessCameraWarning() can |
| 79 | // invalidate |closestSpeedCam|. |
| 80 | auto const closestSpeedCam = m_cachedSpeedCameras.front(); |
| 81 | |
| 82 | if (NeedToUpdateClosestCamera(passedDistanceMeters, info.m_speed, closestSpeedCam)) |
| 83 | { |
| 84 | m_closestCamera = closestSpeedCam; |
| 85 | ResetNotifications(); |
| 86 | m_cachedSpeedCameras.pop(); |
| 87 | PassClosestCameraToUI(); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | if (m_closestCamera.IsValid() && SetNotificationFlags(passedDistanceMeters, info.m_speed, m_closestCamera)) |
| 92 | { |
| 93 | // If some notifications available now. |
| 94 | SendNotificationStat(passedDistanceMeters, info.m_speed, m_closestCamera); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | void SpeedCameraManager::GenerateNotifications(std::vector<std::string> & notifications) |
| 99 | { |
nothing calls this directly
no test coverage detected