summaryrefslogtreecommitdiff
path: root/platform/android/src/file_source.hpp
blob: 572ac647b7462f9b5d946726889377f15b76e830 (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
56
57
58
59
60
61
62
#pragma once

#include <mbgl/storage/default_file_source.hpp>

#include "asset_manager.hpp"

#include <jni/jni.hpp>

namespace mbgl {

template <typename T> class Actor;
class ResourceTransform;

namespace android {

/**
 * Peer class for the Android FileSource holder. Ensures that a single DefaultFileSource is used
 */
class FileSource {
public:

    static constexpr auto Name() { return "com/mapbox/mapboxsdk/storage/FileSource"; };

    struct ResourceTransformCallback {
        static constexpr auto Name() { return "com/mapbox/mapboxsdk/storage/FileSource$ResourceTransformCallback"; }

        static std::string onURL(jni::JNIEnv&, const jni::Object<FileSource::ResourceTransformCallback>&, int, std::string);
    };

    FileSource(jni::JNIEnv&, const jni::String&, const jni::String&, const jni::Object<AssetManager>&);

    ~FileSource();

    jni::Local<jni::String> getAccessToken(jni::JNIEnv&);

    void setAccessToken(jni::JNIEnv&, const jni::String&);

    void setAPIBaseUrl(jni::JNIEnv&, const jni::String&);

    void setResourceTransform(jni::JNIEnv&, const jni::Object<FileSource::ResourceTransformCallback>&);

    void resume(jni::JNIEnv&);

    void pause(jni::JNIEnv&);

    jni::jboolean isResumed(jni::JNIEnv&);

    static FileSource* getNativePeer(jni::JNIEnv&, const jni::Object<FileSource>&);

    static mbgl::DefaultFileSource& getDefaultFileSource(jni::JNIEnv&, const jni::Object<FileSource>&);

    static void registerNative(jni::JNIEnv&);

private:
    optional<int> activationCounter;
    std::unique_ptr<Actor<ResourceTransform>> resourceTransform;
    std::unique_ptr<mbgl::DefaultFileSource> fileSource;
};


} // namespace android
} // namespace mbgl