From 86f3b5ffee6a34b8e11d48e8ee49e615837b3043 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 1 May 2012 20:49:45 +0200 Subject: [PATCH] Fix build --- OsmAnd/.cproject | 2 +- OsmAnd/.project | 4 +- Osmand-kernel/osmand/Makefile | 4 +- Osmand-kernel/osmand/src/binaryRead.cpp | 123 ++++++++++++------------ Osmand-kernel/osmand/src/binaryRead.h | 22 ++++- Osmand-kernel/osmand/src/common.h | 52 +++++----- 6 files changed, 109 insertions(+), 98 deletions(-) diff --git a/OsmAnd/.cproject b/OsmAnd/.cproject index 8f6765b984..9ad6c99d07 100644 --- a/OsmAnd/.cproject +++ b/OsmAnd/.cproject @@ -20,7 +20,7 @@ - + diff --git a/OsmAnd/.project b/OsmAnd/.project index 990ad94e42..54da46b446 100644 --- a/OsmAnd/.project +++ b/OsmAnd/.project @@ -7,7 +7,7 @@ org.eclipse.cdt.managedbuilder.core.genmakebuilder - full,incremental, + ?children? @@ -47,7 +47,7 @@ org.eclipse.cdt.make.core.enableFullBuild - true + false org.eclipse.cdt.make.core.fullBuildTarget diff --git a/Osmand-kernel/osmand/Makefile b/Osmand-kernel/osmand/Makefile index ef40470b3a..49a4c29883 100644 --- a/Osmand-kernel/osmand/Makefile +++ b/Osmand-kernel/osmand/Makefile @@ -20,8 +20,8 @@ CPPFLAGS := \ -DSK_ALLOW_STATIC_GLOBAL_INITIALIZERS=0 \ -DSK_RELEASE \ -DGR_RELEASE=1 \ - -c -fpic -I$(JAVA_HOME)/include \ - -DHAVING_HASH \ + -c -Fpic -I$(JAVA_HOME)/include \ + -DHASH_MAP_GNU \ $(C_INCLUDES) target : ../$(RUNFILE) diff --git a/Osmand-kernel/osmand/src/binaryRead.cpp b/Osmand-kernel/osmand/src/binaryRead.cpp index 8b98e23980..723f43dd25 100644 --- a/Osmand-kernel/osmand/src/binaryRead.cpp +++ b/Osmand-kernel/osmand/src/binaryRead.cpp @@ -2,29 +2,26 @@ #define _OSMAND_BINARY_READ #include "binaryRead.h" -#include "osmand_log.h" -#include "google/protobuf/io/zero_copy_stream_impl.h" +#include #include "google/protobuf/wire_format_lite.h" +#include "google/protobuf/io/zero_copy_stream_impl.h" #include "google/protobuf/wire_format_lite.cc" - -#include "renderRules.h" -#include "common.h" -#include "mapObjects.h" -#include "multipolygons.h" #include "proto/osmand_odb.pb.h" -using namespace std; +#include "osmand_log.h" +using namespace std; #define DO_(EXPRESSION) if (!(EXPRESSION)) return false -using namespace google::protobuf; -using namespace google::protobuf::internal; +using google::protobuf::io::CodedInputStream; +using google::protobuf::io::FileInputStream; +using google::protobuf::internal::WireFormatLite; +//using namespace google::protobuf::internal; static const int MAP_VERSION = 2; static const int BASEMAP_ZOOM = 11; -struct BinaryMapFile; -std::map openFiles; +std::map< std::string, BinaryMapFile* > openFiles; -inline bool readInt(io::CodedInputStream* input, uint32* sz) { +inline bool readInt(CodedInputStream* input, uint32* sz ){ uint8 buf[4]; if (!input->ReadRaw(buf, 4)) { return false; @@ -33,7 +30,7 @@ inline bool readInt(io::CodedInputStream* input, uint32* sz) { return true; } -bool skipFixed32(io::CodedInputStream* input) { +bool skipFixed32(CodedInputStream* input) { uint32 sz; if (!readInt(input, &sz)) { return false; @@ -41,7 +38,7 @@ bool skipFixed32(io::CodedInputStream* input) { return input->Skip(sz); } -bool skipUnknownFields(io::CodedInputStream* input, int tag) { +bool skipUnknownFields(CodedInputStream* input, int tag) { if (WireFormatLite::GetTagWireType(tag) == WireFormatLite::WIRETYPE_FIXED32_LENGTH_DELIMITED) { if (!skipFixed32(input)) { return false; @@ -92,7 +89,7 @@ struct SearchQuery { }; -bool readMapTreeBounds(io::CodedInputStream* input, MapTreeBounds* tree, MapRoot* root) { +bool readMapTreeBounds(CodedInputStream* input, MapTreeBounds* tree, MapRoot* root) { int init = 0; int tag; int32 si; @@ -139,7 +136,7 @@ bool readMapTreeBounds(io::CodedInputStream* input, MapTreeBounds* tree, MapRoot return true; } -bool readMapLevel(io::CodedInputStream* input, MapRoot* root) { +bool readMapLevel(CodedInputStream* input, MapRoot* root) { int tag; int si; while ((tag = input->ReadTag()) != 0) { @@ -203,7 +200,7 @@ bool readMapLevel(io::CodedInputStream* input, MapRoot* root) { return true; } -bool readMapEncodingRule(io::CodedInputStream* input, MapIndex* index, uint32 id) { +bool readMapEncodingRule(CodedInputStream* input, MapIndex* index, uint32 id) { int tag; std::string tagS; std::string value; @@ -242,7 +239,7 @@ bool readMapEncodingRule(io::CodedInputStream* input, MapIndex* index, uint32 id return true; } -bool readMapIndex(io::CodedInputStream* input, MapIndex* mapIndex) { +bool readMapIndex(CodedInputStream* input, MapIndex* mapIndex) { uint32 tag; uint32 defaultId = 1; while ((tag = input->ReadTag()) != 0) { @@ -288,7 +285,7 @@ bool readMapIndex(io::CodedInputStream* input, MapIndex* mapIndex) { //display google::protobuf::internal::WireFormatLite::GetTagWireType(tag) // display google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag) -bool initMapStructure(io::CodedInputStream* input, BinaryMapFile* file) { +bool initMapStructure(CodedInputStream* input, BinaryMapFile* file) { uint32 tag; uint32 version = -1; uint32 versionConfirm = -2; @@ -347,7 +344,7 @@ extern "C" JNIEXPORT void JNICALL Java_net_osmand_plus_render_NativeOsmandLibrar } } -bool readStringTable(io::CodedInputStream* input, std::vector& list) { +bool readStringTable(CodedInputStream* input, std::vector& list) { uint32 tag; while ((tag = input->ReadTag()) != 0) { switch (WireFormatLite::GetTagFieldNumber(tag)) { @@ -395,7 +392,7 @@ bool acceptTypes(SearchQuery* req, std::vector& types, MapIndex* root return false; } -MapDataObject* readMapDataObject(io::CodedInputStream* input, MapTreeBounds* tree, SearchQuery* req, +MapDataObject* readMapDataObject(CodedInputStream* input, MapTreeBounds* tree, SearchQuery* req, MapIndex* root) { uint32 tag = WireFormatLite::GetTagFieldNumber(input->ReadTag()); bool area = MapData::kAreaCoordinatesFieldNumber == tag; @@ -557,7 +554,7 @@ MapDataObject* readMapDataObject(io::CodedInputStream* input, MapTreeBounds* tre -bool searchMapTreeBounds(io::CodedInputStream* input, MapTreeBounds* current, MapTreeBounds* parent, +bool searchMapTreeBounds(CodedInputStream* input, MapTreeBounds* current, MapTreeBounds* parent, SearchQuery* req, std::vector* foundSubtrees) { int init = 0; int tag; @@ -645,7 +642,7 @@ bool searchMapTreeBounds(io::CodedInputStream* input, MapTreeBounds* current, Ma return true; } -bool readMapDataBlocks(io::CodedInputStream* input, SearchQuery* req, MapTreeBounds* tree, MapIndex* root) { +bool readMapDataBlocks(CodedInputStream* input, SearchQuery* req, MapTreeBounds* tree, MapIndex* root) { long long baseId = 0; int tag; std::vector< MapDataObject* > results; @@ -711,7 +708,7 @@ bool readMapDataBlocks(io::CodedInputStream* input, SearchQuery* req, MapTreeBou bool sortTreeBounds (const MapTreeBounds& i,const MapTreeBounds& j) { return (i.mapDataBlock::iterator i = root->bounds.begin(); i != root->bounds.end(); i++) { @@ -746,9 +743,7 @@ void searchMapData(io::CodedInputStream* input, MapRoot* root, MapIndex* ind, Se } - - -extern "C" JNIEXPORT jint JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_searchNativeObjectsForRendering(JNIEnv* ienv, +JNIEXPORT jint JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_searchNativeObjectsForRendering(JNIEnv* ienv, jobject obj, jint sleft, jint sright, jint stop, jint sbottom, jint zoom, jobject renderingRuleSearchRequest, bool skipDuplicates, jobject objInterrupted, jstring msgNothingFound) { RenderingRuleSearchRequest* req = initSearchRequest(ienv, renderingRuleSearchRequest); @@ -759,6 +754,14 @@ extern "C" JNIEXPORT jint JNICALL Java_net_osmand_plus_render_NativeOsmandLibrar SearchQuery q(sleft, sright, stop, sbottom, req, objInterrupted, interruptedField, ienv); q.zoom = zoom; + SearchResult* res = searchObjectsForRendering(&q, req, skipDuplicates, getString(ienv, msgNothingFound)); + delete req; + return (jint) res; +} + + +SearchResult* searchObjectsForRendering(SearchQuery* q, RenderingRuleSearchRequest* req, + bool skipDuplicates, std::string msgNothingFound) { SearchResult* searchRes = new SearchResult(); map::iterator i = openFiles.begin(); HMAP::hash_set ids; @@ -769,40 +772,40 @@ extern "C" JNIEXPORT jint JNICALL Java_net_osmand_plus_render_NativeOsmandLibrar std::vector coastLines; std::vector basemapCoastLines; - for (; i != openFiles.end() && !q.isCancelled(); i++) { + for (; i != openFiles.end() && !q->isCancelled(); i++) { BinaryMapFile* file = i->second; fseek(file->f, 0, 0); - io::FileInputStream input(fileno(file->f)); + FileInputStream input(fileno(file->f)); input.SetCloseOnDelete(false); - io::CodedInputStream cis(&input); + CodedInputStream cis(&input); cis.SetTotalBytesLimit(INT_MAX, INT_MAX >> 2); if (req != NULL) { req->clearState(); } - q.result.clear(); + q->result.clear(); for (std::vector::iterator mapIndex = file->mapIndexes.begin(); mapIndex != file->mapIndexes.end(); mapIndex++) { for (std::vector::iterator mapLevel = mapIndex->levels.begin(); mapLevel != mapIndex->levels.end(); mapLevel++) { - if (q.isCancelled()) { + if (q->isCancelled()) { break; } - if (mapLevel->minZoom <= zoom && mapLevel->maxZoom >= zoom) { - if (mapLevel->right >= q.left && q.right >= mapLevel->left && mapLevel->bottom >= q.top - && q.bottom >= mapLevel->top) { + if (mapLevel->minZoom <= q->zoom && mapLevel->maxZoom >= q->zoom) { + if (mapLevel->right >= q->left && q->right >= mapLevel->left && mapLevel->bottom >= q->top + && q->bottom >= mapLevel->top) { osmand_log_print(LOG_INFO, "Search map %s", mapIndex->name.c_str()); - searchMapData(&cis, &(*mapLevel), &(*mapIndex), &q); + searchMapData(&cis, &(*mapLevel), &(*mapIndex), q); } } } } - if (q.ocean) { + if (q->ocean) { ocean = true; } - if (!q.isCancelled()) { - std::vector::iterator r = q.result.begin(); - tempResult.reserve((size_t)(q.result.size() + tempResult.size())); - for (; r != q.result.end(); r++) { + if (!q->isCancelled()) { + std::vector::iterator r = q->result.begin(); + tempResult.reserve((size_t)(q->result.size() + tempResult.size())); + for (; r != q->result.end(); r++) { // TODO skip duplicates doesn't work correctly with basemap (id < 0?) if (skipDuplicates && (*r)->id > 0 && false) { if (ids.find((*r)->id) != ids.end()) { @@ -829,24 +832,24 @@ extern "C" JNIEXPORT jint JNICALL Java_net_osmand_plus_render_NativeOsmandLibrar } } } - if (q.isCancelled()) { + if (q->isCancelled()) { deleteObjects(coastLines); deleteObjects(tempResult); deleteObjects(basemapCoastLines); deleteObjects(basemapResult); } else { bool addBasemapCoastlines = true; - bool emptyData = zoom > BASEMAP_ZOOM && tempResult.empty() && coastLines.empty(); + bool emptyData = q->zoom > BASEMAP_ZOOM && tempResult.empty() && coastLines.empty(); if (!coastLines.empty()) { std::vector pcoastlines; - processCoastlines(coastLines, sleft, sright, sbottom, stop, zoom, basemapCoastLines.empty(), pcoastlines); - addBasemapCoastlines = pcoastlines.empty() || zoom <= BASEMAP_ZOOM; + processCoastlines(coastLines, q->left, q->right, q->bottom, q->top, q->zoom, basemapCoastLines.empty(), pcoastlines); + addBasemapCoastlines = pcoastlines.empty() || q->zoom <= BASEMAP_ZOOM; tempResult.insert(tempResult.end(), pcoastlines.begin(), pcoastlines.end()); } if (addBasemapCoastlines) { addBasemapCoastlines = false; std::vector pcoastlines; - processCoastlines(basemapCoastLines, sleft, sright, sbottom, stop, zoom, true, pcoastlines); + processCoastlines(basemapCoastLines, q->left, q->right, q->bottom, q->top, q->zoom, true, pcoastlines); addBasemapCoastlines = pcoastlines.empty(); tempResult.insert(tempResult.end(), pcoastlines.begin(), pcoastlines.end()); } @@ -855,11 +858,11 @@ extern "C" JNIEXPORT jint JNICALL Java_net_osmand_plus_render_NativeOsmandLibrar deleteObjects(coastLines); if (addBasemapCoastlines) { MapDataObject* o = new MapDataObject(); - o->points.push_back(int_pair(sleft, stop)); - o->points.push_back(int_pair(sright, stop)); - o->points.push_back(int_pair(sright, sbottom)); - o->points.push_back(int_pair(sleft, sbottom)); - o->points.push_back(int_pair(sleft, stop)); + o->points.push_back(int_pair(q->left, q->top)); + o->points.push_back(int_pair(q->right, q->top)); + o->points.push_back(int_pair(q->right, q->bottom)); + o->points.push_back(int_pair(q->left, q->bottom)); + o->points.push_back(int_pair(q->left, q->top)); if (ocean) { o->types.push_back(tag_value("natural", "coastline")); } else { @@ -871,22 +874,21 @@ extern "C" JNIEXPORT jint JNICALL Java_net_osmand_plus_render_NativeOsmandLibrar // message // avoid overflow int errors MapDataObject* o = new MapDataObject(); - o->points.push_back(int_pair(sleft + (sright - sleft) / 2, stop + (sbottom - stop) / 2)); + o->points.push_back(int_pair(q->left + (q->right - q->left) / 2, q->top + (q->bottom - q->top) / 2)); o->types.push_back(tag_value("natural", "coastline")); - o->objectNames["name"] = getString(ienv, msgNothingFound); + o->objectNames["name"] = msgNothingFound; tempResult.push_back(o); } - if (zoom <= BASEMAP_ZOOM || emptyData) { + if (q->zoom <= BASEMAP_ZOOM || emptyData) { tempResult.insert(tempResult.end(), basemapResult.begin(), basemapResult.end()); } searchRes->result.insert(searchRes->result.end(), tempResult.begin(), tempResult.end()); osmand_log_print(LOG_INFO, "Search : tree - read( %d), accept( %d), objs - visit( %d), accept(%d), in result(%d) ", - q.numberOfReadSubtrees, q.numberOfAcceptedSubtrees, q.numberOfVisitedObjects, q.numberOfAcceptedObjects, + q->numberOfReadSubtrees, q->numberOfAcceptedSubtrees, q->numberOfVisitedObjects, q->numberOfAcceptedObjects, searchRes->result.size()); } - delete req; - return (jint) searchRes; + return searchRes; } extern "C" JNIEXPORT void JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_closeBinaryMapFile(JNIEnv* ienv, @@ -925,9 +927,9 @@ BinaryMapFile* initBinaryMapFile(std::string inputName) { } BinaryMapFile* mapFile = new BinaryMapFile(); mapFile->f = file; - io::FileInputStream input(fileno(file)); + FileInputStream input(fileno(file)); input.SetCloseOnDelete(false); - io::CodedInputStream cis(&input); + CodedInputStream cis(&input); cis.SetTotalBytesLimit(INT_MAX, INT_MAX >> 2); if (!initMapStructure(&cis, mapFile)) { osmand_log_print(LOG_ERROR, "File not initialised : %s", inputName.c_str()); @@ -939,6 +941,5 @@ BinaryMapFile* initBinaryMapFile(std::string inputName) { openFiles.insert(std::pair(inputName, mapFile)); return mapFile; } - #undef DO_ #endif diff --git a/Osmand-kernel/osmand/src/binaryRead.h b/Osmand-kernel/osmand/src/binaryRead.h index 63498a4cbb..9ba8bcfbff 100644 --- a/Osmand-kernel/osmand/src/binaryRead.h +++ b/Osmand-kernel/osmand/src/binaryRead.h @@ -3,15 +3,19 @@ #include #include -#include #include #include #include -#include "google/protobuf/wire_format_lite.h" -#include "common.h" -#include "mapObjects.h" +#include "mapObjects.h" +#include "multipolygons.h" +#include "common.h" + + +#include "mapObjects.h" +#include "renderRules.h" + struct MapTreeBounds { uint32 length; @@ -116,9 +120,19 @@ struct BinaryMapFile { } }; +struct SearchQuery; +struct SearchResult; + extern "C" JNIEXPORT jboolean JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_initBinaryMapFile(JNIEnv* ienv, jobject obj, jobject path); +extern "C" JNIEXPORT jint JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_searchNativeObjectsForRendering(JNIEnv* ienv, + jobject obj, jint sleft, jint sright, jint stop, jint sbottom, jint zoom, + jobject renderingRuleSearchRequest, bool skipDuplicates, jobject objInterrupted, jstring msgNothingFound); + +SearchResult* searchObjectsForRendering(SearchQuery* q, RenderingRuleSearchRequest* req, + bool skipDuplicates, std::string msgNothingFound); + BinaryMapFile* initBinaryMapFile(std::string inputName); #endif diff --git a/Osmand-kernel/osmand/src/common.h b/Osmand-kernel/osmand/src/common.h index fa980bb729..ae09689a1c 100644 --- a/Osmand-kernel/osmand/src/common.h +++ b/Osmand-kernel/osmand/src/common.h @@ -7,10 +7,33 @@ #include #include +#include +#include +#ifdef _MSC_VER +typedef __int8 int8; +typedef __int16 int16; +typedef __int32 int32; +typedef __int64 int64; -#ifdef HAVING_HASH +typedef unsigned __int8 uint8; +typedef unsigned __int16 uint16; +typedef unsigned __int32 uint32; +typedef unsigned __int64 uint64; +#else +typedef int8_t int8; +typedef int16_t int16; +typedef int32_t int32; +typedef int64_t int64; + +typedef uint8_t uint8; +typedef uint16_t uint16; +typedef uint32_t uint32; +typedef uint64_t uint64; +#endif + +#ifdef HASH_MAP_GNU #define HMAP __gnu_cxx namespace __gnu_cxx { @@ -40,28 +63,6 @@ namespace __gnu_cxx { }; } -#ifdef _MSC_VER -typedef __int8 int8; -typedef __int16 int16; -typedef __int32 int32; -typedef __int64 int64; - -typedef unsigned __int8 uint8; -typedef unsigned __int16 uint16; -typedef unsigned __int32 uint32; -typedef unsigned __int64 uint64; -#else -typedef int8_t int8; -typedef int16_t int16; -typedef int32_t int32; -typedef int64_t int64; - -typedef uint8_t uint8; -typedef uint16_t uint16; -typedef uint32_t uint32; -typedef uint64_t uint64; -#endif - #else @@ -71,8 +72,6 @@ typedef uint64_t uint64; using namespace std; -#include -#include #ifdef PROFILE_NATIVE_OPERATIONS #define PROFILE_NATIVE_OPERATION(rc, op) rc->nativeOperations.pause(); op; rc->nativeOperations.start() @@ -83,9 +82,6 @@ using namespace std; struct RenderingContext; -// Android helpers -extern const char* const LOG_TAG; - // JNI Helpers void throwNewException(JNIEnv* env, const char* msg); jclass findClass(JNIEnv* env, const char* className, bool mustHave = true);