| 1914 | } |
| 1915 | |
| 1916 | void Storage::GetNodeAttrs(CountryId const & countryId, NodeAttrs & nodeAttrs) const |
| 1917 | { |
| 1918 | CHECK_THREAD_CHECKER(m_threadChecker, ()); |
| 1919 | |
| 1920 | CountryTree::NodesBufferT nodes; |
| 1921 | m_countries.Find(countryId, nodes); |
| 1922 | CHECK(!nodes.empty(), (countryId)); |
| 1923 | // If nodes.size() > 1 countryId corresponds to a disputed territories. |
| 1924 | // In that case it's guaranteed that most of attributes are equal for |
| 1925 | // each element of nodes. See Country class description for further details. |
| 1926 | CountryTree::Node const * const node = nodes[0]; |
| 1927 | |
| 1928 | Country const & nodeValue = node->Value(); |
| 1929 | nodeAttrs.m_mwmCounter = nodeValue.GetSubtreeMwmCounter(); |
| 1930 | nodeAttrs.m_mwmSize = nodeValue.GetSubtreeMwmSizeBytes(); |
| 1931 | StatusAndError statusAndErr = GetNodeStatus(*node); |
| 1932 | nodeAttrs.m_status = statusAndErr.status; |
| 1933 | nodeAttrs.m_error = statusAndErr.error; |
| 1934 | nodeAttrs.m_nodeLocalName = m_countryNameGetter(countryId); |
| 1935 | nodeAttrs.m_nodeLocalDescription = m_countryNameGetter.Get(countryId + LOCALIZATION_DESCRIPTION_SUFFIX); |
| 1936 | |
| 1937 | // Progress. |
| 1938 | if (nodeAttrs.m_status == NodeStatus::OnDisk) |
| 1939 | { |
| 1940 | // Group or leaf node is on disk and up to date. |
| 1941 | MwmSize const subTreeSizeBytes = node->Value().GetSubtreeMwmSizeBytes(); |
| 1942 | nodeAttrs.m_downloadingProgress.m_bytesDownloaded = subTreeSizeBytes; |
| 1943 | nodeAttrs.m_downloadingProgress.m_bytesTotal = subTreeSizeBytes; |
| 1944 | } |
| 1945 | else |
| 1946 | { |
| 1947 | CountriesVec subtree; |
| 1948 | node->ForEachInSubtree([&subtree](CountryTree::Node const & d) { subtree.push_back(d.Value().Name()); }); |
| 1949 | |
| 1950 | nodeAttrs.m_downloadingProgress = CalculateProgress(subtree); |
| 1951 | } |
| 1952 | |
| 1953 | // Local mwm information and information about downloading mwms. |
| 1954 | nodeAttrs.m_localMwmCounter = 0; |
| 1955 | nodeAttrs.m_localMwmSize = 0; |
| 1956 | nodeAttrs.m_downloadingMwmCounter = 0; |
| 1957 | nodeAttrs.m_downloadingMwmSize = 0; |
| 1958 | CountriesSet visitedLocalNodes; |
| 1959 | node->ForEachInSubtree([this, &nodeAttrs, &visitedLocalNodes](CountryTree::Node const & d) |
| 1960 | { |
| 1961 | CountryId const & countryId = d.Value().Name(); |
| 1962 | if (!visitedLocalNodes.insert(countryId).second) |
| 1963 | return; |
| 1964 | |
| 1965 | // Downloading mwm information. |
| 1966 | StatusAndError const statusAndErr = GetNodeStatus(d); |
| 1967 | ASSERT_NOT_EQUAL(statusAndErr.status, NodeStatus::Undefined, ()); |
| 1968 | if (statusAndErr.status != NodeStatus::NotDownloaded && statusAndErr.status != NodeStatus::Partly && |
| 1969 | d.ChildrenCount() == 0) |
| 1970 | { |
| 1971 | nodeAttrs.m_downloadingMwmCounter += 1; |
| 1972 | nodeAttrs.m_downloadingMwmSize += d.Value().GetSubtreeMwmSizeBytes(); |
| 1973 | } |