summaryrefslogtreecommitdiffstats
path: root/src/libwindowmanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libwindowmanager.cpp')
-rw-r--r--src/libwindowmanager.cpp92
1 files changed, 91 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));
}