summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSudarsana Babu Nagineni <sudarsana.babu@mapbox.com>2019-08-22 11:42:09 +0300
committerSudarsana Babu Nagineni <sudarsana.babu@mapbox.com>2019-08-22 17:56:13 +0300
commit0baaf6396856b3e31c07607d4b1d44139cc2bae5 (patch)
treeeee4427eacb9f32c2b64e98b0c92e25e50c2402e
parent4a05d58df6b2736a56015eea7dd9433ca822573a (diff)
downloadqtlocation-mapboxgl-upstream/nagineni-jni-refactor.tar.gz
[android] jni binding refactorupstream/nagineni-jni-refactor
Move registerNatives() call to a separate file to remove native headers dependency from jni.cpp.
-rw-r--r--platform/android/core-files.json2
-rwxr-xr-xplatform/android/src/jni.cpp157
-rw-r--r--platform/android/src/jni.hpp3
-rw-r--r--platform/android/src/main.cpp3
-rwxr-xr-xplatform/android/src/native.cpp162
-rw-r--r--platform/android/src/native.hpp11
6 files changed, 178 insertions, 160 deletions
diff --git a/platform/android/core-files.json b/platform/android/core-files.json
index 62ecc0c671..ea226c20ec 100644
--- a/platform/android/core-files.json
+++ b/platform/android/core-files.json
@@ -44,6 +44,7 @@
"platform/android/src/map/image.cpp",
"platform/android/src/map_renderer.cpp",
"platform/android/src/map_renderer_runnable.cpp",
+ "platform/android/src/native.cpp",
"platform/android/src/native_map_view.cpp",
"platform/android/src/run_loop.cpp",
"platform/android/src/snapshotter/map_snapshot.cpp",
@@ -147,6 +148,7 @@
"map/image.hpp": "platform/android/src/map/image.hpp",
"map_renderer.hpp": "platform/android/src/map_renderer.hpp",
"map_renderer_runnable.hpp": "platform/android/src/map_renderer_runnable.hpp",
+ "native.hpp": "platform/android/src/native.hpp",
"native_map_view.hpp": "platform/android/src/native_map_view.hpp",
"run_loop_impl.hpp": "platform/android/src/run_loop_impl.hpp",
"snapshotter/map_snapshot.hpp": "platform/android/src/snapshotter/map_snapshot.hpp",
diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp
index 088b3b796c..189ec29dce 100755
--- a/platform/android/src/jni.cpp
+++ b/platform/android/src/jni.cpp
@@ -2,66 +2,9 @@
#include <mbgl/util/logging.hpp>
-#include "annotation/marker.hpp"
-#include "annotation/polygon.hpp"
-#include "annotation/polyline.hpp"
-#include "bitmap.hpp"
-#include "bitmap_factory.hpp"
-#include "connectivity_listener.hpp"
-#include "conversion/conversion.hpp"
-#include "conversion/collection.hpp"
-#include "file_source.hpp"
-#include "geojson/feature.hpp"
-#include "geojson/feature_collection.hpp"
-#include "geojson/geometry.hpp"
-#include "geojson/geometry_collection.hpp"
-#include "geojson/line_string.hpp"
-#include "geojson/multi_line_string.hpp"
-#include "geojson/multi_point.hpp"
-#include "geojson/multi_polygon.hpp"
-#include "geojson/point.hpp"
-#include "geojson/polygon.hpp"
-#include "geometry/lat_lng.hpp"
-#include "geometry/lat_lng_bounds.hpp"
-#include "geometry/lat_lng_quad.hpp"
-#include "geometry/projected_meters.hpp"
-#include "graphics/pointf.hpp"
-#include "graphics/rectf.hpp"
-#include "gson/json_array.hpp"
-#include "gson/json_element.hpp"
-#include "gson/json_object.hpp"
-#include "gson/json_primitive.hpp"
-#include "java_types.hpp"
-#include "map_renderer.hpp"
-#include "map_renderer_runnable.hpp"
-#include "native_map_view.hpp"
-#ifndef MBGL_MODULE_OFFLINE_DISABLE
-#include "offline/offline_manager.hpp"
-#include "offline/offline_region.hpp"
-#include "offline/offline_region_definition.hpp"
-#include "offline/offline_region_error.hpp"
-#include "offline/offline_region_status.hpp"
-#endif
-#include "style/transition_options.hpp"
-#include "style/layers/layer_manager.hpp"
-#include "style/sources/source.hpp"
-#include "style/light.hpp"
-#include "style/formatted.hpp"
-#include "style/formatted_section.hpp"
-#ifndef MBGL_MODULE_SNAPSHOT_DISABLE
-#include "snapshotter/map_snapshotter.hpp"
-#include "snapshotter/map_snapshot.hpp"
-#endif
-#include "text/collator_jni.hpp"
-#include "text/local_glyph_rasterizer_jni.hpp"
-#include "text/format_number_jni.hpp"
-#include "logger.hpp"
-
namespace mbgl {
namespace android {
-void RegisterNativeHTTPRequest(JNIEnv&);
-
JavaVM* theJVM;
//TODO: remove
@@ -107,105 +50,5 @@ void detach_jni_thread(JavaVM* vm, JNIEnv** env, bool detach) {
*env = nullptr;
}
-void registerNatives(JavaVM *vm) {
- theJVM = vm;
-
- jni::JNIEnv& env = jni::GetEnv(*vm, jni::jni_version_1_6);
-
- // For the DefaultFileSource
- static mbgl::util::RunLoop mainRunLoop;
- FileSource::registerNative(env);
-
- // Basic types
- java::registerNatives(env);
- java::util::registerNative(env);
- PointF::registerNative(env);
- RectF::registerNative(env);
-
- // GeoJSON
- geojson::Feature::registerNative(env);
- geojson::FeatureCollection::registerNative(env);
- geojson::Geometry::registerNative(env);
- geojson::GeometryCollection::registerNative(env);
- geojson::LineString::registerNative(env);
- geojson::MultiLineString::registerNative(env);
- geojson::MultiPoint::registerNative(env);
- geojson::MultiPolygon::registerNative(env);
- geojson::Point::registerNative(env);
- geojson::Polygon::registerNative(env);
-
- // Geometry
- LatLng::registerNative(env);
- LatLngBounds::registerNative(env);
- LatLngQuad::registerNative(env);
- ProjectedMeters::registerNative(env);
-
- // GSon
- gson::JsonArray::registerNative(env);
- gson::JsonElement::registerNative(env);
- gson::JsonObject::registerNative(env);
- gson::JsonPrimitive::registerNative(env);
-
- //Annotation
- Marker::registerNative(env);
- Polygon::registerNative(env);
- Polyline::registerNative(env);
-
- // Map
- MapRenderer::registerNative(env);
- MapRendererRunnable::registerNative(env);
- NativeMapView::registerNative(env);
-
- // Http
- RegisterNativeHTTPRequest(env);
-
- // Bitmap
- Bitmap::registerNative(env);
- BitmapFactory::registerNative(env);
-
- // Style
- TransitionOptions::registerNative(env);
- LayerManagerAndroid::get()->registerNative(env);
- Source::registerNative(env);
- Light::registerNative(env);
- Position::registerNative(env);
- Formatted::registerNative(env);
- FormattedSection::registerNative(env);
-
- // Map
- CameraPosition::registerNative(env);
- Image::registerNative(env);
-
- // Connectivity
- ConnectivityListener::registerNative(env);
-
- // Offline
-#ifndef MBGL_MODULE_OFFLINE_DISABLE
- OfflineManager::registerNative(env);
- OfflineRegion::registerNative(env);
- OfflineRegionDefinition::registerNative(env);
- OfflineTilePyramidRegionDefinition::registerNative(env);
- OfflineGeometryRegionDefinition::registerNative(env);
- OfflineRegionError::registerNative(env);
- OfflineRegionStatus::registerNative(env);
-#endif
-
- // Snapshotter
-#ifndef MBGL_MODULE_SNAPSHOT_DISABLE
- MapSnapshotter::registerNative(env);
- MapSnapshot::registerNative(env);
-#endif
-
- // text
- LocalGlyphRasterizer::registerNative(env);
- Locale::registerNative(env);
- Collator::registerNative(env);
- StringUtils::registerNative(env);
- NumberFormat::registerNative(env);
-
- // Logger
- Logger::registerNative(env);
-}
-
} // namespace android
} // namespace mbgl
diff --git a/platform/android/src/jni.hpp b/platform/android/src/jni.hpp
index e5df92e701..cb519f911d 100644
--- a/platform/android/src/jni.hpp
+++ b/platform/android/src/jni.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <string>
+#include <jni/jni.hpp>
typedef struct _jmethodID* jmethodID;
typedef struct _JavaVM JavaVM;
@@ -17,7 +18,5 @@ extern std::string dataPath;
bool attach_jni_thread(JavaVM* vm, JNIEnv** env, std::string threadName);
void detach_jni_thread(JavaVM* vm, JNIEnv** env, bool detach);
-extern void registerNatives(JavaVM* vm);
-
} // namespace android
} // namespace mbgl
diff --git a/platform/android/src/main.cpp b/platform/android/src/main.cpp
index 03a8288719..80dc767ec1 100644
--- a/platform/android/src/main.cpp
+++ b/platform/android/src/main.cpp
@@ -1,9 +1,10 @@
#include "jni.hpp"
+#include "native.hpp"
#include <jni/jni.hpp>
extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *) {
assert(vm != nullptr);
+ mbgl::android::theJVM = vm;
mbgl::android::registerNatives(vm);
return JNI_VERSION_1_6;
}
-
diff --git a/platform/android/src/native.cpp b/platform/android/src/native.cpp
new file mode 100755
index 0000000000..c79a2536e6
--- /dev/null
+++ b/platform/android/src/native.cpp
@@ -0,0 +1,162 @@
+#include "native.hpp"
+
+#include "annotation/marker.hpp"
+#include "annotation/polygon.hpp"
+#include "annotation/polyline.hpp"
+#include "bitmap.hpp"
+#include "bitmap_factory.hpp"
+#include "connectivity_listener.hpp"
+#include "conversion/conversion.hpp"
+#include "conversion/collection.hpp"
+#include "file_source.hpp"
+#include "geojson/feature.hpp"
+#include "geojson/feature_collection.hpp"
+#include "geojson/geometry.hpp"
+#include "geojson/geometry_collection.hpp"
+#include "geojson/line_string.hpp"
+#include "geojson/multi_line_string.hpp"
+#include "geojson/multi_point.hpp"
+#include "geojson/multi_polygon.hpp"
+#include "geojson/point.hpp"
+#include "geojson/polygon.hpp"
+#include "geometry/lat_lng.hpp"
+#include "geometry/lat_lng_bounds.hpp"
+#include "geometry/lat_lng_quad.hpp"
+#include "geometry/projected_meters.hpp"
+#include "graphics/pointf.hpp"
+#include "graphics/rectf.hpp"
+#include "gson/json_array.hpp"
+#include "gson/json_element.hpp"
+#include "gson/json_object.hpp"
+#include "gson/json_primitive.hpp"
+#include "java_types.hpp"
+#include "map_renderer.hpp"
+#include "map_renderer_runnable.hpp"
+#include "native_map_view.hpp"
+#ifndef MBGL_MODULE_OFFLINE_DISABLE
+#include "offline/offline_manager.hpp"
+#include "offline/offline_region.hpp"
+#include "offline/offline_region_definition.hpp"
+#include "offline/offline_region_error.hpp"
+#include "offline/offline_region_status.hpp"
+#endif
+#include "style/transition_options.hpp"
+#include "style/layers/layer_manager.hpp"
+#include "style/sources/source.hpp"
+#include "style/light.hpp"
+#include "style/formatted.hpp"
+#include "style/formatted_section.hpp"
+#ifndef MBGL_MODULE_SNAPSHOT_DISABLE
+#include "snapshotter/map_snapshotter.hpp"
+#include "snapshotter/map_snapshot.hpp"
+#endif
+#include "text/collator_jni.hpp"
+#include "text/local_glyph_rasterizer_jni.hpp"
+#include "text/format_number_jni.hpp"
+#include "logger.hpp"
+
+namespace mbgl {
+namespace android {
+
+void RegisterNativeHTTPRequest(JNIEnv&);
+
+void registerNatives(JavaVM *vm) {
+ jni::JNIEnv& env = jni::GetEnv(*vm, jni::jni_version_1_6);
+
+ // For the DefaultFileSource
+ static mbgl::util::RunLoop mainRunLoop;
+ FileSource::registerNative(env);
+
+ // Basic types
+ java::registerNatives(env);
+ java::util::registerNative(env);
+ PointF::registerNative(env);
+ RectF::registerNative(env);
+
+ // GeoJSON
+ geojson::Feature::registerNative(env);
+ geojson::FeatureCollection::registerNative(env);
+ geojson::Geometry::registerNative(env);
+ geojson::GeometryCollection::registerNative(env);
+ geojson::LineString::registerNative(env);
+ geojson::MultiLineString::registerNative(env);
+ geojson::MultiPoint::registerNative(env);
+ geojson::MultiPolygon::registerNative(env);
+ geojson::Point::registerNative(env);
+ geojson::Polygon::registerNative(env);
+
+ // Geometry
+ LatLng::registerNative(env);
+ LatLngBounds::registerNative(env);
+ LatLngQuad::registerNative(env);
+ ProjectedMeters::registerNative(env);
+
+ // GSon
+ gson::JsonArray::registerNative(env);
+ gson::JsonElement::registerNative(env);
+ gson::JsonObject::registerNative(env);
+ gson::JsonPrimitive::registerNative(env);
+
+ //Annotation
+ Marker::registerNative(env);
+ Polygon::registerNative(env);
+ Polyline::registerNative(env);
+
+ // Map
+ MapRenderer::registerNative(env);
+ MapRendererRunnable::registerNative(env);
+ NativeMapView::registerNative(env);
+
+ // Http
+ RegisterNativeHTTPRequest(env);
+
+ // Bitmap
+ Bitmap::registerNative(env);
+ BitmapFactory::registerNative(env);
+
+ // Style
+ TransitionOptions::registerNative(env);
+ LayerManagerAndroid::get()->registerNative(env);
+ Source::registerNative(env);
+ Light::registerNative(env);
+ Position::registerNative(env);
+ Formatted::registerNative(env);
+ FormattedSection::registerNative(env);
+
+ // Map
+ CameraPosition::registerNative(env);
+ Image::registerNative(env);
+
+ // Connectivity
+ ConnectivityListener::registerNative(env);
+
+ // Offline
+#ifndef MBGL_MODULE_OFFLINE_DISABLE
+ OfflineManager::registerNative(env);
+ OfflineRegion::registerNative(env);
+ OfflineRegionDefinition::registerNative(env);
+ OfflineTilePyramidRegionDefinition::registerNative(env);
+ OfflineGeometryRegionDefinition::registerNative(env);
+ OfflineRegionError::registerNative(env);
+ OfflineRegionStatus::registerNative(env);
+#endif
+
+ // Snapshotter
+#ifndef MBGL_MODULE_SNAPSHOT_DISABLE
+ MapSnapshotter::registerNative(env);
+ MapSnapshot::registerNative(env);
+#endif
+
+ // text
+ LocalGlyphRasterizer::registerNative(env);
+ Locale::registerNative(env);
+ Collator::registerNative(env);
+ StringUtils::registerNative(env);
+ NumberFormat::registerNative(env);
+
+ // Logger
+ Logger::registerNative(env);
+}
+
+} // namespace android
+} // namespace mbgl
diff --git a/platform/android/src/native.hpp b/platform/android/src/native.hpp
new file mode 100644
index 0000000000..3464e85b1d
--- /dev/null
+++ b/platform/android/src/native.hpp
@@ -0,0 +1,11 @@
+#pragma once
+
+#include "jni.hpp"
+
+namespace mbgl {
+namespace android {
+
+extern void registerNatives(JavaVM* vm);
+
+} // namespace android
+} // namespace mbgl