Overte C++ Documentation
ResourceManager.h
1 //
2 // ResourceManager.h
3 // libraries/networking/src
4 //
5 // Created by Ryan Huffman on 2015/07/23
6 // Copyright 2015 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_ResourceManager_h
13 #define hifi_ResourceManager_h
14 
15 #include <functional>
16 
17 #include <QObject>
18 #include <QtCore/QMutex>
19 #include <QThread>
20 
21 #include <DependencyManager.h>
22 
23 #include "ResourceRequest.h"
24 
25 class ResourceManager: public QObject, public Dependency {
26  Q_OBJECT
27  SINGLETON_DEPENDENCY
28 
29 public:
30  ResourceManager(bool atpSupportEnabled = true);
31  ~ResourceManager();
32 
33  void setUrlPrefixOverride(const QString& prefix, const QString& replacement);
34  QString normalizeURL(const QString& urlString);
35  QUrl normalizeURL(const QUrl& url);
36 
37  ResourceRequest* createResourceRequest(
38  QObject* parent,
39  const QUrl& url,
40  const bool isObservable = true,
41  const qint64 callerId = -1,
42  const QString& extra = "");
43 
44  void init();
45  void cleanup();
46 
47  // Blocking call to check if a resource exists. This function uses a QEventLoop internally
48  // to return to the calling thread so that events can still be processed.
49  bool resourceExists(const QUrl& url);
50 
51  // adjust where we persist the cache
52  void setCacheDir(const QString& cacheDir);
53 
54 private:
55  QThread _thread;
56 
57  using PrefixMap = std::map<QString, QString>;
58 
59  bool _atpSupportEnabled;
60  PrefixMap _prefixMap;
61  QMutex _prefixMapLock;
62 
63 };
64 
65 #endif