[core] move invariant Source ID from SourceInfo to Source
This commit is contained in:
committed by
John Firebaugh
parent
8cca5c89b2
commit
cef05b9017
@@ -112,8 +112,7 @@ std::unique_ptr<AnnotationTile> AnnotationManager::getTile(const TileID& tileID)
|
||||
void AnnotationManager::updateStyle(Style& style) {
|
||||
// Create annotation source, point layer, and point bucket
|
||||
if (!style.getSource(SourceID)) {
|
||||
std::unique_ptr<Source> source = std::make_unique<Source>(SourceType::Annotations);
|
||||
source->info.source_id = SourceID;
|
||||
std::unique_ptr<Source> source = std::make_unique<Source>(SourceType::Annotations, SourceID);
|
||||
source->enabled = true;
|
||||
style.addSource(std::move(source));
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ void parse(const JSValue& value, std::array<float, N>& target, const char* name)
|
||||
|
||||
} // end namespace
|
||||
|
||||
Source::Source(SourceType type_) : type(type_) {}
|
||||
Source::Source(SourceType type_, const std::string& id_) : type(type_), id(id_) {}
|
||||
|
||||
Source::~Source() = default;
|
||||
|
||||
@@ -334,7 +334,7 @@ TileData::State Source::addTile(const TileID& tileID, const StyleUpdateParameter
|
||||
|
||||
newTile->data = std::make_shared<VectorTileData>(normalizedID,
|
||||
std::move(monitor),
|
||||
info.source_id,
|
||||
id,
|
||||
parameters.style,
|
||||
parameters.mode,
|
||||
callback);
|
||||
@@ -591,7 +591,7 @@ void Source::tileLoadingCompleteCallback(const TileID& tileID, const TransformSt
|
||||
}
|
||||
|
||||
void Source::dumpDebugLogs() const {
|
||||
Log::Info(Event::General, "Source::id: %s", info.source_id.c_str());
|
||||
Log::Info(Event::General, "Source::id: %s", id.c_str());
|
||||
Log::Info(Event::General, "Source::loaded: %d", loaded);
|
||||
|
||||
for (const auto& tile : tiles) {
|
||||
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
virtual void onTileError(Source&, const TileID&, std::exception_ptr) {};
|
||||
};
|
||||
|
||||
Source(SourceType);
|
||||
Source(SourceType, const std::string& id);
|
||||
~Source();
|
||||
|
||||
void parseTileJSON(const JSValue&);
|
||||
@@ -70,6 +70,7 @@ public:
|
||||
void dumpDebugLogs() const;
|
||||
|
||||
const SourceType type;
|
||||
const std::string id;
|
||||
SourceInfo info;
|
||||
bool enabled = false;
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ public:
|
||||
std::string attribution;
|
||||
std::array<float, 3> center = { { 0, 0, 0 } };
|
||||
std::array<float, 4> bounds = { { -180, -90, 180, 90 } };
|
||||
std::string source_id = "";
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -194,7 +194,7 @@ void Style::recalculate(float z) {
|
||||
|
||||
Source* Style::getSource(const std::string& id) const {
|
||||
const auto it = std::find_if(sources.begin(), sources.end(), [&](const auto& source) {
|
||||
return source->info.source_id == id;
|
||||
return source->id == id;
|
||||
});
|
||||
|
||||
return it != sources.end() ? it->get() : nullptr;
|
||||
@@ -331,7 +331,7 @@ void Style::onSourceLoaded(Source& source) {
|
||||
void Style::onSourceError(Source& source, std::exception_ptr error) {
|
||||
lastError = error;
|
||||
Log::Error(Event::Style, "Failed to load source %s: %s",
|
||||
source.info.source_id.c_str(), util::toString(error).c_str());
|
||||
source.id.c_str(), util::toString(error).c_str());
|
||||
observer->onSourceError(source, error);
|
||||
observer->onResourceError(error);
|
||||
}
|
||||
@@ -348,7 +348,7 @@ void Style::onTileLoaded(Source& source, const TileID& tileID, bool isNewTile) {
|
||||
void Style::onTileError(Source& source, const TileID& tileID, std::exception_ptr error) {
|
||||
lastError = error;
|
||||
Log::Error(Event::Style, "Failed to load tile %s for source %s: %s",
|
||||
std::string(tileID).c_str(), source.info.source_id.c_str(), util::toString(error).c_str());
|
||||
std::string(tileID).c_str(), source.id.c_str(), util::toString(error).c_str());
|
||||
observer->onTileError(source, tileID, error);
|
||||
observer->onResourceError(error);
|
||||
}
|
||||
|
||||
@@ -68,8 +68,8 @@ void StyleParser::parseSources(const JSValue& value) {
|
||||
}
|
||||
|
||||
const auto type = SourceTypeClass({ typeVal.GetString(), typeVal.GetStringLength() });
|
||||
std::unique_ptr<Source> source = std::make_unique<Source>(type);
|
||||
source->info.source_id = { nameVal.GetString(), nameVal.GetStringLength() };
|
||||
const std::string id { nameVal.GetString(), nameVal.GetStringLength() };
|
||||
std::unique_ptr<Source> source = std::make_unique<Source>(type, id);
|
||||
|
||||
switch (type) {
|
||||
case SourceType::Vector:
|
||||
@@ -91,7 +91,7 @@ void StyleParser::parseSources(const JSValue& value) {
|
||||
Log::Warning(Event::ParseStyle, "source type %s is not supported", type.c_str());
|
||||
}
|
||||
|
||||
sourcesMap.emplace(source->info.source_id, source.get());
|
||||
sourcesMap.emplace(id, source.get());
|
||||
sources.emplace_back(std::move(source));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ TEST(ResourceLoading, RasterSourceFail) {
|
||||
ResourceLoadingTest test(MockFileSource::RequestFail, "source_raster.json");
|
||||
|
||||
test.observer.sourceError = [&] (Source& source, std::exception_ptr error) {
|
||||
EXPECT_EQ(source.info.source_id, "rastersource");
|
||||
EXPECT_EQ(source.id, "rastersource");
|
||||
EXPECT_EQ(util::toString(error), "Failed by the test case");
|
||||
test.end();
|
||||
};
|
||||
@@ -94,7 +94,7 @@ TEST(ResourceLoading, VectorSourceFail) {
|
||||
ResourceLoadingTest test(MockFileSource::RequestFail, "source_vector.json");
|
||||
|
||||
test.observer.sourceError = [&] (Source& source, std::exception_ptr error) {
|
||||
EXPECT_EQ(source.info.source_id, "vectorsource");
|
||||
EXPECT_EQ(source.id, "vectorsource");
|
||||
EXPECT_EQ(util::toString(error), "Failed by the test case");
|
||||
test.end();
|
||||
};
|
||||
@@ -128,7 +128,7 @@ TEST(ResourceLoading, RasterTileFail) {
|
||||
ResourceLoadingTest test(MockFileSource::RequestFail, "raster.png");
|
||||
|
||||
test.observer.tileError = [&] (Source& source, const TileID& tileID, std::exception_ptr error) {
|
||||
EXPECT_EQ(source.info.source_id, "rastersource");
|
||||
EXPECT_EQ(source.id, "rastersource");
|
||||
EXPECT_EQ(std::string(tileID), "0/0/0");
|
||||
EXPECT_EQ(util::toString(error), "Failed by the test case");
|
||||
test.end();
|
||||
@@ -141,7 +141,7 @@ TEST(ResourceLoading, VectorTileFail) {
|
||||
ResourceLoadingTest test(MockFileSource::RequestFail, "vector.pbf");
|
||||
|
||||
test.observer.tileError = [&] (Source& source, const TileID& tileID, std::exception_ptr error) {
|
||||
EXPECT_EQ(source.info.source_id, "vectorsource");
|
||||
EXPECT_EQ(source.id, "vectorsource");
|
||||
EXPECT_EQ(std::string(tileID), "0/0/0");
|
||||
EXPECT_EQ(util::toString(error), "Failed by the test case");
|
||||
test.end();
|
||||
@@ -166,7 +166,7 @@ TEST(ResourceLoading, RasterSourceCorrupt) {
|
||||
ResourceLoadingTest test(MockFileSource::RequestWithCorruptedData, "source_raster.json");
|
||||
|
||||
test.observer.sourceError = [&] (Source& source, std::exception_ptr error) {
|
||||
EXPECT_EQ(source.info.source_id, "rastersource");
|
||||
EXPECT_EQ(source.id, "rastersource");
|
||||
EXPECT_EQ(util::toString(error), "0 - Invalid value.");
|
||||
test.end();
|
||||
};
|
||||
@@ -178,7 +178,7 @@ TEST(ResourceLoading, VectorSourceCorrupt) {
|
||||
ResourceLoadingTest test(MockFileSource::RequestWithCorruptedData, "source_vector.json");
|
||||
|
||||
test.observer.sourceError = [&] (Source& source, std::exception_ptr error) {
|
||||
EXPECT_EQ(source.info.source_id, "vectorsource");
|
||||
EXPECT_EQ(source.id, "vectorsource");
|
||||
EXPECT_EQ(util::toString(error), "0 - Invalid value.");
|
||||
test.end();
|
||||
};
|
||||
@@ -213,7 +213,7 @@ TEST(ResourceLoading, RasterTileCorrupt) {
|
||||
ResourceLoadingTest test(MockFileSource::RequestWithCorruptedData, "raster.png");
|
||||
|
||||
test.observer.tileError = [&] (Source& source, const TileID& tileID, std::exception_ptr error) {
|
||||
EXPECT_EQ(source.info.source_id, "rastersource");
|
||||
EXPECT_EQ(source.id, "rastersource");
|
||||
EXPECT_EQ(std::string(tileID), "0/0/0");
|
||||
EXPECT_TRUE(bool(error));
|
||||
// Not asserting on platform-specific error text.
|
||||
@@ -227,7 +227,7 @@ TEST(ResourceLoading, VectorTileCorrupt) {
|
||||
ResourceLoadingTest test(MockFileSource::RequestWithCorruptedData, "vector.pbf");
|
||||
|
||||
test.observer.tileError = [&] (Source& source, const TileID& tileID, std::exception_ptr error) {
|
||||
EXPECT_EQ(source.info.source_id, "vectorsource");
|
||||
EXPECT_EQ(source.id, "vectorsource");
|
||||
EXPECT_EQ(std::string(tileID), "0/0/0");
|
||||
EXPECT_EQ(util::toString(error), "pbf unknown field type exception");
|
||||
test.end();
|
||||
|
||||
Reference in New Issue
Block a user