aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app.cpp37
-rw-r--r--src/app.hpp1
-rw-r--r--src/main.cpp35
3 files changed, 68 insertions, 5 deletions
diff --git a/src/app.cpp b/src/app.cpp
index ac789ad..eaebd59 100644
--- a/src/app.cpp
+++ b/src/app.cpp
@@ -807,11 +807,6 @@ result<json_object *> App::api_get_area_info(char const *drawing_name) {
return Err<json_object *>("Could not find layer for surface");
}
- struct LayoutState &state = *o_state;
- if ((state.main != *surface_id) && (state.sub != *surface_id)) {
- return Err<json_object *>("Surface is inactive");
- }
-
// Set area rectangle
compositor::rect area_info = this->area_info[*surface_id];
json_object *object = json_object_new_object();
@@ -823,6 +818,38 @@ result<json_object *> App::api_get_area_info(char const *drawing_name) {
return Ok<json_object *>(object);
}
+result<json_object *> App::api_get_car_info(char const *label) {
+ HMI_DEBUG("wm", "called");
+
+ json_object *j_in = nullptr;
+ json_object *j_out = nullptr;
+
+ if (0 == strcmp("parking_brake_status", label)) {
+ // Get parking brake status
+ json_bool val = this->crr_car_info_.parking_brake_stt;
+ j_in = json_object_new_boolean(val);
+ }
+ else if (0 == strcmp("accelerator.pedal.position", label)) {
+ // Get accelerator pedal position
+ double val = this->crr_car_info_.accel_pedal_pos;
+ j_in = json_object_new_double(val);
+ }
+ else if (0 == strcmp("car_state", label)) {
+ // Get car state
+ const char* val = this->crr_car_info_.car_stt;
+ j_in = json_object_new_string(val);
+ }
+ else {
+ return Err<json_object *>("Car info does not exist");
+ }
+
+ // Create output object
+ j_out = json_object_new_object();
+ json_object_object_add(j_out, "value", j_in);
+
+ return Ok<json_object *>(j_out);
+}
+
void App::activate(int id) {
auto ip = this->controller->sprops.find(id);
if (ip != this->controller->sprops.end()) {
diff --git a/src/app.hpp b/src/app.hpp
index 13bc421..2e6ad69 100644
--- a/src/app.hpp
+++ b/src/app.hpp
@@ -233,6 +233,7 @@ struct App {
void api_enddraw(char const *drawing_name);
result<json_object *> api_get_display_info();
result<json_object *> api_get_area_info(char const *drawing_name);
+ result<json_object *> api_get_car_info(char const *label);
void api_ping();
void send_event(char const *evname);
void send_event(char const *evname, char const *label);
diff --git a/src/main.cpp b/src/main.cpp
index 1db33a4..99ad323 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -452,6 +452,40 @@ void windowmanager_getareainfo_thunk(afb_req req) noexcept {
}
+void windowmanager_getcarinfo_thunk(afb_req req) noexcept {
+ std::lock_guard<std::mutex> guard(binding_m);
+ #ifdef ST
+ ST();
+ #endif
+ if (g_afb_instance == nullptr) {
+ afb_req_fail(req, "failed", "Binding not initialized, did the compositor die?");
+ return;
+ }
+
+ try {
+ json_object *jreq = afb_req_json(req);
+
+ json_object *j_label = nullptr;
+ if (! json_object_object_get_ex(jreq, "label", &j_label)) {
+ afb_req_fail(req, "failed", "Need char const* argument label");
+ return;
+ }
+ char const* a_label = json_object_get_string(j_label);
+
+ auto ret = g_afb_instance->app.api_get_car_info(a_label);
+ if (ret.is_err()) {
+ afb_req_fail(req, "failed", ret.unwrap_err());
+ return;
+ }
+
+ afb_req_success(req, ret.unwrap(), "success");
+ } catch (std::exception &e) {
+ afb_req_fail_f(req, "failed", "Uncaught exception while calling getcarinfo: %s", e.what());
+ return;
+ }
+
+}
+
void windowmanager_wm_subscribe(afb_req req) noexcept {
std::lock_guard<std::mutex> guard(binding_m);
#ifdef ST
@@ -650,6 +684,7 @@ const struct afb_verb_v2 windowmanager_verbs[] = {
{ "getdisplayinfo", windowmanager_getdisplayinfo_thunk, nullptr, nullptr, AFB_SESSION_NONE },
{ "getareainfo", windowmanager_getareainfo_thunk, nullptr, nullptr, AFB_SESSION_NONE },
{ "wm_subscribe", windowmanager_wm_subscribe, nullptr, nullptr, AFB_SESSION_NONE },
+ { "getcarinfo", windowmanager_getcarinfo_thunk, nullptr, nullptr, AFB_SESSION_NONE },
{ "list_drawing_names", windowmanager_list_drawing_names, nullptr, nullptr, AFB_SESSION_NONE },
{ "ping", windowmanager_ping, nullptr, nullptr, AFB_SESSION_NONE },
{ "debug_status", windowmanager_debug_status, nullptr, nullptr, AFB_SESSION_NONE },