Fix xdg-runcher doesn't show up 95/20595/4
authorKazumasa Mitsunari <knimitz@witz-inc.co.jp>
Wed, 13 Mar 2019 09:02:37 +0000 (18:02 +0900)
committerKazumasa Mitsunari <knimitz@witz-inc.co.jp>
Thu, 14 Mar 2019 04:01:46 +0000 (13:01 +0900)
xdg-runcher calls "subscribe" before requestSurface,
then windowmanager reject it because WMClient object
is not created yet.
This patch changes to register WMClient
if it is not created when App calls "subscribe".
Application doesn't need to care about the order of
"requestSurface" and "subscribe".

Bug-AGL: SPEC-2218

Change-Id: Ia82ff939dfdb2bbfd377bd50fd3d4b844451cd3b
Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
src/applist.cpp
src/applist.hpp
src/window_manager.cpp
src/window_manager.hpp
src/wm_client.cpp
src/wm_client.hpp

index 67980f1..473d687 100644 (file)
@@ -81,6 +81,27 @@ void AppList::addClient(const string &appid, unsigned layer, const string &role)
     this->clientDump();
 }
 
+/**
+ * Add Client to the list
+ *
+ * This function is overload function.
+ * But this function just register application.
+ * So an application does not have role, surface, layer.
+ * Client need to register role and layer afterward.
+ *
+ * @param     string[in]   Application id. This will be the key to withdraw the information.
+ * @return    None
+ * @attention This function should be called once for the app
+ *            Caller should take care not to be called more than once.
+ */
+void AppList::addClient(const string &appid)
+{
+    std::lock_guard<std::mutex> lock(this->mtx);
+    shared_ptr<WMClient> client = std::make_shared<WMClient>(appid, 0, "");
+    this->app2client[appid] = client;
+    this->clientDump();
+}
+
 /**
  * Remove WMClient from the list
  *
index 085504a..0fe3bbd 100644 (file)
@@ -45,6 +45,7 @@ class AppList
     void addClient(const std::string &appid, unsigned layer,
                     unsigned surface, const std::string &role);
     void addClient(const std::string &appid, unsigned layer, const std::string &role);
+    void addClient(const std::string &appid);
     void removeClient(const std::string &appid);
     bool contains(const std::string &appid) const;
     int  countClient() const;
index 4fcab5f..1e3a926 100644 (file)
@@ -167,21 +167,25 @@ result<int> WindowManager::api_request_surface(char const *appid, char const *dr
 
     if(!g_app_list.contains(str_id))
     {
-        lid = this->lc->getNewLayerID(role);
+        unsigned lid = this->generateLayerForClient(role);
         if (lid == 0)
         {
-            // register drawing_name as fallback and make it displayed.
-            lid = this->lc->getNewLayerID(string("fallback"));
-            HMI_DEBUG("%s is not registered in layers.json, then fallback as normal app", role.c_str());
-            if (lid == 0)
-            {
-                return Err<int>("Designated role does not match any role, fallback is disabled");
-            }
+            return Err<int>("Designated role does not match any role, fallback is disabled");
         }
-        this->lc->createNewLayer(lid);
         // add client into the db
         g_app_list.addClient(str_id, lid, role);
     }
+    else
+    {
+        // This case occurs when an client calls "subscribe" before request_surface.
+        // Then application doesn't have layer and role yet.
+        auto client = g_app_list.lookUpClient(str_id);
+        if(client->layerID() == 0)
+        {
+            client->setLayerID(this->generateLayerForClient(role));
+        }
+        client->setRole(role);
+    }
 
     // generate surface ID for ivi-shell application
     auto rname = this->id_alloc.lookup(role);
@@ -224,21 +228,25 @@ char const *WindowManager::api_request_surface(char const *appid, char const *dr
 
     if(!g_app_list.contains(str_id))
     {
-        unsigned l_id = this->lc->getNewLayerID(role);
+        unsigned l_id = this->generateLayerForClient(role);
         if (l_id == 0)
         {
-            // register drawing_name as fallback and make it displayed.
-            l_id = this->lc->getNewLayerID("fallback");
-            HMI_DEBUG("%s is not registered in layers.json, then fallback as normal app", role.c_str());
-            if (l_id == 0)
-            {
-                return "Designated role does not match any role, fallback is disabled";
-            }
+            return "Designated role does not match any role, fallback is disabled";
         }
-        this->lc->createNewLayer(l_id);
         // add client into the db
         g_app_list.addClient(str_id, l_id, role);
     }
+    else
+    {
+        // This case occurs when an client calls "subscribe" before request_surface.
+        // Then application doesn't have layer and role yet.
+        auto client = g_app_list.lookUpClient(str_id);
+        if(client->layerID() == 0)
+        {
+            client->setLayerID(this->generateLayerForClient(role));
+        }
+        client->setRole(role);
+    }
 
     auto rname = this->id_alloc.lookup(role);
 
@@ -501,11 +509,15 @@ bool WindowManager::api_subscribe(afb_req_t req, EventType event_id)
     {
         string id = appid;
         free(appid);
-        auto client = g_app_list.lookUpClient(id);
-        if(client != nullptr)
+        if(!g_app_list.contains(id))
         {
-            ret = client->subscribe(req, kListEventName[event_id]);
+            g_app_list.addClient(id);
         }
+        g_app_list.lookUpClient(id)->subscribe(req, kListEventName[event_id]);
+    }
+    else
+    {
+        HMI_ERROR("appid is not set");
     }
     return ret;
 }
@@ -699,6 +711,24 @@ void WindowManager::processError(WMError error)
     this->processNextRequest();
 }
 
+unsigned WindowManager::generateLayerForClient(const string& role)
+{
+    unsigned lid = this->lc->getNewLayerID(role);
+    if (lid == 0)
+    {
+        // register drawing_name as fallback and make it displayed.
+        lid = this->lc->getNewLayerID(string("fallback"));
+        HMI_DEBUG("%s is not registered in layers.json, then fallback as normal app", role.c_str());
+        if (lid == 0)
+        {
+            return lid;
+        }
+    }
+    this->lc->createNewLayer(lid);
+    // add client into the db
+    return lid;
+}
+
 WMError WindowManager::setRequest(const string& appid, const string &role, const string &area,
                             Task task, unsigned* req_num)
 {
index eac6576..4c2c49b 100644 (file)
@@ -134,7 +134,6 @@ struct TmpClient
     unsigned layer;
 };
 
-
 class WindowManager
 {
   public:
@@ -195,6 +194,7 @@ class WindowManager
     void processError(WMError error);
 
   private:
+    unsigned generateLayerForClient(const std::string &role);
     WMError setRequest(const std::string &appid, const std::string &role, const std::string &area,
                              Task task, unsigned *req_num);
     WMError checkPolicy(unsigned req_num);
index d3f0364..4bccb8c 100644 (file)
@@ -120,11 +120,21 @@ string WMClient::role() const
     return this->main_role;
 }
 
+void WMClient::setRole(const string& role)
+{
+    this->main_role = role;
+}
+
 unsigned WMClient::layerID() const
 {
     return this->layer;
 }
 
+void WMClient::setLayerID(unsigned id)
+{
+    this->layer = id;
+}
+
 unsigned WMClient::surfaceID() const
 {
     return this->surface;
index 17d2221..7df4dea 100644 (file)
@@ -45,7 +45,9 @@ class WMClient
 
     std::string appID() const;
     std::string role() const;
+    void setRole(const std::string& role);
     unsigned layerID() const;
+    void setLayerID(unsigned id);
     unsigned surfaceID() const;
     void registerSurface(unsigned surface);
     void activate();