1 // Copyright 2017 AW SOFTWARE CO.,LTD
2 // Copyright 2017 AISIN AW CO.,LTD
4 #include "binder_reply.h"
5 #include "genivi/genivi-navicore-constants.h"
8 * @brief GeniviAPI GetPosition call
9 * @param[in] posList Map information on key and value of information acquired from Genivi
10 * @return Response information
12 APIResponse BinderReply::ReplyNavicoreGetPosition( std::map<int32_t, double>& posList )
14 APIResponse response = {0};
16 // Json information to return as a response
17 struct json_object* response_json = json_object_new_array();
18 std::map<int32_t, double>::iterator it;
20 // If the argument map is empty return
23 response.isSuccess = false;
24 response.errMessage = "posList is empty";
25 response.json_data = response_json;
29 // Make the passed Genivi response json format
30 for (it = posList.begin(); it != posList.end(); it++)
32 struct json_object* obj = json_object_new_object();
36 case NAVICORE_LATITUDE:
37 json_object_object_add(obj, "key", json_object_new_int(NAVICORE_LATITUDE));
38 json_object_object_add(obj, "value", json_object_new_double(it->second) );
39 json_object_array_add(response_json, obj);
42 case NAVICORE_LONGITUDE:
43 json_object_object_add(obj, "key", json_object_new_int(NAVICORE_LONGITUDE));
44 json_object_object_add(obj, "value", json_object_new_double(it->second));
45 json_object_array_add(response_json, obj);
48 case NAVICORE_HEADING:
49 json_object_object_add(obj, "key", json_object_new_int(NAVICORE_HEADING));
50 json_object_object_add(obj, "value", json_object_new_boolean (it->second));
51 json_object_array_add(response_json, obj);
55 case NAVICORE_TIMESTAMP:
56 json_object_object_add(obj, "key", json_object_new_int(NAVICORE_TIMESTAMP));
57 json_object_object_add(obj, "value", json_object_new_int(it->second));
58 json_object_array_add(response_json, obj);
63 json_object_object_add(obj, "key", json_object_new_int(NAVICORE_SPEED));
64 json_object_object_add(obj, "value", json_object_new_int(it->second));
65 json_object_array_add(response_json, obj);
69 case NAVICORE_SIMULATION_MODE:
70 json_object_object_add(obj, "key", json_object_new_int(NAVICORE_SIMULATION_MODE));
71 json_object_object_add(obj, "value", json_object_new_boolean (it->second));
72 json_object_array_add(response_json, obj);
76 fprintf(stderr, "Unknown key.");
82 response.json_data = response_json;
83 response.isSuccess = true;
88 * @brief GeniviAPI GetAllRoutes call
89 * @param[in] allRoutes Route handle information
90 * @return Response information
92 APIResponse BinderReply::ReplyNavicoreGetAllRoutes( std::vector< uint32_t > &allRoutes )
94 APIResponse response = {0};
96 // Json information to return as a response
97 struct json_object* response_json = json_object_new_array();
99 if (0 < allRoutes.size())
101 std::vector< uint32_t >::iterator it;
103 for (it = allRoutes.begin(); it != allRoutes.end(); it++)
105 struct json_object* obj = json_object_new_object();
106 json_object_object_add(obj, "route", json_object_new_int(*it));
107 json_object_array_add(response_json, obj);
111 response.json_data = response_json;
112 response.isSuccess = true;
117 * @brief GeniviAPI CreateRoute call
118 * @param[in] route Route handle
119 * @return Response information
121 APIResponse BinderReply::ReplyNavicoreCreateRoute( uint32_t route )
123 APIResponse response;
125 // Json information to return as a response
126 struct json_object* response_json = json_object_new_object();
127 json_object_object_add(response_json, "route", json_object_new_int(route));
129 response.json_data = response_json;
130 response.isSuccess = true;
135 * @brief GeniviAPI GetAllSessions call
136 * @param[in] allSessions Map information on key and value of information acquired from Genivi
137 * @return Response information
139 APIResponse BinderReply::ReplyNavicoreGetAllSessions( std::map<uint32_t, std::string> &allSessions )
141 APIResponse response = {0};
143 // Json information to return as a response
144 struct json_object* response_json = json_object_new_array();
145 std::map<uint32_t, std::string>::iterator it;
147 for (it = allSessions.begin(); it != allSessions.end(); it++)
149 struct json_object* obj = json_object_new_object();
151 if (NAVICORE_INVALID != it->first)
153 json_object_object_add(obj, "sessionHandle", json_object_new_int(it->first));
154 json_object_object_add(obj, "client", json_object_new_string(it->second.c_str()));
155 json_object_array_add(response_json, obj);
159 fprintf(stderr, "invalid key.");
160 json_object_put(obj);
164 response.json_data = response_json;
165 response.isSuccess = true;