Make request and reparse pure virtual

This commit is contained in:
John Firebaugh
2015-06-04 15:54:42 -07:00
parent ee46378583
commit 7e71145a89
6 changed files with 101 additions and 51 deletions

View File

@@ -1,13 +1,6 @@
#include <mbgl/map/tile_data.hpp>
#include <mbgl/map/source.hpp>
#include <mbgl/map/transform_state.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/storage/file_source.hpp>
#include <mbgl/util/work_request.hpp>
#include <mbgl/util/worker.hpp>
#include <sstream>
using namespace mbgl;
@@ -35,32 +28,6 @@ void TileData::setState(const State& state_) {
state = state_;
}
void TileData::request(Worker& worker,
float pixelRatio,
const std::function<void()>& callback) {
std::string url = source.tileURL(id, pixelRatio);
state = State::loading;
FileSource* fs = util::ThreadContext::getFileSource();
req = fs->request({ Resource::Kind::Tile, url }, util::RunLoop::current.get()->get(), [url, callback, &worker, this](const Response &res) {
req = nullptr;
if (res.status != Response::Successful) {
std::stringstream message;
message << "Failed to load [" << url << "]: " << res.message;
setError(message.str());
callback();
return;
}
state = State::loaded;
data = res.data;
// Schedule tile parsing in another thread
reparse(worker, callback);
});
}
void TileData::cancel() {
if (state != State::obsolete) {
state = State::obsolete;
@@ -80,15 +47,6 @@ void TileData::endParsing() {
parsing.clear(std::memory_order_release);
}
bool TileData::reparse(Worker& worker, std::function<void()> callback) {
if (!mayStartParsing()) {
return false;
}
workRequest = worker.send([this] { parse(); endParsing(); }, callback);
return true;
}
void TileData::setError(const std::string& message) {
error = message;
setState(State::obsolete);