Adds rapidjson dependency 10/77710/1
authorKevin Kreiser <kevinkreiser@gmail.com>
Mon, 20 Jun 2016 13:35:38 +0000 (09:35 -0400)
committerBaldur Gudbjornsson <baldur@mapzen.com>
Thu, 30 Jun 2016 13:46:09 +0000 (09:46 -0400)
Change-Id: Ib6e971f92bdb3bf4c408fd2bbfe0d12e053028b5

12 files changed:
.gitmodules
CMakeLists.txt
add_deps.sh [new file with mode: 0755]
packaging/deps.tar.gz [new file with mode: 0644]
packaging/maps-plugin-mapzen.spec
rapidjson [deleted submodule]
src/mapzen/mapzen_jsonparser.cpp [moved from src/mapzen/mapzen_jsonparser.c with 80% similarity]
src/mapzen/mapzen_jsonparser.hpp [moved from src/mapzen/mapzen_jsonparser.h with 100% similarity]
src/mapzen/mapzen_queue.c
src/mapzen/mapzen_restcurl.c
src/mapzen/mapzen_route.cpp [moved from src/mapzen/mapzen_route.c with 92% similarity]
src/mapzen/mapzen_route.hpp [moved from src/mapzen/mapzen_route.h with 87% similarity]

index 21ec3ff..c415963 100644 (file)
@@ -1,3 +1,3 @@
-[submodule "rapidjson"]
-       path = rapidjson
-       url = https://github.com/miloyip/rapidjson
+[submodule "inc/rapidjson"]
+       path = inc/rapidjson
+       url = https://github.com/miloyip/rapidjson.git
index 0373c39..a906efc 100644 (file)
@@ -36,7 +36,7 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fvisibility=hidden -fPIC -Wall -Werror")
 SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -Wall -fPIC -std=c++0x -fvisibility=hidden")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -Wall -fPIC -std=c++11 -fvisibility=hidden")
 SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
 
 ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
@@ -45,13 +45,15 @@ ADD_DEFINITIONS("-DTIZEN_DEBUG")
 
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIBDIR}")
 
-# Main Include file
+# Includes
 SET(INC_DIR
        inc
+       src/mapzen
+       external/rapidjson/include      
 )
 
 INCLUDE_DIRECTORIES(
-       ${INC_DIR}
+       ${INC_DIR}
 )
 
 #This file must be corrected
