diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/app.cpp | 56 | ||||
-rw-r--r-- | src/app.hpp | 8 | ||||
-rw-r--r-- | src/main.cpp | 44 |
3 files changed, 59 insertions, 49 deletions
diff --git a/src/app.cpp b/src/app.cpp index 1a82eef..937da6a 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -333,31 +333,38 @@ void App::layout_commit() { this->display->flush(); } -char const *App::api_activate_surface(char const *drawing_name, char const *drawing_area) { +void App::api_activate_surface(char const *drawing_name, char const *drawing_area, const reply_func &reply) { ST(); auto const &surface_id = this->lookup_id(drawing_name); if (!surface_id) { - return "Surface does not exist"; + reply("Surface does not exist"); + return; } if (!this->controller->surface_exists(*surface_id)) { - return "Surface does not exist in controller!"; + reply("Surface does not exist in controller!"); + return; } auto layer_id = this->layers.get_layer_id(*surface_id); if (!layer_id) { - return "Surface is not on any layer!"; + reply("Surface is not on any layer!"); + return; } auto o_state = *this->layers.get_layout_state(*surface_id); if (o_state == nullptr) { - return "Could not find layer for surface"; + 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 @@ -477,40 +484,47 @@ char const *App::api_activate_surface(char const *drawing_name, char const *draw } } } - - // no error - return nullptr; } -char const *App::api_deactivate_surface(char const *drawing_name) { +void App::api_deactivate_surface(char const *drawing_name, const reply_func &reply) { ST(); auto const &surface_id = this->lookup_id(drawing_name); if (!surface_id) { - return "Surface does not exist"; - } + reply ("Surface does not exist"); + return; + } if (*surface_id == this->layers.main_surface) { - return "Cannot deactivate main_surface"; + reply("Cannot deactivate main_surface"); + return; } auto o_state = *this->layers.get_layout_state(*surface_id); if (o_state == nullptr) { - return "Could not find layer for surface"; + reply("Could not find layer for surface"); + return; } struct LayoutState &state = *o_state; if (state.main == -1) { - return "No surface active"; + reply("No surface active"); + return; } // Check against main_surface, main_surface_name is the configuration item. if (*surface_id == this->layers.main_surface) { HMI_DEBUG("wm", "Refusing to deactivate main_surface %d", *surface_id); - return nullptr; + reply(nullptr); + return; } + if((state.main == *surface_id) && (state.sub == *surface_id)){ + reply("Surface is not active"); + return; + } + reply(nullptr); if (state.main == *surface_id) { if (state.sub != -1) { @@ -552,11 +566,7 @@ char const *App::api_deactivate_surface(char const *drawing_name) { area_rect.x, area_rect.y, area_rect.w, area_rect.h); this->enqueue_flushdraw(state.main); }); - } else { - return "Surface is not active"; } - - return nullptr; } void App::enqueue_flushdraw(int surface_id) { @@ -579,7 +589,7 @@ void App::check_flushdraw(int surface_id) { } } -char const *App::api_enddraw(char const *drawing_name) { +void App::api_enddraw(char const *drawing_name) { 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) { @@ -587,10 +597,8 @@ char const *App::api_enddraw(char const *drawing_name) { this->pending_end_draw.resize(iend - 1); this->activate(this->pending_end_draw[i]); this->emit_flushdraw(drawing_name); - return nullptr; } } - return "No EndDraw pending for surface"; } void App::api_ping() { this->dispatch_pending_events(); } @@ -663,7 +671,7 @@ void App::surface_removed(uint32_t surface_id) { } else { auto drawing_name = this->lookup_name(surface_id); if (drawing_name) { - this->api_deactivate_surface(drawing_name->c_str()); + this->api_deactivate_surface(drawing_name->c_str(), [](const char*){}); } } @@ -904,7 +912,7 @@ void App::deactivate(int id) { void App::deactivate_main_surface() { this->layers.main_surface = -1; - this->api_deactivate_surface(this->layers.main_surface_name.c_str()); + this->api_deactivate_surface(this->layers.main_surface_name.c_str(), [](const char*){}); } bool App::can_split(struct LayoutState const &state, int new_id) { diff --git a/src/app.hpp b/src/app.hpp index 07bd918..d1393c0 100644 --- a/src/app.hpp +++ b/src/app.hpp @@ -130,6 +130,7 @@ struct id_allocator { struct App { typedef std::unordered_map<uint32_t, struct compositor::rect> rect_map; + typedef std::function<void(const char* err_msg)> reply_func; enum EventType { Event_Val_Min = 0, @@ -202,12 +203,11 @@ struct App { result<int> api_request_surface(char const *drawing_name); char const *api_request_surface(char const *drawing_name, char const *ivi_id); - char const *api_activate_surface(char const *drawing_name, char const *drawing_area); - char const *api_deactivate_surface(char const *drawing_name); - char const *api_enddraw(char const *drawing_name); + void api_activate_surface(char const *drawing_name, char const *drawing_area, const reply_func &reply); + void api_deactivate_surface(char const *drawing_name, const reply_func &reply); + void api_enddraw(char const *drawing_name); result<json_object *> api_get_display_info(); result<json_object *> api_get_area_info(char const *drawing_name); - char const *api_subscribe(afb_req *req, char const *event_name); void api_ping(); void send_event(char const *evname, char const *label); void send_event(char const *evname, char const *label, char const *area, int x, int y, int w, int h); diff --git a/src/main.cpp b/src/main.cpp index fd96d33..2f813a3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -298,15 +298,18 @@ void windowmanager_activatesurface(afb_req req) noexcept { return; } - auto ret = g_afb_instance->app.api_activate_surface(a_drawing_name, a_drawing_area); - if (ret != nullptr) { - afb_req_fail(req, "failed", ret); - return; - } + g_afb_instance->app.api_activate_surface(a_drawing_name, a_drawing_area, + [&req](const char* errmsg){ + if (errmsg != nullptr) { + HMI_ERROR("wm", errmsg); + afb_req_fail(req, "failed", errmsg); + return; + } + afb_req_success(req, NULL, "success"); + }); - afb_req_success(req, NULL, "success"); } catch (std::exception &e) { - afb_req_fail_f(req, "failed", "Uncaught exception while calling activatesurface: %s", e.what()); + HMI_WARNING("wm", "failed", "Uncaught exception while calling activatesurface: %s", e.what()); return; } @@ -329,15 +332,18 @@ void windowmanager_deactivatesurface(afb_req req) noexcept { return; } - auto ret = g_afb_instance->app.api_deactivate_surface(a_drawing_name); - if (ret != nullptr) { - afb_req_fail(req, "failed", ret); - return; - } + g_afb_instance->app.api_deactivate_surface(a_drawing_name, + [&req](const char* errmsg){ + if (errmsg != nullptr) { + HMI_ERROR("wm", errmsg); + afb_req_fail(req, "failed", errmsg); + return; + } + afb_req_success(req, NULL, "success"); + }); - afb_req_success(req, NULL, "success"); } catch (std::exception &e) { - afb_req_fail_f(req, "failed", "Uncaught exception while calling deactivatesurface: %s", e.what()); + HMI_WARNING("wm", "Uncaught exception while calling deactivatesurface: %s", e.what()); return; } } @@ -358,16 +364,12 @@ void windowmanager_enddraw(afb_req req) noexcept { afb_req_fail(req, "failed", "Need char const* argument drawing_name"); return; } + afb_req_success(req, NULL, "success"); - auto ret = g_afb_instance->app.api_enddraw(a_drawing_name); - if (ret != nullptr) { - afb_req_fail(req, "failed", ret); - return; - } + g_afb_instance->app.api_enddraw(a_drawing_name); - afb_req_success(req, NULL, "success"); } catch (std::exception &e) { - afb_req_fail_f(req, "failed", "Uncaught exception while calling enddraw: %s", e.what()); + HMI_WARNING("wm", "failed", "Uncaught exception while calling enddraw: %s", e.what()); return; } |