aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazumasa Mitsunari <knimitz@witz-inc.co.jp>2018-05-25 17:12:19 +0900
committerKazumasa Mitsunari <knimitz@witz-inc.co.jp>2018-05-25 19:16:58 +0900
commit6d0e22de7814f4fbf2201d84d207eec570e821cd (patch)
tree389dfb91b1a68681a68d843683af998b00844619
parentb04339fc03543cbd34b6e9db7adc9eb35caed5c0 (diff)
Rework: Block the sequence
Todo: * emit error event ** decide error format * rework release WR Change-Id: Id96fa629aff984aa03ed68f1d3db711bb43ba77b Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
-rw-r--r--include/hmi-debug.h2
-rw-r--r--src/app.cpp287
-rw-r--r--src/app.hpp9
-rw-r--r--src/applist.cpp31
-rw-r--r--src/applist.hpp7
5 files changed, 203 insertions, 133 deletions
diff --git a/include/hmi-debug.h b/include/hmi-debug.h
index 282386c..a70b49b 100644
--- a/include/hmi-debug.h
+++ b/include/hmi-debug.h
@@ -93,7 +93,7 @@ static void _HMI_SEQ_LOG(enum LOG_LEVEL level, const char* file, const char* fun
va_start(args, log);
if (log == NULL || vasprintf(&message, log, args) < 0)
message = NULL;
- fprintf(stderr, "[%10.3f] [wm %s] [%s, %s(), Line:%d] >>> seq %d: %s \n", time / 1000.0, ERROR_FLAG[level], file, func, line, seq_num, message);
+ fprintf(stderr, "[%10.3f] [wm %s] [%s, %s(), Line:%d] >>> req %d: %s \n", time / 1000.0, ERROR_FLAG[level], file, func, line, seq_num, message);
va_end(args);
free(message);
}
diff --git a/src/app.cpp b/src/app.cpp
index 7462c99..e64b248 100644
--- a/src/app.cpp
+++ b/src/app.cpp
@@ -122,9 +122,14 @@ processTimerHandler(sd_event_source *s, uint64_t usec, void *userdata)
void App::timerHandler()
{
- // TODO: write reset process
unsigned seq = app_list.currentSequenceNumber();
+ HMI_SEQ_DEBUG(seq, "Timer expired remove Request");
app_list.removeRequest(seq);
+ app_list.next();
+ if (app_list.haveRequest())
+ {
+ this->process_request();
+ }
}
/**
@@ -400,29 +405,13 @@ 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 (!app_list.requestFinished());
-
- // lm_.updateLayout(jobj);
- // TODO: emit syncDraw with application
- do
- {
- //client->emit_syncdraw(role);
- } while (!app_list.requestFinished());
-
- // is the below necessary?
- //app_list.setAllocated(sequence_number);
-
+void App::set_timer(){
+ HMI_SEQ_DEBUG(app_list.currentSequenceNumber(), "Timer set activate");
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);
+ CLOCK_REALTIME, time(NULL) + TIME_OUT, 0, processTimerHandler, this);
if (ret < 0)
{
HMI_ERROR("wm", "Can't set timer");
@@ -436,54 +425,13 @@ void App::do_allocate_window_resource(unsigned sequence_number)
}
}
-void App::api_activate_surface(char const *appid, char const *drawing_name, char const *drawing_area, const reply_func &reply)
+bool App::do_allocate_window_resource(unsigned request_seq)
{
- ST();
-
- /*
- * Check Phase
- */
-
- auto const &surface_id = this->lookup_id(drawing_name);
- std::string id = appid;
- std::string role = drawing_name;
- std::string area = drawing_area;
-
- if(!app_list.contains(id)){
- reply("app doesn't request 'requestSurface' yet");
- return;
- }
-
- auto client = app_list.lookUpClient(id);
-
- /*
- * Queueing Phase
- */
- unsigned current = app_list.currentSequenceNumber();
- unsigned requested_num = app_list.getSequenceNumber(id);
- if (requested_num != 0)
- {
- HMI_SEQ_INFO(requested_num, "%s %s %s request is already queued", id.c_str(), role.c_str(), area.c_str());
- reply("already requested");
- return;
- }
-
- WMRequest req = WMRequest(id, role, area, Task::TASK_ALLOCATE);
- unsigned new_req = app_list.addAllocateRequest(req);
-
- HMI_SEQ_DEBUG(new_req, "%s start sequence with %s, %s", id.c_str(), role.c_str(), area.c_str());
-
- if (new_req != current)
- {
- // Add request, then invoked after the previous task is finished
- HMI_SEQ_DEBUG(new_req, "request is accepted");
- reply(nullptr);
- return;
- }
-
/*
* Check Policy
*/
+ // get current trigger
+ auto trigger = app_list.getRequest(request_seq);
// json_object* newState = checkPolicy(role);
/* The following error check is not necessary because main.cpp will reject the message form not registered object
@@ -491,53 +439,31 @@ void App::api_activate_surface(char const *appid, char const *drawing_name, char
reply("client is not registered");
return;
} */
+ HMI_SEQ_NOTICE(request_seq, "ATM, Policy manager does't exist, then set WMAction as is");
- // get surfaceID from role
- /* auto const &surface_id_tmp = client->surfaceID(role);
- auto const &layer_id_tmp = client->layerID();
+ bool ret = app_list.setAction(request_seq, trigger.appid, trigger.role, trigger.area);
- 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);
- } */
+ app_list.req_dump();
+ // TODO: Tasks will be changed according to policy manager result
+ // do task(onTransition (activate))
- /*
- * Do allocate tasks
- */
- this->do_allocate_window_resource(new_req);
-
- if (!surface_id)
- {
- reply("Surface does not exist");
- return;
- }
+ // lm_.updateLayout(jobj);
+ // TODO: emit syncDraw with application
- if (!this->controller->surface_exists(*surface_id))
- {
- reply("Surface does not exist in controller!");
- return;
+ //client->emit_syncdraw(role);
+ if (ret) {
+ this->set_timer();
+ } else {
+ //this->emit_error(request_seq, 0 /*error_num*/, "error happens"); // test
}
+ return ret;
+}
+void App::lm_layout_change(unsigned req, const char* drawing_name)
+{
+ auto const &surface_id = this->lookup_id(drawing_name);
auto layer_id = this->layers.get_layer_id(*surface_id);
-
- if (!layer_id)
- {
- reply("Surface is not on any layer!");
- return;
- }
-
auto o_state = *this->layers.get_layout_state(*surface_id);
-
- if (o_state == nullptr)
- {
- reply("Could not find layer for surface");
- return;
- }
-
- HMI_DEBUG("wm", "surface %d is detected", *surface_id);
- reply(nullptr);
-
struct LayoutState &state = *o_state;
// disable layers that are above our current layer
@@ -678,6 +604,106 @@ void App::api_activate_surface(char const *appid, char const *drawing_name, char
}
}
+const char* App::check_surface_exist(unsigned req, const char* drawing_name)
+{
+ auto const &surface_id = this->lookup_id(drawing_name);
+ if (!surface_id)
+ {
+ //reply("Surface does not exist");
+ return "Surface does not exist";
+ }
+
+ if (!this->controller->surface_exists(*surface_id))
+ {
+ //reply("Surface does not exist in controller!");
+ return "Surface does not exist in controller!";
+ }
+
+ auto layer_id = this->layers.get_layer_id(*surface_id);
+
+ if (!layer_id)
+ {
+ //reply("Surface is not on any layer!");
+ return "Surface is not on any layer!";
+ }
+
+ auto o_state = *this->layers.get_layout_state(*surface_id);
+
+ if (o_state == nullptr)
+ {
+ //reply("Could not find layer for surface");
+ return "Could not find layer for surface";
+ }
+
+ HMI_DEBUG("wm", "surface %d is detected", *surface_id);
+ return nullptr;
+ //reply(nullptr);
+}
+
+void App::api_activate_surface(char const *appid, char const *drawing_name, char const *drawing_area, const reply_func &reply)
+{
+ ST();
+
+ /*
+ * Check Phase
+ */
+
+ std::string id = appid;
+ std::string role = drawing_name;
+ std::string area = drawing_area;
+
+ if(!app_list.contains(id)){
+ reply("app doesn't request 'requestSurface' yet");
+ return;
+ }
+
+ auto client = app_list.lookUpClient(id);
+
+ /*
+ * Queueing Phase
+ */
+ unsigned current = app_list.currentSequenceNumber();
+ unsigned requested_num = app_list.getSequenceNumber(id);
+ if (requested_num != 0)
+ {
+ HMI_SEQ_INFO(requested_num, "%s %s %s request is already queued", id.c_str(), role.c_str(), area.c_str());
+ reply("already requested");
+ return;
+ }
+
+ WMRequest req = WMRequest(id, role, area, Task::TASK_ALLOCATE);
+ unsigned new_req = app_list.addAllocateRequest(req);
+ app_list.req_dump();
+
+ HMI_SEQ_DEBUG(current, "%s start sequence with %s, %s", id.c_str(), role.c_str(), area.c_str());
+
+ if (new_req != current)
+ {
+ // Add request, then invoked after the previous task is finished
+ HMI_SEQ_DEBUG(new_req, "request is accepted");
+ reply(nullptr);
+ return;
+ }
+
+ /*
+ * Do allocate tasks
+ */
+ bool ret = this->do_allocate_window_resource(new_req);
+
+ // layer manager task
+ const char* msg = this->check_surface_exist(new_req, drawing_name); // this function will be integrated in do_allocate_window_resource()
+
+ if(msg){
+ HMI_SEQ_DEBUG(new_req,"surface doesn't exist");
+ reply(msg);
+ app_list.removeRequest(new_req);
+ return;
+ }
+ this->lm_layout_change(new_req, drawing_name); // this function will be integrated in do_allocate_window_resource()
+
+ reply(nullptr);
+}
+
void App::api_deactivate_surface(char const *appid, char const *drawing_name, const reply_func &reply)
{
ST();
@@ -805,25 +831,46 @@ void App::check_flushdraw(int surface_id)
}
}
-void App::do_enddraw(unsigned sequence_number)
-{
- HMI_SEQ_INFO(sequence_number, "do endDraw");
- do
+void App::lm_enddraw(const char* drawing_name){
+ HMI_DEBUG("wm", "end draw %s", drawing_name);
+ for (unsigned i = 0, iend = this->pending_end_draw.size(); i < iend; i++)
{
- // make visible application
- } while (!app_list.requestFinished());
+ auto n = this->lookup_name(this->pending_end_draw[i]);
+ if (n && *n == drawing_name)
+ {
+ std::swap(this->pending_end_draw[i], this->pending_end_draw[iend - 1]);
+ this->pending_end_draw.resize(iend - 1);
+ this->activate(this->pending_end_draw[i]);
+ this->emit_flushdraw(drawing_name);
+ }
+ }
+}
+
+void App::do_enddraw(unsigned request_seq)
+{
+ // get actions
+ auto actions = app_list.getActions(request_seq);
+ HMI_SEQ_INFO(request_seq, "do endDraw");
- HMI_SEQ_INFO(sequence_number, "emit flushDraw");
- do
+ for(const auto& act : actions){
+ HMI_SEQ_DEBUG(request_seq, "visible %s", act.role.c_str());
+ this->lm_enddraw(act.role.c_str());
+ }
+
+ HMI_SEQ_INFO(request_seq, "emit flushDraw");
+/* do
{
// emit flush Draw
//emitFlushDrawToAll(&app_list, request_seq);
// emit status change event
- } while (!app_list.requestFinished());
+ } while (!app_list.requestFinished());*/
}
void App::process_request()
{
+ unsigned req = app_list.currentSequenceNumber();
+ HMI_SEQ_DEBUG(req, "Do next request");
+ do_allocate_window_resource(req);
}
void App::api_enddraw(char const *appid, char const *drawing_name)
@@ -832,6 +879,7 @@ void App::api_enddraw(char const *appid, char const *drawing_name)
std::string role(drawing_name);
unsigned current_seq = app_list.currentSequenceNumber();
bool result = app_list.setEndDrawFinished(current_seq, id, role);
+
if (!result)
{
HMI_ERROR("wm", "%s doesn't have Window Resource", id.c_str());
@@ -841,9 +889,11 @@ void App::api_enddraw(char const *appid, char const *drawing_name)
if (app_list.endDrawFullfilled(current_seq))
{
// do task for endDraw
+ //this->stop_timer();
this->do_enddraw(current_seq);
+
app_list.removeRequest(current_seq);
- HMI_SEQ_INFO(current_seq, "Finish sequence");
+ HMI_SEQ_INFO(current_seq, "Finish request");
app_list.next();
if (app_list.haveRequest())
{
@@ -855,17 +905,6 @@ void App::api_enddraw(char const *appid, char const *drawing_name)
HMI_SEQ_INFO(current_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]);
- if (n && *n == drawing_name)
- {
- std::swap(this->pending_end_draw[i], this->pending_end_draw[iend - 1]);
- this->pending_end_draw.resize(iend - 1);
- this->activate(this->pending_end_draw[i]);
- this->emit_flushdraw(drawing_name);
- }
- }
}
void App::api_ping() { this->dispatch_pending_events(); }
diff --git a/src/app.hpp b/src/app.hpp
index b25f568..1950680 100644
--- a/src/app.hpp
+++ b/src/app.hpp
@@ -243,9 +243,10 @@ struct App {
void emit_invisible(char const *label);
void emit_visible(char const *label);
- void do_allocate_window_resource(unsigned sequence_number);
+ bool do_allocate_window_resource(unsigned sequence_number);
void do_enddraw(unsigned sequence_number);
void process_request();
+ void set_timer();
void activate(int id);
void deactivate(int id);
@@ -255,6 +256,12 @@ struct App {
void try_layout(struct LayoutState &state,
struct LayoutState const &new_layout,
std::function<void(LayoutState const &nl)> apply);
+
+ // The following function is temporary.
+ // Then will be removed when layermanager is finished
+ void lm_layout_change(unsigned req, const char* drawing_name);
+ void lm_enddraw(const char* drawing_name);
+ const char *check_surface_exist(unsigned req, const char *drawing_name);
};
} // namespace wm
diff --git a/src/applist.cpp b/src/applist.cpp
index be88977..36c5917 100644
--- a/src/applist.cpp
+++ b/src/applist.cpp
@@ -21,6 +21,7 @@
using std::shared_ptr;
using std::string;
using std::unique_ptr;
+using std::vector;
namespace wm {
@@ -81,19 +82,39 @@ unsigned AppList::getSequenceNumber(const string &appid){
unsigned AppList::addAllocateRequest(WMRequest req){
if(req_list.size() == 0){
- req.seq_num = 1;
+ req.seq_num = current_seq;
}
else{
+ HMI_SEQ_DEBUG(current_seq, "real: %d", req_list.back().seq_num + 1);
req.seq_num = req_list.back().seq_num + 1;
}
req_list.push_back(req);
- return req.seq_num;
+ return req.seq_num; // return 1; if you test time_expire
}
bool AppList::requestFinished(){
return req_list.empty();
}
+struct WMTrigger AppList::getRequest(unsigned request_seq){
+ for(auto& x : req_list){
+ if (request_seq == x.seq_num)
+ {
+ return x.trigger;
+ }
+ }
+}
+
+const vector<struct WMAction>& AppList::getActions(unsigned request_seq){
+ for (auto &x : req_list)
+ {
+ if (request_seq == x.seq_num)
+ {
+ return x.sync_draw_req;
+ }
+ }
+}
+
bool AppList::setAction(unsigned request_seq, const string &appid, const string &role, const string &area){
bool result = false;
for (auto& x : req_list)
@@ -190,9 +211,9 @@ void AppList::client_dump(){
void AppList::req_dump()
{
DUMP("======= req dump =====");
- DUMP("current sequence: %d", current_seq);
+ DUMP("current request : %d", current_seq);
for(const auto& x : req_list){
- DUMP("sequence number: %d", x.seq_num);
+ DUMP("requested with : %d", x.seq_num);
DUMP("Trigger : (APPID :%s, ROLE :%s, AREA :%s, TASK: %d)",
x.trigger.appid.c_str(),
x.trigger.role.c_str(),
@@ -201,7 +222,7 @@ void AppList::req_dump()
for (const auto& y : x.sync_draw_req){
DUMP(
- "Action : (APPID :%s, ROLE :%s, AREA :%s, END_RAW_FINISHED: %d)",
+ "Action : (APPID :%s, ROLE :%s, AREA :%s, END_DRAW_FINISHED: %d)",
y.appid.c_str(),
y.role.c_str(),
y.area.c_str(),
diff --git a/src/applist.hpp b/src/applist.hpp
index 5da91cf..f91e7c8 100644
--- a/src/applist.hpp
+++ b/src/applist.hpp
@@ -33,7 +33,7 @@ typedef enum Task{
TASK_RELEASE
}ResourceTask;
-struct WMTriger {
+struct WMTrigger {
std::string appid;
std::string role;
std::string area;
@@ -57,7 +57,7 @@ struct WMRequest
WMRequest(const WMRequest &obj);
unsigned seq_num;
- struct WMTriger trigger;
+ struct WMTrigger trigger;
std::vector<struct WMAction> sync_draw_req;
};
@@ -89,6 +89,9 @@ public:
void next();
bool haveRequest();
+ struct WMTrigger getRequest(unsigned request_seq);
+ const std::vector<struct WMAction>& getActions(unsigned request_seq);
+
void client_dump();
void req_dump();