Add conversion map role2app
authorYuta Doi <yuta-d@witz-inc.co.jp>
Wed, 9 May 2018 08:15:42 +0000 (17:15 +0900)
committerYuta Doi <yuta-d@witz-inc.co.jp>
Wed, 9 May 2018 08:15:42 +0000 (17:15 +0900)
Change-Id: I1e194ecc9fb90ccb4c24e114ac1513ed19f0c0a3
Signed-off-by: Yuta Doi <yuta-d@witz-inc.co.jp>
src/app.cpp
src/app.hpp

index afd690f..b9338a9 100644 (file)
@@ -673,6 +673,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);
    }
 
@@ -853,7 +858,7 @@ void App::deactivate(int id) {
 }
 
 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");
@@ -1036,7 +1041,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);
 
@@ -1044,18 +1049,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");
index 57ffee2..b7d6815 100644 (file)
@@ -235,23 +235,22 @@ struct App {
    void surface_removed(uint32_t surface_id);
 
 private:
-#if 1 // @@@@@
    PolicyManager pm_;
    LayoutManager lm_;
    std::unordered_map<std::string, int> role2surfaceid_;
    std::unordered_map<std::string, std::string> app2role_;
+   std::unordered_map<std::string, std::string> role2app_;
    std::unordered_map<int, int> appid2role_;
 
    int allocateSurface();
    void setSurfaceSize(const char* role, const char* area);
-   std::string roleToApp(std::string role);
    int loadAppDb();
 
 #if 0
    struct id_allocator app_id_alloc_;
    std::unordered_map<std::string, int> appname2appid_;
 #endif
-#endif
+
    optional<int> lookup_id(char const *name);
    optional<std::string> lookup_name(int id);