You.i Engine
YiRemoteAssetCatalog.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2017. All rights reserved.
2 #ifndef _YI_REMOTE_ASSET_CATALOG_H_
3 #define _YI_REMOTE_ASSET_CATALOG_H_
4 
5 #include "asset/YiAsset.h"
9 
31 {
32  friend class CYIAssetLoader;
33 
34 public:
42  static std::shared_ptr<CYIRemoteAssetCatalog> Create(const CYIString &name);
43 
48  {
53  };
54 
55  virtual ~CYIRemoteAssetCatalog();
56 
60  const CYIUrl &GetUrl() const;
61 
65  uint64_t GetCatalogID() const;
66 
70  CYIString GetAbsoluteCatalogUrlForAsset(const CYIString &assetName) const;
71 
75  CYIString GetRelativeCatalogUrlForAsset(const CYIString &assetName) const;
76 
83  void DownloadManifest(const CYIUrl &url);
84 
90  void DownloadAssets();
91 
102  void DownloadManifestAndAssets(const CYIUrl &url);
103 
107  void CancelDownload();
108 
109  virtual std::pair<uint32_t, uint32_t> GetApproximateSize() const override;
110 
116  bool AddAssetToDownloadList(const CYIString &assetName, const CYIRuntimeTypeInfo &assetTypeInfo);
117 
123  void RemoveAssetFromDownloadList(const CYIString &assetName);
124 
131  std::shared_ptr<CYIAsset> GetAsset(const CYIString &assetName) const;
132 
136  void ClearData();
137 
141  std::vector<CYIString> GetAssetList() const;
142 
146  const CYIAssetManifest &GetAssetManifest() const;
147 
151  bool IsManifestDownloaded() const;
152 
158  bool IsAssetInDownloadList(const CYIString &assetName) const;
159 
164 
168  CYISignal<const CYIUrl & /*catalog*/, const FAILURE_TYPE, const CYIUrl & /*asset*/> AssetDownloadFailed;
169 
174 
179 
184 
185 protected:
191  CYIRemoteAssetCatalog(const CYIString &name);
192 
196  const std::vector<uint8_t> &GetData(const CYIString &assetName) const;
197 
201  void OnManifestDownloadCompleted(const std::shared_ptr<CYIHTTPRequest> &pRequest, const std::shared_ptr<CYIHTTPResponse> &pResponse, bool bCachedResponse);
202 
206  void OnManifestDownloadFailed(const std::shared_ptr<CYIHTTPRequest> &pRequest, const HTTP_STATUS_CODE statusCode, const CYIString &errorMessage);
207 
211  void OnAssetDownloadCompleted(const CYIUrl &url);
212 
218  void OnAssetDownloadFailed(CYIRemoteAssetDownloadHelper::FAILURE_TYPE eFailureType, const CYIUrl &url);
219 
233  std::shared_ptr<CYIAsset> DecodeAsset(const CYIString &path, CYIAssetLoadParams *pLoadParams = nullptr) const;
234 
238  CYIUrl GetAssetDownloadURL(const CYIString &assetName, const CYIRuntimeTypeInfo &typeInfo) const;
239 
243  bool QueueTemplateDependenciesForDownload(const CYIString &assetName);
244 
245 private:
246  struct AssetDownloadInfo
247  {
248  AssetDownloadInfo(const std::shared_ptr<CYIRemoteAssetDownloadHelper> &pDownloadHelper, const CYIRuntimeTypeInfo &assetType);
249 
250  std::shared_ptr<CYIRemoteAssetDownloadHelper> m_pDownloadHelper;
251  const CYIRuntimeTypeInfo &m_AssetType;
252  };
253 
259  void FetchAssetsFromManifest();
260 
264  bool IsAssetInCatalog(const CYIString &assetName, const CYIRuntimeTypeInfo &assetTypeInfo) const;
265 
266  uint64_t m_uCatalogID;
267  CYIUrl m_Url;
268  CYIAssetManifest m_manifest;
269  std::shared_ptr<CYIHTTPRequest> m_pManifestDownloadRequest;
270  std::map<CYIString, AssetDownloadInfo> m_assetsData;
271  bool m_bManifestDowloaded;
272 
275 };
276 
281 #endif // _YI_REMOTE_ASSET_CATALOG_H_
void RemoveAssetFromDownloadList(const CYIString &assetName)
An asset representing remote asset catalogs.
Definition: YiRemoteAssetCatalog.h:30
const std::vector< uint8_t > & GetData(const CYIString &assetName) const
CYIString GetRelativeCatalogUrlForAsset(const CYIString &assetName) const
#define YI_DISALLOW_COPY_AND_ASSIGN(TypeName)
Delete the copy constructor and assignment operator (and consequently the move constructor as well) ...
Definition: YiPredef.h:114
Occurs if the manifest is empty while attempting to fetch assets.
Definition: YiRemoteAssetCatalog.h:52
std::shared_ptr< CYIAsset > GetAsset(const CYIString &assetName) const
virtual ~CYIRemoteAssetCatalog()
Container class for Unicode strings. Conceptually, a CYIString object is a sequence of Unicode charac...
Definition: YiString.h:35
CYISignal< const CYIUrl &, const FAILURE_TYPE, const CYIUrl & > AssetDownloadFailed
Definition: YiRemoteAssetCatalog.h:168
std::vector< CYIString > GetAssetList() const
void OnAssetDownloadFailed(CYIRemoteAssetDownloadHelper::FAILURE_TYPE eFailureType, const CYIUrl &url)
CYISignal< const CYIUrl & > AssetDownloadCompleted
Definition: YiRemoteAssetCatalog.h:163
#define YI_TYPE_BASES(...)
Definition: YiRtti.h:350
void OnManifestDownloadFailed(const std::shared_ptr< CYIHTTPRequest > &pRequest, const HTTP_STATUS_CODE statusCode, const CYIString &errorMessage)
void DownloadManifest(const CYIUrl &url)
const CYIUrl & GetUrl() const
Stores information for the asset manifest.
Definition: YiAssetManifest.h:21
std::shared_ptr< CYIAsset > DecodeAsset(const CYIString &path, CYIAssetLoadParams *pLoadParams=nullptr) const
FAILURE_TYPE
Definition: YiAbstractDownloadHelper.h:38
CYIRemoteAssetCatalog(const CYIString &name)
void OnAssetDownloadCompleted(const CYIUrl &url)
Base class for decoders which can accept specialized parameter objects.
Definition: YiAssetLoadParams.h:16
virtual std::pair< uint32_t, uint32_t > GetApproximateSize() const override
CYIString GetAbsoluteCatalogUrlForAsset(const CYIString &assetName) const
bool IsManifestDownloaded() const
static std::shared_ptr< CYIRemoteAssetCatalog > Create(const CYIString &name)
Occurs if the manifest URL provided is invalid.
Definition: YiRemoteAssetCatalog.h:49
bool AddAssetToDownloadList(const CYIString &assetName, const CYIRuntimeTypeInfo &assetTypeInfo)
Occurs if while downloading, the HTTP request fails for any reason.
Definition: YiRemoteAssetCatalog.h:50
bool QueueTemplateDependenciesForDownload(const CYIString &assetName)
The abstract runtime representation of a C++ type.
Definition: YiRtti.h:48
A class used to encapsulate an URL.
Definition: YiUrl.h:24
uint64_t GetCatalogID() const
CYIUrl GetAssetDownloadURL(const CYIString &assetName, const CYIRuntimeTypeInfo &typeInfo) const
CYISignal< const CYIUrl & > DownloadCancelled
Definition: YiRemoteAssetCatalog.h:178
Definition: YiSignalHandler.h:174
HTTP_STATUS_CODE
Definition: YiHTTPService.h:20
CYISignal< const CYIUrl & > ManifestDownloadCompleted
Definition: YiRemoteAssetCatalog.h:183
Occurs if while parsing or decoding, the asset is invalid for the specified type. ...
Definition: YiRemoteAssetCatalog.h:51
Base class for any asset. An asset provides functions for dynamically loading and unloading itself an...
Definition: YiAsset.h:33
bool IsAssetInDownloadList(const CYIString &assetName) const
CYISignal< const CYIUrl &, const FAILURE_TYPE > ManifestDownloadFailed
Definition: YiRemoteAssetCatalog.h:173
void DownloadManifestAndAssets(const CYIUrl &url)
const CYIAssetManifest & GetAssetManifest() const
void OnManifestDownloadCompleted(const std::shared_ptr< CYIHTTPRequest > &pRequest, const std::shared_ptr< CYIHTTPResponse > &pResponse, bool bCachedResponse)
FAILURE_TYPE
Definition: YiRemoteAssetCatalog.h:47
The asset loader provides an interface for loading asset objects, which in turn wrap resource objects...
Definition: YiAssetLoader.h:39