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
{
// 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();
}
}
+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
*/
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);
}
}