@@ -59,9 +61,16 @@ INCLUDE_DIRECTORIES(
 # Source Lists
 SET(SRCS
        # Maps API
-       src/mapzen_utils.cpp
-       src/mapzen_plugin.cpp
-       src/mapzen_api.cpp
+       src/mapzen_plugin.c
+       src/mapzen/mapzen_api.c
+       src/mapzen/mapzen_geocode.c
+       src/mapzen/mapzen_jsonparser.cpp
+       src/mapzen/mapzen_place.c
+       src/mapzen/mapzen_queue.c
+       src/mapzen/mapzen_restcurl.c
+       src/mapzen/mapzen_revgeocode.c
+       src/mapzen/mapzen_route.cpp
+       src/mapzen/mapzen_util.c
 )
 
 ADD_LIBRARY(${pkg_name} SHARED ${SRCS})
diff --git a/add_deps.sh b/add_deps.sh
new file mode 100755 (executable)
index 0000000..7ca178f
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+tar pczf packaging/deps.tar.gz --anchored external/rapidjson/include
diff --git a/packaging/deps.tar.gz b/packaging/deps.tar.gz
new file mode 100644 (file)
index 0000000..681052e
Binary files /dev/null and b/packaging/deps.tar.gz differ
index d6bc1e8..f0e38f0 100644 (file)
@@ -5,11 +5,13 @@ Release:    1
 Group:      Location/Libraries
 License:    Apache-2.0 
 Source0:    %{name}-%{version}.tar.gz
+Source1:    deps.tar.gz
 ExclusiveArch:  %ix86 x86_64 %arm aarch64
 
 BuildRequires: cmake
 BuildRequires: pkgconfig(libxml-2.0)
 BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(libcurl)
 BuildRequires: pkgconfig(capi-maps-service)
 BuildRequires: capi-maps-service-plugin-devel
 BuildRequires: pkgconfig(capi-network-connection)
@@ -47,6 +49,7 @@ This package provides Plugin APIs for Mapzen.
 
 %prep
 %setup -q
+%setup -q -T -D -a 1
 
 %build
 %if 0%{?tizen_build_binary_release_type_eng}
diff --git a/rapidjson b/rapidjson
deleted file mode 160000 (submodule)
index 3d5848a..0000000
--- a/rapidjson
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 3d5848a7cd3367c5cb451c6493165b7745948308
similarity index 80%
rename from src/mapzen/mapzen_jsonparser.c
rename to src/mapzen/mapzen_jsonparser.cpp
index 62142a8..34a847d 100644 (file)
  * limitations under the License.
  */
 
+#include <maps_coordinates.h>
+
 #include <stdlib.h>
 #include "rapidjson/rapidjson.h"
-#include "mapzen_jsonparser.h"
+#include "mapzen_jsonparser.hpp"
 #include "mapzen_queue.h"
 #include "mapzen_debug.h"
 #include "mapzen_util.h"
 
+#include <string>
+#include <vector>
+
 #define ROUTE_UNIT_CONVERSION_MILE_TO_M(x)     (1609.34 * (x))
 #define ROUTE_UNIT_CONVERSION_MILE_TO_KM(x)    (1.60934 * (x))
 #define ROUTE_UNIT_CONVERSION_MILE_TO_FT(x)    (5280 * (x))
 #define ROUTE_UNIT_CONVERSION_MILE_TO_YD(x)    (1760 * (x))
 
-static route_unit __route_unit = ROUTE_UNIT_M;
+static route_unit __route_unit = UNIT_M;
 static int __maneuver_index = 0;
 static coords_s __destination_point;
+constexpr double kPolylinePrecision = 1E6;
+constexpr double kInvPolylinePrecision = 1.0 / kPolylinePrecision;
+
+
+//TODO: port this to c? or port the whole project to c++ or add all the proper externs
+void decode_shape(const std::string& encoded,
+                         std::vector<maps_coordinates_s>& output)
+{
+        // what byte are we looking at
+        size_t i = 0;
+
+        // Handy lambda to turn a few bytes of an encoded string into an integer
+        auto deserialize = [&encoded, &i](const int previous) {
+                // Grab each 5 bits and mask it in where it belongs using the shift
+                int byte, shift = 0, result = 0;
+                do {
+                        byte = static_cast<int>(encoded[i++]) - 63;
+                        result |= (byte & 0x1f) << shift;
+                        shift += 5;
+                } while (byte >= 0x20);
+
+                // Undo the left shift from above or the bit flipping and add
+                // to previous since its an offset
+                return previous + (result & 1 ? ~(result >> 1) : (result >> 1));
+        };
+
+        // Iterate over all characters of the encoded shape string
+        int last_lon = 0, last_lat = 0;
+        while (i < encoded.length())
+        {
+                // Decode the coordinates, lat first
+                int lat = deserialize(last_lat);
+                int lon = deserialize(last_lon);
+
+                // Shift the decimal point 5 places to the left and add to the output
+                maps_coordinates_s ll;
+                ll.latitude  = static_cast<double>(lat) * kInvPolylinePrecision;
+                ll.longitude = static_cast<double>(lon) * kInvPolylinePrecision;
+                output.emplace_back(std::move(ll));
+
+                // Remember the last one we encountered
+                last_lat = lat;
+                last_lon = lon;
+        }
+}
+
 
 static mapzen_error_e __convert_status(int status)
 {
index da8364a..e4b08c0 100644 (file)
 #include "mapzen_queue.h"
 #include "mapzen_geocode.h"
 #include "mapzen_revgeocode.h"
-#include "mapzen_route.h"
+#include "mapzen_route.hpp"
 #include "mapzen_place.h"
 #include "mapzen_restcurl.h"
 #include "mapzen_util.h"
 #include "mapzen_debug.h"
-#include <json-glib/json-glib.h>
 
 pthread_mutex_t __requestLock;
 static GAsyncQueue *responseQueue = NULL;
index 8d41417..9530345 100644 (file)
@@ -21,7 +21,7 @@
 #include <network/net_connection.h>
 #include "mapzen_restcurl.h"
 #include "mapzen_types.h"
-#include "mapzen_jsonparser.h"
+#include "mapzen_jsonparser.hpp"
 #include "mapzen_debug.h"
 
 #define RESTCURL_USE_MULTI_CURL
similarity index 92%
rename from src/mapzen/mapzen_route.c
rename to src/mapzen/mapzen_route.cpp
index b1d24ef..1f72746 100644 (file)
@@ -17,7 +17,7 @@
 #include <stdio.h>
 #include <glib.h>
 #include <pthread.h>
-#include "mapzen_route.h"
+#include "mapzen_route.hpp"
 #include "mapzen_types.h"
 #include "mapzen_server_private.h"
 #include "mapzen_debug.h"
@@ -27,7 +27,7 @@
 
 #define ROUTE_URL       "https://valhalla.mapzen.com/route?api_key=%s&json="
 
-int query_route(gchar *maps_key, coords_s startPoint, coords_s endPoint, costing costing, feature_penalties avoids, route_driving_style style, GList *waypoints, gpointer user_data)
+int query_route(gchar *maps_key, coords_s startPoint, coords_s endPoint, route_type type, route_feature_avoids avoids, route_driving_style style, GList *waypoints, gpointer user_data)
 {
        char url[1024] = "";
        char tmpStr[512];
@@ -39,7 +39,7 @@ int query_route(gchar *maps_key, coords_s startPoint, coords_s endPoint, costing
 
        STRCPY(url, tmpStr);
 
-       STRCAT(url, '"directions_options":{"units":"mi"}');     /* Keeping default as miles and conversion will be done later */
+       /*STRCAT(url, '"directions_options":{"units":"mi"}');    Keeping default as miles and conversion will be done later
 
        if (costing == COSTING_AUTO)
                STRCAT(url, '"costing":"auto"');
@@ -113,7 +113,7 @@ int query_route(gchar *maps_key, coords_s startPoint, coords_s endPoint, costing
        } else {
                snprintf(tmpStr, sizeof(tmpStr), '"locations":[{"lat":%f,"lon":%f},{"lat":%f,"lon":%f}]', startPoint.latitude, startPoint.longitude, endPoint.latitude, endPoint.longitude);
                STRCAT(url, tmpStr);
-       }
+       }*/
 
        //TODO:  url encode (curl_escape) the json part of the request
 
similarity index 87%
rename from src/mapzen/mapzen_route.h
rename to src/mapzen/mapzen_route.hpp
index 810e0b2..2e9ec0f 100644 (file)
@@ -20,6 +20,6 @@
 #include "mapzen_api.h"
 #include "mapzen_types.h"
 
-int query_route(gchar *maps_key, coords_s startPoint, coords_s endPoint, costing costing, feature_penalties avoids, route_driving_style style, GList *waypoints, gpointer user_data);
+int query_route(gchar *maps_key, coords_s startPoint, coords_s endPoint, route_type type, route_feature_avoids avoids, route_driving_style style, GList *waypoints, gpointer user_data);
 
 #endif /* _MAPZEN_ROUTE_H_ */