All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Payload.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "Types.h"
6 #include "PoolHandle.h"
7 #include "WorkItem.h"
8 #include "Streaming.h"
9 #include "Web.h"
10 #include "Resources.h"
11 #include <string>
12 #include <vector>
13 
14 namespace Eegeo
15 {
16  namespace Resources
17  {
18  class IResourceBuilder;
19  class IBuiltResource;
20  }
21 }
22 
23 namespace Eegeo
24 {
25  namespace PayloadState
26  {
27  enum PayloadStateValues
28  {
29  INVALID=0,
30  TO_BE_LOADED,
31  LOADING,
32  READY_FOR_BUILDING,
33  BUILDING,
34  BUILT,
35  BUILD_FAILED,
36  IN_SCENE_GRAPH,
37  LOAD_FAILED,
38  FINAL_PLACEHOLDER,
39  MAX
40  };
41  }
42 
43  namespace Streaming
44  {
45  class QuadTreeNode;
46  class IResourceStream;
47  class ResourceNode;
48  class PayloadBuildManager;
49  class ResourceNodeCache;
50 
51  class Payload : protected Eegeo::NonCopyable
52  {
53  public:
55  private:
56  uint lastVisibleUpdate;
57  public:
58  QuadTreeNode *node;
59  bool isLocallyCached;
60 
61  private:
62  IResourceStream *m_pStream;
63  ResourceStreamComponent* m_resourceStreamComponent;
64  PayloadState::PayloadStateValues m_state;
65  float m_priority;
66  int m_earliestUpdateCountForLoad;
67  Web::IWebLoadRequest* m_webLoadRequest;
68  PayloadWebLoader* m_payloadWebLoader;
69  const std::vector<Byte>* m_resourceData;
70  bool m_successfulLoad;
71 
72  Concurrency::Tasks::WorkItem *m_pWorkItem;
73  ResourceNodeCache* m_pResourceNodeCache;
74  ResourceNode *m_pResourceNode;
75  int m_failedLoadAttemptCount;
76  bool m_shouldBuildPlaceholder;
77  Resources::IBuiltResource* m_pPlaceholder;
78 
79  long long m_timeOfLastStateChange;
80  long long m_timePerState[PayloadState::MAX];
81 
82  void setState(PayloadState::PayloadStateValues newState);
83  bool stateIs(PayloadState::PayloadStateValues stateToCheckFor) const;
84  void tryClearPlaceholder();
85 
86  public:
87  IResourceStream* GetResourceStream() const { return m_pStream; };
88  ResourceNode *resourceNode() const { return m_pResourceNode; }
89  MortonKey key() const;
90 
91  bool shouldBuildPlaceholder() const { return m_shouldBuildPlaceholder; }
92  Resources::IResourceBuilder* resourceBuilder() const;
93  Resources::IPlaceholderBuilder* placeholderBuilder() const;
94  uint StreamPriority() const;
95  std::string url(bool relativeUrl = false) const;
96  const std::vector<Byte>* GetResourceData() const { return m_resourceData; }
97  bool SuccessfulLoad() { return m_successfulLoad; }
98 
99  float GetPriority() const { return m_priority; }
100  void SetPriority(float priority) { m_priority = priority; }
101  void SetEarliestUpdateCountForLoad(int updateCount) { m_earliestUpdateCountForLoad = updateCount; }
102 
103  Payload();
104  ~Payload();
105 
106  void SetPlaceholder(Resources::IBuiltResource* placeholder);
107  void OnAllocatedFromPool(DataStructures::PoolHandle poolHandle);
108  void init(QuadTreeNode *pNode, IResourceStream *pStream, ResourceStreamComponent* resourceStreamComponent);
109  void initWithoutResourceStreamComponent(QuadTreeNode *pNode, IResourceStream *pStream);
110  void setNeedsPlaceholder(bool dontBuildOnTopOf);
111  void onReleaseToPool();
112 
113  void SetToBeLoaded();
114  void LoadStarted(PayloadWebLoader* payloadWebLoader, Web::IWebLoadRequest* webLoadRequest);
115  void LoadCompleted(Web::IWebResponse& webResponse);
116 
117  void abortLoad();
118 
119  void loadErrored();
120  void loadFailed();
121  void startedBuilding(Concurrency::Tasks::WorkItem *pWorkItem);
122  void abortBuild();
123  void buildComplete(ResourceNode* pResourceNode, ResourceNodeCache* pResourceNodeCache);
124  void buildErrored();
125  void addedToSceneGraph();
126 
127  bool hasPlaceholder() const;
128  bool isReadyForBuilding(int updateCount) const;
129  bool isReadyForLoading(int updateCount) const;
130  bool isReadyForSceneGraph(int updateCount) const;
131  bool isLate(int updateCount) const;
132  bool isInSceneGraph() const;
133  bool isInSceneGraphOrHasPlaceholder() const;
134  bool isBuilt() const;
135  bool isLoadFailure() const;
136  bool isBuildFailure() const;
137  bool isPendingLoadCompletion(int updateCount) const;
138  bool isInVisibleSet(int updateCount) const;
139  bool shouldForwardErroredRequestsToBuilder() const;
140  bool shouldBeLoaded() const;
141  float timeInState(PayloadState::PayloadStateValues state) const;
142  PayloadState::PayloadStateValues GetState() const;
143  void SetLastVisibleUpdate(int updateCount) { lastVisibleUpdate = updateCount; }
144 
145  void LogFailedRequest();
146  void LogSuccessfulRequest(Web::IWebResponse& webResponse);
147  };
148  }
149 }