X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fwindow_manager.cpp;h=7fc47c3e141b6f5caebd243701ef121340304dac;hb=c0adba3e6e8527c67d4d7699c9a8d8248f07b843;hp=cc6f410dbf11811282c4e0723085227f5c926efe;hpb=671b366ab609ccd58456e8debf0a20e46315b3e6;p=apps%2Fagl-service-windowmanager.git diff --git a/src/window_manager.cpp b/src/window_manager.cpp index cc6f410..7fc47c3 100644 --- a/src/window_manager.cpp +++ b/src/window_manager.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2017 TOYOTA MOTOR CORPORATION + * Copyright (c) 2019 Konsulko Group * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +29,7 @@ extern "C" using std::string; using std::vector; +using std::unordered_map; namespace wm { @@ -69,6 +71,9 @@ static const vector kListEventName{ static sd_event_source *g_timer_ev_src = nullptr; static AppList g_app_list; static WindowManager *g_context; +static vector white_list_area_size_change = { + "homescreen", "settings" +}; namespace { @@ -133,10 +138,10 @@ int WindowManager::init() // Register callback to PolicyManager this->pmw.registerCallback(onStateTransitioned, onError); - // Make afb event - for (int i = Event_Val_Min; i <= Event_Val_Max; i++) + // Make afb event for subscriber + for (int i = Event_ScreenUpdated; i < Event_Error; 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"); @@ -163,21 +168,25 @@ result WindowManager::api_request_surface(char const *appid, char const *dr if(!g_app_list.contains(str_id)) { - lid = this->lc->getNewLayerID(role); + lid = this->generateLayerForClient(role); if (lid == 0) { - // 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"); - } + 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); } + else + { + // This case occurs when an client calls "subscribe" before request_surface. + // Then application doesn't have layer and role yet. + auto client = g_app_list.lookUpClient(str_id); + if(client->layerID() == 0) + { + client->setLayerID(this->generateLayerForClient(role)); + } + client->setRole(role); + } // generate surface ID for ivi-shell application auto rname = this->id_alloc.lookup(role); @@ -187,6 +196,9 @@ result WindowManager::api_request_surface(char const *appid, char const *dr auto id = int(this->id_alloc.generate_id(role)); this->tmp_surface2app[id] = {str_id, lid}; + auto client = g_app_list.lookUpClient(str_id); + client->registerSurface(id); + return Ok(id); } @@ -217,21 +229,25 @@ char const *WindowManager::api_request_surface(char const *appid, char const *dr if(!g_app_list.contains(str_id)) { - unsigned l_id = this->lc->getNewLayerID(role); + unsigned l_id = this->generateLayerForClient(role); if (l_id == 0) { - // 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"; - } + 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); } + else + { + // This case occurs when an client calls "subscribe" before request_surface. + // Then application doesn't have layer and role yet. + auto client = g_app_list.lookUpClient(str_id); + if(client->layerID() == 0) + { + client->setLayerID(this->generateLayerForClient(role)); + } + client->setRole(role); + } auto rname = this->id_alloc.lookup(role); @@ -285,7 +301,6 @@ void WindowManager::api_activate_window(char const *appid, char const *drawing_n } // Do allocate tasks - ret = this->checkPolicy(req_num); if (ret != WMError::SUCCESS) @@ -378,10 +393,135 @@ void WindowManager::api_enddraw(char const *appid, char const *drawing_name) } } -int WindowManager::api_subscribe(afb_req req, int event_id) +json_object* WindowManager::api_get_area_list() +{ + json_object* ret = json_object_new_object(); + json_object* jarray = json_object_new_array(); + unordered_map area2size = this->lc->getAreaList(); + for(const auto& area : area2size) + { + json_object* j = json_object_new_object(); + json_object_object_add(j, "name", json_object_new_string(area.first.c_str())); + json_object* jrect = json_object_new_object(); + json_object_object_add(jrect, "x", json_object_new_int(area.second.x)); + json_object_object_add(jrect, "y", json_object_new_int(area.second.y)); + json_object_object_add(jrect, "w", json_object_new_int(area.second.w)); + json_object_object_add(jrect, "h", json_object_new_int(area.second.h)); + json_object_object_add(j, "rect", jrect); + json_object_array_add(jarray, j); + } + json_object_object_add(ret, "areas", jarray); + HMI_DEBUG("area_list: %s", json_object_get_string(ret)); + return ret; +} + +void WindowManager::api_change_area_size(ChangeAreaReq &areas) { - struct afb_event event = this->map_afb_event[kListEventName[event_id]]; - return afb_req_subscribe(req, event); + // Error check + areas.dump(); + auto client = g_app_list.lookUpClient(areas.appname); + WMError ret; + if(client == nullptr) + { + HMI_ERROR("Call register your role with setRole or requestSurface"); + return; + } + if(std::find(white_list_area_size_change.begin(), + white_list_area_size_change.end(), client->role()) == white_list_area_size_change.end()) + { + HMI_ERROR("Application %s which has the role %s is not allowed to change area size", client->appID().c_str(), client->role().c_str()); + return; + } + + // Update + ret = this->lc->updateAreaList(areas); + if(ret != WMError::SUCCESS) + { + HMI_ERROR("%d : %s", ret, errorDescription(ret)); + return; + } + ret = this->lc->getUpdateAreaList(&areas); + areas.dump(); + if(ret != WMError::SUCCESS) + { + HMI_ERROR("%d : %s", ret, errorDescription(ret)); + return; + } + + // Create Action + unsigned req_num; + bool found = false; + ret = this->setRequest(client->appID(), client->role(), "-", Task::TASK_CHANGE_AREA, &req_num); // area is null + if(ret != WMError::SUCCESS) + { + HMI_SEQ_ERROR(req_num, "%d : %s", ret, errorDescription(ret)); + return; + } + for(const auto &update: areas.update_app2area) + { + // create action + auto client = g_app_list.lookUpClient(update.first); + if(client == nullptr) + { + HMI_SEQ_ERROR(req_num, "%s : %s", update.first.c_str(), errorDescription(ret)); + g_app_list.removeRequest(req_num); + this->processNextRequest(); + return; + } + ret = g_app_list.setAction(req_num, client, client->role(), update.second, TaskVisible::VISIBLE); + if(ret != WMError::SUCCESS) + { + HMI_SEQ_ERROR(req_num, "Failed to set request"); + return; + } + } + HMI_SEQ_INFO(req_num, "Area change request"); + g_app_list.reqDump(); + + // Request change size to applications + for(const auto &action : g_app_list.getActions(req_num, &found)) + { + struct rect r = this->lc->getAreaSize(action.area); + action.client->emitSyncDraw(action.area, r); + } +} + +bool WindowManager::api_subscribe(afb_req_t req, EventType event_id) +{ + bool ret = false; + char* appid = afb_req_get_application_id(req); + if(event_id < Event_Val_Min || event_id > Event_Val_Max) + { + HMI_ERROR("not defined in Window Manager", event_id); + free(appid); + return ret; + } + HMI_INFO("%s subscribe %s : %d", appid, kListEventName[event_id].c_str(), event_id); + if(event_id == Event_ScreenUpdated) + { + // Event_ScreenUpdated should be emitted to subscriber + afb_event_t event = this->map_afb_event[kListEventName[event_id]]; + int rc = afb_req_subscribe(req, event); + if(rc == 0) + { + ret = true; + } + } + else if(appid) + { + string id = appid; + if(!g_app_list.contains(id)) + { + g_app_list.addClient(id); + } + ret = g_app_list.lookUpClient(id)->subscribe(req, kListEventName[event_id]); + } + else + { + HMI_ERROR("appid is not set"); + } + free(appid); + return ret; } result WindowManager::api_get_display_info() @@ -423,39 +563,6 @@ result WindowManager::api_get_area_info(char const *drawing_name) return Ok(object); } -void WindowManager::send_event(const string& evname, const string& role) -{ - json_object *j = json_object_new_object(); - json_object_object_add(j, kKeyDrawingName, json_object_new_string(role.c_str())); - - int ret = afb_event_push(this->map_afb_event[evname], j); - if (ret != 0) - { - HMI_DEBUG("afb_event_push failed: %m"); - } -} - -void WindowManager::send_event(const string& evname, const string& role, const string& area, - int x, int y, int w, int h) -{ - json_object *j_rect = json_object_new_object(); - json_object_object_add(j_rect, kKeyX, json_object_new_int(x)); - json_object_object_add(j_rect, kKeyY, json_object_new_int(y)); - json_object_object_add(j_rect, kKeyWidth, json_object_new_int(w)); - json_object_object_add(j_rect, kKeyHeight, json_object_new_int(h)); - - json_object *j = json_object_new_object(); - json_object_object_add(j, kKeyDrawingName, json_object_new_string(role.c_str())); - json_object_object_add(j, kKeyDrawingArea, json_object_new_string(area.c_str())); - json_object_object_add(j, kKeyDrawingRect, j_rect); - - int ret = afb_event_push(this->map_afb_event[evname], j); - if (ret != 0) - { - HMI_DEBUG("afb_event_push failed: %m"); - } -} - /** * proxied events */ @@ -606,49 +713,28 @@ void WindowManager::processError(WMError error) this->processNextRequest(); } -/* - ******* Private Functions ******* - */ - -void WindowManager::emit_activated(const string& role) +unsigned WindowManager::generateLayerForClient(const string& role) { - this->send_event(kListEventName[Event_Active], role); -} - -void WindowManager::emit_deactivated(const string& role) -{ - this->send_event(kListEventName[Event_Inactive], role); -} - -void WindowManager::emit_syncdraw(const string& role, char const *area, int x, int y, int w, int h) -{ - this->send_event(kListEventName[Event_SyncDraw], role, area, x, y, w, h); -} - -void WindowManager::emit_syncdraw(const string &role, const string &area) -{ - struct rect rect = this->lc->getAreaSize(area); - this->send_event(kListEventName[Event_SyncDraw], - role, area, rect.x, rect.y, rect.w, rect.h); -} + string l_name; + unsigned lid = this->lc->getNewLayerID(role, &l_name); + if (lid == 0) + { + // 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.c_str()); + if (lid == 0) + { + return lid; + } + } -void WindowManager::emit_flushdraw(const string& role) -{ - this->send_event(kListEventName[Event_FlushDraw], role); -} + // TODO: remote layer name is fixed + this->lc->createNewLayer(lid, ("Remote" == l_name)); -void WindowManager::emit_visible(const string& role, bool is_visible) -{ - this->send_event(is_visible ? kListEventName[Event_Visible] : kListEventName[Event_Invisible], role); + // add client into the db + return lid; } -void WindowManager::emit_invisible(const string& role) -{ - return emit_visible(role, false); -} - -void WindowManager::emit_visible(const string& role) { return emit_visible(role, true); } - WMError WindowManager::setRequest(const string& appid, const string &role, const string &area, Task task, unsigned* req_num) { @@ -738,10 +824,8 @@ WMError WindowManager::startTransition(unsigned req_num) if (action.visible == TaskVisible::VISIBLE) { sync_draw_happen = true; - 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); */ + struct rect r = this->lc->getAreaSize(action.area); + action.client->emitSyncDraw(action.area, r); } } @@ -756,12 +840,7 @@ WMError WindowManager::startTransition(unsigned req_num) for (const auto &x : actions) { this->lc->visibilityChange(x); - 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)); - } */ + x.client->emitVisible(false); } this->lc->renderLayers(); ret = WMError::NO_LAYOUT_CHANGE; @@ -797,17 +876,7 @@ WMError WindowManager::doEndDraw(unsigned req_num) return ret; } ret = this->lc->visibilityChange(act); - - if(act.visible == VISIBLE) - { - emit_visible(act.role); - emit_activated(act.role); - } - else - { - emit_invisible(act.role); - emit_deactivated(act.role); - } + act.client->emitVisible((act.visible == VISIBLE)); if (ret != WMError::SUCCESS) { @@ -826,7 +895,7 @@ WMError WindowManager::doEndDraw(unsigned req_num) { if(act_flush.visible == TaskVisible::VISIBLE) { - this->emit_flushdraw(act_flush.role); + act_flush.client->emitFlushDraw(); } } @@ -839,6 +908,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(); @@ -856,7 +932,7 @@ void WindowManager::emitScreenUpdated(unsigned req_num) int ret = afb_event_push( this->map_afb_event[kListEventName[Event_ScreenUpdated]], j); - if (ret != 0) + if (ret < 0) { HMI_DEBUG("afb_event_push failed: %m"); } @@ -874,7 +950,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) {