aboutsummaryrefslogtreecommitdiffstats
path: root/src/binder_reply.cpp
blob: 172a22a4ae9e3bf5794f8e5cbfa6ca0069beea05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
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;
}