+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);
+}
+