X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fhs-clientmanager.cpp;fp=src%2Fhs-clientmanager.cpp;h=913e9b671444c2cd9c13709f9fd93005aa4b6fc1;hb=b47445061a00ba7bde7a8edd145a7d109b22d4a7;hp=a1472b85f754c97046a2fd1a71dfa2b0aa33f694;hpb=d90e4284fc6fc61371c7b31b8cbb9fd99c369636;p=apps%2Fagl-service-homescreen.git diff --git a/src/hs-clientmanager.cpp b/src/hs-clientmanager.cpp index a1472b8..913e9b6 100644 --- a/src/hs-clientmanager.cpp +++ b/src/hs-clientmanager.cpp @@ -22,7 +22,6 @@ static const char _homescreen[] = "homescreen"; static const char _area[] = "area"; static const char _parameter[] = "parameter"; -const std::string _listen_all("all"); HS_ClientManager* HS_ClientManager::me = nullptr; @@ -76,8 +75,6 @@ HS_ClientManager* HS_ClientManager::instance(void) int HS_ClientManager::init(void) { listener_list.clear(); - std::list interface_list; - listener_list[_listen_all] = std::move(interface_list); } /** @@ -246,40 +243,6 @@ int HS_ClientManager::pushEvent(const char *event, struct json_object *param, st return 0; } -/** - * check register application - * - * #### Parameters - * - api : the api - * - appid : register application's id - * - * #### Return - * true : checked - * false : not checked - * - */ -bool HS_ClientManager::checkRegisterApp(afb_api_t api, const std::string &appid) -{ - bool ret = true; - auto &ip = listener_list[_listen_all]; - if(!ip.empty()) { - for(auto &it : ip) { - it->notify(api, appid); - } - } - else if(startup_appid == appid) { - startup_appid.clear(); - struct json_object* json_param = json_object_new_object(); - json_object_object_add(json_param, _area, json_object_new_string(startup_area.c_str())); - pushEvent("showWindow", json_param, appid); - startup_area.clear(); - } - else { - ret = false; - } - return ret; -} - /** * check whether application was started * @@ -309,17 +272,7 @@ bool HS_ClientManager::isAppStarted(const std::string &appid) */ void HS_ClientManager::addListener(listener_interface* listener) { - for (auto &it : listener->listenAppSet()) { - auto ip = listener_list.find(it); - if(ip != listener_list.end()) { - ip->second.push_back(listener); - } - else { - std::list lst; - lst.push_back(listener); - listener_list[it] = std::move(lst); - } - } + listener_list[listener->myUid()] = listener; } /** @@ -334,21 +287,7 @@ void HS_ClientManager::addListener(listener_interface* listener) */ void HS_ClientManager::removeListener(listener_interface* listener) { - for (auto &iter : listener->listenAppSet()) { - auto it = listener_list.find(iter); - if(it != listener_list.end()) { - auto ip = it->second.begin(); - for(; ip != it->second.end(); ++ip) { - if(listener->myUid() == (*ip)->myUid()) { - break; - } - } - it->second.erase(ip); - if(it->second.empty()) { - listener_list.erase(it->first); - } - } - } + listener_list.erase(listener->myUid()); } /** @@ -364,25 +303,18 @@ void HS_ClientManager::removeListener(listener_interface* listener) */ void HS_ClientManager::notifyListener(afb_api_t api, const std::string &appid) { - if (checkRegisterApp(api, appid)) { - return; - } - AFB_INFO("listen %s, notified", appid.c_str()); - std::list interface_list; - auto ip = listener_list.find(appid); - if(ip != listener_list.end()) { - if(!ip->second.empty()) { - interface_list = ip->second; - } - else { - AFB_WARNING("listener is null."); - return; + for(auto &it : listener_list) { + if(it.second->isListenAppId(appid)) { + it.second->notify(api, appid); } } - for(auto &it : interface_list) { - it->notify(api, appid); + if(startup_appid == appid) { + struct json_object* json_param = json_object_new_object(); + json_object_object_add(json_param, _area, json_object_new_string(startup_area.c_str())); + startup_area.clear(); + startup_appid.clear(); + pushEvent("showWindow", json_param, appid); } - } \ No newline at end of file