Skip to content

Commit

Permalink
Merge pull request #1014 from tangrams/raw-datasources
Browse files Browse the repository at this point in the history
DataSource refactoring
  • Loading branch information
tallytalwar authored Jan 12, 2017
2 parents 3a4142f + 0302990 commit 6b23cc0
Show file tree
Hide file tree
Showing 42 changed files with 797 additions and 674 deletions.
18 changes: 9 additions & 9 deletions android/tangram/src/main/cpp/jniExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,29 +357,29 @@ extern "C" {
map->markerRemoveAll();
}

JNIEXPORT jlong JNICALL Java_com_mapzen_tangram_MapController_nativeAddDataSource(JNIEnv* jniEnv, jobject obj, jlong mapPtr, jstring name) {
JNIEXPORT jlong JNICALL Java_com_mapzen_tangram_MapController_nativeAddTileSource(JNIEnv* jniEnv, jobject obj, jlong mapPtr, jstring name) {
assert(mapPtr > 0);
auto map = reinterpret_cast<Tangram::Map*>(mapPtr);
auto sourceName = stringFromJString(jniEnv, name);
auto source = std::shared_ptr<Tangram::DataSource>(new Tangram::ClientGeoJsonSource(sourceName, ""));
map->addDataSource(source);
auto source = std::shared_ptr<Tangram::TileSource>(new Tangram::ClientGeoJsonSource(sourceName, ""));
map->addTileSource(source);
return reinterpret_cast<jlong>(source.get());
}

JNIEXPORT void JNICALL Java_com_mapzen_tangram_MapController_nativeRemoveDataSource(JNIEnv* jniEnv, jobject obj, jlong mapPtr, jlong sourcePtr) {
JNIEXPORT void JNICALL Java_com_mapzen_tangram_MapController_nativeRemoveTileSource(JNIEnv* jniEnv, jobject obj, jlong mapPtr, jlong sourcePtr) {
assert(mapPtr > 0);
auto map = reinterpret_cast<Tangram::Map*>(mapPtr);
assert(sourcePtr > 0);
auto source = reinterpret_cast<Tangram::DataSource*>(sourcePtr);
map->removeDataSource(*source);
auto source = reinterpret_cast<Tangram::TileSource*>(sourcePtr);
map->removeTileSource(*source);
}

JNIEXPORT void JNICALL Java_com_mapzen_tangram_MapController_nativeClearDataSource(JNIEnv* jniEnv, jobject obj, jlong mapPtr, jlong sourcePtr) {
JNIEXPORT void JNICALL Java_com_mapzen_tangram_MapController_nativeClearTileSource(JNIEnv* jniEnv, jobject obj, jlong mapPtr, jlong sourcePtr) {
assert(mapPtr > 0);
auto map = reinterpret_cast<Tangram::Map*>(mapPtr);
assert(sourcePtr > 0);
auto source = reinterpret_cast<Tangram::DataSource*>(sourcePtr);
map->clearDataSource(*source, true, true);
auto source = reinterpret_cast<Tangram::TileSource*>(sourcePtr);
map->clearTileSource(*source, true, true);
}

JNIEXPORT void JNICALL Java_com_mapzen_tangram_MapController_nativeAddFeature(JNIEnv* jniEnv, jobject obj, jlong mapPtr, jlong sourcePtr,
Expand Down
30 changes: 15 additions & 15 deletions android/tangram/src/main/java/com/mapzen/tangram/MapController.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,14 @@ void dispose() {
public void run() {
// Dispose each data sources by first removing it from the HashMap values and then
// calling remove(), so that we don't improperly modify the HashMap while iterating.
for (Iterator<MapData> it = clientDataSources.values().iterator(); it.hasNext();) {
for (Iterator<MapData> it = clientTileSources.values().iterator(); it.hasNext();) {
MapData mapData = it.next();
it.remove();
mapData.remove();
}
nativeDispose(mapPointer);
mapPointer = 0;
clientDataSources.clear();
clientTileSources.clear();
markers.clear();
}
});
Expand Down Expand Up @@ -490,17 +490,17 @@ public PointF lngLatToScreenPosition(LngLat lngLat) {
* object will be returned.
*/
public MapData addDataLayer(String name) {
MapData mapData = clientDataSources.get(name);
MapData mapData = clientTileSources.get(name);
if (mapData != null) {
return mapData;
}
checkPointer(mapPointer);
long pointer = nativeAddDataSource(mapPointer, name);
long pointer = nativeAddTileSource(mapPointer, name);
if (pointer <= 0) {
throw new RuntimeException("Unable to create new data source");
}
mapData = new MapData(name, pointer, this);
clientDataSources.put(name, mapData);
clientTileSources.put(name, mapData);
return mapData;
}

Expand All @@ -509,10 +509,10 @@ public MapData addDataLayer(String name) {
* @param mapData The {@code MapData} to remove
*/
void removeDataLayer(MapData mapData) {
clientDataSources.remove(mapData.name);
clientTileSources.remove(mapData.name);
checkPointer(mapPointer);
checkPointer(mapData.pointer);
nativeRemoveDataSource(mapPointer, mapData.pointer);
nativeRemoveTileSource(mapPointer, mapData.pointer);
}

/**
Expand Down Expand Up @@ -841,16 +841,16 @@ public void useCachedGlState(boolean use) {
// Package private methods
// =======================

void removeDataSource(long sourcePtr) {
void removeTileSource(long sourcePtr) {
checkPointer(mapPointer);
checkPointer(sourcePtr);
nativeRemoveDataSource(mapPointer, sourcePtr);
nativeRemoveTileSource(mapPointer, sourcePtr);
}

void clearDataSource(long sourcePtr) {
void clearTileSource(long sourcePtr) {
checkPointer(mapPointer);
checkPointer(sourcePtr);
nativeClearDataSource(mapPointer, sourcePtr);
nativeClearTileSource(mapPointer, sourcePtr);
}

void addFeature(long sourcePtr, double[] coordinates, int[] rings, String[] properties) {
Expand Down Expand Up @@ -1007,9 +1007,9 @@ Marker markerById(long markerId) {
private native void nativeOnUrlSuccess(byte[] rawDataBytes, long callbackPtr);
private native void nativeOnUrlFailure(long callbackPtr);

synchronized native long nativeAddDataSource(long mapPtr, String name);
synchronized native void nativeRemoveDataSource(long mapPtr, long sourcePtr);
synchronized native void nativeClearDataSource(long mapPtr, long sourcePtr);
synchronized native long nativeAddTileSource(long mapPtr, String name);
synchronized native void nativeRemoveTileSource(long mapPtr, long sourcePtr);
synchronized native void nativeClearTileSource(long mapPtr, long sourcePtr);
synchronized native void nativeAddFeature(long mapPtr, long sourcePtr, double[] coordinates, int[] rings, String[] properties);
synchronized native void nativeAddGeoJson(long mapPtr, long sourcePtr, String geoJson);

Expand All @@ -1033,7 +1033,7 @@ Marker markerById(long markerId) {
private ViewCompleteListener viewCompleteListener;
private FrameCaptureCallback frameCaptureCallback;
private boolean frameCaptureAwaitCompleteView;
private Map<String, MapData> clientDataSources = new HashMap<>();
private Map<String, MapData> clientTileSources = new HashMap<>();
private Map<Long, Marker> markers = new HashMap<>();

// GLSurfaceView.Renderer methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public MapData addGeoJson(String data) {
* @return This object, for chaining.
*/
public MapData clear() {
map.clearDataSource(pointer);
map.clearTileSource(pointer);
return this;
}

Expand Down
10 changes: 5 additions & 5 deletions bench/src/tileLoading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "gl.h"
#include "platform.h"
#include "log.h"
#include "data/dataSource.h"
#include "data/tileSource.h"
#include "scene/sceneLoader.h"
#include "scene/scene.h"
#include "style/style.h"
Expand Down Expand Up @@ -30,7 +30,7 @@ struct TestContext {
std::shared_ptr<Scene> scene;
StyleContext styleContext;

std::shared_ptr<DataSource> source;
std::shared_ptr<TileSource> source;

std::vector<char> rawTileData;

Expand All @@ -54,7 +54,7 @@ struct TestContext {
styleContext.initFunctions(*scene);
styleContext.setKeywordZoom(0);

source = *scene->dataSources().begin();
source = *scene->tileSources().begin();
tileBuilder = std::make_unique<TileBuilder>(scene);
}

Expand All @@ -76,9 +76,9 @@ struct TestContext {

void parseTile() {
Tile tile({0,0,10,10,0}, s_projection);
source = *scene->dataSources().begin();
source = *scene->tileSources().begin();
auto task = source->createTask(tile.getID());
auto& t = dynamic_cast<DownloadTileTask&>(*task);
auto& t = dynamic_cast<BinaryTileTask&>(*task);
t.rawTileData = std::make_shared<std::vector<char>>(rawTileData);

tileData = source->parse(*task, s_projection);
Expand Down
15 changes: 10 additions & 5 deletions core/src/data/clientGeoJsonSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Point transformPoint(geojsonvt::TilePoint pt) {
// TODO: pass scene's resourcePath to constructor to be used with `stringFromFile`
ClientGeoJsonSource::ClientGeoJsonSource(const std::string& _name, const std::string& _url,
int32_t _minDisplayZoom, int32_t _maxDisplayZoom, int32_t _maxZoom)
: DataSource(_name, _url, _minDisplayZoom, _maxDisplayZoom, _maxZoom) {
: TileSource(_name, nullptr, _minDisplayZoom, _maxDisplayZoom, _maxZoom) {

// TODO: handle network url for client datasource data
// TODO: generic uri handling
Expand Down Expand Up @@ -74,15 +74,20 @@ void ClientGeoJsonSource::addData(const std::string& _data) {

}

bool ClientGeoJsonSource::loadTileData(std::shared_ptr<TileTask>&& _task, TileTaskCb _cb) {
void ClientGeoJsonSource::loadTileData(std::shared_ptr<TileTask> _task, TileTaskCb _cb) {

if (m_hasPendingData) {
return false;
return;
}

_cb.func(std::move(_task));
if (_task->needsLoading()) {
_task->startedLoading();

return true;
_cb.func(_task);
}

// Load subsources
TileSource::loadTileData(_task, _cb);
}

void ClientGeoJsonSource::clearData() {
Expand Down
6 changes: 3 additions & 3 deletions core/src/data/clientGeoJsonSource.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "dataSource.h"
#include "tileSource.h"
#include "util/types.h"

#include <mutex>
Expand All @@ -19,7 +19,7 @@ using GeoJSONVT = mapbox::util::geojsonvt::GeoJSONVT;

struct Properties;

class ClientGeoJsonSource : public DataSource {
class ClientGeoJsonSource : public TileSource {

public:

Expand All @@ -33,7 +33,7 @@ class ClientGeoJsonSource : public DataSource {
void addLine(const Properties& _tags, const Coordinates& _line);
void addPoly(const Properties& _tags, const std::vector<Coordinates>& _poly);

virtual bool loadTileData(std::shared_ptr<TileTask>&& _task, TileTaskCb _cb) override;
virtual void loadTileData(std::shared_ptr<TileTask> _task, TileTaskCb _cb) override;
std::shared_ptr<TileTask> createTask(TileID _tileId, int _subTask) override;

virtual void cancelLoadingTile(const TileID& _tile) override {};
Expand Down
Loading

0 comments on commit 6b23cc0

Please sign in to comment.