1 // Copyright 2017 AW SOFTWARE CO.,LTD
2 // Copyright 2017 AISIN AW CO.,LTD
4 #include "genivi/genivi-navicore-constants.h"
5 #include "analyze_request.h"
8 #include <json-c/json.h>
13 * @brief Create arguments to pass to Genivi API GetPosition.
14 * @param[in] req_json_str JSON request from BinderClient
15 * @param[out] Params An array of key information you want to obtain
16 * @return Success or failure of processing
18 bool AnalyzeRequest::CreateParamsGetPosition( const char* req_json_str, std::vector< int32_t >& Params)
20 struct json_object *req_json = json_tokener_parse(req_json_str);
21 struct json_object* jValuesToReturn = NULL;
22 if( json_object_object_get_ex(req_json, "valuesToReturn", &jValuesToReturn) )
24 if( json_object_is_type(jValuesToReturn, json_type_array) )
26 for (int i = 0; i < json_object_array_length(jValuesToReturn); ++i)
28 struct json_object* j_elem = json_object_array_get_idx(jValuesToReturn, i);
30 // JSON type acquisition
31 if( json_object_is_type(j_elem, json_type_int ) )
33 int32_t req_key = json_object_get_int (j_elem);
36 if ((NAVICORE_TIMESTAMP == req_key) || (NAVICORE_SPEED == req_key))
40 Params.push_back(req_key);
44 fprintf(stdout, "key is not integer type.\n");
51 fprintf(stdout, "request is not array type.\n");
57 fprintf(stdout, "key valuesToReturn not found.\n");
66 * @brief Create arguments to pass to Genivi API CreateRoute
67 * @param[in] req_json_str JSON request from BinderClient
68 * @param[out] sessionHdl Session handle
69 * @return Success or failure of processing
71 bool AnalyzeRequest::CreateParamsCreateRoute( const char* req_json_str, uint32_t& sessionHdl )
73 // Get sessionHandle information
74 return JsonObjectGetSessionHdl(req_json_str, sessionHdl);
79 * @brief Create arguments to pass to Genivi API PauseSimulation
80 * @param[in] req_json_str JSON request from BinderClient
81 * @param[out] sessionHdl Session handle
82 * @return Success or failure of processing
84 bool AnalyzeRequest::CreateParamsPauseSimulation( const char* req_json_str, uint32_t& sessionHdl )
86 // Get sessionHandle information
87 return JsonObjectGetSessionHdl(req_json_str, sessionHdl);
92 * @brief Create arguments to pass to Genivi API CreateRoute
93 * @param[in] req_json_str JSON request from BinderClient
94 * @param[out] sessionHdl Session handle
95 * @param[out] simuMode Simulation mode
96 * @return Success or failure of processing
98 bool AnalyzeRequest::CreateParamsSetSimulationMode( const char* req_json_str, uint32_t& sessionHdl, bool& simuMode )
101 struct json_object *sess = NULL;
102 struct json_object *simu = NULL;
104 struct json_object *req_json = json_tokener_parse(req_json_str);
105 if ((json_object_object_get_ex(req_json, "sessionHandle", &sess)) &&
106 (json_object_object_get_ex(req_json, "simulationMode", &simu)))
108 if (json_object_is_type(sess, json_type_int) &&
109 json_object_is_type(simu, json_type_boolean))
111 sessionHdl = json_object_get_int(sess);
112 simuMode = json_object_get_int(simu);
117 fprintf(stdout, "key is invalid type.\n");
122 fprintf(stdout, "key sessionHandle or simulationMode not found.\n");
130 * @brief Create arguments to pass to Genivi API CancelRouteCalculation
131 * @param[in] req_json_str JSON request from BinderClient
132 * @param[out] sessionHdl Session handle
133 * @param[out] routeHdl Route handle
134 * @return Success or failure of processing
136 bool AnalyzeRequest::CreateParamsCancelRouteCalculation( const char* req_json_str, uint32_t& sessionHdl, uint32_t& routeHdl )
138 // Get sessionHandle, RouteHandle
139 return JsonObjectGetSessionHdlRouteHdl(req_json_str, sessionHdl, routeHdl);
144 * @brief Create arguments to pass to Genivi API SetWaypoints
145 * @param[in] req_json_str JSON request from BinderClient
146 * @param[out] sessionHdl Session handle
147 * @param[out] routeHdl Route handle
148 * @param[out] currentPos Whether or not to draw a route from the position of the vehicle
149 * @param[out] waypointsList Destination coordinates
150 * @return Success or failure of processing
152 bool AnalyzeRequest::CreateParamsSetWaypoints( const char* req_json_str, uint32_t& sessionHdl, uint32_t& routeHdl,
153 bool& currentPos, std::vector<Waypoint>& waypointsList )
156 struct json_object *sess = NULL;
157 struct json_object *rou = NULL;
158 struct json_object *current = NULL;
159 struct json_object *wpl = NULL;
161 struct json_object *req_json = json_tokener_parse(req_json_str);
162 if ((json_object_object_get_ex(req_json, "sessionHandle", &sess)) &&
163 (json_object_object_get_ex(req_json, "route", &rou)) &&
164 (json_object_object_get_ex(req_json, "startFromCurrentPosition", ¤t)) &&
165 (json_object_object_get_ex(req_json, "", &wpl)))
167 if (json_object_is_type(sess, json_type_int) &&
168 json_object_is_type(rou, json_type_int) &&
169 json_object_is_type(current, json_type_boolean) &&
170 json_object_is_type(wpl, json_type_array))
172 sessionHdl = json_object_get_int(sess);
173 routeHdl = json_object_get_int(rou);
174 currentPos = json_object_get_boolean(current);
176 // Get latitude, longitude
177 for (int i = 0; i < json_object_array_length(wpl); ++i)
179 struct json_object *array = json_object_array_get_idx(wpl, i);
180 struct json_object *lati = NULL;
181 struct json_object *longi = NULL;
183 if (json_object_object_get_ex(array, "latitude", &lati) &&
184 json_object_object_get_ex(array, "longitude", &longi)) {
186 double latitude = json_object_get_double(lati);
187 double longitude = json_object_get_double(longi);
188 Waypoint destWp(latitude, longitude);
189 waypointsList.push_back(destWp);
194 fprintf(stdout, "key latitude or longitude not found.\n");
200 fprintf(stdout, "key is invalid type.\n");
205 fprintf(stdout, "key valuesToReturn not found.\n");
213 * @brief Create arguments to pass to Genivi API CalculateRoute
214 * @param[in] req_json_str JSON request from BinderClient
215 * @param[out] sessionHdl Session handle
216 * @param[out] routeHdl Route handle
217 * @return Success or failure of processing
219 bool AnalyzeRequest::CreateParamsCalculateRoute( const char* req_json_str, uint32_t& sessionHdl, uint32_t& routeHdl )
221 // Get sessionHandle, RouteHandle
222 return JsonObjectGetSessionHdlRouteHdl(req_json_str, sessionHdl, routeHdl);
227 * @brief Get session handle and route handle information from JSON
228 * @param[in] req_json_str JSON request from BinderClient
229 * @param[out] Session handle value
230 * @return Success or failure of processing
233 bool AnalyzeRequest::JsonObjectGetSessionHdl( const char* req_json_str, uint32_t& sessionHdl)
236 struct json_object *sess = NULL;
238 struct json_object *req_json = json_tokener_parse(req_json_str);
239 if (json_object_object_get_ex(req_json, "sessionHandle", &sess))
241 if (json_object_is_type(sess, json_type_int))
243 sessionHdl = json_object_get_int(sess);
248 fprintf(stdout, "key is not integer type.\n");
253 fprintf(stdout, "key sessionHandle not found.\n");
261 * @brief Get session handle and route handle information from JSON
262 * @param[in] req_json_str JSON request from BinderClient
263 * @param[out] Session handle value
264 * @param[out] Route handle value
265 * @return Success or failure of processing
268 bool AnalyzeRequest::JsonObjectGetSessionHdlRouteHdl( const char* req_json_str, uint32_t& sessionHdl, uint32_t& routeHdl)
271 struct json_object *sess = NULL;
272 struct json_object *rou = NULL;
274 struct json_object *req_json = json_tokener_parse(req_json_str);
275 if ((json_object_object_get_ex(req_json, "sessionHandle", &sess)) &&
276 (json_object_object_get_ex(req_json, "route", &rou)))
278 if (json_object_is_type(sess, json_type_int) &&
279 json_object_is_type(rou, json_type_int))
281 sessionHdl = json_object_get_int(sess);
282 routeHdl = json_object_get_int(rou);
287 fprintf(stdout, "key is not integer type.\n");
292 fprintf(stdout, "key sessionHandle or route not found.\n");