From 5529ff5051d8da4acb6157c6c6fa0043de2e685b Mon Sep 17 00:00:00 2001 From: Kazumasa Mitsunari Date: Thu, 17 May 2018 11:44:12 +0900 Subject: [Local]:3rd step for blocking sequence Change-Id: Ieef89545fa6f6ec1704b9c4b51f92dd5d624aff1 Signed-off-by: Kazumasa Mitsunari --- src/allocate_queue.cpp | 47 +++++++++++++++++- src/allocate_queue.hpp | 21 +++++--- src/app.cpp | 130 +++++++++++++++++++++++++++++++++---------------- 3 files changed, 150 insertions(+), 48 deletions(-) diff --git a/src/allocate_queue.cpp b/src/allocate_queue.cpp index 029c516..0d7a646 100644 --- a/src/allocate_queue.cpp +++ b/src/allocate_queue.cpp @@ -15,12 +15,57 @@ */ #include "allocate_queue.hpp" +#include namespace wm { AllocateRequestList::AllocateRequestList(){} AllocateRequestList::~AllocateRequestList(){} -void AllocateRequestList::addClient(WMClient* client){ +bool AllocateRequestList::addClient(WMClient* client){ + return true; } + +void AllocateRequestList::removeClient(const char* appid){ + return true; +} + +const WMClient* AllocateRequestList::lookUpClient(const char appid){ + std::string key = std::string(appid); + auto itr = client_list.find(appid); + return (itr != client_list.end()) ? itr.second() : nullptr; +} + +unsigned AllocateRequestList::getSequenceNumber(appid, role, area){ + return 0; +} + +bool AllocateRequestList::addAllocateRequest(WMClient &client, unsigned seq_num, std::string &task){ + return true; +} + +bool AllocateRequestList::requestFinished(){ + return true; +} + +unsigned AllocateRequestList::lookUpAllocatingApp(const char *appid){ + return 1; +} + +unsigned AllocateRequestList::currentSequnce(const char *appid){ + return 1; +} + +void AllocateRequestList::removeRequest(unsigned req_seq){ + +} + +void AllocateRequestList::setCurrentSequence(unsigned req_seq){ + +} + +bool AllocateRequestList::haveRequest(){ + return true; +} + } \ No newline at end of file diff --git a/src/allocate_queue.hpp b/src/allocate_queue.hpp index 68b9008..df57370 100644 --- a/src/allocate_queue.hpp +++ b/src/allocate_queue.hpp @@ -31,14 +31,23 @@ public: typedef std::function onReverted; // Client Database Interface - void addClient(WMClient* client); - WMClient* loopUpClient(const char* appid); + bool addClient(WMClient &client); + bool removeClient(const char* appid); + const WMClient* loopUpClient(const char* appid); // Request Interface - bool hasRequestingApp(const char *appid); - void revertRequestingState(); - void removeAllRequesting(); - bool addRequest(WMClient *, onEndDraw, onReverted); + unsigned currentSequnceNumber(); + unsigned getSequenceNumber(appid, role, area); + bool addAllocateRequest(WMClient &client, unsigned seq_num, std::string &task); + bool requestFinished(); + unsigned lookUpAllocatingApp(const char *appid); + unsigned currentSequence(); + void setEndDrawFinished(unsigned request_seq, const std::string &role); + void removeRequest(unsigned request_seq); + void setCurrentSequence(unsigned request_seq); + bool haveRequest(); + /* void revertRequestingState(); + void removeAllRequesting(); */ //void revertRequestingState();//??? diff --git a/src/app.cpp b/src/app.cpp index 6d3f1bb..8038f4c 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -62,6 +62,9 @@ const char kKeyHeightPixel[] = "height_pixel"; const char kKeyWidthMm[] = "width_mm"; const char kKeyHeightMm[] = "height_mm"; +static const std::string task_allocate = "allocate" +static const std::string task_release = "release" + static AllocateRequestList allocate_list; namespace { @@ -348,6 +351,33 @@ void App::layout_commit() { this->display->flush(); } +void App::do_allocate_window_resource(unsigned sequence_number){ + do { + // TODO: Tasks will be changed according to policy manager result + // do task(onTransition (activate)) + }while (!allocate_list.requestFinished()) + + // lm_.updateLayout(jobj); + // TODO: emit syncDraw with application + do{ + client->emit_syncdraw(role); + }while (!allocate_list.requestFinished()); + + // is this needed? + //allocate_list.setAllocated(sequence_number); + + if(timer_ev_src != nullptr){ + // firsttime set into sd_event + int ret = sd_event_add_time(afb_daemon_get_event_loop(), &timer_ev_src, + CLOCK_BOOTTIME, time(NULL) + TIME_OUT, 0, processTimerHandler, this); + } + else{ + // update timer limitation after second time + sd_event_source_set_time(timer_ev_src, time(NULL) + TIME_OUT); + sd_event_source_set_enabled(timer_ev_src, SD_EVENT_ONESHOT); + } +} + void App::api_activate_surface(char const *appid, char const *drawing_name, char const *drawing_area, const reply_func &reply) { ST(); @@ -357,30 +387,49 @@ void App::api_activate_surface(char const *appid, char const *drawing_name, char auto const &surface_id = this->lookup_id(drawing_name); std::string role = std::string(drawing_name); - // newState = checkPolicy(role); + std::string area = std::string(drawing_area); + const WMClient* client = allocate_list.loopUpClient(appid); + if(!client){ + reply("%d doesn't request 'requestSurface' yet", appid); + return; + } + + // json_object* newState = checkPolicy(role); + /* The following error check is not necessary because main.cpp will reject the message form not registered object if(client != nullptr){ reply("client is not registered"); return; - } - auto const &surface_id_tmp = client->surfaceID(role); + } */ + + // get surfaceID from role + /* auto const &surface_id_tmp = client->surfaceID(role); auto const &layer_id_tmp = client->layerID(); if(!surface_id_tmp && !layer_id_tmp){ reply("invalid window manager client"); HMI_DEBUG("appid:%s, requested_role:%s, surfaceID:%d in layer %d", appid, role, surface_id_tmp, layer_id_tmp); - } + } */ /* * Queueing Phase */ - static unsigned ++sequence_number; unsigned current = allocate_list.curerntSequenceNumber(); + unsigned requested_num = getSequenceNumber(appid, role, area); + if(requested_num != 0){ + HMI_SEQ_INFO(requested_num, "%s %s %s request is already queued", appid, role, area); + reply("already requested"); + return; + } + + static unsigned ++sequence_number; + HMI_SEQ_DEBUG(sequence_number, "%s start sequence with %s, %s", appid, role, area); if(sequence_number != current){ // Add request, then invoked after the previous task is finished - allocate_list.addAllocateRequest(client, sequence_number, tasks); + allocate_list.addAllocateRequest(client, sequence_number, task_allocate); + HMI_SEQ_DEBUG(sequence_number, "request is accepted"); reply(nullptr); return; } @@ -388,27 +437,7 @@ void App::api_activate_surface(char const *appid, char const *drawing_name, char /* * Do allocate tasks */ - do { - // TODO: Tasks will be changed according to policy manager result - // do task(onTransition (activate)) - }while (!allocate_list.requestFinished()) - - // lm_.updateLayout(jobj); - // TODO: emit syncDraw with application - do{ - client->emit_syncdraw(role); - }while (!allocate_list.requestFinished()); - - if(timer_ev_src != nullptr){ - // firsttime set into sd_event - int ret = sd_event_add_time(afb_daemon_get_event_loop(), &timer_ev_src, - CLOCK_BOOTTIME, time(NULL) + TIME_OUT, 0, processTimerHandler, this); - } - else{ - // update timer limitation after second time - sd_event_source_set_time(timer_ev_src, time(NULL) + TIME_OUT); - sd_event_source_set_enabled(timer_ev_src, SD_EVENT_ONESHOT); - } + this->do_allocate_window_resource(sequence_number); if (!surface_id) { @@ -559,7 +588,7 @@ void App::api_activate_surface(char const *appid, char const *drawing_name, char } } -void App::api_deactivate_surface(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(); auto const &surface_id = this->lookup_id(drawing_name); WMClient* client = allocate_list.lookupClient(appid); @@ -663,31 +692,50 @@ void App::check_flushdraw(int surface_id) { } } -void App::api_enddraw(char const *drawing_name) { - unsigned request_seq = allocate_list.searchAllocatingApp(appid); +void App::do_enddraw(unsigned sequence_number){ + HMI_SEQ_INFO(sequence_number, "do endDraw"); + do{ + // make visible application + }while(!allocate_list.requestFinished()); + + HMI_SEQ_INFO(sequence_number, "emit flushDraw"); + do{ + // emit flush Draw + //emitFlushDrawToAll(&allocate_list, request_seq); + // emit status change event + }while(!allocate_list.requestFinished()); +} + +void App::api_enddraw(char const *appid, char const *drawing_name) { + unsigned request_seq = allocate_list.lookUpAllocatingApp(appid); unsigned current_seq = allocate_list.currentSequence(); if(current_seq != request_seq){ if(request_seq == 0){ - HMI_ERROR("[req_num:%d] You don't have Window Resource", request_seq); + HMI_ERROR("You don't have Window Resource"); } else{ - HMI_ERROR("[req_num:%d] unknown error. Application may not obey the sequence manner. please call endDraw after syncDraw"); + HMI_ERROR("wm", "unknown error. Application may not obey the sequence manner. please call endDraw after syncDraw"); } return; } - allocate_list.allocate(appid, request_seq); + + std::string role = drawing_name; + std::string area = drawing_area; + allocate_list.setEndDrawFinished(request_seq, role); + if(allocate_list.endDrawFullfilled(request_seq)){ // do task for endDraw - do{ - // visible application - }while(false); - do{ - // emit flush Draw - allocate_list.resetRequest(request_seq); - }while(false); + this->do_enddraw(request_seq); + allocate_list.removeRequest(request_seq); + HMI_SEQ_INFO(request_seq, "Finish sequence"); + allocate_list.setCurrentSequence(request_seq + 1); + if(allocate_list.haveRequest()){ + this->process_request(); + } } else{ - // wait other apps call endDraw + HMI_SEQ_INFO(request_seq, "Wait other App call endDraw"); + return; } for (unsigned i = 0, iend = this->pending_end_draw.size(); i < iend; i++) { auto n = this->lookup_name(this->pending_end_draw[i]); -- cgit 1.2.3-korg