fix bug
[staging/xdg-launcher.git] / src / runxdg.cpp
index 5553ff5..5fd4ac1 100644 (file)
@@ -72,7 +72,7 @@ void RunXDG::notify_ivi_control_cb (ilmObjectType object, t_ilm_uint id,
     pid_t surf_pid = surf_props.creatorPid;
 
     if (!created) {
-      AGL_DEBUG("ivi surface (id=%d, pid=%d) destroyed.", id, surf_pid);
+      AGL_DEBUG("ivi surface (id=%d, pid=%d)surf_pid destroyed.", id, surf_pid);
       m_launcher->unregister_surfpid(surf_pid);
       m_surfaces.erase(surf_pid);
       return;
@@ -328,24 +328,25 @@ int RunXDG::init_hs (void)
 
   std::function< void(json_object*) > handler = [this] (json_object* object) {
     json_object *val;
-
+      
     if (json_object_object_get_ex(object, "application_name", &val)) {
       const char *name = json_object_get_string(val);
 
       AGL_DEBUG("Event_TapShortcut <%s>", name);
-
-      if (strcmp(name, this->m_role.c_str()) == 0) {
-        // check app exist and re-launch if needed
-        AGL_DEBUG("Activesurface %s ", this->m_role.c_str());
-
-        json_object *obj = json_object_new_object();
-        json_object_object_add(obj, this->m_wm->kKeyDrawingName,
-                               json_object_new_string(this->m_role.c_str()));
-        json_object_object_add(obj, this->m_wm->kKeyDrawingArea,
-                               json_object_new_string("normal.full"));
-
-        this->m_wm->activateSurface(obj);
-      }
+    
+         json_object *para, *area;
+         json_object_object_get_ex(object, "parameter", &para);
+         json_object_object_get_ex(para, "area", &area);
+         const char *displayArea = json_object_get_string(area);
+         AGL_DEBUG("display area=%s",displayArea);
+
+      json_object *obj = json_object_new_object();
+      json_object_object_add(obj, this->m_wm->kKeyDrawingName,
+                             json_object_new_string(this->m_role.c_str()));
+      json_object_object_add(obj, this->m_wm->kKeyDrawingArea,
+                               json_object_new_string(displayArea));
+         this->m_wm->activateWindow(obj);
+      
     }
   };
   m_hs->set_event_handler(LibHomeScreen::Event_TapShortcut, handler);
@@ -410,7 +411,29 @@ int RunXDG::parse_config (const char *path_to_config)
   auto params = app->get_array_of<std::string>("params");
   for (const auto& param : *params)
   {
+    // replace special string "@port@" and "@token@"
+    size_t found = param.find("@port@");
+    if (found != std::string::npos) {
+      std::string sub1 = param.substr(0, found);
+      std::string sub2 = param.substr(found + 6, param.size() - found);
+      std::string str = sub1 + std::to_string(m_port) + sub2;
+      pl->m_args_v.push_back(str);
+      AGL_DEBUG("params[%s] (match @port@)", str.c_str());
+      continue;
+    }
+
+    found = param.find("@token@");
+    if (found != std::string::npos) {
+      std::string sub1 = param.substr(0, found);
+      std::string sub2 = param.substr(found + 7, param.size() - found);
+      std::string str = sub1 + m_token + sub2;
+      pl->m_args_v.push_back(str);
+      AGL_DEBUG("params[%s] (match @token@)", str.c_str());
+      continue;
+    }
+
     pl->m_args_v.push_back(param);
+
     AGL_DEBUG("params[%s]", param.c_str());
   }
 
@@ -422,6 +445,7 @@ RunXDG::RunXDG (int port, const char* token, const char* id)
   m_id = std::string(id);
   m_port = port;
   m_token = std::string(token);
+  is_first = true;
 
 
   auto path = std::string(getenv("AFM_APP_INSTALL_DIR"));
@@ -445,7 +469,6 @@ RunXDG::RunXDG (int port, const char* token, const char* id)
 
   // Setup ilmController API
   m_ic = new ILMControl(notify_ivi_control_cb_static, this);
-
   AGL_DEBUG("RunXDG created.");
 }
 
@@ -468,12 +491,13 @@ void RunXDG::setup_surface (int id)
     // the application has not been run yet (1st time launch)
     m_pending_create = false;
 
+  AGL_DEBUG("requestSurface(%s,%s)", m_role.c_str(), sid.c_str());
     json_object *obj = json_object_new_object();
     json_object_object_add(obj, m_wm->kKeyDrawingName,
                            json_object_new_string(m_role.c_str()));
     json_object_object_add(obj, m_wm->kKeyDrawingArea,
                            json_object_new_string("normal.full"));
-    m_wm->activateSurface(obj);
+    m_wm->activateWindow(obj);
   }
 }
 
@@ -503,7 +527,6 @@ void POSIXLauncher::unregister_surfpid (pid_t surf_pid)
 
 pid_t POSIXLauncher::find_surfpid_by_rid (pid_t rid)
 {
-  AGL_DEBUG("find surfpid by rid(%d)", rid);
   if (std::count(m_pid_v.begin(), m_pid_v.end(), rid)) {
     AGL_DEBUG("found return(%d)", rid);
     return rid;
@@ -568,7 +591,9 @@ void RunXDG::start (void)
 
   // in case, target app has already run
   if (m_launcher->m_rid) {
+         AGL_DEBUG("RunXDG::start");
     pid_t surf_pid = m_launcher->find_surfpid_by_rid(m_launcher->m_rid);
+         AGL_DEBUG("surf_pid--=%d",surf_pid);
     if (surf_pid > 0) {
       AGL_DEBUG("match: surf:pid=%d, afm:rid=%d", surf_pid,
                 m_launcher->m_rid);