aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazumasa Mitsunari <knimitz@witz-inc.co.jp>2018-09-25 19:30:10 +0900
committerKazumasa Mitsunari <knimitz@witz-inc.co.jp>2018-09-25 19:30:10 +0900
commit98472cfd1ecbc5667d8383c8ef1e1a8d538d9fc1 (patch)
treeea8ce152a1bd71e1192938927b12d588b9fc3e61
parentb9da444f98dd5075dcda05932c47c732a5ae230f (diff)
Merge branch 'sandbox/knimitz/fix_set_role'
Change-Id: Ia53eb039ef5dd6a1eac3bb333d5fe67b4d906ef9 Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
-rw-r--r--src/window_manager.cpp161
-rw-r--r--src/window_manager.hpp2
2 files changed, 98 insertions, 65 deletions
diff --git a/src/window_manager.cpp b/src/window_manager.cpp
index f0258f7..f53107e 100644
--- a/src/window_manager.cpp
+++ b/src/window_manager.cpp
@@ -61,6 +61,16 @@ static sd_event_source *g_timer_ev_src = nullptr;
static AppList g_app_list;
static WindowManager *g_context;
+struct AfbClosure {
+public:
+ AfbClosure(unsigned pid, unsigned ppid, unsigned surface)
+ : pid(pid), ppid(ppid), surface(surface) {}
+ ~AfbClosure() = default;
+ unsigned pid;
+ unsigned ppid;
+ unsigned surface;
+};
+
namespace
{
@@ -293,7 +303,7 @@ bool WindowManager::api_set_role(char const *appid, char const *drawing_name)
// add client into the db
g_app_list.addClient(s_appid, l_id, s_role);
// Set role map of (new, old)
- this->rolenew2old[role] = s_role;
+ this->rolenew2old[role] = string(drawing_name);
}
// for(auto itr = this->tmp_surface2app.begin();
@@ -608,6 +618,72 @@ void WindowManager::send_event(char const *evname, char const *label, char const
}
}
+string WindowManager::searchApp(unsigned pid, unsigned ppid, unsigned surface, json_object* resp)
+{
+ // retrieve appid from pid from application manager
+ string appid;
+ // check appid then add it to the client
+ HMI_INFO("Runners:%s", json_object_get_string(resp));
+ int size = json_object_array_length(resp);
+ HMI_INFO("pid %d, ppid %d, surface %d",pid, ppid, surface);
+ for(int i = 0; i < size; i++)
+ {
+ json_object *j = json_object_array_get_idx(resp, i);
+ int runid = jh::getIntFromJson(j, "runid");
+ const char* id = jh::getStringFromJson(j, "id");
+ HMI_DEBUG("Appid %s, runid %d", id, runid);
+ if(id && (runid == ppid))
+ {
+ string s_id = id;
+ s_id.erase(s_id.find('@'));
+ appid = s_id;
+ HMI_INFO("App found %s", appid.c_str());
+ break;
+ }
+ }
+ if(appid.empty())
+ {
+ HMI_WARNING("Failed to retrieve id");
+ }
+ return appid;
+}
+
+void WindowManager::storeSurface(const string& appid, unsigned ppid, unsigned surface)
+{
+ auto elem = std::find_if(this->tmp_services.begin(), this->tmp_services.end(),
+ [&appid](TmpService& ts){
+ return (ts.dest == appid );
+ });
+
+ if(elem == this->tmp_services.end())
+ {
+ // attachApp
+ auto client = g_app_list.lookUpClient(elem->dest);
+ if(client == nullptr)
+ {
+ return;
+ }
+ HMI_INFO("Attach surface %d (service %s) to app %s", surface, elem->service.c_str(), elem->dest.c_str());
+ client->attachServiceSurface(elem->service, surface);
+ }
+ else
+ {
+ // setRole
+ auto client = g_app_list.lookUpClient(appid);
+ if(client != nullptr)
+ {
+ client->addSurface(surface);
+ this->id_alloc.register_name_id(client->role(), surface);
+ }
+ else
+ {
+ // Store tmp surface and appid for application
+ // who requests setRole after creating shell surface
+ this->tmp_surface2app.emplace(surface, TmpClient{appid, ppid});
+ }
+ }
+}
+
/**
* proxied events
*/
@@ -650,75 +726,30 @@ void WindowManager::surface_created(unsigned pid, unsigned surface_id)
HMI_ERROR("File system may be different");
return;
}
+ struct AfbClosure* c = new struct AfbClosure(pid, ppid, surface_id);
// search pid from surfaceID
- json_object *response;
- afb_service_call_sync("afm-main", "runners", nullptr, &response);
-
- // retrieve appid from pid from application manager
- string appid = "";
- if(response == nullptr)
- {
- HMI_ERROR("No runners");
- }
- else
- {
- // check appid then add it to the client
- HMI_INFO("Runners:%s", json_object_get_string(response));
- int size = json_object_array_length(response);
- for(int i = 0; i < size; i++)
- {
- json_object *j = json_object_array_get_idx(response, i);
- const char* id = jh::getStringFromJson(j, "id");
- int runid = jh::getIntFromJson(j, "runid");
- if(id && (runid > 0))
+ afb_service_call("afm-main", "runners", json_object_new_object(),
+ [](void* closure, int stat, json_object* resp){
+ HMI_DEBUG("check %s", json_object_get_string(resp));
+ struct AfbClosure* c = static_cast<struct AfbClosure*>(closure);
+ HMI_DEBUG("check");
+ if(stat != 0)
{
- if(runid == ppid)
+ HMI_ERROR("Failed to call runners");
+ }
+ else
+ {
+ json_object* j;
+ json_object_object_get_ex(resp, "response", &j);
+ string appid = g_context->searchApp(c->pid, c->ppid, c->surface, j);
+ if(!appid.empty())
{
- appid = id;
- break;
+ g_context->storeSurface(appid, c->ppid, c->surface);
}
}
- }
- if(appid == "")
- {
- HMI_ERROR("Not found");
- }
- }
- json_object_put(response);
-
- auto elem = std::find_if(this->tmp_services.begin(), this->tmp_services.end(),
- [&appid](TmpService& ts){
- return (ts.dest == appid );
- });
- if(elem == this->tmp_services.end())
- {
- // attachApp
- auto client = g_app_list.lookUpClient(elem->dest);
- if(client == nullptr)
- {
- return;
- }
- HMI_INFO("Attach surface %d (service %s) to app %s", surface_id, elem->service.c_str(), elem->dest.c_str());
- client->attachServiceSurface(elem->service, surface_id);
- }
- else
- {
- // setRole
- auto client = g_app_list.lookUpClient(appid);
- if(client != nullptr)
- {
- client->addSurface(surface_id);
- this->id_alloc.register_name_id(client->role(), surface_id);
- }
- else
- {
- /*
- * Store tmp surface and appid for application
- * who requests setRole after creating shell surface
- */
- this->tmp_surface2app.emplace(surface_id, TmpClient{appid, ppid});
- }
- }
+ json_object_put(resp);
+ delete c;
+ }, c);
}
}
diff --git a/src/window_manager.hpp b/src/window_manager.hpp
index 481d16c..6811110 100644
--- a/src/window_manager.hpp
+++ b/src/window_manager.hpp
@@ -207,6 +207,8 @@ class WindowManager
void timerHandler();
void startTransitionWrapper(std::vector<WMAction> &actions);
void processError(WMError error);
+ std::string searchApp(unsigned pid, unsigned ppid, unsigned surface, json_object* resp);
+ void storeSurface(const std::string& appid, unsigned ppid, unsigned surface);
const std::vector<const char *> kListEventName{
"active",