X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fapp.cpp;h=8ff0c17cdf57102187de40f1c9b8a5ac53824352;hb=6aad766f32dcfcb81b0006248852845778d179a8;hp=6689148992c1893aaa984bf49ab1b41133aacf36;hpb=e3dd2dd3952bf3ba27858422b1800b31ef8e2ee0;p=apps%2Fagl-service-windowmanager.git diff --git a/src/app.cpp b/src/app.cpp index 6689148..8ff0c17 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -46,7 +46,7 @@ extern "C" namespace wm { -const unsigned kTimeOut = 10000000UL; /* 10s */ +static const unsigned kTimeOut = 3000000UL; /* 3s */ /* DrawingArea name used by "{layout}.{area}" */ const char kNameLayoutNormal[] = "normal"; @@ -133,6 +133,15 @@ void App::removeClient(const std::string &appid) g_app_list.removeClient(appid); } +void App::exeptionProcessForTransition() +{ + unsigned req_num = g_app_list.currentRequestNumber(); + HMI_SEQ_NOTICE(req_num, "Process exeption handling for request. Remove current request %d", req_num); + g_app_list.removeRequest(req_num); + HMI_SEQ_NOTICE(g_app_list.currentRequestNumber(), "Process next request if exists"); + this->processNextRequest(); +} + bool App::subscribeEventForApp(const std::string &appid, afb_req req, const std::string &evname) { if(!g_app_list.contains(appid)){ @@ -151,17 +160,26 @@ App::App(wl::display *d) display{d}, controller{}, outputs(), - config(), layers(), id_alloc{}, - pending_events(false), - policy{} + pending_events(false) { + char const *path_layers_json = getenv("AFM_APP_INSTALL_DIR"); + std::string path; + if (!path_layers_json) + { + HMI_ERROR("wm", "AFM_APP_INSTALL_DIR is not defined"); + path = std::string(path_layers_json); + } + else + { + path = std::string(path_layers_json) + std::string("/etc/layers.json"); + } + try { { - auto l = load_layer_map( - this->config.get_string("layers.json").value().c_str()); + auto l = load_layer_map(path.c_str()); if (l.is_ok()) { this->layers = l.unwrap(); @@ -339,6 +357,8 @@ void App::surface_set_layout(int surface_id, const std::string& area) auto const &layer = this->layers.get_layer(layer_id); auto rect = this->layers.getAreaSize(area); + HMI_SEQ_DEBUG(g_app_list.currentRequestNumber(), "%s : x:%d y:%d w:%d h:%d", area.c_str(), + rect.x, rect.y, rect.w, rect.h); auto &s = this->controller->surfaces[surface_id]; int x = rect.x; @@ -386,7 +406,7 @@ void App::setTimer() { // firsttime set into sd_event int ret = sd_event_add_time(afb_daemon_get_event_loop(), &g_timer_ev_src, - CLOCK_REALTIME, time(NULL) * (1000000UL) + kTimeOut, 1, processTimerHandler, this); + CLOCK_REALTIME, time(NULL) * (1000000UL) + kTimeOut, 1, processTimerHandler, this); if (ret < 0) { HMI_ERROR("wm", "Could't set timer"); @@ -411,103 +431,6 @@ void App::stopTimer() } } -WMError App::lm_release(const struct WMAction &action) -{ - //auto const &surface_id = this->lookup_id(drawing_name); - WMError ret = WMError::LAYOUT_CHANGE_FAIL; - unsigned req_num = g_app_list.currentRequestNumber(); - auto const &surface_id = this->lookup_id(action.role.c_str()); - if (!surface_id) - { - HMI_SEQ_ERROR(req_num, "Surface does not exist"); - return ret; - } - - if (*surface_id == this->layers.main_surface) - { - HMI_SEQ_ERROR(req_num, "Cannot deactivate main_surface"); - return ret; - } - - auto o_state = *this->layers.get_layout_state(*surface_id); - - if (o_state == nullptr) - { - HMI_SEQ_ERROR(req_num, "Could not find layer for surface"); - return ret; - } - - struct LayoutState &state = *o_state; - - if (state.main == -1) - { - HMI_SEQ_ERROR(req_num, "No surface active"); - return ret; - } - - // Check against main_surface, main_surface_name is the configuration item. - if (*surface_id == this->layers.main_surface) - { - HMI_SEQ_DEBUG(req_num, "Refusing to deactivate main_surface %d", *surface_id); - //reply(nullptr); - return WMError::SUCCESS; - } - if ((state.main == *surface_id) && (state.sub == *surface_id)) - { - HMI_SEQ_ERROR(req_num, "Surface is not active"); - return ret; - } - - if (state.main == *surface_id) - { - if (state.sub != -1) - { - this->try_layout( - state, LayoutState{state.sub, -1}, [&](LayoutState const &nl) { - std::string sub = std::move(*this->lookup_name(state.sub)); - - this->deactivate(*surface_id); - this->surface_set_layout(state.sub); - state = nl; - - this->layout_commit(); - std::string str_area = std::string(kNameLayoutNormal) + "." + std::string(kNameAreaFull); - compositor::rect area_rect = this->area_info[state.sub]; - this->emit_syncdraw(sub.c_str(), str_area.c_str(), - area_rect.x, area_rect.y, area_rect.w, area_rect.h); - this->enqueue_flushdraw(state.sub); - }); - } - else - { - this->try_layout(state, LayoutState{-1, -1}, [&](LayoutState const &nl) { - this->deactivate(*surface_id); - state = nl; - this->layout_commit(); - }); - } - } - else if (state.sub == *surface_id) - { - this->try_layout( - state, LayoutState{state.main, -1}, [&](LayoutState const &nl) { - std::string main = std::move(*this->lookup_name(state.main)); - - this->deactivate(*surface_id); - this->surface_set_layout(state.main); - state = nl; - - this->layout_commit(); - std::string str_area = std::string(kNameLayoutNormal) + "." + std::string(kNameAreaFull); - compositor::rect area_rect = this->area_info[state.main]; - this->emit_syncdraw(main.c_str(), str_area.c_str(), - area_rect.x, area_rect.y, area_rect.w, area_rect.h); - this->enqueue_flushdraw(state.main); - }); - } - return WMError::SUCCESS; -} - WMError App::doTransition(unsigned req_num) { HMI_SEQ_DEBUG(req_num, "check policy"); @@ -567,7 +490,8 @@ WMError App::checkPolicy(unsigned req_num) std::string add_area = std::string(kNameLayoutSplit) + "." + std::string(kNameAreaMain); // Change request area req_area = std::string(kNameLayoutSplit) + "." + std::string(kNameAreaSub); - HMI_SEQ_NOTICE(req_num, "Change request area from %s to %s, because split is happen", trigger.area, req_area); + HMI_SEQ_NOTICE(req_num, "Change request area from %s to %s, because split is happen", + trigger.area, req_area); // set another action std::string add_name = g_app_list.getAppID(curernt_sid, add_role, &found); if (!found) @@ -610,7 +534,14 @@ WMError App::checkPolicy(unsigned req_num) /* get new status from Policy Manager */ HMI_SEQ_NOTICE(req_num, "ATM, Policy manager does't exist, then set WMAction as is"); - TaskVisible task_visible = (trigger.task == Task::TASK_ALLOCATE) ? TaskVisible::VISIBLE : TaskVisible::INVISIBLE; + if(trigger.role == "HomeScreen") + { + // TODO : Remove when Policy Manager completed + HMI_SEQ_NOTICE(req_num, "Hack. This process will be removed. Change HomeScreen code!!"); + req_area = "fullscreen"; + } + TaskVisible task_visible = + (trigger.task == Task::TASK_ALLOCATE) ? TaskVisible::VISIBLE : TaskVisible::INVISIBLE; ret = g_app_list.setAction(req_num, trigger.appid, trigger.role, req_area, task_visible); g_app_list.reqDump(); @@ -627,16 +558,17 @@ WMError App::startTransition(unsigned req_num) if (!found) { ret = WMError::NO_ENTRY; - HMI_SEQ_ERROR(req_num, "Window Manager bug :%s : Action is not set", errorDescription(ret)); + HMI_SEQ_ERROR(req_num, + "Window Manager bug :%s : Action is not set", errorDescription(ret)); return ret; } - for (const auto &y : actions) + for (const auto &action : actions) { - if (y.visible != TaskVisible::INVISIBLE) + if (action.visible != TaskVisible::INVISIBLE) { sync_draw_happen = true; - this->emit_syncdraw(y.role, y.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); */ @@ -651,12 +583,12 @@ WMError App::startTransition(unsigned req_num) { // deactivate only, no syncDraw // Make it deactivate here - for (const auto &z : actions) + for (const auto &x : actions) { - if (g_app_list.contains(z.appid)) + if (g_app_list.contains(x.appid)) { - auto client = g_app_list.lookUpClient(z.appid); - this->deactivate(client->surfaceID(z.role)); + auto client = g_app_list.lookUpClient(x.appid); + this->deactivate(client->surfaceID(x.role)); } } ret = NO_LAYOUT_CHANGE; @@ -666,8 +598,8 @@ WMError App::startTransition(unsigned req_num) WMError App::setInvisibleTask(const std::string &role, bool split) { - unsigned req = g_app_list.currentRequestNumber(); - HMI_SEQ_DEBUG(req, "set current visible app to invisible task"); + unsigned req_num = g_app_list.currentRequestNumber(); + HMI_SEQ_DEBUG(req_num, "set current visible app to invisible task"); // This task is copied from original actiavete surface const char *drawing_name = role.c_str(); auto const &surface_id = this->lookup_id(drawing_name); @@ -687,6 +619,7 @@ WMError App::setInvisibleTask(const std::string &role, bool split) { continue; } + HMI_DEBUG("wm", "debug: main %d , sub : %d", l.second.state.main, l.second.state.sub); if (l.second.state.main != -1) { //this->deactivate(l.second.state.main); @@ -696,9 +629,9 @@ WMError App::setInvisibleTask(const std::string &role, bool split) if(!found){ return WMError::NOT_REGISTERED; } - HMI_SEQ_INFO(req, "Invisible %s", add_name.c_str()); + HMI_SEQ_INFO(req_num, "Invisible %s", add_name.c_str()); WMAction act{add_name, add_role, add_area, task_visible, end_draw_finished}; - g_app_list.setAction(req, act); + g_app_list.setAction(req_num, act); l.second.state.main = -1; } @@ -712,9 +645,9 @@ WMError App::setInvisibleTask(const std::string &role, bool split) { return WMError::NOT_REGISTERED; } - HMI_SEQ_INFO(req, "Invisible %s", add_name.c_str()); + HMI_SEQ_INFO(req_num, "Invisible %s", add_name.c_str()); WMAction act{add_name, add_role, add_area, task_visible, end_draw_finished}; - g_app_list.setAction(req, act); + g_app_list.setAction(req_num, act); l.second.state.sub = -1; } } @@ -725,15 +658,6 @@ WMError App::setInvisibleTask(const std::string &role, bool split) if (state.main == -1) { HMI_DEBUG("wm", "Layout: %s", kNameLayoutNormal); - //state = LayoutState{*surface_id}; - /* this->try_layout( - state, LayoutState{*surface_id}, [&](LayoutState const &nl) { - HMI_DEBUG("wm", "Layout: %s", kNameLayoutNormal); - //this->surface_set_layout(*surface_id); - state = nl; - - //compositor::rect area_rect = this->area_info[*surface_id]; - }); */ } else { @@ -754,13 +678,13 @@ WMError App::setInvisibleTask(const std::string &role, bool split) deact_sub.appid = g_app_list.getAppID(state.sub, main, &found); if (!found) { - HMI_SEQ_DEBUG(req, "sub surface doesn't exist"); + HMI_SEQ_DEBUG(req_num, "sub surface doesn't exist"); return WMError::NOT_REGISTERED; } deact_sub.visible = task_visible; deact_sub.end_draw_finished = end_draw_finished; - HMI_SEQ_DEBUG(req, "sub surface doesn't exist"); - g_app_list.setAction(req, deact_sub); + HMI_SEQ_DEBUG(req_num, "sub surface doesn't exist"); + g_app_list.setAction(req_num, deact_sub); } } //state = LayoutState{state.main, *surface_id}; @@ -780,13 +704,13 @@ WMError App::setInvisibleTask(const std::string &role, bool split) deact_main.appid = g_app_list.getAppID(state.main, deact_main.role, &found); if (!found) { - HMI_SEQ_DEBUG(req, "sub surface ddoesn't exist"); + HMI_SEQ_DEBUG(req_num, "sub surface ddoesn't exist"); return WMError::NOT_REGISTERED; } deact_main.visible = task_visible; deact_main.end_draw_finished = end_draw_finished; - HMI_SEQ_DEBUG(req, "sub surface doesn't exist"); - g_app_list.setAction(req, deact_main); + HMI_SEQ_DEBUG(req_num, "sub surface doesn't exist"); + g_app_list.setAction(req_num, deact_main); } if (state.sub != -1) { @@ -800,13 +724,13 @@ WMError App::setInvisibleTask(const std::string &role, bool split) deact_sub.appid = g_app_list.getAppID(state.sub, deact_sub.role, &found); if (!found) { - HMI_SEQ_DEBUG(req, "sub surface ddoesn't exist"); + HMI_SEQ_DEBUG(req_num, "sub surface ddoesn't exist"); return WMError::NOT_REGISTERED; } deact_sub.visible = task_visible; deact_sub.end_draw_finished = end_draw_finished; - HMI_SEQ_DEBUG(req, "sub surface doesn't exist"); - g_app_list.setAction(req, deact_sub); + HMI_SEQ_DEBUG(req_num, "sub surface doesn't exist"); + g_app_list.setAction(req_num, deact_sub); } } //state = LayoutState{*surface_id}; @@ -869,12 +793,13 @@ WMError App::setRequest(const std::string& appid, const std::string &role, const unsigned requested_num = g_app_list.getRequestNumber(appid); if (requested_num != 0) { - HMI_SEQ_INFO(requested_num, "%s %s %s request is already queued", appid.c_str(), role.c_str(), area.c_str()); + HMI_SEQ_INFO(requested_num, + "%s %s %s request is already queued", appid.c_str(), role.c_str(), area.c_str()); return REQ_REJECTED; } WMRequest req = WMRequest(appid, role, area, task); - unsigned new_req = g_app_list.addAllocateRequest(req); + unsigned new_req = g_app_list.addRequest(req); *req_num = new_req; g_app_list.reqDump(); @@ -883,7 +808,8 @@ WMError App::setRequest(const std::string& appid, const std::string &role, const return WMError::SUCCESS; } -void App::api_activate_surface(char const *appid, char const *drawing_name, char const *drawing_area, const reply_func &reply) +void App::api_activate_surface(char const *appid, char const *drawing_name, + char const *drawing_area, const reply_func &reply) { ST(); @@ -921,12 +847,12 @@ void App::api_activate_surface(char const *appid, char const *drawing_name, char //this->emit_error() HMI_SEQ_ERROR(req_num, errorDescription(ret)); g_app_list.removeRequest(req_num); - g_app_list.next(); - g_app_list.reqDump(); + this->processNextRequest(); } } -void App::api_deactivate_surface(char const *appid, char const *drawing_name, const reply_func &reply) +void App::api_deactivate_surface(char const *appid, char const *drawing_name, + const reply_func &reply) { ST(); @@ -936,74 +862,38 @@ void App::api_deactivate_surface(char const *appid, char const *drawing_name, co std::string id = appid; std::string role = drawing_name; std::string area = ""; //drawing_area; + Task task = Task::TASK_RELEASE; + unsigned req_num = 0; + WMError ret = WMError::UNKNOWN; - if (!g_app_list.contains(id)) - { - reply("app doesn't request 'requestSurface' yet"); - return; - } - auto client = g_app_list.lookUpClient(id); + ret = this->setRequest(id, role, area, task, &req_num); - /* - * Queueing Phase - */ - unsigned current = g_app_list.currentRequestNumber(); - unsigned requested_num = g_app_list.getRequestNumber(id); - if (requested_num != 0) + if (ret != WMError::SUCCESS) { - HMI_SEQ_INFO(requested_num, "%s %s %s request is already queued", id.c_str(), role.c_str(), area.c_str()); - reply("already requested"); + HMI_ERROR("wm", errorDescription(ret)); + reply("Failed to set request"); return; } - WMRequest req = WMRequest(id, role, area, Task::TASK_RELEASE); - unsigned new_req = g_app_list.addAllocateRequest(req); - g_app_list.reqDump(); - - HMI_SEQ_DEBUG(current, "%s start sequence with %s, %s", id.c_str(), role.c_str(), area.c_str()); - reply(nullptr); - if (new_req != current) + if (req_num != g_app_list.currentRequestNumber()) { // Add request, then invoked after the previous task is finished - HMI_SEQ_DEBUG(new_req, "request is accepted"); + HMI_SEQ_DEBUG(req_num, "request is accepted"); return; } /* * Do allocate tasks */ - WMError ret = this->doTransition(new_req); + ret = this->doTransition(req_num); if (ret != WMError::SUCCESS) { - HMI_SEQ_ERROR(new_req, errorDescription(ret)); - g_app_list.removeRequest(new_req); - g_app_list.next(); //this->emit_error() - } -} - -void App::enqueue_flushdraw(int surface_id) -{ - this->check_flushdraw(surface_id); - HMI_DEBUG("wm", "Enqueuing EndDraw for surface_id %d", surface_id); - this->pending_end_draw.push_back(surface_id); -} - -void App::check_flushdraw(int surface_id) -{ - auto i = std::find(std::begin(this->pending_end_draw), - std::end(this->pending_end_draw), surface_id); - if (i != std::end(this->pending_end_draw)) - { - auto n = this->lookup_name(surface_id); - HMI_ERROR("wm", "Application %s (%d) has pending EndDraw call(s)!", - n ? n->c_str() : "unknown-name", surface_id); - std::swap(this->pending_end_draw[std::distance( - std::begin(this->pending_end_draw), i)], - this->pending_end_draw.back()); - this->pending_end_draw.resize(this->pending_end_draw.size() - 1); + HMI_SEQ_ERROR(req_num, errorDescription(ret)); + g_app_list.removeRequest(req_num); + this->processNextRequest(); } } @@ -1031,13 +921,15 @@ WMError App::doEndDraw(unsigned req_num) ret = this->layoutChange(act); if(ret != WMError::SUCCESS) { - HMI_SEQ_WARNING(req_num, "Failed to manipulate surfaces while state change : %s", errorDescription(ret)); + HMI_SEQ_WARNING(req_num, + "Failed to manipulate surfaces while state change : %s", errorDescription(ret)); return ret; } ret = this->visibilityChange(act); if (ret != WMError::SUCCESS) { - HMI_SEQ_WARNING(req_num, "Failed to manipulate surfaces while state change : %s", errorDescription(ret)); + HMI_SEQ_WARNING(req_num, + "Failed to manipulate surfaces while state change : %s", errorDescription(ret)); return ret; } HMI_SEQ_DEBUG(req_num, "visible %s", act.role.c_str()); @@ -1133,8 +1025,8 @@ WMError App::changeCurrentState(unsigned req_num) if(!g_app_list.contains(action.appid)){ return WMError::NOT_REGISTERED; } - auto client = g_app_list.lookUpClient(trigger.appid); - auto pCurState = *this->layers.get_layout_state((int)client->surfaceID(trigger.role)); + auto client = g_app_list.lookUpClient(action.appid); + auto pCurState = *this->layers.get_layout_state((int)client->surfaceID(action.role)); if(pCurState == nullptr) { HMI_SEQ_ERROR(req_num, "Counldn't find current status"); @@ -1159,13 +1051,14 @@ WMError App::changeCurrentState(unsigned req_num) if (action.visible != TaskVisible::INVISIBLE) { surface = (int)client->surfaceID(action.role); - HMI_SEQ_INFO(req_num, "Change %s state visible area : %s", action.role.c_str(), action.area.c_str()); + HMI_SEQ_INFO(req_num, "Change %s surface : %d, state visible area : %s", + action.role.c_str(), surface, action.area.c_str()); // visible == true -> layout changes if(action.area == "normal.full" || action.area == "split.main") { pLayerCurState->main = surface; } - else if(action.role == "split.sub") + else if (action.area == "split.sub") { pLayerCurState->sub = surface; } @@ -1293,19 +1186,6 @@ void App::surface_created(uint32_t surface_id) this->controller->layers[*layer_id]->add_surface(surface_id); this->layout_commit(); - // activate the main_surface right away - /*if (surface_id == static_cast(this->layers.main_surface)) { - HMI_DEBUG("wm", "Activating main_surface (%d)", surface_id); - - this->api_activate_surface( - this->lookup_name(surface_id).value_or("unknown-name").c_str()); - }*/ - - // search pid from surfaceID - - // pick up appid from pid from application manager - - // check appid then add it to the client } void App::surface_removed(uint32_t surface_id) @@ -1591,13 +1471,6 @@ void App::deactivate(int id) } } -void App::deactivate_main_surface() -{ - this->layers.main_surface = -1; - std::string appid = "HomeScreen"; - this->api_deactivate_surface(appid.c_str(), this->layers.main_surface_name.c_str(), [](const char *) {}); -} - bool App::can_split(struct LayoutState const &state, int new_id) { if (state.main != -1 && state.main != new_id) @@ -1644,16 +1517,6 @@ bool App::can_split(struct LayoutState const &state, int new_id) return false; } -void App::try_layout(struct LayoutState & /*state*/, - struct LayoutState const &new_layout, - std::function apply) -{ - if (this->policy.layout_is_valid(new_layout)) - { - apply(new_layout); - } -} - /** * controller_hooks */