All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
PrecacheService.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Types.h"
6 #include "Web.h"
7 #include "Streaming.h"
8 #include "Helpers.h"
9 #include "WebLoadRequestCompletionCallback.h"
10 #include "ICityThemesService.h"
11 #include "IWebLoadRequest.h"
12 #include "CallbackCollection.h"
13 #include <vector>
14 #include <string>
15 #include <deque>
16 #include "PendingWebRequestsContainer.h"
17 
18 namespace Eegeo
19 {
20  namespace Streaming
21  {
22  class IStreamingVolume;
23  }
24 
25  namespace Web
26  {
28  {
29  public:
30  PrecacheService(IWebLoadRequestFactory* webLoadRequestFactory,
31  Eegeo::Streaming::PayloadSlotStreamMap *pPayloadSlotStreamMap,
34 
35  int TotalUrlsToLoad() const { return m_totalUrlsToLoad; }
36  int UrlsErrored() const { return m_erroredRequests; }
37  int Urls404ed() const { return m_fourOhFourRequests; }
38  int UrlsLoaded() const { return TotalUrlsToLoad() - m_numberUrlsRemainingLoad; }
39 
40  float PercentCompleted() const;
41  bool CurrentlyPrecaching() const { return m_numberUrlsRemainingLoad > 0; }
42  bool IsCancelling() const { return false; }
43 
44  void CancelPrecaching();
45 
46  bool CanPrecache(double altitude);
47  void Precache(Streaming::IStreamingVolume& volume);
48  void IssueRequests();
49  uint EstimatedPrecacheSizekB(Streaming::IStreamingVolume& volume);
50 
51  void InsertPrecacheCancelledCallback(Eegeo::Helpers::ICallback0& callback);
52 
53  void RemovePrecacheCancelledCallback(Eegeo::Helpers::ICallback0& callback);
54 
55  void InsertPrecacheCompletedCallback(Eegeo::Helpers::ICallback0& callback);
56 
57  void RemovePrecacheCompletedCallback(Eegeo::Helpers::ICallback0& callback);
58  private:
59 
60  const static int MAX_PRECACHE_REQUESTS_IN_FLIGHT = 10;
61 
62  int m_totalUrlsToLoad;
63  int m_numberUrlsRemainingLoad;
64  int m_requestsInFlightCount;
65  int m_erroredRequests;
66  int m_fourOhFourRequests;
67 
68  std::deque<std::string> m_requestsToIssue;
69 
71  IWebLoadRequestFactory* m_webLoadRequestFactory;
72  Eegeo::Streaming::PayloadSlotStreamMap *m_pPayloadSlotStreamMap;
74 
75  TWebLoadRequestCompletionCallback<PrecacheService> m_webLoadRequestCompletionCallback;
76 
77  Eegeo::Helpers::CallbackCollection0 m_preloadCancelledCallbacks;
78  Eegeo::Helpers::CallbackCollection0 m_preloadCompletedCallbacks;
79 
80  Web::PendingWebRequestsContainer m_pendingWebRequestsContainer;
81 
82  void EnqueueRequest(const std::string& url);
83  void PrecacheCustomBuildingTextures(const Web::TResourceData* data);
84  void OnWebLoadRequestCompleted(IWebResponse& webResponse);
85  std::vector<Streaming::MortonKey> GetCellsIntersectingVolume(Streaming::IStreamingVolume& volume);
86  };
87  }
88 }