summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuta Doi <yuta-d@witz-inc.co.jp>2018-05-18 16:27:38 +0900
committerYuta Doi <yuta-d@witz-inc.co.jp>2018-05-18 16:27:38 +0900
commit74efea57ed46f34dcc5d4e70682e94e6aed0ab73 (patch)
treeb6720b1ecd59237f7a521d0273f10fb9cea89ff9
parent9bd3d91218f196da4246e87c8273548f04ced57e (diff)
Add API which can get information about the car state
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 c62550b..fb833d4 100644
--- a/src/libwindowmanager.cpp
+++ b/src/libwindowmanager.cpp
@@ -80,6 +80,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);
@@ -557,6 +558,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)
{
}
@@ -615,7 +694,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).
@@ -782,6 +862,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 bac9f46..59372e1 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,
@@ -79,8 +80,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);