From 5ac52dc6412f8311b6cfbd0e99652c914d5c6168 Mon Sep 17 00:00:00 2001 From: Kazumasa Mitsunari Date: Fri, 25 May 2018 11:17:55 +0900 Subject: [Local]:5th step for blocking sequence Change-Id: Ic47c59a77d3b45f62bed8ee2617dddc4ed58afbe Signed-off-by: Kazumasa Mitsunari --- src/applist.cpp | 154 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 115 insertions(+), 39 deletions(-) (limited to 'src/applist.cpp') diff --git a/src/applist.cpp b/src/applist.cpp index 477a51b..be88977 100644 --- a/src/applist.cpp +++ b/src/applist.cpp @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +#include #include #include "applist.hpp" #include "../include/hmi-debug.h" @@ -25,11 +25,16 @@ using std::unique_ptr; namespace wm { -AppList::AppList(){} +AppList::AppList() + : req_list(0), + client_list(0), + current_seq(1) +{} + AppList::~AppList(){} -void AppList::addClient(const std::string &appid, const std::string &role){ - shared_ptr client(new WMClient(appid, role)); +void AppList::addClient(const string &appid, const string &role){ + shared_ptr client = std::make_shared(appid, role); client_list[appid] = client; } @@ -42,25 +47,31 @@ bool AppList::contains(const string &appid){ return (client_list.end() != result) ? true : false; } -/* -* Call contains before calling this function -*/ +/** + * @brief get WMClient object. Before call this function, must call "contains" + * to check the key is contained, otherwise, you have to take care of std::out_of_range. + * @param string[in] application id(key) + * @return WMClient object + */ shared_ptr AppList::lookUpClient(const string &appid) { - /* auto result = client_list.find(appid); - return (client_list.end() != result) ? - &(result->second()) : nullptr; */ - return client_list[appid]; + return client_list.at(appid); +} + +int AppList::countClient() +{ + return client_list.size(); } unsigned AppList::currentSequenceNumber(){ return current_seq; } +// Is this function necessary ? unsigned AppList::getSequenceNumber(const string &appid){ - for(auto x : req_list){ + for(const auto& x : req_list){ // Since app will not request twice and more, comparing appid is enough? - if( (x.appid == appid)) + if( (x.trigger.appid == appid)) { return x.seq_num; } @@ -69,9 +80,12 @@ unsigned AppList::getSequenceNumber(const string &appid){ } unsigned AppList::addAllocateRequest(WMRequest req){ - req.seq_num = req_list.back().seq_num + 1; - req.allocating = false; - req.end_draw_finished = false; + if(req_list.size() == 0){ + req.seq_num = 1; + } + else{ + req.seq_num = req_list.back().seq_num + 1; + } req_list.push_back(req); return req.seq_num; } @@ -80,37 +94,65 @@ bool AppList::requestFinished(){ return req_list.empty(); } -unsigned AppList::lookUpAllocatingApp(const string &appid){ - for(auto x: req_list){ - if(appid == x.appid){ - if(false == x.allocating) - return x.seq_num; +bool AppList::setAction(unsigned request_seq, const string &appid, const string &role, const string &area){ + bool result = false; + for (auto& x : req_list) + { + if (request_seq != x.seq_num) + { + continue; } + WMAction action{appid, role, area, false}; + + x.sync_draw_req.push_back(action); + result = true; + break; } - return 0; + return result; } -void AppList::setEndDrawFinished(unsigned request_seq, const string &role){ - for(auto x: req_list){ - if(request_seq == x.seq_num){ - if(role == x.role){ - x.end_draw_finished = true; +bool AppList::setEndDrawFinished(unsigned request_seq, const string &appid, const string &role){ + bool result = false; + for (auto& x : req_list) + { + if (request_seq < x.seq_num) + { + break; + } + if (request_seq == x.seq_num) + { + for(auto& y : x.sync_draw_req){ + if (y.appid == appid && y.role == role) + { + y.end_draw_finished = true; + result = true; + } } } } + req_dump(); + return result; } +/** + * @brief check all actions of the requested sequence is finished + * @param unsigned sequence_num + * @return true if all action is set. + */ bool AppList::endDrawFullfilled(unsigned request_seq){ bool result = false; - for (auto x : req_list) + for (const auto& x : req_list) { if(request_seq < x.seq_num){ break; } if(request_seq == x.seq_num){ - result = x.end_draw_finished && x.allocating; - if(result == false){ - break; + result = true; + for(const auto& y : x.sync_draw_req){ + result &= y.end_draw_finished; + if(!result){ + break; + } } } } @@ -119,19 +161,53 @@ bool AppList::endDrawFullfilled(unsigned request_seq){ void AppList::removeRequest(unsigned req_seq){ req_list.erase(remove_if(req_list.begin(), req_list.end(), - [req_seq](WMRequest x) { return x.seq_num == req_seq;} - )); + [req_seq](WMRequest x) { + return x.seq_num == req_seq; + })); } -void AppList::setCurrentSequence(unsigned req_seq){ - this->current_seq = req_seq; - if(0 == this->current_seq){ - this->current_seq = 1; - } +void AppList::next(){ + ++this->current_seq; + if (0 == this->current_seq) + { + this->current_seq = 1; + } } bool AppList::haveRequest(){ - return true; + return !req_list.empty(); +} + +void AppList::client_dump(){ + DUMP("======= client dump ====="); + for(const auto& x : client_list){ + const auto& y = x.second; + DUMP("APPID : %s", y->appID().c_str()); + } + DUMP("======= client dump end====="); } +void AppList::req_dump() +{ + DUMP("======= req dump ====="); + DUMP("current sequence: %d", current_seq); + for(const auto& x : req_list){ + DUMP("sequence number: %d", x.seq_num); + DUMP("Trigger : (APPID :%s, ROLE :%s, AREA :%s, TASK: %d)", + x.trigger.appid.c_str(), + x.trigger.role.c_str(), + x.trigger.area.c_str(), + x.trigger.task); + + for (const auto& y : x.sync_draw_req){ + DUMP( + "Action : (APPID :%s, ROLE :%s, AREA :%s, END_RAW_FINISHED: %d)", + y.appid.c_str(), + y.role.c_str(), + y.area.c_str(), + y.end_draw_finished); + } + } + DUMP("======= req dump end =====\n"); +} } \ No newline at end of file -- cgit 1.2.3-korg