aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTadao Tanikawa <tanikawa.tadao@jp.panasonic.com>2017-12-09 18:20:35 +0900
committerTadao Tanikawa <tanikawa.tadao@jp.panasonic.com>2017-12-09 18:20:35 +0900
commit901ee93f95c8a4ae9e5a10e1f2832d171ba546f6 (patch)
tree255a5828523f889fd56827f849fa15d2e65da36a
parent325511abff423ffee62ce5df0b64b512d9346912 (diff)
RunXDG: Improve pid matching
Change-Id: I2271506314bdd2aaea8688a4aa2e2f06a59f2d25 Signed-off-by: Tadao Tanikawa <tanikawa.tadao@jp.panasonic.com>
-rw-r--r--xdg-launcher/src/runxdg.cpp76
-rw-r--r--xdg-launcher/src/runxdg.hpp5
2 files changed, 68 insertions, 13 deletions
diff --git a/xdg-launcher/src/runxdg.cpp b/xdg-launcher/src/runxdg.cpp
index 7fca08c..e3db8a1 100644
--- a/xdg-launcher/src/runxdg.cpp
+++ b/xdg-launcher/src/runxdg.cpp
@@ -86,11 +86,14 @@ void RunXDG::notify_ivi_control_cb (ilmObjectType object, t_ilm_uint id,
if (!created) {
AGL_DEBUG("ivi surface (id=%d, pid=%d) destroyed.", id, surf_pid);
+ m_pgids.erase(surf_pid);
m_surfaces.erase(surf_pid);
return;
}
- if (m_afm->m_rid == surf_pid) {
+ register_surfpid(surf_pid);
+ if (surf_pid == find_surfpid_by_rid(m_afm->m_rid)) {
+ AGL_DEBUG("match: surf:pid=%d, afm:rid=%d", surf_pid, m_afm->m_rid);
setup_surface(id);
}
@@ -178,14 +181,14 @@ int AFMDBus::launch (std::string &name)
AGL_DEBUG("dbus message get (%s)", val);
- m_rid = std::stol(std::string(val));
- AGL_DEBUG("RID = %d", m_rid);
+ pid_t rid = std::stol(std::string(val));
+ AGL_DEBUG("RID = %d", rid);
g_object_unref(conn);
g_object_unref(msg);
g_object_unref(re);
- return 0;
+ return rid;
}
volatile sig_atomic_t e_flag = 0;
@@ -282,6 +285,7 @@ int RunXDG::init_hs (void)
AGL_DEBUG("Event_TapShortcut <%s>", name);
if (strcmp(name, app_name.c_str()) == 0) {
+ // check app exist and re-launch if needed
AGL_DEBUG("Activesurface %s ", app_name.c_str());
json_object *obj = json_object_new_object();
@@ -316,6 +320,8 @@ RunXDG::RunXDG (int bus_type, int port, const char* &token)
else
m_afm = new AFMWebSocket();
+ m_afm->m_rid = -1;
+
// Setup HomeScreen/WindowManager API
if (init_wm())
AGL_FATAL("cannot setup wm API");
@@ -356,29 +362,73 @@ void RunXDG::setup_surface (int id)
}
}
+void RunXDG::register_surfpid (pid_t surf_pid)
+{
+ pid_t pgid = 0;
+
+ pgid = getpgid(surf_pid);
+
+ if (pgid < 0) {
+ AGL_DEBUG("fail to get process group id");
+ return;
+ }
+
+ AGL_DEBUG("Surface creator is pid=%d, pgid=%d", surf_pid, pgid);
+
+ if (!m_pgids.count(pgid)) {
+ m_pgids[pgid] = surf_pid;
+ }
+}
+
+void RunXDG::unregister_surfpid (pid_t surf_pid)
+{
+ auto itr = m_pgids.begin();
+ while (itr != m_pgids.end()) {
+ if (itr->second == surf_pid) {
+ m_pgids.erase(itr++);
+ } else {
+ ++itr;
+ }
+ }
+}
+
+pid_t RunXDG::find_surfpid_by_rid (pid_t rid)
+{
+ auto itr = m_pgids.find(rid);
+ if (itr != m_pgids.end())
+ return itr->second;
+
+ return -1;
+}
+
void RunXDG::start (void)
{
// Initialize SIGTERM handler
init_signal();
/* Launch XDG application */
- int ret;
+ pid_t rid;
- ret = m_afm->launch(target_app_id);
- if (ret < 0) {
+ rid = m_afm->launch(target_app_id);
+ if (rid < 0) {
AGL_FATAL("cannot launch XDG app (%s)", target_app_id);
}
+ m_afm->m_rid = rid;
// take care 1st time launch
- m_pending_create = true;
AGL_DEBUG("waiting for notification: surafce created");
+ m_pending_create = true;
// in case, target app has already run
- auto itr = m_surfaces.find(m_afm->m_rid);
- if (itr != m_surfaces.end()) {
- int id = itr->second;
- AGL_DEBUG("surface %d for <%s> already exists", id, app_name.c_str());
- setup_surface(id);
+ pid_t surf_pid = find_surfpid_by_rid(m_afm->m_rid);
+ if (surf_pid > 0) {
+ AGL_DEBUG("match: surf:pid=%d, afm:rid=%d", surf_pid, m_afm->m_rid);
+ auto itr = m_surfaces.find(surf_pid);
+ if (itr != m_surfaces.end()) {
+ int id = itr->second;
+ AGL_DEBUG("surface %d for <%s> already exists", id, app_name.c_str());
+ setup_surface(id);
+ }
}
/* sleep until terminate */
diff --git a/xdg-launcher/src/runxdg.hpp b/xdg-launcher/src/runxdg.hpp
index df8f51c..2a94732 100644
--- a/xdg-launcher/src/runxdg.hpp
+++ b/xdg-launcher/src/runxdg.hpp
@@ -108,6 +108,7 @@ class RunXDG
ILMControl *m_ic;
std::map<int, int> m_surfaces; // pair of <afm:rid, ivi:id>
+ std::map<int, int> m_pgids; // pair of <afm:rid, ivi:pid>
bool m_pending_create = false;
@@ -115,6 +116,10 @@ class RunXDG
int init_hs(void);
void setup_surface(int id);
+
+ void register_surfpid(pid_t surf_pid);
+ void unregister_surfpid(pid_t surf_pid);
+ pid_t find_surfpid_by_rid(pid_t app_pid);
};
#endif // RUNXDG_HPP