summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuta Doi <yuta-d@witz-inc.co.jp>2018-05-18 16:27:38 +0900
committerKazumasa Mitsunari <knimitz@witz-inc.co.jp>2018-05-22 17:55:40 +0900
commit41a3a8263790c2ca197f3a2ea9ee1d0a94d1d534 (patch)
treee471cd3288e72626b36b2ce9c39053b85aaac57f
parent1d0f277f06f283ab28aa5e7d6b2d43b466d2baa4 (diff)
Add API which can get information about the car statesandbox/knimitz/add_event
getCarInfo() can get the car state informations as follows: - parking brake state : true/false - accelerator pedal position : 0-127.5 - car state : "stop"/"run" The details are described in doc/ApplicationGuide.md in project apps/agl-service-windowmanager-2017. Change-Id: Iac1052c172414b652aa94d94b386e22dff94cfdb Signed-off-by: Yuta Doi <yuta-d@witz-inc.co.jp>
-rw-r--r--src/libwindowmanager.cpp92
-rw-r--r--src/libwindowmanager.h3
2 files changed, 94 insertions, 1 deletions
diff --git a/src/libwindowmanager.cpp b/src/libwindowmanager.cpp
index 3caf470..5030322 100644
--- a/src/libwindowmanager.cpp
+++ b/src/libwindowmanager.cpp
@@ -83,6 +83,7 @@ class LibWindowmanager::Impl {
int getDisplayInfo(json_object *object);
int getAreaInfo(json_object *in_obj, json_object *out_obj);
+ int getCarInfo(json_object *in_obj, json_object *out_obj);
void set_event_handler(enum EventType et, handler_fun func);
@@ -560,6 +561,84 @@ int LibWindowmanager::Impl::getAreaInfo(json_object *in_obj, json_object *out_ob
return rc;
}
+int LibWindowmanager::Impl::getCarInfo(json_object *in_obj, json_object *out_obj) {
+ TRACE();
+ HMI_DEBUG("libwm", "called");
+
+ if (nullptr == in_obj) {
+ HMI_ERROR("libwm", "Argment is NULL!");
+ return -EINVAL;
+ }
+
+ if ((nullptr == this->loop) || (nullptr == this->wsj1)) {
+ HMI_ERROR("libwm", "LibWindowmanager is not initialized!");
+ return -EPERM;
+ }
+
+ int rc = -1;
+ /* send the request */
+ int rc2 =
+ this->api_call("GetCarInfo", in_obj,
+ [&rc, out_obj](bool ok, json_object *j) {
+ if (ok) {
+ json_object *j_res;
+ HMI_DEBUG("libwm", "j:%s", json_object_get_string(j));
+ if (json_object_object_get_ex(j, "response", &j_res)) {
+ HMI_DEBUG("libwm", "responce:%s", json_object_get_string(j_res));
+
+ json_object *j_val = nullptr;
+ if (!json_object_object_get_ex(j_res, "value", &j_val)) {
+ HMI_ERROR("libwm", "Not found key \"value\"");
+ rc = -EINVAL;
+ return;
+ }
+
+ if (json_type_boolean == json_object_get_type(j_val)) {
+ json_bool val_bool = json_object_get_boolean(j_val);
+ json_object_object_add(out_obj, "value", json_object_new_boolean(val_bool));
+ }
+ else if (json_type_double == json_object_get_type(j_val)) {
+ double val_double = json_object_get_double(j_val);
+ json_object_object_add(out_obj, "value", json_object_new_double(val_double));
+ }
+ else if (json_type_string == json_object_get_type(j_val)) {
+ const char* val_string = json_object_get_string(j_val);
+ json_object_object_add(out_obj, "value", json_object_new_string(val_string));
+ }
+ else if (json_type_int == json_object_get_type(j_val)) {
+ int val_int = json_object_get_int(j_val);
+ json_object_object_add(out_obj, "value", json_object_new_int(val_int));
+ }
+ else {
+ HMI_ERROR("libwm", "Invalid json_type");
+ rc = -EINVAL;
+ }
+ rc = 0;
+ }
+ else {
+ HMI_ERROR("libwm", "Not found key \"response\"");
+ rc = -EINVAL;
+ return;
+ }
+ } else {
+ HMI_ERROR("libwm", "Could not get car info: %s",
+ j != nullptr ? json_object_to_json_string_ext(
+ j, JSON_C_TO_STRING_PRETTY)
+ : "no-info");
+ rc = -EINVAL;
+ }
+ });
+
+ if (0 > rc2) {
+ HMI_ERROR("libwm", "api_call() failed");
+ rc = rc2;
+ }
+
+ HMI_DEBUG("libwm", "out_obj:%s", json_object_get_string(out_obj));
+
+ return rc;
+}
+
static void _on_reply_static(void *closure, struct afb_wsj1_msg *msg)
{
}
@@ -618,7 +697,8 @@ int LibWindowmanager::Impl::api_call(
int rc = 0;
if ((0 == strcmp("RequestSurface", verb)) ||
(0 == strcmp("GetDisplayInfo", verb)) ||
- (0 == strcmp("GetAreaInfo", verb))) {
+ (0 == strcmp("GetAreaInfo", verb)) ||
+ (0 == strcmp("GetCarInfo", verb))) {
// We need to wrap the actual onReply call once in order to
// *look* like a normal functions pointer (std::functions<>
// with captures cannot convert to function pointers).
@@ -785,6 +865,16 @@ int LibWindowmanager::getAreaInfo(const char *label, json_object *out_obj) {
return this->d->getAreaInfo(object, out_obj);
}
+int LibWindowmanager::getCarInfo(json_object *in_obj, json_object *out_obj) {
+ return this->d->getCarInfo(in_obj, out_obj);
+}
+
+int LibWindowmanager::getCarInfo(const char *label, json_object *out_obj) {
+ json_object *object = json_object_new_object();
+ json_object_object_add(object, this->kKeyLabel, json_object_new_string(label));
+ return this->d->getCarInfo(object, out_obj);
+}
+
void LibWindowmanager::set_event_handler(enum EventType et, handler_fun f) {
return this->d->set_event_handler(et, std::move(f));
}
diff --git a/src/libwindowmanager.h b/src/libwindowmanager.h
index 7c9bc5a..ea136de 100644
--- a/src/libwindowmanager.h
+++ b/src/libwindowmanager.h
@@ -42,6 +42,7 @@ public:
const char *kKeyDrawingArea = "drawing_area";
const char *kKeyDrawingRect = "drawing_rect";
const char *kKeyIviId = "ivi_id";
+ const char *kKeyLabel = "label";
enum EventType {
Event_Val_Invalid = -1,
@@ -84,8 +85,10 @@ public:
int endDraw(json_object *object);
int getDisplayInfo(json_object *object);
int getAreaInfo(json_object *in_obj, json_object *out_obj);
+ int getCarInfo(json_object *in_obj, json_object *out_obj);
int getAreaInfo(const char *label, json_object *out_obj);
+ int getCarInfo(const char *label, json_object *out_obj);
void set_event_handler(enum EventType et, handler_fun f);