summaryrefslogtreecommitdiff
path: root/src/mbgl/sprite/sprite_loader_worker.cpp
blob: 8258923aa57ac14825d02d9448e8a3d38b13b76f (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
#include <mbgl/sprite/sprite_loader_worker.hpp>
#include <mbgl/sprite/sprite_loader.hpp>
#include <mbgl/sprite/sprite_parser.hpp>

namespace mbgl {

SpriteLoaderWorker::SpriteLoaderWorker(ActorRef<SpriteLoaderWorker>, ActorRef<SpriteLoader> parent_)
    : parent(std::move(parent_)) {
}

void SpriteLoaderWorker::parse(std::shared_ptr<const std::string> image,
                               std::shared_ptr<const std::string> json,
                               const uint64_t correlationID) {
    try {
        if (!image) {
            // This shouldn't happen, since we always invoke it with a non-empty pointer.
            throw std::runtime_error("missing sprite image");
        }
        if (!json) {
            // This shouldn't happen, since we always invoke it with a non-empty pointer.
            throw std::runtime_error("missing sprite metadata");
        }

        parent.invoke(&SpriteLoader::onParsed, parseSprite(*image, *json), correlationID);
    } catch (...) {
        parent.invoke(&SpriteLoader::onError, std::current_exception(), correlationID);
    }
}

} // namespace mbgl