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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "fsCloudSaveFactory.h"

#include <vector>

#if defined(fsCloudSaveSteam)
    #include "src/impl/steam/fsCloudSaveServiceSteam.h"
#elif defined(fsCloudSavePlayGames)
    #include "src/impl/android/fsCloudSaveServiceAndroid.h"
#elif defined(fsCloudSaveLocalFolder)
    #include "src/impl/localFolder/fsCloudSaveServiceLocalFolder.h"
#endif

namespace
{
// "none": never available, so the sync layer does nothing.
class fsCloudSaveServiceStub : public fsCloudSaveService
{
public:
    void initialize(const fsCloudSaveConfig& config) override
    {
        if (!config.providerName.empty())
        {
            mProviderName = config.providerName;
        }
    }

    const std::string& providerNameGet() const override
    {
        return mProviderName;
    }

    bool availableGet() const override
    {
        return false;
    }

    void read(const std::string&, ReadCallback done) override
    {
        mPending.push_back([done]() { done(fsCloudSaveResult::eUNAVAILABLE, std::string()); });
    }

    void write(const std::string&, const std::string&, DoneCallback done) override
    {
        mPending.push_back([done]() { done(fsCloudSaveResult::eUNAVAILABLE); });
    }

    void remove(const std::string&, DoneCallback done) override
    {
        mPending.push_back([done]() { done(fsCloudSaveResult::eUNAVAILABLE); });
    }

    void update() override
    {
        std::vector<std::function<void()>> pending;
        pending.swap(mPending);
        for (auto& call : pending)<--- Variable 'call' can be declared as reference to const
        {
            call();
        }
    }

    void shutdown() override
    {
    }

private:
    std::string mProviderName{"none"};
    std::vector<std::function<void()>> mPending;
};
}

std::unique_ptr<fsCloudSaveService> fsCloudSaveServiceCreate()
{
#if defined(fsCloudSaveSteam)
    return std::make_unique<fsCloudSaveServiceSteam>();
#elif defined(fsCloudSavePlayGames)
    return std::make_unique<fsCloudSaveServiceAndroid>();
#elif defined(fsCloudSaveLocalFolder)
    return std::make_unique<fsCloudSaveServiceLocalFolder>();
#else
    return std::make_unique<fsCloudSaveServiceStub>();
#endif
}