summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/analyze_request.cpp296
-rw-r--r--src/api.cpp419
-rw-r--r--src/binder_reply.cpp168
-rw-r--r--src/genivi_request.cpp350
-rw-r--r--src/traces.h38
5 files changed, 1271 insertions, 0 deletions
diff --git a/src/analyze_request.cpp b/src/analyze_request.cpp
new file mode 100644
index 0000000..593ed42
--- /dev/null
+++ b/src/analyze_request.cpp
@@ -0,0 +1,296 @@
+// Copyright 2017 AW SOFTWARE CO.,LTD
+// Copyright 2017 AISIN AW CO.,LTD
+
+#include "genivi/genivi-navicore-constants.h"
+#include "analyze_request.h"
+#include <stdio.h>
+#include <string.h>
+#include <json-c/json.h>
+#include <string>
+
+
+/**
+ * @brief Create arguments to pass to Genivi API GetPosition.
+ * @param[in] req_json_str JSON request from BinderClient
+ * @param[out] Params An array of key information you want to obtain
+ * @return Success or failure of processing
+ */
+bool AnalyzeRequest::CreateParamsGetPosition( const char* req_json_str, std::vector< int32_t >& Params)
+{
+ struct json_object *req_json = json_tokener_parse(req_json_str);
+ struct json_object* jValuesToReturn = NULL;
+ if( json_object_object_get_ex(req_json, "valuesToReturn", &jValuesToReturn) )
+ {
+ if( json_object_is_type(jValuesToReturn, json_type_array) )
+ {
+ for (int i = 0; i < json_object_array_length(jValuesToReturn); ++i)
+ {
+ struct json_object* j_elem = json_object_array_get_idx(jValuesToReturn, i);
+
+ // JSON type acquisition
+ if( json_object_is_type(j_elem, json_type_int ) )
+ {
+ int32_t req_key = json_object_get_int (j_elem);
+
+ // no supported.
+ if ((NAVICORE_TIMESTAMP == req_key) || (NAVICORE_SPEED == req_key))
+ {
+ continue;
+ }
+ Params.push_back(req_key);
+ }
+ else
+ {
+ fprintf(stdout, "key is not integer type.\n");
+ return false;
+ }
+ }
+ }
+ else
+ {
+ fprintf(stdout, "request is not array type.\n");
+ return false;
+ }
+ }
+ else
+ {
+ fprintf(stdout, "key valuesToReturn not found.\n");
+ return false;
+ }
+
+ return true;
+}
+
+
+/**
+ * @brief Create arguments to pass to Genivi API CreateRoute
+ * @param[in] req_json_str JSON request from BinderClient
+ * @param[out] sessionHdl Session handle
+ * @return Success or failure of processing
+ */
+bool AnalyzeRequest::CreateParamsCreateRoute( const char* req_json_str, uint32_t& sessionHdl )
+{
+ // Get sessionHandle information
+ return JsonObjectGetSessionHdl(req_json_str, sessionHdl);
+}
+
+
+/**
+ * @brief Create arguments to pass to Genivi API PauseSimulation
+ * @param[in] req_json_str JSON request from BinderClient
+ * @param[out] sessionHdl Session handle
+ * @return Success or failure of processing
+ */
+bool AnalyzeRequest::CreateParamsPauseSimulation( const char* req_json_str, uint32_t& sessionHdl )
+{
+ // Get sessionHandle information
+ return JsonObjectGetSessionHdl(req_json_str, sessionHdl);
+}
+
+
+/**
+ * @brief Create arguments to pass to Genivi API CreateRoute
+ * @param[in] req_json_str JSON request from BinderClient
+ * @param[out] sessionHdl Session handle
+ * @param[out] simuMode Simulation mode
+ * @return Success or failure of processing
+ */
+bool AnalyzeRequest::CreateParamsSetSimulationMode( const char* req_json_str, uint32_t& sessionHdl, bool& simuMode )
+{
+ bool ret = false;
+ struct json_object *sess = NULL;
+ struct json_object *simu = NULL;
+
+ struct json_object *req_json = json_tokener_parse(req_json_str);
+ if ((json_object_object_get_ex(req_json, "sessionHandle", &sess)) &&
+ (json_object_object_get_ex(req_json, "simulationMode", &simu)))
+ {
+ if (json_object_is_type(sess, json_type_int) &&
+ json_object_is_type(simu, json_type_boolean))
+ {
+ sessionHdl = json_object_get_int(sess);
+ simuMode = json_object_get_int(simu);
+ ret = true;
+ }
+ else
+ {
+ fprintf(stdout, "key is invalid type.\n");
+ }
+ }
+ else
+ {
+ fprintf(stdout, "key sessionHandle or simulationMode not found.\n");
+ }
+
+ return ret;
+}
+
+
+/**
+ * @brief Create arguments to pass to Genivi API CancelRouteCalculation
+ * @param[in] req_json_str JSON request from BinderClient
+ * @param[out] sessionHdl Session handle
+ * @param[out] routeHdl Route handle
+ * @return Success or failure of processing
+ */
+bool AnalyzeRequest::CreateParamsCancelRouteCalculation( const char* req_json_str, uint32_t& sessionHdl, uint32_t& routeHdl )
+{
+ // Get sessionHandle, RouteHandle
+ return JsonObjectGetSessionHdlRouteHdl(req_json_str, sessionHdl, routeHdl);
+}
+
+
+/**
+ * @brief Create arguments to pass to Genivi API SetWaypoints
+ * @param[in] req_json_str JSON request from BinderClient
+ * @param[out] sessionHdl Session handle
+ * @param[out] routeHdl Route handle
+ * @param[out] currentPos Whether or not to draw a route from the position of the vehicle
+ * @param[out] waypointsList Destination coordinates
+ * @return Success or failure of processing
+ */
+bool AnalyzeRequest::CreateParamsSetWaypoints( const char* req_json_str, uint32_t& sessionHdl, uint32_t& routeHdl,
+ bool& currentPos, std::vector<Waypoint>& waypointsList )
+{
+ bool ret = false;
+ struct json_object *sess = NULL;
+ struct json_object *rou = NULL;
+ struct json_object *current = NULL;
+ struct json_object *wpl = NULL;
+
+ struct json_object *req_json = json_tokener_parse(req_json_str);
+ if ((json_object_object_get_ex(req_json, "sessionHandle", &sess)) &&
+ (json_object_object_get_ex(req_json, "route", &rou)) &&
+ (json_object_object_get_ex(req_json, "startFromCurrentPosition", &current)) &&
+ (json_object_object_get_ex(req_json, "", &wpl)))
+ {
+ if (json_object_is_type(sess, json_type_int) &&
+ json_object_is_type(rou, json_type_int) &&
+ json_object_is_type(current, json_type_boolean) &&
+ json_object_is_type(wpl, json_type_array))
+ {
+ sessionHdl = json_object_get_int(sess);
+ routeHdl = json_object_get_int(rou);
+ currentPos = json_object_get_boolean(current);
+
+ // Get latitude, longitude
+ for (int i = 0; i < json_object_array_length(wpl); ++i)
+ {
+ struct json_object *array = json_object_array_get_idx(wpl, i);
+ struct json_object *lati = NULL;
+ struct json_object *longi = NULL;
+
+ if (json_object_object_get_ex(array, "latitude", &lati) &&
+ json_object_object_get_ex(array, "longitude", &longi)) {
+
+ double latitude = json_object_get_double(lati);
+ double longitude = json_object_get_double(longi);
+ Waypoint destWp(latitude, longitude);
+ waypointsList.push_back(destWp);
+ ret = true;
+ }
+ else
+ {
+ fprintf(stdout, "key latitude or longitude not found.\n");
+ }
+ }
+ }
+ else
+ {
+ fprintf(stdout, "key is invalid type.\n");
+ }
+ }
+ else
+ {
+ fprintf(stdout, "key valuesToReturn not found.\n");
+ }
+
+ return ret;
+}
+
+
+/**
+ * @brief Create arguments to pass to Genivi API CalculateRoute
+ * @param[in] req_json_str JSON request from BinderClient
+ * @param[out] sessionHdl Session handle
+ * @param[out] routeHdl Route handle
+ * @return Success or failure of processing
+ */
+bool AnalyzeRequest::CreateParamsCalculateRoute( const char* req_json_str, uint32_t& sessionHdl, uint32_t& routeHdl )
+{
+ // Get sessionHandle, RouteHandle
+ return JsonObjectGetSessionHdlRouteHdl(req_json_str, sessionHdl, routeHdl);
+}
+
+
+/**
+ * @brief Get session handle and route handle information from JSON
+ * @param[in] req_json_str JSON request from BinderClient
+ * @param[out] Session handle value
+ * @return Success or failure of processing
+ */
+
+bool AnalyzeRequest::JsonObjectGetSessionHdl( const char* req_json_str, uint32_t& sessionHdl)
+{
+ bool ret = false;
+ struct json_object *sess = NULL;
+
+ struct json_object *req_json = json_tokener_parse(req_json_str);
+ if (json_object_object_get_ex(req_json, "sessionHandle", &sess))
+ {
+ if (json_object_is_type(sess, json_type_int))
+ {
+ sessionHdl = json_object_get_int(sess);
+ ret = true;
+ }
+ else
+ {
+ fprintf(stdout, "key is not integer type.\n");
+ }
+ }
+ else
+ {
+ fprintf(stdout, "key sessionHandle not found.\n");
+ }
+
+ return ret;
+}
+
+
+/**
+ * @brief Get session handle and route handle information from JSON
+ * @param[in] req_json_str JSON request from BinderClient
+ * @param[out] Session handle value
+ * @param[out] Route handle value
+ * @return Success or failure of processing
+ */
+
+bool AnalyzeRequest::JsonObjectGetSessionHdlRouteHdl( const char* req_json_str, uint32_t& sessionHdl, uint32_t& routeHdl)
+{
+ bool ret = false;
+ struct json_object *sess = NULL;
+ struct json_object *rou = NULL;
+
+ struct json_object *req_json = json_tokener_parse(req_json_str);
+ if ((json_object_object_get_ex(req_json, "sessionHandle", &sess)) &&
+ (json_object_object_get_ex(req_json, "route", &rou)))
+ {
+ if (json_object_is_type(sess, json_type_int) &&
+ json_object_is_type(rou, json_type_int))
+ {
+ sessionHdl = json_object_get_int(sess);
+ routeHdl = json_object_get_int(rou);
+ ret = true;
+ }
+ else
+ {
+ fprintf(stdout, "key is not integer type.\n");
+ }
+ }
+ else
+ {
+ fprintf(stdout, "key sessionHandle or route not found.\n");
+ }
+
+ return ret;
+}
diff --git a/src/api.cpp b/src/api.cpp
new file mode 100644
index 0000000..bf04453
--- /dev/null
+++ b/src/api.cpp
@@ -0,0 +1,419 @@
+// Copyright 2017 AW SOFTWARE CO.,LTD
+// Copyright 2017 AISIN AW CO.,LTD
+
+#include <string.h>
+
+#include "binder_reply.h"
+#include "genivi_request.h"
+#include "analyze_request.h"
+#include "genivi/genivi-navicore-constants.h"
+
+#define AFB_BINDING_VERSION 2
+
+extern "C" {
+ #include <afb/afb-binding.h>
+}
+
+/**
+ * Variable declaration
+ */
+GeniviRequest* geniviRequest; // Send request to Genivi
+BinderReply* binderReply; // Convert Genivi response result to json format
+AnalyzeRequest* analyzeRequest; // Analyze BinderClient's request and create arguments to pass to GeniviAPI
+
+/**
+ * @brief navicore_getposition request callback
+ * @param[in] req Request from client
+ */
+void OnRequestNavicoreGetPosition(afb_req req)
+{
+ AFB_REQ_NOTICE(req, "--> Start %s()", __func__);
+ AFB_REQ_DEBUG(req, "request navicore_getposition");
+
+ // Request of Json format request
+ json_object* req_json = afb_req_json(req);
+ const char* req_json_str = json_object_to_json_string(req_json);
+ AFB_REQ_NOTICE(req, "req_json_str = %s", req_json_str);
+
+ // Request analysis and create arguments to pass to Genivi
+ std::vector< int32_t > Params;
+ if( !analyzeRequest->CreateParamsGetPosition( req_json_str, Params ))
+ {
+ afb_req_fail(req, "failed", "navicore_getposition Bad Request");
+ return;
+ }
+
+ // GENIVI API call
+ std::map< int32_t, double > posList = geniviRequest->NavicoreGetPosition( Params );
+
+ // Convert to json style response
+ APIResponse response = binderReply->ReplyNavicoreGetPosition( posList );
+
+ // On success
+ if(response.isSuccess)
+ {
+ AFB_REQ_NOTICE(req, "res_json_str = %s", json_object_to_json_string(response.json_data));
+ // Return success to BinderClient
+ afb_req_success(req, response.json_data, "navicore_getposition");
+ }
+ else
+ {
+ AFB_REQ_ERROR(req, "%s - %s:%d", response.errMessage.c_str(), __FILE__, __LINE__);
+ afb_req_fail(req, "failed", "navicore_getposition Bad Request");
+ }
+
+ // Json object release
+ json_object_put(response.json_data);
+
+ AFB_REQ_NOTICE(req, "<-- End %s()", __func__);
+}
+
+
+/**
+ * @brief navicore_getallroutes request callback
+ * @param[in] req Request from client
+ */
+void OnRequestNavicoreGetAllRoutes(afb_req req)
+{
+ AFB_REQ_NOTICE(req, "--> Start %s()", __func__);
+ AFB_REQ_DEBUG(req, "request navicore_getallroutes");
+
+ // No request information in json format
+ AFB_REQ_NOTICE(req, "req_json_str = none");
+
+ // GENEVI API call
+ std::vector< uint32_t > allRoutes = geniviRequest->NavicoreGetAllRoutes();
+
+ // Convert to json style response
+ APIResponse response = binderReply->ReplyNavicoreGetAllRoutes( allRoutes );
+
+ // On success
+ if(response.isSuccess)
+ {
+ AFB_REQ_NOTICE(req, "res_json_str = %s", json_object_to_json_string(response.json_data));
+ // Return success to BinderClient
+ afb_req_success(req, response.json_data, "navicore_getallroutes");
+ }
+ else
+ {
+ AFB_REQ_ERROR(req, "%s - %s:%d", response.errMessage.c_str(), __FILE__, __LINE__);
+ afb_req_fail(req, "failed", "navicore_getallroutes Bad Request");
+ }
+
+ // json object release
+ json_object_put(response.json_data);
+
+ AFB_REQ_NOTICE(req, "<-- End %s()", __func__);
+}
+
+
+/**
+ * @brief navicore_createroute request callback
+ * @param[in] req Request from client
+ */
+void OnRequestNavicoreCreateRoute(afb_req req)
+{
+ AFB_REQ_NOTICE(req, "--> Start %s ", __func__);
+ AFB_REQ_DEBUG(req, "request navicore_createroute");
+
+ // Request of json format request
+ json_object* req_json = afb_req_json(req);
+ const char* req_json_str = json_object_to_json_string(req_json);
+ AFB_REQ_NOTICE(req, "req_json_str = %s", req_json_str);
+
+ // Request analysis and create arguments to pass to Genivi
+ uint32_t sessionHdl = 0;
+ if( !analyzeRequest->CreateParamsCreateRoute( req_json_str, sessionHdl ))
+ {
+ afb_req_fail(req, "failed", "navicore_createroute Bad Request");
+ return;
+ }
+
+ // GENEVI API call
+ uint32_t routeHdl = geniviRequest->NavicoreCreateRoute( sessionHdl );
+
+ // Convert to json style response
+ APIResponse response = binderReply->ReplyNavicoreCreateRoute( routeHdl );
+
+ // On success
+ if(response.isSuccess)
+ {
+ AFB_REQ_NOTICE(req, "res_json_str = %s", json_object_to_json_string(response.json_data));
+ // Return success to BinderClient
+ afb_req_success(req, response.json_data, "navicore_createroute");
+ }
+ else
+ {
+ AFB_REQ_ERROR(req, "%s - %s:%d", response.errMessage.c_str(), __FILE__, __LINE__);
+ afb_req_fail(req, "failed", "navicore_createroute Bad Request");
+ }
+
+ // json object release
+ json_object_put(response.json_data);
+
+ AFB_REQ_NOTICE(req, "<-- End %s()", __func__);
+}
+
+
+/**
+ * @brief navicore_pausesimulation request callback
+ * @param[in] req Request from client
+ */
+void OnRequestNavicorePauseSimulation(afb_req req)
+{
+ AFB_REQ_NOTICE(req, "--> Start %s()", __func__);
+ AFB_REQ_DEBUG(req, "request navicore_pausesimulation");
+
+ // Request of json format request
+ json_object* req_json = afb_req_json(req);
+ const char* req_json_str = json_object_to_json_string(req_json);
+ AFB_REQ_NOTICE(req, "req_json_str = %s", req_json_str);
+
+ // Request analysis and create arguments to pass to Genivi
+ uint32_t sessionHdl = 0;
+ if( !analyzeRequest->CreateParamsPauseSimulation( req_json_str, sessionHdl ))
+ {
+ afb_req_fail(req, "failed", "navicore_pausesimulation Bad Request");
+ return;
+ }
+
+ // GENEVI API call
+ geniviRequest->NavicorePauseSimulation( sessionHdl );
+
+ // No reply unnecessary API for conversion to json format response is unnecessary
+ AFB_REQ_NOTICE(req, "res_json_str = none");
+
+ // Return success to BinderClient
+ afb_req_success(req, NULL, "navicore_pausesimulation");
+
+ AFB_REQ_NOTICE(req, "<-- End %s()", __func__);
+}
+
+
+/**
+ * @brief navicore_setsimulationmode request callback
+ * @param[in] req Request from client
+ */
+void OnRequestNavicoreSetSimulationMode(afb_req req)
+{
+ AFB_REQ_NOTICE(req, "--> Start %s()", __func__);
+ AFB_REQ_DEBUG(req, "request navicore_setsimulationmode");
+
+ // Request of json format request
+ json_object* req_json = afb_req_json(req);
+ const char* req_json_str = json_object_to_json_string(req_json);
+ AFB_REQ_NOTICE(req, "req_json_str = %s", req_json_str);
+
+ // Request analysis and create arguments to pass to Genivi
+ uint32_t sessionHdl = 0;
+ bool simuMode = false;
+ if( !analyzeRequest->CreateParamsSetSimulationMode( req_json_str, sessionHdl, simuMode ))
+ {
+ afb_req_fail(req, "failed", "navicore_setsimulationmode Bad Request");
+ return;
+ }
+
+ // GENEVI API call
+ geniviRequest->NavicoreSetSimulationMode( sessionHdl, simuMode );
+
+ // No reply unnecessary API for conversion to json format response is unnecessary
+ AFB_REQ_NOTICE(req, "res_json_str = none");
+
+ // Return success to BinderClient
+ afb_req_success(req, NULL, "navicore_setsimulationmode");
+
+ AFB_REQ_NOTICE(req, "<-- End %s()", __func__);
+}
+
+
+/**
+ * @brief navicore_cancelroutecalculation request callback
+ * @param[in] req Request from client
+ */
+void OnRequestNavicoreCancelRouteCalculation(afb_req req)
+{
+ AFB_REQ_NOTICE(req, "--> Start %s()", __func__);
+ AFB_REQ_DEBUG(req, "request navicore_cancelroutecalculation");
+
+ // Request of Json format request
+ json_object* req_json = afb_req_json(req);
+ const char* req_json_str = json_object_to_json_string(req_json);
+ AFB_REQ_NOTICE(req, "req_json_str = %s", req_json_str);
+
+ // Request analysis and create arguments to pass to Genivi
+ uint32_t sessionHdl = 0;
+ uint32_t routeHdl = 0;
+ if( !analyzeRequest->CreateParamsCancelRouteCalculation( req_json_str, sessionHdl, routeHdl ))
+ {
+ afb_req_fail(req, "failed", "navicore_cancelroutecalculation Bad Request");
+ return;
+ }
+
+ // GENEVI API call
+ geniviRequest->NavicoreCancelRouteCalculation( sessionHdl, routeHdl );
+
+ // No reply unnecessary API for conversion to json format response is unnecessary
+ AFB_REQ_NOTICE(req, "res_json_str = none");
+
+ // Return success to BinderClient
+ afb_req_success(req, NULL, "navicore_cancelroutecalculation");
+
+ AFB_REQ_NOTICE(req, "<-- End %s()", __func__);
+}
+
+
+/**
+ * @brief navicore_setwaypoints request callback
+ * @param[in] req Request from client
+ */
+void OnRequestNavicoreWaypoints(afb_req req)
+{
+ AFB_REQ_NOTICE(req, "--> Start %s()", __func__);
+ AFB_REQ_DEBUG(req, "request navicore_setwaypoints");
+
+ // Request of Json format request
+ json_object* req_json = afb_req_json(req);
+ const char* req_json_str = json_object_to_json_string(req_json);
+ AFB_REQ_NOTICE(req, "req_json_str = %s", req_json_str);
+
+ // Request analysis and create arguments to pass to Genivi
+ uint32_t sessionHdl = 0;
+ uint32_t routeHdl = 0;
+ bool currentPos = false;
+ std::vector<Waypoint> waypointsList;
+ if( !analyzeRequest->CreateParamsSetWaypoints( req_json_str, sessionHdl, routeHdl, currentPos, waypointsList ))
+ {
+ afb_req_fail(req, "failed", "navicore_setwaypoints Bad Request");
+ return;
+ }
+
+ // GENEVI API call
+ geniviRequest->NavicoreSetWaypoints( sessionHdl, routeHdl, currentPos, waypointsList );
+
+ // No reply unnecessary API for conversion to json format response is unnecessary
+ AFB_REQ_NOTICE(req, "res_json_str = none");
+
+ // Return success to BinderClient
+ afb_req_success(req, NULL, "navicore_setwaypoints");
+
+ AFB_REQ_NOTICE(req, "<-- End %s()", __func__);
+}
+
+
+/**
+ * @brief navicore_calculateroute request callback
+ * @param[in] req Request from client
+ */
+void OnRequestNavicoreCalculateRoute(afb_req req)
+{
+ AFB_REQ_NOTICE(req, "--> Start %s()", __func__);
+ AFB_REQ_DEBUG(req, "request navicore_calculateroute");
+
+ // Request of Json format request
+ json_object* req_json = afb_req_json(req);
+ const char* req_json_str = json_object_to_json_string(req_json);
+ AFB_REQ_NOTICE(req, "req_json_str = %s", req_json_str);
+
+ // Request analysis and create arguments to pass to Genivi
+ uint32_t sessionHdl = 0;
+ uint32_t routeHdl = 0;
+ if( !analyzeRequest->CreateParamsCalculateRoute( req_json_str, sessionHdl, routeHdl ))
+ {
+ afb_req_fail(req, "failed", "navicore_calculateroute Bad Request");
+ return;
+ }
+
+ // GENEVI API call
+ geniviRequest->NavicoreCalculateRoute( sessionHdl, routeHdl );
+
+ // No reply unnecessary API for conversion to json format response is unnecessary
+ AFB_REQ_NOTICE(req, "res_json_str = none");
+
+ // Return success to BinderClient
+ afb_req_success(req, NULL, "navicore_calculateroute");
+
+ AFB_REQ_NOTICE(req, "<-- End %s()", __func__);
+}
+
+
+/**
+ * @brief navicore_getallsessions request callback
+ * @param[in] req Request from client
+ */
+void OnRequestNavicoreGetAllSessions(afb_req req)
+{
+ AFB_REQ_NOTICE(req, "--> Start %s()", __func__);
+ AFB_REQ_DEBUG(req, "request navicore_getallsessions");
+
+ // No request information in Json format
+ AFB_REQ_NOTICE(req, "req_json_str = none");
+
+ // GENEVI API call
+ std::map<uint32_t, std::string> allSessions = geniviRequest->NavicoreGetAllSessions();
+
+ // Convert to json style response
+ APIResponse response = binderReply->ReplyNavicoreGetAllSessions( allSessions );
+
+ // On success
+ if(response.isSuccess)
+ {
+ AFB_REQ_NOTICE(req, "res_json_str = %s", json_object_to_json_string(response.json_data));
+ // Return success to BinderClient
+ afb_req_success(req, response.json_data, "navicore_getallsessions");
+ }
+ else
+ {
+ AFB_REQ_ERROR(req, "%s - %s:%d", response.errMessage.c_str(), __FILE__, __LINE__);
+ afb_req_fail(req, "failed", "navicore_getallsessions Bad Request");
+ }
+
+ // json object release
+ json_object_put(response.json_data);
+
+ AFB_REQ_NOTICE(req, "<-- End %s()", __func__);
+}
+
+
+/**
+ * @brief Callback called at service startup
+ */
+int Init()
+{
+ // Create instance
+ geniviRequest = new GeniviRequest();
+ binderReply = new BinderReply();
+ analyzeRequest = new AnalyzeRequest();
+
+ return 0;
+}
+
+/**
+ * @brief API definition
+ */
+const afb_verb_v2 verbs[] =
+{
+ { verb : "navicore_getposition", callback : OnRequestNavicoreGetPosition },
+ { verb : "navicore_getallroutes", callback : OnRequestNavicoreGetAllRoutes },
+ { verb : "navicore_createroute", callback : OnRequestNavicoreCreateRoute },
+ { verb : "navicore_pausesimulation", callback : OnRequestNavicorePauseSimulation },
+ { verb : "navicore_setsimulationmode", callback : OnRequestNavicoreSetSimulationMode },
+ { verb : "navicore_cancelroutecalculation", callback : OnRequestNavicoreCancelRouteCalculation },
+ { verb : "navicore_setwaypoints", callback : OnRequestNavicoreWaypoints },
+ { verb : "navicore_calculateroute", callback : OnRequestNavicoreCalculateRoute },
+ { verb : "navicore_getallsessions", callback : OnRequestNavicoreGetAllSessions },
+ { verb : NULL }
+};
+
+/**
+ * @brief Service definition
+ */
+const afb_binding_v2 afbBindingV2 =
+{
+ "naviapi",
+ "",
+ "",
+ verbs,
+ NULL,
+ Init
+};
+
diff --git a/src/binder_reply.cpp b/src/binder_reply.cpp
new file mode 100644
index 0000000..172a22a
--- /dev/null
+++ b/src/binder_reply.cpp
@@ -0,0 +1,168 @@
+// Copyright 2017 AW SOFTWARE CO.,LTD
+// Copyright 2017 AISIN AW CO.,LTD
+
+#include "binder_reply.h"
+#include "genivi/genivi-navicore-constants.h"
+
+/**
+ * @brief GeniviAPI GetPosition call
+ * @param[in] posList Map information on key and value of information acquired from Genivi
+ * @return Response information
+ */
+APIResponse BinderReply::ReplyNavicoreGetPosition( std::map<int32_t, double>& posList )
+{
+ APIResponse response = {0};
+
+ // Json information to return as a response
+ struct json_object* response_json = json_object_new_array();
+ std::map<int32_t, double>::iterator it;
+
+ // If the argument map is empty return
+ if(posList.empty())
+ {
+ response.isSuccess = false;
+ response.errMessage = "posList is empty";
+ response.json_data = response_json;
+ return response;
+ }
+
+ // Make the passed Genivi response json format
+ for (it = posList.begin(); it != posList.end(); it++)
+ {
+ struct json_object* obj = json_object_new_object();
+
+ switch(it->first)
+ {
+ case NAVICORE_LATITUDE:
+ json_object_object_add(obj, "key", json_object_new_int(NAVICORE_LATITUDE));
+ json_object_object_add(obj, "value", json_object_new_double(it->second) );
+ json_object_array_add(response_json, obj);
+ break;
+
+ case NAVICORE_LONGITUDE:
+ json_object_object_add(obj, "key", json_object_new_int(NAVICORE_LONGITUDE));
+ json_object_object_add(obj, "value", json_object_new_double(it->second));
+ json_object_array_add(response_json, obj);
+ break;
+
+ case NAVICORE_HEADING:
+ json_object_object_add(obj, "key", json_object_new_int(NAVICORE_HEADING));
+ json_object_object_add(obj, "value", json_object_new_boolean (it->second));
+ json_object_array_add(response_json, obj);
+ break;
+#if 0
+ // no support
+ case NAVICORE_TIMESTAMP:
+ json_object_object_add(obj, "key", json_object_new_int(NAVICORE_TIMESTAMP));
+ json_object_object_add(obj, "value", json_object_new_int(it->second));
+ json_object_array_add(response_json, obj);
+ break;
+
+ // no support
+ case NAVICORE_SPEED:
+ json_object_object_add(obj, "key", json_object_new_int(NAVICORE_SPEED));
+ json_object_object_add(obj, "value", json_object_new_int(it->second));
+ json_object_array_add(response_json, obj);
+ break;
+#endif
+
+ case NAVICORE_SIMULATION_MODE:
+ json_object_object_add(obj, "key", json_object_new_int(NAVICORE_SIMULATION_MODE));
+ json_object_object_add(obj, "value", json_object_new_boolean (it->second));
+ json_object_array_add(response_json, obj);
+ break;
+
+ default:
+ fprintf(stderr, "Unknown key.");
+ json_object_put(obj);
+ break;
+ }
+ }
+
+ response.json_data = response_json;
+ response.isSuccess = true;
+ return response;
+}
+
+/**
+ * @brief GeniviAPI GetAllRoutes call
+ * @param[in] allRoutes Route handle information
+ * @return Response information
+ */
+APIResponse BinderReply::ReplyNavicoreGetAllRoutes( std::vector< uint32_t > &allRoutes )
+{
+ APIResponse response = {0};
+
+ // Json information to return as a response
+ struct json_object* response_json = json_object_new_array();
+
+ if (0 < allRoutes.size())
+ {
+ std::vector< uint32_t >::iterator it;
+
+ for (it = allRoutes.begin(); it != allRoutes.end(); it++)
+ {
+ struct json_object* obj = json_object_new_object();
+ json_object_object_add(obj, "route", json_object_new_int(*it));
+ json_object_array_add(response_json, obj);
+ }
+ }
+
+ response.json_data = response_json;
+ response.isSuccess = true;
+ return response;
+}
+
+/**
+ * @brief GeniviAPI CreateRoute call
+ * @param[in] route Route handle
+ * @return Response information
+ */
+APIResponse BinderReply::ReplyNavicoreCreateRoute( uint32_t route )
+{
+ APIResponse response;
+
+ // Json information to return as a response
+ struct json_object* response_json = json_object_new_object();
+ json_object_object_add(response_json, "route", json_object_new_int(route));
+
+ response.json_data = response_json;
+ response.isSuccess = true;
+ return response;
+}
+
+/**
+ * @brief GeniviAPI GetAllSessions call
+ * @param[in] allSessions Map information on key and value of information acquired from Genivi
+ * @return Response information
+ */
+APIResponse BinderReply::ReplyNavicoreGetAllSessions( std::map<uint32_t, std::string> &allSessions )
+{
+ APIResponse response = {0};
+
+ // Json information to return as a response
+ struct json_object* response_json = json_object_new_array();
+ std::map<uint32_t, std::string>::iterator it;
+
+ for (it = allSessions.begin(); it != allSessions.end(); it++)
+ {
+ struct json_object* obj = json_object_new_object();
+
+ if (NAVICORE_INVALID != it->first)
+ {
+ json_object_object_add(obj, "sessionHandle", json_object_new_int(it->first));
+ json_object_object_add(obj, "client", json_object_new_string(it->second.c_str()));
+ json_object_array_add(response_json, obj);
+ }
+ else
+ {
+ fprintf(stderr, "invalid key.");
+ json_object_put(obj);
+ }
+ }
+
+ response.json_data = response_json;
+ response.isSuccess = true;
+ return response;
+}
+
diff --git a/src/genivi_request.cpp b/src/genivi_request.cpp
new file mode 100644
index 0000000..a485667
--- /dev/null
+++ b/src/genivi_request.cpp
@@ -0,0 +1,350 @@
+// Copyright 2017 AW SOFTWARE CO.,LTD
+// Copyright 2017 AISIN AW CO.,LTD
+
+#include "genivi/navicore.h"
+#include "genivi/genivi-navicore-constants.h"
+#include "genivi_request.h"
+#include <stdio.h>
+#include <exception>
+#include <dbus-c++-1/dbus-c++/dbus.h>
+
+/**
+ * @brief Destructor
+ */
+GeniviRequest::~GeniviRequest()
+{
+ delete (Navicore*)navicore_;
+ navicore_ = NULL;
+}
+
+/**
+ * @brief DBus session creation
+ */
+void GeniviRequest::CreateDBusSession( )
+{
+ try
+ {
+ static DBus::BusDispatcher dispatcher;
+ DBus::default_dispatcher = &dispatcher;
+ DBus::Connection conn = DBus::Connection::SessionBus();
+
+ navicore_ = new Navicore(conn, "/org/genivi/navicore", "org.agl.naviapi");
+ }
+ catch(const std::exception& e)
+ {
+ fprintf(stderr, "Error:%s\n", e.what());
+ }
+}
+
+/**
+ * @brief Check connection status
+ * @return Presence / absence of connection
+ */
+bool GeniviRequest::CheckSession()
+{
+ if(this->navicore_ == NULL)
+ {
+ this->CreateDBusSession();
+ }
+
+ try
+ {
+ // Get connection status
+ DBus::Connection conn = ((Navicore*)navicore_)->conn();
+ bool isConnect = conn.connected();
+
+ // If it is not connected, it issues an error
+ if(!isConnect)
+ {
+ fprintf(stderr, "Service has no session.\n");
+ }
+
+ return isConnect;
+ }
+ catch(const std::exception& e)
+ {
+ fprintf(stderr, "Error:%s\n", e.what());
+ return false;
+ }
+}
+
+/**
+ * @brief Call GeniviAPI GetPosition to get information
+ * @param[in] valuesToReturn Key arrangement of information acquired from Genivi
+ * @return Map information on key and value of information acquired from Genivi
+ */
+std::map< int32_t, double > GeniviRequest::NavicoreGetPosition( const std::vector< int32_t >& valuesToReturn )
+{
+ std::map< int32_t, double > ret;
+
+ if( !CheckSession() )
+ {
+ return ret;
+ }
+
+ try
+ {
+ std::map< int32_t, ::DBus::Struct< uint8_t, ::DBus::Variant > >::iterator it;
+ std::map< int32_t, ::DBus::Struct< uint8_t, ::DBus::Variant > > PosList =
+ ((Navicore*)navicore_)->GetPosition(valuesToReturn);
+ for (it = PosList.begin(); it != PosList.end(); it++)
+ {
+ if (it->first == NAVICORE_LATITUDE || it->second._1 == NAVICORE_LATITUDE)
+ {
+ ret[it->first] = it->second._2.reader().get_double();
+ }
+ else if (it->first == NAVICORE_LONGITUDE || it->second._1 == NAVICORE_LONGITUDE)
+ {
+ ret[it->first] = it->second._2.reader().get_double();
+ }
+ else if (it->first == NAVICORE_HEADING || it->second._1 == NAVICORE_HEADING)
+ {
+ ret[it->first] = it->second._2.reader().get_uint32();
+ }
+#if 0 // no supported
+ else if (it->first == NAVICORE_TIMESTAMP || it->second._1 == NAVICORE_TIMESTAMP)
+ {
+ ret[it->first] = it->second._2.reader().get_uint32();
+ }
+ else if (it->first == NAVICORE_SPEED || it->second._1 == NAVICORE_SPEED)
+ {
+ ret[it->first] = it->second._2.reader().get_int32();
+ }
+#endif
+ else if (it->first == NAVICORE_SIMULATION_MODE || it->second._1 == NAVICORE_SIMULATION_MODE)
+ {
+ ret[it->first] = it->second._2.reader().get_bool();
+ }
+ }
+ }
+ catch(const std::exception& e)
+ {
+ fprintf(stderr, "Error:%s\n", e.what());
+ }
+
+ return ret;
+}
+
+/**
+ * @brief Call GeniviAPI GetPosition to get information
+ * @return Route handle acquired from Genivi
+ */
+std::vector< uint32_t > GeniviRequest::NavicoreGetAllRoutes( void )
+{
+ if( !CheckSession() )
+ {
+ std::vector< uint32_t > no_route;
+ return no_route;
+ }
+
+ std::vector< uint32_t > allRoutes;
+ try
+ {
+ allRoutes = ((Navicore*)navicore_)->GetAllRoutes();
+ }
+ catch(const std::exception& e)
+ {
+ fprintf(stderr, "Error:%s\n", e.what());
+ }
+
+ return allRoutes;
+}
+
+
+/**
+ * @brief Call GeniviAPI GetPosition to get information
+ * @param[in] sessionHandle Session handle
+ * @return Route handle acquired from Genivi
+ */
+uint32_t GeniviRequest::NavicoreCreateRoute( const uint32_t& sessionHandle )
+{
+ if( !CheckSession() )
+ {
+ return 0;
+ }
+
+ uint32_t routeHandle = 0;
+ try
+ {
+ routeHandle = ((Navicore*)navicore_)->CreateRoute(sessionHandle);
+ }
+ catch(const std::exception& e)
+ {
+ fprintf(stderr, "Error:%s\n", e.what());
+ }
+
+ return routeHandle;
+}
+
+/**
+ * @brief Call GeniviAPI PauseSimulation
+ * @param[in] sessionHandle Session handle
+ */
+void GeniviRequest::NavicorePauseSimulation( const uint32_t& sessionHandle )
+{
+ if( !CheckSession() )
+ {
+ return;
+ }
+
+ try
+ {
+ ((Navicore*)navicore_)->PauseSimulation(sessionHandle);
+ }
+ catch(const std::exception& e)
+ {
+ fprintf(stderr, "Error:%s\n", e.what());
+ }
+}
+
+
+/**
+ * @brief Call GeniviAPI SetSimulationMode
+ * @param[in] sessionHandle Session handle
+ * @param[in] activate Simulation mode enabled / disabled
+ */
+void GeniviRequest::NavicoreSetSimulationMode( const uint32_t& sessionHandle, const bool& activate )
+{
+ if( !CheckSession() )
+ {
+ return;
+ }
+
+ try
+ {
+ ((Navicore*)navicore_)->SetSimulationMode(sessionHandle, activate);
+ }
+ catch(const std::exception& e)
+ {
+ fprintf(stderr, "Error:%s\n", e.what());
+ }
+}
+
+
+/**
+ * @brief Call GeniviAPI SetSimulationMode
+ * @param[in] sessionHandle Session handle
+ * @param[in] routeHandle Route handle
+ */
+void GeniviRequest::NavicoreCancelRouteCalculation( const uint32_t& sessionHandle, const uint32_t& routeHandle )
+{
+ if( !CheckSession() )
+ {
+ return;
+ }
+
+ try
+ {
+ ((Navicore*)navicore_)->CancelRouteCalculation(sessionHandle, routeHandle);
+ }
+ catch(const std::exception& e)
+ {
+ fprintf(stderr, "Error:%s\n", e.what());
+ }
+}
+
+/**
+ * @brief Call GeniviAPI SetWaypoints
+ * @param[in] sessionHandle Session handle
+ * @param[in] routeHandle Route handle
+ * @param[in] startFromCurrentPosition Whether or not to draw a route from the position of the vehicle
+ * @param[in] waypointsList Destination coordinates
+ */
+void GeniviRequest::NavicoreSetWaypoints( const uint32_t& sessionHandle, const uint32_t& routeHandle,
+ const bool& startFromCurrentPosition, const std::vector<Waypoint>& waypointsList )
+{
+ if( !CheckSession() )
+ {
+ return;
+ }
+
+ std::vector<Waypoint>::const_iterator it;
+ std::vector< std::map< int32_t, ::DBus::Struct< uint8_t, ::DBus::Variant > > > wpl;
+
+ fprintf(stdout, "session: %d, route: %d, startFromCurrentPosition: %d\n",
+ sessionHandle, routeHandle, startFromCurrentPosition);
+
+ for (it = waypointsList.begin(); it != waypointsList.end(); it++)
+ {
+ std::map< int32_t, ::DBus::Struct< uint8_t, ::DBus::Variant > > Point;
+ ::DBus::Struct< uint8_t, ::DBus::Variant > VarLat, VarLon;
+
+ VarLat._1 = NAVICORE_LATITUDE;
+ VarLat._2.writer().append_double(std::get<0>(*it));
+ fprintf(stdout, "VarLat._1 : %x, VarLat._2 : %lf\n", VarLat._1, VarLat._2.reader().get_double());
+
+ VarLon._1 = NAVICORE_LONGITUDE;
+ VarLon._2.writer().append_double(std::get<1>(*it));
+ fprintf(stdout, "VarLon._1 : %x, VarLon._2 : %lf\n", VarLon._1, VarLon._2.reader().get_double());
+
+ Point[NAVICORE_LATITUDE] = VarLat;
+ Point[NAVICORE_LONGITUDE] = VarLon;
+
+ wpl.push_back(Point);
+ }
+
+ try
+ {
+ ((Navicore*)navicore_)->SetWaypoints(sessionHandle, routeHandle, startFromCurrentPosition, wpl);
+ }
+ catch(const std::exception& e)
+ {
+ fprintf(stderr, "Error:%s\n", e.what());
+ }
+}
+
+/**
+ * @brief Call GeniviAPI CalculateRoute
+ * @param[in] sessionHandle Session handle
+ * @param[in] routeHandle Route handle
+ */
+void GeniviRequest::NavicoreCalculateRoute( const uint32_t& sessionHandle, const uint32_t& routeHandle )
+{
+ if( !CheckSession() )
+ {
+ return;
+ }
+
+ try
+ {
+ ((Navicore*)navicore_)->CalculateRoute(sessionHandle, routeHandle);
+ }
+ catch(const std::exception& e)
+ {
+ fprintf(stderr, "Error:%s\n", e.what());
+ }
+}
+
+
+/**
+ * @brief Call GeniviAPI CalculateRoute
+ * @return Map information on key and value of information acquired from Genivi
+ */
+std::map<uint32_t, std::string> GeniviRequest::NavicoreGetAllSessions()
+{
+ std::map<uint32_t, std::string> ret;
+
+ if( !CheckSession() )
+ {
+ return ret;
+ }
+
+ std::vector< ::DBus::Struct< uint32_t, std::string > > ncAllSessions;
+ std::vector< ::DBus::Struct< uint32_t, std::string > >::iterator it;
+
+ try
+ {
+ ncAllSessions = ((Navicore*)navicore_)->GetAllSessions();
+ for (it = ncAllSessions.begin(); it != ncAllSessions.end(); it++)
+ {
+ ret[it->_1] = it->_2;
+ }
+ }
+ catch(const std::exception& e)
+ {
+ fprintf(stderr, "Error:%s\n", e.what());
+ }
+
+ return ret;
+}
+
diff --git a/src/traces.h b/src/traces.h
new file mode 100644
index 0000000..a1f96ec
--- /dev/null
+++ b/src/traces.h
@@ -0,0 +1,38 @@
+// Copyright 2017 AISIN AW CO.,LTD
+
+#ifndef __TRACE_H__
+#define __TRACE_H__
+
+#include <stdio.h>
+
+#define BLACK "\033[30m"
+#define RED "\033[31m"
+#define GREEN "\033[32m"
+#define YELLOW "\033[33m"
+#define BLUE "\033[34m"
+#define PURPLE "\033[35m"
+#define DGREEN "\033[6m"
+#define WHITE "\033[7m"
+#define CYAN "\x1b[36m"
+#define NONE "\033[0m"
+
+#ifdef NDEBUG
+
+#define TRACE_DEBUG_JSON(fmt, args...)
+#define TRACE_DEBUG(fmt, args...)
+#define TRACE_INFO(fmt, args...)
+#define TRACE_WARN(fmt, args...)
+#define TRACE_ERROR(fmt, args...)
+
+#else
+
+#define TRACE_DEBUG(fmt, args...) do { fprintf(stderr, "[%s:%d] " CYAN "DEBUG" NONE ": " fmt "\n", __func__, __LINE__, ##args); } while(0)
+#define TRACE_INFO(fmt, args...) do { fprintf(stderr, "[%s:%d] " GREEN "INFO" NONE ": " fmt "\n", __func__, __LINE__, ##args); } while(0)
+#define TRACE_WARN(fmt, args...) do { fprintf(stderr, "[%s:%d] " YELLOW "WARN" NONE": " fmt "\n", __func__, __LINE__, ##args); } while(0)
+#define TRACE_ERROR(fmt, args...) do { fprintf(stderr, "[%s:%d] " RED "ERROR" NONE ": " fmt "\n", __func__, __LINE__, ##args); } while(0)
+
+#define TRACE_DEBUG_JSON(fmt, args...)
+
+#endif
+
+#endif // __TRACE_H__