From: hyunho Date: Mon, 15 Jul 2019 02:31:16 +0000 (+0900) Subject: Remove frame, service dependency from component X-Git-Tag: submit/tizen/20190717.022738~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7c35994a855b192c620dde9331bc24750f022f49;p=platform%2Fcore%2Fappfw%2Fcomponent-based-application.git Remove frame, service dependency from component Change-Id: I69cd4c1c0dcafdc983cc3f348d49ddfa2999e980 Signed-off-by: hyunho --- diff --git a/component_based/base/component.cc b/component_based/base/component.cc index 25bb68d..52b2117 100644 --- a/component_based/base/component.cc +++ b/component_based/base/component.cc @@ -25,8 +25,6 @@ #include "component_based/base/component.h" #include "component_based/base/component_implementation.h" #include "component_based/base/dlog_internal.h" -#include "component_based/base/frame_component.h" -#include "component_based/base/service_component.h" namespace component_based { @@ -47,34 +45,9 @@ bool Component::Impl::OnCreate() { return false; } - if (parent_->GetType() == Component::Type::Frame) { - FrameComponent* component = static_cast(parent_); - std::unique_ptr win = component->OnCreate(); - if (win == nullptr) { - LOGE("OnCreate() returns nullptr"); - return false; - } - - auto& mgr = internal::ComponentManager::GetInst(); - if (!mgr.Bind(component->GetInstanceID(), std::move(win))) { - LOGE("Bind window fail"); - return false; - } - - ret = aul_comp_status_update(inst_id_.c_str(), STATUS_CREATED); - if (ret != AUL_R_OK) { - LOGE("Fail to update status (%d)", ret); - return false; - } - - } else { - ServiceComponent* component = static_cast(parent_); - bool r = component->OnCreate(); - if (!r) { - LOGE("OnCreate() returns false"); - return false; - } - } + if (!parent_->OnBaseCreate()) + return false; + state_ = State::Created; return true; } @@ -87,57 +60,22 @@ void Component::Impl::OnDestroy() { } state_ = State::Dying; - if (parent_->GetType() == Component::Type::Frame) { - FrameComponent* component = static_cast(parent_); - component->OnDestroy(); - } else { - ServiceComponent* component = static_cast(parent_); - component->OnDestroy(); - } + parent_->OnBaseDestroy(); aul_comp_notify_exit(inst_id_.c_str()); } void Component::Impl::OnStart(AppControl control, bool restarted) { - if (parent_->GetType() == Component::Type::Frame) { - FrameComponent* component = static_cast(parent_); - tizen_base::Bundle content = GetContent(); - component->OnRestoreContent(content); - component->OnStart(control, restarted); - } else { - ServiceComponent* component = static_cast(parent_); - tizen_base::Bundle content = GetContent(); - component->OnRestoreContent(content); - component->OnStartCommand(control, restarted); - component->OnSaveContent(content); - SetContent(std::move(content)); - } - + parent_->OnBaseStart(control, restarted); state_ = State::Started; } void Component::Impl::OnResume() { - if (parent_->GetType() == Component::Type::Frame) { - if (state_ == State::Paused || - state_ == State::Started || - state_ == State::Stopped) { - FrameComponent* component = static_cast(parent_); - component->OnResume(); - state_ = State::Running; - } - aul_comp_status_update(inst_id_.c_str(), STATUS_VISIBLE); - } + parent_->OnBaseResume(); } void Component::Impl::OnPause() { - if (parent_->GetType() == Component::Type::Frame) { - if (state_ == State::Running) { - FrameComponent* component = static_cast(parent_); - component->OnPause(); - state_ = State::Paused; - } - aul_comp_status_update(inst_id_.c_str(), STATUS_BG); - } + parent_->OnBasePause(); } void Component::Impl::OnStop() { @@ -146,43 +84,84 @@ void Component::Impl::OnStop() { state_ == State::Stopped) return; - if (parent_->GetType() == Component::Type::Frame) { - FrameComponent* component = static_cast(parent_); - component->OnStop(); - tizen_base::Bundle content = GetContent(); - component->OnSaveContent(content); - SetContent(std::move(content)); - } + parent_->OnBaseStop(); state_ = State::Stopped; } void Component::Impl::OnAction(std::string action, AppControl app_control) { - parent_->OnAction(std::move(action), std::move(app_control)); + parent_->OnBaseAction(std::move(action), std::move(app_control)); } void Component::Impl::OnLowMemory(LowMemory::Status status) { - parent_->OnLowMemory(status); + parent_->OnBaseLowMemory(status); } void Component::Impl::OnLowBattery(LowBattery::Status status) { - parent_->OnLowBattery(status); + parent_->OnBaseLowBattery(status); } void Component::Impl::OnDeviceOrientationChanged( DeviceOrientation::Orientation orientation) { - parent_->OnDeviceOrientationChanged(orientation); + parent_->OnBaseDeviceOrientationChanged(orientation); } void Component::Impl::OnLanguageChanged(std::string lang) { - parent_->OnLanguageChanged(std::move(lang)); + parent_->OnBaseLanguageChanged(std::move(lang)); } void Component::Impl::OnRegionFormatChanged(std::string region) { - parent_->OnRegionFormatChanged(std::move(region)); + parent_->OnBaseRegionFormatChanged(std::move(region)); } void Component::Impl::OnSuspendedStateChanged(SuspendedState::State state) { - parent_->OnSuspendedStateChanged(state); + parent_->OnBaseSuspendedStateChanged(state); +} + +bool Component::OnBaseCreate() { + return true; +} + +void Component::OnBaseDestroy() { +} + +void Component::OnBaseStart(AppControl control, bool restarted) { +} + +void Component::OnBaseResume() { +} + +void Component::OnBasePause() { +} + +void Component::OnBaseStop() { +} + +void Component::OnBaseRestoreContent(tizen_base::Bundle content) { +} + +void Component::OnBaseSaveContent(tizen_base::Bundle& content) { +} + +void Component::OnBaseAction(std::string action, AppControl app_control) { +} + +void Component::OnBaseDeviceOrientationChanged( + DeviceOrientation::Orientation orientation) { +} + +void Component::OnBaseLanguageChanged(std::string language) { +} + +void Component::OnBaseRegionFormatChanged(std::string region) { +} + +void Component::OnBaseLowBattery(LowBattery::Status status) { +} + +void Component::OnBaseLowMemory(LowMemory::Status status) { +} + +void Component::OnBaseSuspendedStateChanged(SuspendedState::State state) { } void Component::Impl::RegisterAction(std::string app_control_name) { @@ -248,6 +227,22 @@ void Component::Impl::OnAppControlResult(app_control_h request, } } +Component::State Component::GetState() { + return impl_->state_; +} + +void Component::SetState(Component::State state) { + impl_->state_ = state; +} + +tizen_base::Bundle Component::GetContent() { + return impl_->content_mgr_->GetContent(); +} + +void Component::SetContent(tizen_base::Bundle content) { + impl_->content_mgr_->SetContent(std::move(content)); +} + void Component::Impl::SendAsync(AppControl control, AppControl::IEventListener* ev) { if (ev == nullptr) @@ -307,34 +302,6 @@ Component::Component(Component::Type type, std::string comp_id, Component::~Component() = default; -void Component::OnRestoreContent(tizen_base::Bundle content) { -} - -void Component::OnSaveContent(tizen_base::Bundle& content) { -} - -void Component::OnAction(std::string action, AppControl app_control) { -} - -void Component::OnDeviceOrientationChanged( - DeviceOrientation::Orientation orientation) { -} - -void Component::OnLanguageChanged(std::string language) { -} - -void Component::OnRegionFormatChanged(std::string region) { -} - -void Component::OnLowBattery(LowBattery::Status status) { -} - -void Component::OnLowMemory(LowMemory::Status status) { -} - -void Component::OnSuspendedStateChanged(SuspendedState::State state) { -} - std::string Component::GetComponentID() { return impl_->GetComponentID(); } diff --git a/component_based/base/component.h b/component_based/base/component.h index 2469014..8b9a58a 100644 --- a/component_based/base/component.h +++ b/component_based/base/component.h @@ -37,6 +37,16 @@ namespace component_based { class EXPORT_API Component { public: + enum class State { + None, + Created, + Started, + Running, + Paused, + Stopped, + Dying, + }; + enum class Type { Frame, Service, @@ -51,16 +61,22 @@ class EXPORT_API Component { Component(Type type, std::string comp_id, std::string inst_id); virtual ~Component(); - virtual void OnRestoreContent(tizen_base::Bundle content); - virtual void OnSaveContent(tizen_base::Bundle& content); - virtual void OnAction(std::string action, AppControl app_control); - virtual void OnDeviceOrientationChanged( + virtual bool OnBaseCreate(); + virtual void OnBaseDestroy(); + virtual void OnBaseStart(AppControl control, bool restarted); + virtual void OnBaseResume(); + virtual void OnBasePause(); + virtual void OnBaseStop(); + virtual void OnBaseRestoreContent(tizen_base::Bundle content); + virtual void OnBaseSaveContent(tizen_base::Bundle& content); + virtual void OnBaseAction(std::string action, AppControl app_control); + virtual void OnBaseDeviceOrientationChanged( DeviceOrientation::Orientation orientation); - virtual void OnLanguageChanged(std::string language); - virtual void OnRegionFormatChanged(std::string region); - virtual void OnLowBattery(LowBattery::Status status); - virtual void OnLowMemory(LowMemory::Status status); - virtual void OnSuspendedStateChanged(SuspendedState::State state); + virtual void OnBaseLanguageChanged(std::string language); + virtual void OnBaseRegionFormatChanged(std::string region); + virtual void OnBaseLowBattery(LowBattery::Status status); + virtual void OnBaseLowMemory(LowMemory::Status status); + virtual void OnBaseSuspendedStateChanged(SuspendedState::State state); std::string GetComponentID(); std::string GetInstanceID(); @@ -72,6 +88,12 @@ class EXPORT_API Component { void SendAsync(AppControl control, AppControl::IEventListener* ev); AppControl Send(AppControl control); + protected: + State GetState(); + void SetState(State state); + tizen_base::Bundle GetContent(); + void SetContent(tizen_base::Bundle content); + private: class Impl; std::unique_ptr impl_; diff --git a/component_based/base/component_implementation.h b/component_based/base/component_implementation.h index e1d0c39..568aec4 100644 --- a/component_based/base/component_implementation.h +++ b/component_based/base/component_implementation.h @@ -37,15 +37,6 @@ class Component::Impl : internal::ComponentManager::IEventListener, internal::SystemEvent::IEventListener, internal::Action::IEventListener { public: - enum class State { - None, - Created, - Started, - Running, - Paused, - Stopped, - Dying, - }; virtual ~Impl() = default; bool OnCreate() override; @@ -84,14 +75,6 @@ class Component::Impl : internal::ComponentManager::IEventListener, return res_mgr_; } - tizen_base::Bundle GetContent() { - return content_mgr_->GetContent(); - } - - void SetContent(tizen_base::Bundle content) { - content_mgr_->SetContent(std::move(content)); - } - void SendAsync(AppControl control, AppControl::IEventListener* ev); AppControl Send(AppControl control); diff --git a/component_based/base/frame_component.cc b/component_based/base/frame_component.cc index 982e0be..d003277 100644 --- a/component_based/base/frame_component.cc +++ b/component_based/base/frame_component.cc @@ -15,6 +15,8 @@ */ #include +#include +#include #include @@ -50,6 +52,91 @@ const IWindow* FrameComponent::GetWindow() { return mgr.GetWindow(GetInstanceID()); } +bool FrameComponent::OnBaseCreate() { + std::unique_ptr win = OnCreate(); + if (win == nullptr) { + LOGE("OnCreate() returns nullptr"); + return false; + } + + auto& mgr = internal::ComponentManager::GetInst(); + if (!mgr.Bind(GetInstanceID(), std::move(win))) { + LOGE("Bind window fail"); + return false; + } + + int ret = aul_comp_status_update(GetInstanceID().c_str(), STATUS_CREATED); + if (ret != AUL_R_OK) { + LOGE("Fail to update status (%d)", ret); + return false; + } + return true; +} + +void FrameComponent::OnBaseDestroy() { + OnDestroy(); +} + +void FrameComponent::OnBaseStart(AppControl control, bool restarted) { + tizen_base::Bundle content = GetContent(); + OnBaseRestoreContent(content); + OnStart(control, restarted); +} + +void FrameComponent::OnBaseResume() { + + if (GetState() == State::Paused || + GetState() == State::Started || + GetState() == State::Stopped) { + OnResume(); + SetState(State::Running); + } + aul_comp_status_update(GetInstanceID().c_str(), STATUS_VISIBLE); +} + +void FrameComponent::OnBasePause() { + if (GetState() == State::Running) { + OnPause(); + SetState(State::Paused); + } + aul_comp_status_update(GetInstanceID().c_str(), STATUS_BG); +} + +void FrameComponent::OnBaseStop() { + OnStop(); + tizen_base::Bundle content = GetContent(); + OnBaseSaveContent(content); + SetContent(std::move(content)); +} + +void FrameComponent::OnBaseRestoreContent(tizen_base::Bundle content) { +} + +void FrameComponent::OnBaseSaveContent(tizen_base::Bundle& content) { +} + +void FrameComponent::OnBaseAction(std::string action, AppControl app_control) { +} + +void FrameComponent::OnBaseDeviceOrientationChanged( + DeviceOrientation::Orientation orientation) { +} + +void FrameComponent::OnBaseLanguageChanged(std::string language) { +} + +void FrameComponent::OnBaseRegionFormatChanged(std::string region) { +} + +void FrameComponent::OnBaseLowBattery(LowBattery::Status status) { +} + +void FrameComponent::OnBaseLowMemory(LowMemory::Status status) { +} + +void FrameComponent::OnBaseSuspendedStateChanged(SuspendedState::State state) { +} + std::unique_ptr FrameComponent::OnCreate() { return nullptr; } diff --git a/component_based/base/frame_component.h b/component_based/base/frame_component.h index d8ebb44..26125df 100644 --- a/component_based/base/frame_component.h +++ b/component_based/base/frame_component.h @@ -52,6 +52,23 @@ class EXPORT_API FrameComponent : public Component { DisplayStatus GetDisplayStatus(); const IWindow* GetWindow(); + bool OnBaseCreate() override; + void OnBaseDestroy() override; + void OnBaseStart(AppControl control, bool restarted) override; + void OnBaseResume() override; + void OnBasePause() override; + void OnBaseStop() override; + void OnBaseRestoreContent(tizen_base::Bundle content) override; + void OnBaseSaveContent(tizen_base::Bundle& content) override; + void OnBaseAction(std::string action, AppControl app_control) override; + void OnBaseDeviceOrientationChanged( + DeviceOrientation::Orientation orientation) override; + void OnBaseLanguageChanged(std::string language) override; + void OnBaseRegionFormatChanged(std::string region) override; + void OnBaseLowBattery(LowBattery::Status status) override; + void OnBaseLowMemory(LowMemory::Status status) override; + void OnBaseSuspendedStateChanged(SuspendedState::State state) override; + virtual std::unique_ptr OnCreate(); virtual void OnStart(AppControl app_control, bool restarted); virtual void OnResume(); diff --git a/component_based/base/service_component.cc b/component_based/base/service_component.cc index 6c8daa9..b57e7b5 100644 --- a/component_based/base/service_component.cc +++ b/component_based/base/service_component.cc @@ -27,6 +27,64 @@ ServiceComponent::ServiceComponent(std::string comp_id, std::string inst_id) ServiceComponent::~ServiceComponent() = default; +bool ServiceComponent::OnBaseCreate() { + bool r = OnCreate(); + if (!r) { + LOGE("OnCreate() returns false"); + return false; + } + return true; +} + +void ServiceComponent::OnBaseDestroy() { + OnDestroy(); +} + +void ServiceComponent::OnBaseStart(AppControl control, bool restarted) { + tizen_base::Bundle content = GetContent(); + OnBaseRestoreContent(content); + OnStartCommand(control, restarted); + OnBaseSaveContent(content); + SetContent(std::move(content)); +} + +void ServiceComponent::OnBaseResume() { +} + +void ServiceComponent::OnBasePause() { +} + +void ServiceComponent::OnBaseStop() { +} + +void ServiceComponent::OnBaseRestoreContent(tizen_base::Bundle content) { +} + +void ServiceComponent::OnBaseSaveContent(tizen_base::Bundle& content) { +} + +void ServiceComponent::OnBaseAction(std::string action, AppControl app_control) { +} + +void ServiceComponent::OnBaseDeviceOrientationChanged( + DeviceOrientation::Orientation orientation) { +} + +void ServiceComponent::OnBaseLanguageChanged(std::string language) { +} + +void ServiceComponent::OnBaseRegionFormatChanged(std::string region) { +} + +void ServiceComponent::OnBaseLowBattery(LowBattery::Status status) { +} + +void ServiceComponent::OnBaseLowMemory(LowMemory::Status status) { +} + +void ServiceComponent::OnBaseSuspendedStateChanged(SuspendedState::State state) { +} + bool ServiceComponent::OnCreate() { return false; } diff --git a/component_based/base/service_component.h b/component_based/base/service_component.h index fbf6b72..5e2f1ef 100644 --- a/component_based/base/service_component.h +++ b/component_based/base/service_component.h @@ -42,6 +42,23 @@ class EXPORT_API ServiceComponent : public Component { ServiceComponent(std::string comp_id, std::string inst_id); virtual ~ServiceComponent(); + bool OnBaseCreate() override; + void OnBaseDestroy() override; + void OnBaseStart(AppControl control, bool restarted) override; + void OnBaseResume() override; + void OnBasePause() override; + void OnBaseStop() override; + void OnBaseRestoreContent(tizen_base::Bundle content) override; + void OnBaseSaveContent(tizen_base::Bundle& content) override; + void OnBaseAction(std::string action, AppControl app_control) override; + void OnBaseDeviceOrientationChanged( + DeviceOrientation::Orientation orientation) override; + void OnBaseLanguageChanged(std::string language) override; + void OnBaseRegionFormatChanged(std::string region) override; + void OnBaseLowBattery(LowBattery::Status status) override; + void OnBaseLowMemory(LowMemory::Status status) override; + void OnBaseSuspendedStateChanged(SuspendedState::State state) override; + virtual bool OnCreate(); virtual void OnStartCommand(AppControl app_control, bool restarted); virtual void OnDestroy(); diff --git a/component_based/efl_base/stub.cc b/component_based/efl_base/stub.cc index 788187b..1e311f7 100644 --- a/component_based/efl_base/stub.cc +++ b/component_based/efl_base/stub.cc @@ -216,23 +216,23 @@ class StubFrameComponent : public component_based::FrameComponent { cb_.destroy(this, user_data_); } - void OnRestoreContent(tizen_base::Bundle content) override { + void OnBaseRestoreContent(tizen_base::Bundle content) override { if (cb_.restore_content) cb_.restore_content(this, content.GetHandle(), user_data_); } - void OnSaveContent(tizen_base::Bundle& content) override { + void OnBaseSaveContent(tizen_base::Bundle& content) override { if (cb_.save_content) cb_.save_content(this, content.GetHandle(), user_data_); } - void OnAction(std::string action, + void OnBaseAction(std::string action, component_based::AppControl app_control) override { if (cb_.action) cb_.action(this, action.c_str(), app_control.GetHandle(), user_data_); } - void OnDeviceOrientationChanged( + void OnBaseDeviceOrientationChanged( component_based::DeviceOrientation::Orientation orientation) override { if (cb_.device_orientation_changed) { cb_.device_orientation_changed(this, @@ -241,17 +241,17 @@ class StubFrameComponent : public component_based::FrameComponent { } } - void OnLanguageChanged(std::string language) override { + void OnBaseLanguageChanged(std::string language) override { if (cb_.language_changed) cb_.language_changed(this, language.c_str(), user_data_); } - void OnRegionFormatChanged(std::string region) override { + void OnBaseRegionFormatChanged(std::string region) override { if (cb_.region_format_changed) cb_.region_format_changed(this, region.c_str(), user_data_); } - void OnLowBattery(component_based::LowBattery::Status status) override { + void OnBaseLowBattery(component_based::LowBattery::Status status) override { if (cb_.low_battery) { cb_.low_battery(this, static_cast(status), @@ -259,7 +259,7 @@ class StubFrameComponent : public component_based::FrameComponent { } } - void OnLowMemory(component_based::LowMemory::Status status) override { + void OnBaseLowMemory(component_based::LowMemory::Status status) override { if (cb_.low_memory) { cb_.low_memory(this, static_cast(status), @@ -267,7 +267,7 @@ class StubFrameComponent : public component_based::FrameComponent { } } - void OnSuspendedStateChanged( + void OnBaseSuspendedStateChanged( component_based::SuspendedState::State state) override { if (cb_.suspended_state_changed) { cb_.suspended_state_changed(this, @@ -328,23 +328,23 @@ class StubServiceComponent : public component_based::ServiceComponent { cb_.destroy(this, user_data_); } - void OnRestoreContent(tizen_base::Bundle content) override { + void OnBaseRestoreContent(tizen_base::Bundle content) override { if (cb_.restore_content) cb_.restore_content(this, content.GetHandle(), user_data_); } - void OnSaveContent(tizen_base::Bundle& content) override { + void OnBaseSaveContent(tizen_base::Bundle& content) override { if (cb_.save_content) cb_.save_content(this, content.GetHandle(), user_data_); } - void OnAction(std::string action, + void OnBaseAction(std::string action, component_based::AppControl app_control) override { if (cb_.action) cb_.action(this, action.c_str(), app_control.GetHandle(), user_data_); } - void OnDeviceOrientationChanged( + void OnBaseDeviceOrientationChanged( component_based::DeviceOrientation::Orientation orientation) override { if (cb_.device_orientation_changed) { cb_.device_orientation_changed(this, @@ -353,17 +353,17 @@ class StubServiceComponent : public component_based::ServiceComponent { } } - void OnLanguageChanged(std::string language) override { + void OnBaseLanguageChanged(std::string language) override { if (cb_.language_changed) cb_.language_changed(this, language.c_str(), user_data_); } - void OnRegionFormatChanged(std::string region) override { + void OnBaseRegionFormatChanged(std::string region) override { if (cb_.region_format_changed) cb_.region_format_changed(this, region.c_str(), user_data_); } - void OnLowBattery(component_based::LowBattery::Status status) override { + void OnBaseLowBattery(component_based::LowBattery::Status status) override { if (cb_.low_battery) { cb_.low_battery(this, static_cast(status), @@ -371,7 +371,7 @@ class StubServiceComponent : public component_based::ServiceComponent { } } - void OnLowMemory(component_based::LowMemory::Status status) override { + void OnBaseLowMemory(component_based::LowMemory::Status status) override { if (cb_.low_memory) { cb_.low_memory(this, static_cast(status), @@ -379,7 +379,7 @@ class StubServiceComponent : public component_based::ServiceComponent { } } - void OnSuspendedStateChanged( + void OnBaseSuspendedStateChanged( component_based::SuspendedState::State state) override { if (cb_.suspended_state_changed) { cb_.suspended_state_changed(this,