Overte C++ Documentation
ClipCache.h
1 //
2 // Created by Bradley Austin Davis on 2015/11/19
3 // Copyright 2015 High Fidelity, Inc.
4 //
5 // Distributed under the Apache License, Version 2.0.
6 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
7 //
8 #pragma once
9 #ifndef hifi_Recording_ClipCache_h
10 #define hifi_Recording_ClipCache_h
11 
12 #include <QtCore/QSharedPointer>
13 
14 #include <ResourceCache.h>
15 
16 #include "Forward.h"
17 #include "impl/PointerClip.h"
18 
19 namespace recording {
20 
21 class NetworkClip : public PointerClip {
22 public:
23  using Pointer = std::shared_ptr<NetworkClip>;
24 
25  NetworkClip(const QUrl& url) : _url(url) {}
26  virtual void init(const QByteArray& clipData);
27  virtual QString getName() const override { return _url.toString(); }
28 
29 private:
30  QByteArray _clipData;
31  QUrl _url;
32 };
33 
34 class NetworkClipLoader : public Resource {
35  Q_OBJECT
36 public:
37  NetworkClipLoader(const QUrl& url);
38  NetworkClipLoader(const NetworkClipLoader& other) : Resource(other), _clip(other._clip) {}
39 
40  virtual void downloadFinished(const QByteArray& data) override;
41  ClipPointer getClip() { return _clip; }
42  bool completed() { return _failedToLoad || isLoaded(); }
43 
44 signals:
45  void clipLoaded();
46 
47 private:
48  const NetworkClip::Pointer _clip;
49 };
50 
51 using NetworkClipLoaderPointer = QSharedPointer<NetworkClipLoader>;
52 
53 class ClipCache : public ResourceCache, public Dependency {
54  Q_OBJECT
55  SINGLETON_DEPENDENCY
56 
57 public slots:
58  NetworkClipLoaderPointer getClipLoader(const QUrl& url);
59 
60 protected:
61  virtual QSharedPointer<Resource> createResource(const QUrl& url) override;
62  QSharedPointer<Resource> createResourceCopy(const QSharedPointer<Resource>& resource) override;
63 
64 private:
65  ClipCache(QObject* parent = nullptr);
66 };
67 
68 }
69 
70 #endif
Base class for resource caches.
Definition: ResourceCache.h:196
Base class for resources.
Definition: ResourceCache.h:409
virtual bool isLoaded() const
Checks whether the resource has loaded.
Definition: ResourceCache.h:439