Waiting for the surface of new app is created before setting the size
[apps/agl-service-windowmanager.git] / src / app.cpp
index 777a07f..3ddd5e0 100644 (file)
@@ -119,6 +119,13 @@ App::App(wl::display *d)
    } catch (std::exception &e) {
       HMI_ERROR("wm", "Loading of configuration failed: %s", e.what());
    }
+
+   // Initialize current car info
+   this->crr_car_info_.parking_brake_stt = true;
+   this->crr_car_info_.accel_pedal_stt = false;
+   this->crr_car_info_.accel_pedal_pos = 0;
+   this->crr_car_info_.car_stt = "stop";
+   this->crr_car_info_.headlamp_stt = false;
 }
 
 int App::init() {
@@ -287,21 +294,26 @@ void App::allocateWindowResource(char const *event, char const *drawing_name,
         // This process will be removed
         // because the area "normal.full" and "normalfull" will be prohibited
         {
-            if (nullptr == drawing_area) {
-                new_area = "normal";
-            }
-            else if (0 == strcmp("normal.full", drawing_area)) {
-                new_area = "normal";
-            }
-            else if (0 == strcmp("restriction.split.sub", drawing_area)) {
-                new_area = "restriction.split.sub";
-            }
-            else if (0 == strcmp("homescreen", new_role)) {
-                // Now homescreen specifies "normalfull"
-                new_area = "full";
+            if (0 == strcmp("Restriction", drawing_name)) {
+                new_area = drawing_area;
             }
             else {
-                new_area = "normal";
+                if (nullptr == drawing_area) {
+                    new_area = "normal";
+                }
+                else if (0 == strcmp("normal.full", drawing_area)) {
+                    new_area = "normal";
+                }
+                else if (0 == strcmp("restriction.split.sub", drawing_area)) {
+                    new_area = "restriction.split.sub";
+                }
+                else if (0 == strcmp("homescreen", new_role)) {
+                    // Now homescreen specifies "normalfull"
+                    new_area = "full";
+                }
+                else {
+                    new_area = "normal";
+                }
             }
             HMI_DEBUG("wm", "drawing_area:%s, new_area: %s", drawing_area, new_area);
         }
@@ -364,15 +376,16 @@ void App::allocateWindowResource(char const *event, char const *drawing_name,
     json_bool is_changed;
     is_changed = jh::getBoolFromJson(json_parking_brake, "is_changed");
     if (is_changed) {
-        // Update parking brake state
         std::string parking_brake_state = jh::getStringFromJson(json_parking_brake, "state");
         HMI_DEBUG("wm", "parking_brake_state: %s", parking_brake_state.c_str());
 
-        // Emit parking brake event
+        // Update state and emit event
         if ("parking_brake_off" == parking_brake_state) {
+            this->crr_car_info_.parking_brake_stt = false;
             this->emitParkingBrakeOff();
         }
         else if ("parking_brake_on" == parking_brake_state) {
+            this->crr_car_info_.parking_brake_stt = true;
             this->emitParkingBrakeOn();
         }
         else {
@@ -381,6 +394,31 @@ void App::allocateWindowResource(char const *event, char const *drawing_name,
         }
     }
 
+    // Check accelerator pedal state
+    json_object* json_accel_pedal;
+    if (!json_object_object_get_ex(json_out, "accel_pedal", &json_accel_pedal)) {
+        reply("Not found key \"accel_pedal\"");
+        return;
+    }
+
+    is_changed = jh::getBoolFromJson(json_accel_pedal, "is_changed");
+    if (is_changed) {
+        std::string accel_pedal_state = jh::getStringFromJson(json_accel_pedal, "state");
+        HMI_DEBUG("wm", "accel_pedal_state: %s", accel_pedal_state.c_str());
+
+        // Update state
+        if ("accel_pedal_off" == accel_pedal_state) {
+            this->crr_car_info_.accel_pedal_stt = false;
+        }
+        else if ("accel_pedal_on" == accel_pedal_state) {
+            this->crr_car_info_.accel_pedal_stt = true;
+        }
+        else {
+            reply("Unknown accel pedal state");
+            return;
+        }
+    }
+
     // Check car state
     json_object* json_car;
     if (!json_object_object_get_ex(json_out, "car", &json_car)) {
@@ -390,15 +428,16 @@ void App::allocateWindowResource(char const *event, char const *drawing_name,
 
     is_changed = jh::getBoolFromJson(json_car, "is_changed");
     if (is_changed) {
-        // Update car state
         std::string car_state = jh::getStringFromJson(json_car, "state");
         HMI_DEBUG("wm", "car_state: %s", car_state.c_str());
 
         // Emit car event
         if ("car_stop" == car_state) {
+            this->crr_car_info_.car_stt = "stop";
             this->emitCarStop();
         }
         else if ("car_run" == car_state) {
+            this->crr_car_info_.car_stt = "run";
             this->emitCarRun();
         }
         else {
@@ -416,15 +455,16 @@ void App::allocateWindowResource(char const *event, char const *drawing_name,
 
     is_changed = jh::getBoolFromJson(json_lamp, "is_changed");
     if (is_changed) {
-        // Update car state
         std::string lamp_state = jh::getStringFromJson(json_lamp, "state");
         HMI_DEBUG("wm", "lamp_state: %s", lamp_state.c_str());
 
-        // Emit lamp event
+        // Update state and emit event
         if ("lamp_off" == lamp_state) {
+            this->crr_car_info_.headlamp_stt = false;
             this->emitHeadlampOff();
         }
         else if ("lamp_on" == lamp_state) {
+            this->crr_car_info_.headlamp_stt = true;
             this->emitHeadlampOn();
         }
         else {
@@ -855,6 +895,8 @@ void App::deactivate(int id) {
       }
       // <<< FOR CES DEMO
 
+      this->layout_commit();
+
       this->emit_deactivated(label);
       this->emit_invisible(label);
    }
@@ -1031,6 +1073,12 @@ void App::setSurfaceSize(const char* role, const char* area) {
 
     // Set destination to the display rectangle
     int surface_id = this->role2surfaceid_[role];
+
+    if (!this->controller->surface_exists(surface_id)) {
+        // Block until all pending request are processed by wayland display server
+        // because waiting for the surface of new app is created
+        this->display->roundtrip();
+    }
     auto &s = this->controller->surfaces[surface_id];
     s->set_destination_rectangle(size.x, size.y, size.w, size.h);
     this->layout_commit();
@@ -1052,6 +1100,10 @@ void App::setSurfaceSize(const char* role, const char* area) {
     this->enqueue_flushdraw(surface_id);
 }
 
+void App::setAccelPedalPos(double val) {
+    this->crr_car_info_.accel_pedal_pos = val;
+}
+
 extern const char* kDefaultAppDb;
 int App::loadAppDb() {
     HMI_DEBUG("wm", "Call");
@@ -1069,9 +1121,9 @@ int App::loadAppDb() {
     }
 
     // Load app.db
-    HMI_DEBUG("wm", "file_name:%s", file_name.c_str());
-    json_object* json_obj = json_object_from_file(file_name.c_str());
-    if (nullptr == json_obj) {
+    json_object* json_obj;
+    int ret = jh::inputJsonFilie(file_name.c_str(), &json_obj);
+    if (0 > ret) {
         HMI_ERROR("wm", "Could not open app.db, so use default role information");
         json_obj = json_tokener_parse(kDefaultAppDb);
     }