+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_REALTIME, time(NULL) + TIME_OUT, 0, processTimerHandler, this);
+ if (ret < 0)
+ {
+ HMI_ERROR("wm", "Could't set timer");
+ }
+ }
+ 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::stop_timer(){
+ unsigned seq = app_list.currentSequenceNumber();
+ HMI_SEQ_DEBUG(seq, "Timer stop");
+ int rc = sd_event_source_set_enabled(timer_ev_src, SD_EVENT_OFF);
+ if(rc < 0){
+ HMI_SEQ_ERROR(seq, "Timer stop failed");
+ }
+}
+
+bool App::do_allocate_window_resource(unsigned req_num)
+{
+ /*
+ * Check Policy
+ */
+ // get current trigger
+ auto trigger = app_list.getRequest(req_num);
+
+ /* get new status from Policy Manager
+
+ (json_object*?) newLayout = checkPolicy(trigger);
+ (vector<struct WMAction>&) auto actions = translator.inputActionFromLayout(newLayout, currentLayout)
+ for(const auto& x : actions){
+ app_list.setAciton(req_num, x)
+ }
+
+ or
+
+ translator.inputActionFromLayout(newLayout, currentLayout, &app_list, req_num);
+
+ /* The following error check is not necessary because main.cpp will reject the message form not registered object
+ } */
+ HMI_SEQ_NOTICE(req_num, "ATM, Policy manager does't exist, then set WMAction as is");
+
+ bool ret = app_list.setAction(req_num, trigger.appid, trigger.role, trigger.area);
+
+ app_list.req_dump();
+
+ /*
+ lm_.updateLayout(jobj);
+ TODO: emit syncDraw with application
+
+ client->emit_syncdraw(role); */
+
+ // layer manager task
+ const char *msg = this->check_surface_exist(req_num, trigger.appid.c_str());
+
+ if (msg)
+ {
+ HMI_SEQ_DEBUG(req_num, msg);
+ app_list.removeRequest(req_num);
+ return false;
+ }
+ this->lm_layout_change(req_num, trigger.appid.c_str());
+
+ if (ret && (msg == nullptr)) {
+ this->set_timer();
+ } else {
+ //this->emit_error(request_seq, 0 /*error_num*/, "error happens"); // test
+ }
+ return ret;
+}
+
+void App::lm_layout_change(unsigned req_num, const char* drawing_name)
+{
+ auto const &surface_id = this->lookup_id(drawing_name);
+ auto layer_id = this->layers.get_layer_id(*surface_id);
+ auto o_state = *this->layers.get_layout_state(*surface_id);
+ struct LayoutState &state = *o_state;
+
+ // disable layers that are above our current layer
+ for (auto const &l : this->layers.mapping)
+ {
+ if (l.second.layer_id <= *layer_id)
+ {
+ continue;
+ }
+
+ bool flush = false;
+ if (l.second.state.main != -1)
+ {
+ this->deactivate(l.second.state.main);
+ l.second.state.main = -1;
+ flush = true;
+ }
+
+ if (l.second.state.sub != -1)
+ {
+ this->deactivate(l.second.state.sub);
+ l.second.state.sub = -1;
+ flush = true;
+ }
+
+ if (flush)
+ {
+ this->layout_commit();
+ }
+ }
+
+ auto layer = this->layers.get_layer(*layer_id);
+
+ if (state.main == -1)
+ {
+ this->try_layout(
+ state, LayoutState{*surface_id}, [&](LayoutState const &nl) {
+ HMI_DEBUG("wm", "Layout: %s", kNameLayoutNormal);
+ this->surface_set_layout(*surface_id);
+ state = nl;
+
+ // Commit for configuraton
+ this->layout_commit();
+
+ std::string str_area = std::string(kNameLayoutNormal) + "." + std::string(kNameAreaFull);
+ compositor::rect area_rect = this->area_info[*surface_id];
+ this->emit_syncdraw(drawing_name, str_area.c_str(),
+ area_rect.x, area_rect.y, area_rect.w, area_rect.h);
+ this->enqueue_flushdraw(state.main);
+ });
+ }
+ else
+ {
+ if (0 == strcmp(drawing_name, "HomeScreen"))
+ {
+ this->try_layout(
+ state, LayoutState{*surface_id}, [&](LayoutState const &nl) {
+ HMI_DEBUG("wm", "Layout: %s", kNameLayoutNormal);
+ std::string str_area = std::string(kNameLayoutNormal) + "." + std::string(kNameAreaFull);
+ compositor::rect area_rect = this->area_info[*surface_id];
+ this->emit_syncdraw(drawing_name, str_area.c_str(),
+ area_rect.x, area_rect.y, area_rect.w, area_rect.h);
+ this->enqueue_flushdraw(state.main);
+ });
+ }
+ else
+ {
+ bool can_split = this->can_split(state, *surface_id);
+
+ if (can_split)
+ {
+ this->try_layout(
+ state,
+ LayoutState{state.main, *surface_id},
+ [&](LayoutState const &nl) {
+ HMI_DEBUG("wm", "Layout: %s", kNameLayoutSplit);
+ std::string main =
+ std::move(*this->lookup_name(state.main));
+
+ this->surface_set_layout(state.main, surface_id);
+ if (state.sub != *surface_id)
+ {
+ if (state.sub != -1)
+ {
+ this->deactivate(state.sub);
+ }
+ }
+ state = nl;
+
+ // Commit for configuration and visibility(0)
+ this->layout_commit();
+
+ std::string str_area_main = std::string(kNameLayoutSplit) + "." + std::string(kNameAreaMain);
+ std::string str_area_sub = std::string(kNameLayoutSplit) + "." + std::string(kNameAreaSub);
+ compositor::rect area_rect_main = this->area_info[state.main];
+ compositor::rect area_rect_sub = this->area_info[*surface_id];
+ this->emit_syncdraw(main.c_str(), str_area_main.c_str(),
+ area_rect_main.x, area_rect_main.y,
+ area_rect_main.w, area_rect_main.h);
+ this->emit_syncdraw(drawing_name, str_area_sub.c_str(),
+ area_rect_sub.x, area_rect_sub.y,
+ area_rect_sub.w, area_rect_sub.h);
+ this->enqueue_flushdraw(state.main);
+ this->enqueue_flushdraw(state.sub);
+ });
+ }
+ else
+ {
+ this->try_layout(
+ state, LayoutState{*surface_id}, [&](LayoutState const &nl) {
+ HMI_DEBUG("wm", "Layout: %s", kNameLayoutNormal);
+
+ this->surface_set_layout(*surface_id);
+ if (state.main != *surface_id)
+ {
+ this->deactivate(state.main);
+ }
+ if (state.sub != -1)
+ {
+ if (state.sub != *surface_id)
+ {
+ this->deactivate(state.sub);
+ }
+ }
+ state = nl;
+
+ // Commit for configuraton and visibility(0)
+ this->layout_commit();
+
+ std::string str_area = std::string(kNameLayoutNormal) + "." + std::string(kNameAreaFull);
+ compositor::rect area_rect = this->area_info[*surface_id];
+ this->emit_syncdraw(drawing_name, str_area.c_str(),
+ area_rect.x, area_rect.y, area_rect.w, area_rect.h);
+ this->enqueue_flushdraw(state.main);
+ });
+ }
+ }
+ }