From: hyunho Date: Tue, 22 Dec 2020 07:12:11 +0000 (+0900) Subject: Fix wrong event management X-Git-Tag: submit/tizen/20201231.025220~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=36dd50f9d24b7ed4751ff9627341df700848c1aa;p=platform%2Fcore%2Fappfw%2Fcomponent-based-application.git Fix wrong event management Change-Id: I971eda15df04fbc403d6cd2622c0ae10af1dd706 Signed-off-by: hyunho --- diff --git a/component_based/widget_base/widget_component.cc b/component_based/widget_base/widget_component.cc index deac412..fce1de2 100644 --- a/component_based/widget_base/widget_component.cc +++ b/component_based/widget_base/widget_component.cc @@ -27,6 +27,7 @@ #include "component_based/base/component_manager_internal.h" #include "component_based/base/dlog_internal.h" +#include "component_based/common/exception.h" #include "component_based/widget_base/widget_component.h" #include "component_based/widget_base/widget_component_implementation.h" @@ -44,9 +45,16 @@ WidgetComponent::WidgetComponent(std::string comp_id, std::string inst_id, : Component::Component(std::move(comp_id), std::move(inst_id)), impl_(new Impl(this)) { char pkgid[256] = {0, }; - if (aul_app_get_pkgid_bypid(getpid(), pkgid, sizeof(pkgid)) == 0) - impl_->pkgid_ = std::string(pkgid); + if (aul_app_get_pkgid_bypid(getpid(), pkgid, sizeof(pkgid)) != 0) + THROW(Exception::ErrorCodes::IOError); + char appid[256] = {0, }; + if (aul_app_get_appid_bypid(getpid(), appid, sizeof(appid)) != 0) + THROW(Exception::ErrorCodes::IOError); + + impl_->pkgid_ = std::string(pkgid); + impl_->appid_ = std::string(appid); + impl_->widget_id_ = GetComponentID() + "@" + impl_->appid_; impl_->viewer_endpoint_ = start_data.GetString(AUL_K_WIDGET_VIEWER); std::string width_str = start_data.GetString(WIDGET_K_WIDTH); std::string height_str = start_data.GetString(WIDGET_K_HEIGHT); @@ -78,7 +86,7 @@ const IWindow* WidgetComponent::GetWindow() { bool WidgetComponent::Impl::SendStatus(int status, tizen_base::Bundle extra) { int lifecycle; - int ret = aul_widget_send_status_to_viewer(parent_->GetComponentID().c_str(), + int ret = aul_widget_send_status_to_viewer(widget_id_.c_str(), parent_->GetInstanceID().c_str(), viewer_endpoint_.c_str(), status, -1, extra.GetCount() != 0 ? extra.GetHandle() : nullptr); if (ret != 0) @@ -87,7 +95,7 @@ bool WidgetComponent::Impl::SendStatus(int status, tizen_base::Bundle extra) { lifecycle = widget_instance_convert_event_to_lifecycle_status(status); if (lifecycle > -1) { ret = aul_widget_send_status_to_service( - parent_->GetComponentID().c_str(), parent_->GetInstanceID().c_str(), + widget_id_.c_str(), parent_->GetInstanceID().c_str(), pkgid_.c_str(), lifecycle); if (ret != 0) return false; @@ -148,9 +156,21 @@ bool WidgetComponent::OnBaseCreate() { Ecore_Wl2_Display* display = ecore_wl2_connected_display_get(NULL); Ecore_Wl2_Window* wl_win = ecore_wl2_display_window_find(display, win_id); struct wl_surface* surface = ecore_wl2_window_surface_get(wl_win); - screen_connector_provider_remote_enable(GetInstanceID().c_str(), surface); + int ret = screen_connector_provider_remote_enable( + GetInstanceID().c_str(), surface); + if (ret != 0) { + LOGE("Fail to enable sc provider"); + return false; + } + + LOGD("%s is created", impl_->widget_id_.c_str()); + ret = aul_widget_instance_add( + impl_->widget_id_.c_str(), GetInstanceID().c_str()); + if (ret != 0) { + LOGE("Fail to add instance"); + return false; + } - LOGD("%s is created", GetInstanceID().c_str()); if (!impl_->SendStatus(WIDGET_INSTANCE_EVENT_CREATE)) { LOGE("Fail to send create event"); return false; @@ -159,6 +179,10 @@ bool WidgetComponent::OnBaseCreate() { } void WidgetComponent::OnBaseDestroy() { + if (impl_->last_operation_ == "destroy") + impl_->DestroyProcess(); + else + impl_->TerminateProcess(); } void WidgetComponent::Impl::ResizeProcess(tizen_base::Bundle data) { @@ -170,7 +194,8 @@ void WidgetComponent::Impl::ResizeProcess(tizen_base::Bundle data) { height_ = std::stoi(height_str); } parent_->OnResize(width_, height_); - SendStatus(WIDGET_INSTANCE_EVENT_SIZE_CHANGED); + if (!SendStatus(WIDGET_INSTANCE_EVENT_SIZE_CHANGED)) + LOGE("Fail to send the size changed status"); } void WidgetComponent::Impl::UpdateProcess(tizen_base::Bundle data) { @@ -182,26 +207,37 @@ void WidgetComponent::Impl::UpdateProcess(tizen_base::Bundle data) { } else { tizen_base::Bundle data(update_data); parent_->OnUpdate(data, force == "true"); - SendStatus(WIDGET_INSTANCE_EVENT_UPDATE); + if (!SendStatus(WIDGET_INSTANCE_EVENT_UPDATE)) + LOGE("Fail to send the update status"); } } -void WidgetComponent::Impl::DestroyProcess(tizen_base::Bundle data) { - parent_->OnDestroy(false); - aul_widget_instance_del(parent_->GetComponentID().c_str(), +void WidgetComponent::Impl::DestroyProcess() { + LOGE("destroy process!!"); + parent_->OnDestroy(true); + int ret = aul_widget_instance_del(widget_id_.c_str(), parent_->GetInstanceID().c_str()); - SendStatus(WIDGET_INSTANCE_EVENT_DESTROY); - parent_->Finish(); + if (ret != 0) + LOGE("Fail to delete widget instance (%d)", ret); + + if (!SendStatus(WIDGET_INSTANCE_EVENT_DESTROY)) { + LOGE("Fail to send destroy status"); + return; + } } -void WidgetComponent::Impl::TerminateProcess(tizen_base::Bundle data) { - parent_->OnDestroy(true); - aul_widget_instance_del(parent_->GetComponentID().c_str(), - parent_->GetInstanceID().c_str()); - SendStatus(WIDGET_INSTANCE_EVENT_EXTRA_UPDATED, - parent_->GetContent()); - SendStatus(WIDGET_INSTANCE_EVENT_TERMINATE); - parent_->Finish(); +void WidgetComponent::Impl::TerminateProcess() { + parent_->OnDestroy(false); + if (!SendStatus(WIDGET_INSTANCE_EVENT_EXTRA_UPDATED, + parent_->GetContent())) { + LOGE("Fail to send extra update event"); + return; + } + + if (!SendStatus(WIDGET_INSTANCE_EVENT_TERMINATE)) { + LOGE("Fail to send terminate event"); + return; + } } void WidgetComponent::Impl::PeriodProcess(tizen_base::Bundle data) { @@ -218,26 +254,26 @@ void WidgetComponent::OnBaseStart(AppControl control, bool restarted) { bundle* raw_data; app_control_to_bundle(control.GetHandle(), &raw_data); tizen_base::Bundle data(raw_data, true, true); - std::string op = data.GetString("__WIDGET_OP__"); - if (op == "resize") { + impl_->last_operation_ = data.GetString("__WIDGET_OP__"); + if (impl_->last_operation_ == "resize") { impl_->ResizeProcess(data); return; - } else if (op == "update") { + } else if (impl_->last_operation_ == "update") { impl_->UpdateProcess(data); return; - } else if (op == "destroy") { - impl_->DestroyProcess(data); + } else if (impl_->last_operation_ == "destroy") { + Finish(); return; - } else if (op == "terminate") { - impl_->TerminateProcess(data); + } else if (impl_->last_operation_ == "terminate") { + Finish(); return; - } else if (op == "resume") { + } else if (impl_->last_operation_ == "resume") { OnBaseResume(); return; - } else if (op == "pause") { + } else if (impl_->last_operation_ == "pause") { OnBasePause(); return; - } else if (op == "period") { + } else if (impl_->last_operation_ == "period") { impl_->PeriodProcess(data); return; } @@ -260,30 +296,57 @@ void WidgetComponent::OnBaseResume() { if (!impl_->pending_update_data_.empty()) update_data = tizen_base::Bundle(impl_->pending_update_data_.c_str()); OnUpdate(update_data, false); - impl_->SendStatus(WIDGET_INSTANCE_EVENT_UPDATE); + if (!impl_->SendStatus(WIDGET_INSTANCE_EVENT_UPDATE)) { + LOGE("Fail to send update status"); + return; + } impl_->period_timer_ = g_timeout_add_seconds(impl_->period_, impl_->PeriodTimeoutCb, this); } OnResume(); SetState(State::Running); - aul_comp_status_update(GetInstanceID().c_str(), COMP_STATUS_RESUMED); - impl_->SendStatus(WIDGET_INSTANCE_EVENT_RESUME); - aul_widget_instance_change_status( - GetComponentID().c_str(), STATUS_FOREGROUND); + int ret = aul_comp_status_update( + GetInstanceID().c_str(), COMP_STATUS_RESUMED); + if (ret != 0) { + LOGE("fail to update comp status"); + return; + } + if (!impl_->SendStatus(WIDGET_INSTANCE_EVENT_RESUME)) { + LOGE("fail to send resume event"); + return; + } + ret = aul_widget_instance_change_status( + impl_->widget_id_.c_str(), STATUS_FOREGROUND); + if (ret != 0) { + LOGE("Fail to change instance status"); + return; + } } } void WidgetComponent::OnBasePause() { - if (GetState() == State::Running) { - OnPause(); - SetState(State::Paused); - aul_comp_status_update(GetInstanceID().c_str(), COMP_STATUS_PAUSED); - impl_->SendStatus(WIDGET_INSTANCE_EVENT_PAUSE); - aul_widget_instance_change_status( - GetComponentID().c_str(), STATUS_BACKGROUND); + if (GetState() != State::Running) { + LOGW("%s is not running", GetInstanceID().c_str()); + return; + } + OnPause(); + SetState(State::Paused); + int ret = aul_comp_status_update(GetInstanceID().c_str(), COMP_STATUS_PAUSED); + if (ret != 0) { + LOGE("fail to send comp update status"); + return; + } + if (!impl_->SendStatus(WIDGET_INSTANCE_EVENT_PAUSE)) { + LOGE("fail to send pause status"); + return; + } + ret = aul_widget_instance_change_status( + impl_->widget_id_.c_str(), STATUS_BACKGROUND); + if (ret != 0) { + LOGE("fail to send background status"); + return; } - OnBaseStop(); } void WidgetComponent::OnBaseStop() { diff --git a/component_based/widget_base/widget_component_implementation.h b/component_based/widget_base/widget_component_implementation.h index 0154d57..96c1956 100644 --- a/component_based/widget_base/widget_component_implementation.h +++ b/component_based/widget_base/widget_component_implementation.h @@ -40,8 +40,8 @@ class WidgetComponent::Impl { static gboolean PeriodTimeoutCb(gpointer user_data); void ResizeProcess(tizen_base::Bundle data); void UpdateProcess(tizen_base::Bundle data); - void DestroyProcess(tizen_base::Bundle data); - void TerminateProcess(tizen_base::Bundle data); + void DestroyProcess(); + void TerminateProcess(); void PeriodProcess(tizen_base::Bundle data); bool SendStatus(int status, tizen_base::Bundle extra = tizen_base::Bundle()); void SetPendingUpdate(bool update); @@ -52,8 +52,11 @@ class WidgetComponent::Impl { WidgetComponent* parent_; int width_; int height_; + std::string last_operation_; std::string viewer_endpoint_; std::string pkgid_; + std::string appid_; + std::string widget_id_; int period_; guint period_timer_; bool pending_update_;