X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fwindow_manager.cpp;h=bbfd08ccffa014559420947310667129dbb3ab4a;hb=7a4a02d048910615cb15c26fc5534ad471a8d5ac;hp=c69c8396dd3018d077427b002f5d0af9f02d38cc;hpb=b1f7a756ff0fce7ff38d24b256476902f748be0b;p=apps%2Fagl-service-windowmanager.git diff --git a/src/window_manager.cpp b/src/window_manager.cpp index c69c839..bbfd08c 100644 --- a/src/window_manager.cpp +++ b/src/window_manager.cpp @@ -124,11 +124,6 @@ int WindowManager::init() return -1; } - // TODO: application requests by old role, - // so create role map (old, new) - // Load old_role.db - this->loadOldRoleDb(); - // Store my context for calling callback from PolicyManager g_context = this; @@ -141,7 +136,7 @@ int WindowManager::init() // Make afb event for (int i = Event_Val_Min; i <= Event_Val_Max; i++) { - map_afb_event[kListEventName[i]] = afb_daemon_make_event(kListEventName[i].c_str()); + map_afb_event[kListEventName[i]] = afb_api_make_event(afbBindingV3root, kListEventName[i].c_str()); } const struct rect css_bg = this->lc->getAreaSize("fullscreen"); @@ -157,47 +152,45 @@ int WindowManager::init() double scale = static_cast(dp_bg.height()) / css_bg.h; this->lc->setupArea(dp_bg, scale); - this->lc->createLayers(); - return 0; } result WindowManager::api_request_surface(char const *appid, char const *drawing_name) { - // TODO: application requests by old role, - // so convert role old to new - const char *role = this->convertRoleOldToNew(drawing_name); + string str_id = appid; + string role = drawing_name; + unsigned lid = 0; - // auto lid = this->layers.get_layer_id(string(role)); - unsigned lid = this->lc->getLayerID(string(role)); - if (lid == 0) + if(!g_app_list.contains(str_id)) { - /** - * register drawing_name as fallback and make it displayed. - */ - // lid = this->layers.get_layer_id(string("fallback")); - lid = this->lc->getLayerID(string("fallback")); - HMI_DEBUG("%s is not registered in layers.json, then fallback as normal app", role); + lid = this->lc->getNewLayerID(role); if (lid == 0) { - return Err("Drawing name does not match any role, fallback is disabled"); + // register drawing_name as fallback and make it displayed. + lid = this->lc->getNewLayerID(string("fallback")); + HMI_DEBUG("%s is not registered in layers.json, then fallback as normal app", role); + if (lid == 0) + { + return Err("Designated role does not match any role, fallback is disabled"); + } } + this->lc->createNewLayer(lid); + // add client into the db + g_app_list.addClient(str_id, lid, role); } + // generate surface ID for ivi-shell application auto rname = this->id_alloc.lookup(role); if (!rname) { // name does not exist yet, allocate surface id... auto id = int(this->id_alloc.generate_id(role)); - // this->layers.add_surface(id, *lid); - this->tmp_surface2app[id] = {string(appid), lid}; - - // add client into the db - string appid_str(appid); - g_app_list.addClient(appid_str, lid, id, string(role)); + this->tmp_surface2app[id] = {str_id, lid}; - // Set role map of (new, old) - this->rolenew2old[role] = string(drawing_name); + // POI: AGL LifeCycle Management + this->amgr.states[str_id] = lcm::CREATED; + this->amgr.emit_activity_status_changed(str_id.c_str(), + this->amgr.states_s[lcm::CREATED]); return Ok(id); } @@ -209,11 +202,16 @@ result WindowManager::api_request_surface(char const *appid, char const *dr char const *WindowManager::api_request_surface(char const *appid, char const *drawing_name, char const *ivi_id) { - // TODO: application requests by old role, - // so convert role old to new - const char *role = this->convertRoleOldToNew(drawing_name); + string str_id = appid; + string role = drawing_name; unsigned sid = std::stol(ivi_id); + HMI_DEBUG("This API(requestSurfaceXDG) is for XDG Application using runXDG"); + /* + * IVI-shell doesn't send surface_size event via ivi-wm protocol + * if the application is using XDG surface. + * So WM has to set surface size with original size here + */ WMError ret = this->lc->setXDGSurfaceOriginSize(sid); if(ret != SUCCESS) { @@ -222,19 +220,22 @@ char const *WindowManager::api_request_surface(char const *appid, char const *dr return "fail"; } - // auto lid = this->layers.get_layer_id(string(role)); - auto lid = this->lc->getLayerID(string(role)); - if (lid == 0) + if(!g_app_list.contains(str_id)) { - /** - * register drawing_name as fallback and make it displayed. - */ - lid = this->lc->getLayerID(string("fallback")); - HMI_DEBUG("%s is not registered in layers.json, then fallback as normal app", role); - if (lid == 0) + unsigned l_id = this->lc->getNewLayerID(role); + if (l_id == 0) { - return "Drawing name does not match any role, fallback is disabled"; + // register drawing_name as fallback and make it displayed. + l_id = this->lc->getNewLayerID("fallback"); + HMI_DEBUG("%s is not registered in layers.json, then fallback as normal app", role); + if (l_id == 0) + { + return "Designated role does not match any role, fallback is disabled"; + } } + this->lc->createNewLayer(l_id); + // add client into the db + g_app_list.addClient(str_id, l_id, role); } auto rname = this->id_alloc.lookup(role); @@ -246,29 +247,23 @@ char const *WindowManager::api_request_surface(char const *appid, char const *dr // register pair drawing_name and ivi_id this->id_alloc.register_name_id(role, sid); - this->lc->addSurface(sid, lid); - HMI_DEBUG("surface_id is %u, layer_id is %u", sid, lid); + auto client = g_app_list.lookUpClient(str_id); + client->addSurface(sid); - // add client into the list - string appid_str(appid); - g_app_list.addClient(appid_str, lid, sid, string(role)); - - // Set role map of (new, old) - this->rolenew2old[role] = string(drawing_name); + // POI: AGL LifeCycle Management + this->amgr.states[str_id] = lcm::CREATED; + this->amgr.emit_activity_status_changed(str_id.c_str(), + this->amgr.states_s[lcm::CREATED]); return nullptr; } -void WindowManager::api_activate_surface(char const *appid, char const *drawing_name, +void WindowManager::api_activate_window(char const *appid, char const *drawing_name, char const *drawing_area, const reply_func &reply) { - // TODO: application requests by old role, - // so convert role old to new - const char *c_role = this->convertRoleOldToNew(drawing_name); - string id = appid; - string role = c_role; + string role = drawing_name; string area = drawing_area; if(!g_app_list.contains(id)) @@ -276,8 +271,8 @@ void WindowManager::api_activate_surface(char const *appid, char const *drawing_ reply("app doesn't request 'requestSurface' or 'setRole' yet"); return; } - auto client = g_app_list.lookUpClient(id); + Task task = Task::TASK_ALLOCATE; unsigned req_num = 0; WMError ret = WMError::UNKNOWN; @@ -299,9 +294,8 @@ void WindowManager::api_activate_surface(char const *appid, char const *drawing_ return; } - /* - * Do allocate tasks - */ + // Do allocate tasks + ret = this->checkPolicy(req_num); if (ret != WMError::SUCCESS) @@ -310,21 +304,22 @@ void WindowManager::api_activate_surface(char const *appid, char const *drawing_ HMI_SEQ_ERROR(req_num, errorDescription(ret)); g_app_list.removeRequest(req_num); this->processNextRequest(); + } else { + // POI: AGL LifeCycle Management + if (this->amgr.states[id] == lcm::CREATED) { + this->amgr.states[id] = lcm::STARTED; + this->amgr.emit_activity_status_changed(id.c_str(), + this->amgr.states_s[lcm::STARTED]); + } } } -void WindowManager::api_deactivate_surface(char const *appid, char const *drawing_name, +void WindowManager::api_deactivate_window(char const *appid, char const *drawing_name, const reply_func &reply) { - // TODO: application requests by old role, - // so convert role old to new - const char *c_role = this->convertRoleOldToNew(drawing_name); - - /* - * Check Phase - */ + // Check Phase string id = appid; - string role = c_role; + string role = drawing_name; string area = ""; //drawing_area; Task task = Task::TASK_RELEASE; unsigned req_num = 0; @@ -347,9 +342,7 @@ void WindowManager::api_deactivate_surface(char const *appid, char const *drawin return; } - /* - * Do allocate tasks - */ + // Do allocate tasks ret = this->checkPolicy(req_num); if (ret != WMError::SUCCESS) @@ -358,17 +351,21 @@ void WindowManager::api_deactivate_surface(char const *appid, char const *drawin HMI_SEQ_ERROR(req_num, errorDescription(ret)); g_app_list.removeRequest(req_num); this->processNextRequest(); + } else { + // POI: AGL LifeCycle Management + int state = this->amgr.states[id]; + if (state == lcm::STARTED || state == lcm::BACKGROUND) { + this->amgr.states[id] = lcm::STOPPED; + this->amgr.emit_activity_status_changed(id.c_str(), + this->amgr.states_s[lcm::STOPPED]); + } } } void WindowManager::api_enddraw(char const *appid, char const *drawing_name) { - // TODO: application requests by old role, - // so convert role old to new - const char *c_role = this->convertRoleOldToNew(drawing_name); - string id = appid; - string role = c_role; + string role = drawing_name; unsigned current_req = g_app_list.currentRequestNumber(); bool result = g_app_list.setEndDrawFinished(current_req, id, role); @@ -390,6 +387,7 @@ void WindowManager::api_enddraw(char const *appid, char const *drawing_name) // Undo state of PolicyManager this->pmw.undoState(); + this->lc->undoUpdate(); } this->emitScreenUpdated(current_req); HMI_SEQ_INFO(current_req, "Finish request status: %s", errorDescription(ret)); @@ -405,9 +403,9 @@ void WindowManager::api_enddraw(char const *appid, char const *drawing_name) } } -int WindowManager::api_subscribe(afb_req req, int event_id) +int WindowManager::api_subscribe(afb_req_t req, int event_id) { - struct afb_event event = this->map_afb_event[kListEventName[event_id]]; + afb_event_t event = this->map_afb_event[kListEventName[event_id]]; return afb_req_subscribe(req, event); } @@ -430,9 +428,7 @@ result WindowManager::api_get_area_info(char const *drawing_name) { HMI_DEBUG("called"); - // TODO: application requests by old role, - // so convert role old to new - const char *role = this->convertRoleOldToNew(drawing_name); + string role = drawing_name; // Check drawing name, surface/layer id auto const &surface_id = this->id_alloc.lookup(role); @@ -493,10 +489,18 @@ void WindowManager::surface_created(unsigned surface_id) // requestSurface if(this->tmp_surface2app.count(surface_id) != 0) { - unsigned layer_id = this->tmp_surface2app[surface_id].layer; - this->lc->addSurface(surface_id, layer_id); + string appid = this->tmp_surface2app[surface_id].appid; + auto client = g_app_list.lookUpClient(appid); + if(client != nullptr) + { + WMError ret = client->addSurface(surface_id); + HMI_INFO("Add surface %d to \"%s\"", surface_id, appid.c_str()); + if(ret != WMError::SUCCESS) + { + HMI_ERROR("Failed to add surface to client %s", client->appID().c_str()); + } + } this->tmp_surface2app.erase(surface_id); - HMI_DEBUG("surface_id is %u, layer_id is %u", surface_id, layer_id); } } @@ -510,7 +514,15 @@ void WindowManager::surface_removed(unsigned surface_id) void WindowManager::removeClient(const string &appid) { HMI_DEBUG("Remove clinet %s from list", appid.c_str()); + auto client = g_app_list.lookUpClient(appid); + this->lc->appTerminated(client); g_app_list.removeClient(appid); + // POI: AGL LifeCycle Management + if (this->amgr.states[appid] != lcm::DESTROYED) { + this->amgr.states[appid] = lcm::DESTROYED; + this->amgr.emit_activity_status_changed(appid.c_str(), + this->amgr.states_s[lcm::DESTROYED]); + } } void WindowManager::exceptionProcessForTransition() @@ -555,12 +567,12 @@ void WindowManager::startTransitionWrapper(vector &actions) if ("" != act.role) { bool found; - auto const &surface_id = this->id_alloc.lookup(act.role.c_str()); + auto const &surface_id = this->id_alloc.lookup(act.role); if(surface_id == nullopt) { goto proc_remove_request; } - string appid = g_app_list.getAppID(*surface_id, act.role, &found); + string appid = g_app_list.getAppID(*surface_id, &found); if (!found) { if (TaskVisible::INVISIBLE == act.visible) @@ -648,7 +660,7 @@ void WindowManager::emit_syncdraw(const string &role, const string &area) { struct rect rect = this->lc->getAreaSize(area); this->send_event(kListEventName[Event_SyncDraw], - role.c_str(), area.c_str(), rect.x, rect.y, rect.w, rect.h); + role, area, rect.x, rect.y, rect.w, rect.h); } void WindowManager::emit_flushdraw(const string& role) @@ -716,17 +728,6 @@ WMError WindowManager::checkPolicy(unsigned req_num) } string req_area = trigger.area; - if (trigger.task == Task::TASK_ALLOCATE) - { - const char *msg = this->check_surface_exist(trigger.role.c_str()); - - if (msg) - { - HMI_SEQ_ERROR(req_num, msg); - return ret; - } - } - // Input event data to PolicyManager if (0 > this->pmw.setInputEventData(trigger.task, trigger.role, trigger.area)) { @@ -762,17 +763,13 @@ WMError WindowManager::startTransition(unsigned req_num) return ret; } + g_app_list.reqDump(); for (const auto &action : actions) { if (action.visible == TaskVisible::VISIBLE) { sync_draw_happen = true; - - // TODO: application requests by old role, - // so convert role new to old for emitting event - string old_role = this->rolenew2old[action.role]; - - this->emit_syncdraw(old_role, action.area); + this->emit_syncdraw(action.role, action.area); /* TODO: emit event for app not subscriber if(g_app_list.contains(y.appid)) g_app_list.lookUpClient(y.appid)->emit_syncdraw(y.role, y.area); */ @@ -790,14 +787,14 @@ WMError WindowManager::startTransition(unsigned req_num) for (const auto &x : actions) { this->lc->visibilityChange(x); - string old_role = this->rolenew2old[x.role]; - emit_deactivated(old_role.c_str()); + emit_deactivated(x.role); /* if (g_app_list.contains(x.client->appID())) { auto client = g_app_list.lookUpClient(x.client->appID()); this->deactivate(client->surfaceID(x.role)); } */ } + this->lc->renderLayers(); ret = WMError::NO_LAYOUT_CHANGE; } return ret; @@ -832,15 +829,15 @@ WMError WindowManager::doEndDraw(unsigned req_num) } ret = this->lc->visibilityChange(act); - // Emit active/deactive event - string old_role = this->rolenew2old[act.role]; if(act.visible == VISIBLE) { - emit_activated(old_role.c_str()); + emit_visible(act.role); + emit_activated(act.role); } else { - emit_deactivated(old_role.c_str()); + emit_invisible(act.role); + emit_deactivated(act.role); } if (ret != WMError::SUCCESS) @@ -852,6 +849,7 @@ WMError WindowManager::doEndDraw(unsigned req_num) HMI_SEQ_DEBUG(req_num, "visible %s", act.role.c_str()); } } + this->lc->renderLayers(); HMI_SEQ_INFO(req_num, "emit flushDraw"); @@ -859,11 +857,7 @@ WMError WindowManager::doEndDraw(unsigned req_num) { if(act_flush.visible == TaskVisible::VISIBLE) { - // TODO: application requests by old role, - // so convert role new to old for emitting event - string old_role = this->rolenew2old[act_flush.role]; - - this->emit_flushdraw(old_role.c_str()); + this->emit_flushdraw(act_flush.role); } } @@ -876,6 +870,13 @@ void WindowManager::emitScreenUpdated(unsigned req_num) HMI_SEQ_DEBUG(req_num, "emit screen updated"); bool found = false; auto actions = g_app_list.getActions(req_num, &found); + if (!found) + { + HMI_SEQ_ERROR(req_num, + "Window Manager bug :%s : Action is not set", + errorDescription(WMError::NO_ENTRY)); + return; + } // create json object json_object *j = json_object_new_object(); @@ -883,9 +884,22 @@ void WindowManager::emitScreenUpdated(unsigned req_num) for(const auto& action: actions) { + std::string appid = action.client->appID(); + if(action.visible != TaskVisible::INVISIBLE) { - json_object_array_add(jarray, json_object_new_string(action.client->appID().c_str())); + json_object_array_add(jarray, json_object_new_string(appid.c_str())); + // POI: AGL LifeCycle Management + if (this->amgr.states[appid] != lcm::FOREGROUND) { + this->amgr.states[appid] = lcm::FOREGROUND; + this->amgr.emit_activity_status_changed(appid.c_str(), this->amgr.states_s[lcm::FOREGROUND]); + } + } else { + // POI: AGL LifeCycle Management + if (this->amgr.states[appid] != lcm::BACKGROUND) { + this->amgr.states[appid] = lcm::BACKGROUND; + this->amgr.emit_activity_status_changed(appid.c_str(), this->amgr.states_s[lcm::BACKGROUND]); + } } } json_object_object_add(j, kKeyIds, jarray); @@ -911,7 +925,7 @@ void WindowManager::setTimer() if (g_timer_ev_src == nullptr) { // firsttime set into sd_event - int ret = sd_event_add_time(afb_daemon_get_event_loop(), &g_timer_ev_src, + int ret = sd_event_add_time(afb_api_get_event_loop(afbBindingV3root), &g_timer_ev_src, CLOCK_BOOTTIME, (uint64_t)(ts.tv_sec + kTimeOut) * 1000000ULL, 1, processTimerHandler, this); if (ret < 0) { @@ -957,182 +971,165 @@ void WindowManager::processNextRequest() } } -const char* WindowManager::convertRoleOldToNew(char const *old_role) -{ - const char *new_role = nullptr; - - for (auto const &on : this->roleold2new) - { - std::regex regex = std::regex(on.first); - if (std::regex_match(old_role, regex)) - { - // role is old. So convert to new. - new_role = on.second.c_str(); - break; - } - } - - if (nullptr == new_role) - { - // role is new or fallback. - new_role = old_role; - } +} // namespace wm - HMI_DEBUG("old:%s -> new:%s", old_role, new_role); +namespace lcm +{ - return new_role; +ActivityManager::ActivityManager (void) + : states_s { "NOTEXISTS", + "CREATED", + "DESTROYED", + "STARTED", + "STOPPED", + "FOREGROUND", + "BACKGROUND" } +{ + ; } -int WindowManager::loadOldRoleDb() +void ActivityManager::api_register_activity_observer (afb_req_t req, void* &lcm_ctx) { - // Get afm application installed dir - char const *afm_app_install_dir = getenv("AFM_APP_INSTALL_DIR"); - HMI_DEBUG("afm_app_install_dir:%s", afm_app_install_dir); + //std::string observer = afb_req_get_application_id(req); + observer* obs = static_cast(lcm_ctx); - string file_name; - if (!afm_app_install_dir) - { - HMI_ERROR("AFM_APP_INSTALL_DIR is not defined"); + json_object *j_data = afb_req_json(req); + json_object *j_target; + if (!json_object_object_get_ex(j_data, LCM_TARGET, &j_target)) { + afb_req_fail(req, "failed", "Need char const* argument target"); + return; + } + std::string target(json_object_get_string(j_target)); + + if (obs == nullptr) { + // New observer + afb_event_t event = afb_daemon_make_event(LCM_EVENT_STATUS_CHANGED); + //afb_event_t event = afb_daemon_make_event(LCM_EVENT_STATUS_CHANGED); + obs = new observer({ + event, + std::bitset(ACTIVITY_FILTER_ALL_SET) + }); + + if (afb_req_subscribe(req, event) != 0) { + afb_req_fail(req, "failed", "cannot subscribe event"); + return; } - else - { - file_name = string(afm_app_install_dir) + string("/etc/old_roles.db"); + HMI_DEBUG("observer(%p, target=\"%s\") is created.[NEW]", obs, target.c_str()); + + lcm_ctx = static_cast(obs); + } + + if (this->map_observers.count(target)) { + // already registered + HMI_DEBUG("observer(%p, target=\"%s\") is already exist", obs, target.c_str()); + std::vector obs_v = this->map_observers[target]; + auto result = std::find(obs_v.begin(), obs_v.end(), obs); + if (result != obs_v.end()) { + HMI_DEBUG("observer(%p, target=\"%s\") is already registered", obs, target.c_str()); + return; } + } + HMI_DEBUG("observer(%p, target=\"%s\") is registered", obs, target.c_str()); + (this->map_observers[target]).push_back(obs); +} - // Load old_role.db - json_object* json_obj; - int ret = jh::inputJsonFilie(file_name.c_str(), &json_obj); - if (0 > ret) - { - HMI_ERROR("Could not open old_role.db, so use default old_role information"); - json_obj = json_tokener_parse(kDefaultOldRoleDb); +void ActivityManager::remove_observer (observer *obs, std::vector& obs_v) +{ + auto obs_itr = obs_v.begin(); + while (obs_itr != obs_v.end()) { + if (*obs_itr == obs) { + obs_itr = obs_v.erase(obs_itr); + } else { + obs_itr++; } - HMI_DEBUG("json_obj dump:%s", json_object_get_string(json_obj)); + } +} - // Perse apps - json_object* json_cfg; - if (!json_object_object_get_ex(json_obj, "old_roles", &json_cfg)) - { - HMI_ERROR("Parse Error!!"); - return -1; - } +void ActivityManager::api_unregister_activity_observer (afb_req_t req, void* &lcm_ctx) +{ + observer *obs = static_cast(lcm_ctx); - int len = json_object_array_length(json_cfg); - HMI_DEBUG("json_cfg len:%d", len); - HMI_DEBUG("json_cfg dump:%s", json_object_get_string(json_cfg)); + json_object *j_data = afb_req_json(req); + json_object *j_target; - for (int i=0; i\"%s\") is unregistered.", obs, target.c_str()); - const char* new_role = jh::getStringFromJson(json_tmp, "new"); - if (nullptr == new_role) - { - HMI_ERROR("Parse Error!!"); - return -1; - } + if (this->map_observers.count(target) != 0) { + remove_observer(obs, this->map_observers[target]); + } +} - this->roleold2new[old_role] = string(new_role); - } +void ActivityManager::lcm_clear_context (void* &lcm_ctx) +{ + observer *obs = static_cast(lcm_ctx); - // Check - for(auto itr = this->roleold2new.begin(); - itr != this->roleold2new.end(); ++itr) - { - HMI_DEBUG(">>> role old:%s new:%s", - itr->first.c_str(), itr->second.c_str()); - } + for (auto itr = this->map_observers.begin(); itr != this->map_observers.end(); itr++) { + remove_observer(obs, itr->second); + } - // Release json_object - json_object_put(json_obj); + HMI_DEBUG("observer(%p) is removed.", obs); - return 0; + delete obs; } -const char *WindowManager::check_surface_exist(const char *drawing_name) +wm::result ActivityManager::api_get_activity_status (const char *appid) { - auto const &surface_id = this->id_alloc.lookup(drawing_name); - if (!surface_id) - { - return "Surface does not exist"; + std::string id = appid; + int st = NOTEXISTS; + + if (this->states.count(id)) { + st = this->states[id]; + + if (st < 0 || st >= NUM_STATUS) { + HMI_ERROR("Illegal lifecycle state (%d) of [%s]", st, appid); + return wm::Err("Illegal lifecycle state"); } - return nullptr; + } + + const char * state = this->states_s[st]; + + json_object *object = json_object_new_object(); + json_object_object_add(object, LCM_API, json_object_new_string(LCM_API_GET_ACTIVITY_STATUS)); + json_object_object_add(object, LCM_TARGET, json_object_new_string(appid)); + json_object_object_add(object, LCM_STATE, json_object_new_string(state)); + + return wm::Ok(object); } -const char* WindowManager::kDefaultOldRoleDb = "{ \ - \"old_roles\": [ \ - { \ - \"name\": \"HomeScreen\", \ - \"new\": \"homescreen\" \ - }, \ - { \ - \"name\": \"Music\", \ - \"new\": \"music\" \ - }, \ - { \ - \"name\": \"MediaPlayer\", \ - \"new\": \"music\" \ - }, \ - { \ - \"name\": \"Video\", \ - \"new\": \"video\" \ - }, \ - { \ - \"name\": \"VideoPlayer\", \ - \"new\": \"video\" \ - }, \ - { \ - \"name\": \"WebBrowser\", \ - \"new\": \"browser\" \ - }, \ - { \ - \"name\": \"Radio\", \ - \"new\": \"radio\" \ - }, \ - { \ - \"name\": \"Phone\", \ - \"new\": \"phone\" \ - }, \ - { \ - \"name\": \"Navigation\", \ - \"new\": \"map\" \ - }, \ - { \ - \"name\": \"HVAC\", \ - \"new\": \"hvac\" \ - }, \ - { \ - \"name\": \"Settings\", \ - \"new\": \"settings\" \ - }, \ - { \ - \"name\": \"Dashboard\", \ - \"new\": \"dashboard\" \ - }, \ - { \ - \"name\": \"POI\", \ - \"new\": \"poi\" \ - }, \ - { \ - \"name\": \"Mixer\", \ - \"new\": \"mixer\" \ - }, \ - { \ - \"name\": \"Restriction\", \ - \"new\": \"restriction\" \ - }, \ - { \ - \"name\": \"^OnScreen.*\", \ - \"new\": \"on_screen\" \ - } \ - ] \ -}"; +void ActivityManager::emit_activity_status_changed (const char* appid, const char* state) +{ + // POI: AGL LifeCycle Management + // E.g. statusChanged(CREATED->STARTED) + HMI_DEBUG("emit_activity_status_changed(%s, %s)", appid, state); + + std::string id = appid; + + if (this->map_observers.count(id)) { + std::vector& obs_v = this->map_observers[id]; + + for (auto itr = obs_v.begin(); itr != obs_v.end(); ++itr) { + auto obs = *itr; + afb_event_t event = obs->event; + if (afb_event_is_valid(event)) { + json_object *data = json_object_new_object(); + json_object_object_add(data, LCM_STATE, json_object_new_string(state)); + json_object_object_add(data, LCM_TARGET, json_object_new_string(appid)); + + HMI_DEBUG("send Event_statusChanged(%s, %s)", appid, state); + + afb_event_push(event, json_object_get(data)); + json_object_put(data); + } else { + HMI_ERROR("afb_event is not valid"); + } + } + } +} -} // namespace wm +} // namespace lcm