#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 {
return false;
}
- if (parent_->GetType() == Component::Type::Frame) {
- FrameComponent* component = static_cast<FrameComponent*>(parent_);
- std::unique_ptr<IWindow> 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<ServiceComponent*>(parent_);
- bool r = component->OnCreate();
- if (!r) {
- LOGE("OnCreate() returns false");
- return false;
- }
- }
+ if (!parent_->OnBaseCreate())
+ return false;
+
state_ = State::Created;
return true;
}
}
state_ = State::Dying;
- if (parent_->GetType() == Component::Type::Frame) {
- FrameComponent* component = static_cast<FrameComponent*>(parent_);
- component->OnDestroy();
- } else {
- ServiceComponent* component = static_cast<ServiceComponent*>(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<FrameComponent*>(parent_);
- tizen_base::Bundle content = GetContent();
- component->OnRestoreContent(content);
- component->OnStart(control, restarted);
- } else {
- ServiceComponent* component = static_cast<ServiceComponent*>(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<FrameComponent*>(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<FrameComponent*>(parent_);
- component->OnPause();
- state_ = State::Paused;
- }
- aul_comp_status_update(inst_id_.c_str(), STATUS_BG);
- }
+ parent_->OnBasePause();
}
void Component::Impl::OnStop() {
state_ == State::Stopped)
return;
- if (parent_->GetType() == Component::Type::Frame) {
- FrameComponent* component = static_cast<FrameComponent*>(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) {
}
}
+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)
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();
}
class EXPORT_API Component {
public:
+ enum class State {
+ None,
+ Created,
+ Started,
+ Running,
+ Paused,
+ Stopped,
+ Dying,
+ };
+
enum class Type {
Frame,
Service,
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();
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> impl_;
internal::SystemEvent::IEventListener,
internal::Action::IEventListener {
public:
- enum class State {
- None,
- Created,
- Started,
- Running,
- Paused,
- Stopped,
- Dying,
- };
virtual ~Impl() = default;
bool OnCreate() override;
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);
*/
#include <app_common.h>
+#include <aul.h>
+#include <aul_comp_status.h>
#include <memory>
return mgr.GetWindow(GetInstanceID());
}
+bool FrameComponent::OnBaseCreate() {
+ std::unique_ptr<IWindow> 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<IWindow> FrameComponent::OnCreate() {
return nullptr;
}
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<IWindow> OnCreate();
virtual void OnStart(AppControl app_control, bool restarted);
virtual void OnResume();
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;
}
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();
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,
}
}
- 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<component_low_battery_status_e>(status),
}
}
- 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<component_low_memory_status_e>(status),
}
}
- void OnSuspendedStateChanged(
+ void OnBaseSuspendedStateChanged(
component_based::SuspendedState::State state) override {
if (cb_.suspended_state_changed) {
cb_.suspended_state_changed(this,
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,
}
}
- 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<component_low_battery_status_e>(status),
}
}
- 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<component_low_memory_status_e>(status),
}
}
- void OnSuspendedStateChanged(
+ void OnBaseSuspendedStateChanged(
component_based::SuspendedState::State state) override {
if (cb_.suspended_state_changed) {
cb_.suspended_state_changed(this,