The role "video" can be shown in split area for ALS
[apps/agl-service-windowmanager.git] / src / app.cpp
index 20f5b56..07aab0b 100644 (file)
@@ -287,18 +287,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("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);
         }
@@ -351,14 +359,40 @@ void App::allocateWindowResource(char const *event, char const *drawing_name,
     // Release json_object
     json_object_put(json_in);
 
-    // Cat state
+    // Check parking brake state
+    json_object* json_parking_brake;
+    if (!json_object_object_get_ex(json_out, "parking_brake", &json_parking_brake)) {
+        reply("Not found key \"parking_brake\"");
+        return;
+    }
+
+    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
+        if ("parking_brake_off" == parking_brake_state) {
+            this->emitParkingBrakeOff();
+        }
+        else if ("parking_brake_on" == parking_brake_state) {
+            this->emitParkingBrakeOn();
+        }
+        else {
+            reply("Unknown parking brake state");
+            return;
+        }
+    }
+
+    // Check car state
     json_object* json_car;
     if (!json_object_object_get_ex(json_out, "car", &json_car)) {
         reply("Not found key \"car\"");
         return;
     }
 
-    json_bool is_changed;
     is_changed = jh::getBoolFromJson(json_car, "is_changed");
     if (is_changed) {
         // Update car state
@@ -378,7 +412,7 @@ void App::allocateWindowResource(char const *event, char const *drawing_name,
         }
     }
 
-    // Lamp state
+    // Check lamp state
     json_object* json_lamp;
     if (!json_object_object_get_ex(json_out, "lamp", &json_lamp)) {
         reply("Not found key \"lamp\"");
@@ -587,6 +621,16 @@ void App::emitHeadlampOn() {
     this->send_event(kListEventName[Event_HeadlampOn]);
 }
 
+void App::emitParkingBrakeOff() {
+    // Send ParkingBrakeOff event for all application
+    this->send_event(kListEventName[Event_ParkingBrakeOff]);
+}
+
+void App::emitParkingBrakeOn() {
+    // Send ParkingBrakeOn event for all application
+    this->send_event(kListEventName[Event_ParkingBrakeOn]);
+}
+
 void App::emitCarStop() {
     // Send CarStop event for all application
     this->send_event(kListEventName[Event_CarStop]);
@@ -637,6 +681,11 @@ result<int> App::api_request_surface(char const *drawing_name) {
       std::string role = this->app2role_[std::string(drawing_name)];
       this->role2surfaceid_[role] = id;
 
+      // Set map of (role, app)
+      // If the new app which has the same role which is had by existing app is requested,
+      // the role is given to the new app.
+      this->role2app_[role] = std::string(drawing_name);
+
       return Ok<int>(id);
    }
 
@@ -811,13 +860,15 @@ void App::deactivate(int id) {
       }
       // <<< FOR CES DEMO
 
+      this->layout_commit();
+
       this->emit_deactivated(label);
       this->emit_invisible(label);
    }
 }
 
 void App::deactivate(std::string role) {
-    std::string app = this->roleToApp(role);
+    std::string app = this->role2app_[role];
     auto const &id = this->lookup_id(app.c_str());
     if (!id) {
       HMI_ERROR("wm", "Surface does not exist");
@@ -868,7 +919,7 @@ int App::allocateSurface() {
          itr_layers != crr_layers.end(); ++itr_layers) {
         // Get layer
         std::string layer = itr_layers->first;
-        HMI_DEBUG("wm", "Update resource in %s layer", layer.c_str());
+        HMI_DEBUG("wm", "Try to update resource in %s layer", layer.c_str());
 
         // If layout is changed, update resouce
         if (this->lm_.isLayoutChanged(layer.c_str())) {
@@ -912,7 +963,7 @@ int App::allocateSurface() {
                     // Get category name
                     std::string crr_ctg = crr_rol_ctg.begin()->second;
 
-                    // Serch relevant role fron previous displayed role list
+                    // Serch relevant role from previous displayed role list
                     for (auto itr_role = prv_role_list.begin();
                          itr_role != prv_role_list.end(); ++itr_role) {
                         std::string prv_ctg = this->pm_.roleToCategory((*itr_role).c_str());
@@ -1000,7 +1051,7 @@ void App::setSurfaceSize(const char* role, const char* area) {
               size.x, size.y, size.w, size.h);
 
     // Emit syncDraw event
-    const char* app = this->roleToApp(role).c_str();
+    const char* app = this->role2app_[role].c_str();
     this->emit_syncdraw(app, area,
                         size.x, size.y, size.w, size.h);
 
@@ -1008,18 +1059,6 @@ void App::setSurfaceSize(const char* role, const char* area) {
     this->enqueue_flushdraw(surface_id);
 }
 
-std::string App::roleToApp(std::string role) {
-    HMI_DEBUG("wm", "Call");
-
-    for (auto itr = this->app2role_.begin();
-         itr != this->app2role_.end(); itr++) {
-        if (role == itr->second) {
-            return itr->first;
-        }
-    }
-    return std::string("none");
-}
-
 extern const char* kDefaultAppDb;
 int App::loadAppDb() {
     HMI_DEBUG("wm", "Call");
@@ -1037,9 +1076,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);
     }