summaryrefslogtreecommitdiff
path: root/include/mbgl/storage/file_source_manager.hpp
blob: 4c6cd8e558c44b8f31e8db984383c57a14100bc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#pragma once

#include <mbgl/storage/file_source.hpp>
#include <mbgl/util/pass_types.hpp>

namespace mbgl {

class ResourceOptions;
class JointDatabaseStorage;
/**
 * @brief A singleton class responsible for managing file sources.
 *
 * The FileSourceManager provides following functionality:
 *
 * - provides access to file sources of a specific type and configuration
 * - caches previously created file sources of a (type, configuration) tuples
 * - allows to register and unregister file source factories
 */
class FileSourceManager {
public:
    using FileSourceFactory = std::function<std::unique_ptr<FileSource>(const ResourceOptions&)>;

    /**
     * @brief A singleton getter.
     *
     * @return FileSourceManager*
     */
    static FileSourceManager* get() noexcept;

    // Returns shared instance of a file source for (type, options) tuple.
    // Creates new instance via registered factory if needed. If new instance cannot be
    // created, nullptr would be returned.
    PassRefPtr<FileSource> getFileSource(FileSourceType, const ResourceOptions&) noexcept;

    // Returns shared instance of a joint database storage for the given options.
    // Creates new instance, if needed. If new instance cannot be created, nullptr would be returned.
    virtual PassRefPtr<JointDatabaseStorage> getDatabaseStorage(const ResourceOptions&) noexcept;

    // Registers file source factory for a provided FileSourceType type. If factory for the
    // same type was already registered, will unregister previously registered factory.
    // Provided factory must not be null.
    virtual void registerFileSourceFactory(FileSourceType, FileSourceFactory&&) noexcept;

    // Unregisters file source factory. If there are no registered factories for a FileSourceType
    // invocation has no effect.
    virtual FileSourceFactory unRegisterFileSourceFactory(FileSourceType) noexcept;

protected:
    FileSourceManager();
    class Impl;
    std::unique_ptr<Impl> impl;
    virtual ~FileSourceManager();
};

} // namespace mbgl