- Class 'Component' should not be modified even though a new component is added.
- To do this, we need to make a class 'Type' to abstract.
Change-Id: I6cfb98540626a1630c01dc094119e0a188bda17e
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
namespace component_based {
-Component::Impl::Impl(Component* parent, Component::Type type,
- std::string comp_id, std::string inst_id)
- : parent_(parent), type_(std::move(type)),
- comp_id_(std::move(comp_id)), inst_id_(std::move(inst_id)),
+Component::Impl::Impl(Component* parent, std::string comp_id,
+ std::string inst_id)
+ : parent_(parent), comp_id_(std::move(comp_id)), inst_id_(std::move(inst_id)),
sys_ev_(new internal::SystemEvent(this)) {
auto& mgr = internal::ComponentManager::GetInst();
if (mgr.IsSingleInstance(inst_id_))
}
}
-Component::Component(Component::Type type, std::string comp_id,
- std::string inst_id)
- : impl_(new Impl(this, std::move(type), std::move(comp_id),
- std::move(inst_id))) {
+Component::Component(std::string comp_id, std::string inst_id)
+ : impl_(new Impl(this, std::move(comp_id), std::move(inst_id))) {
}
Component::~Component() = default;
mgr.ExitAtIdle(impl_->GetInstanceID());
}
-Component::Type Component::GetType() {
- return impl_->GetType();
-}
-
void Component::RegisterAction(std::string app_control_name) {
try {
impl_->RegisterAction(std::move(app_control_name));
Dying,
};
- enum class Type {
- Frame,
- Service,
+ class Type {
+ public:
+ virtual int GetHash() const {
+ return 0;
+ }
+
+ virtual std::string GetName() const {
+ return "base";
+ }
};
class Factory {
std::string inst_id) = 0;
};
- Component(Type type, std::string comp_id, std::string inst_id);
+ Component(std::string comp_id, std::string inst_id);
virtual ~Component();
virtual bool OnBaseCreate();
virtual void OnBaseLowBattery(LowBattery::Status status);
virtual void OnBaseLowMemory(LowMemory::Status status);
virtual void OnBaseSuspendedStateChanged(SuspendedState::State state);
+ virtual std::unique_ptr<Type> GetType() const {
+ return std::unique_ptr<Type>(new Type());
+ }
std::string GetComponentID();
std::string GetInstanceID();
void Finish();
- Type GetType();
void RegisterAction(std::string app_control_name);
bool DeregisterAction(std::string app_control_name);
void SendAsync(AppControl control, AppControl::IEventListener* ev);
void RegisterAction(std::string app_control_name);
bool DeregisterAction(std::string app_control_name);
- const Component::Type& GetType() {
- return type_;
- }
-
const std::string& GetComponentID() {
return comp_id_;
}
private:
friend class Component;
- Impl(Component* parent, Component::Type type,
- std::string comp_id, std::string inst_id);
+ Impl(Component* parent, std::string comp_id, std::string inst_id);
private:
Component* parent_;
- Component::Type type_;
std::string comp_id_;
std::string inst_id_;
std::unique_ptr<internal::SystemEvent> sys_ev_;
namespace component_based {
FrameComponent::FrameComponent(std::string comp_id, std::string inst_id)
- : Component::Component(Component::Type::Frame, std::move(comp_id),
- std::move(inst_id)) {
+ : Component::Component(std::move(comp_id), std::move(inst_id)) {
}
FrameComponent::~FrameComponent() = default;
Off,
};
+ class FrameType : public Type {
+ public:
+ enum {
+ Hash = 0x1111
+ };
+
+ int GetHash() const override {
+ return Hash;
+ }
+
+ std::string GetName() const override {
+ return "frame";
+ }
+ };
+
FrameComponent(std::string comp_id, std::string inst_id);
virtual ~FrameComponent();
DisplayStatus GetDisplayStatus();
const IWindow* GetWindow();
+ std::unique_ptr<Type> GetType() const override {
+ return std::unique_ptr<Type>(new FrameType());
+ }
+
bool OnBaseCreate() override;
void OnBaseDestroy() override;
void OnBaseStart(AppControl control, bool restarted) override;
namespace component_based {
ServiceComponent::ServiceComponent(std::string comp_id, std::string inst_id)
- : Component::Component(Component::Type::Service, std::move(comp_id),
- std::move(inst_id)) {
+ : Component::Component(std::move(comp_id), std::move(inst_id)) {
}
ServiceComponent::~ServiceComponent() = default;
}
};
+ class ServiceType : public Type {
+ public:
+ enum {
+ Hash = 0x2222
+ };
+
+ int GetHash() const override {
+ return Hash;
+ }
+
+ std::string GetName() const override {
+ return "service";
+ }
+ };
+
ServiceComponent(std::string comp_id, std::string inst_id);
virtual ~ServiceComponent();
+ std::unique_ptr<Type> GetType() const override {
+ return std::unique_ptr<Type>(new ServiceType());
+ }
+
bool OnBaseCreate() override;
void OnBaseDestroy() override;
void OnBaseStart(AppControl control, bool restarted) override;
public:
class Factory : public component_based::Component::Factory {
public:
- Factory(component_type_e type, base_component_lifecycle_callback_s cb, void* user_data)
- : type_(type), cb_(cb), user_data_(user_data) {
+ Factory(base_component_lifecycle_callback_s cb, void* user_data)
+ : cb_(cb), user_data_(user_data) {
}
std::unique_ptr<component_based::Component> Create(std::string comp_id,
std::string inst_id) override {
return std::unique_ptr<component_based::Component>(
- new (std::nothrow) StubBaseComponent(type_,
- std::move(comp_id), std::move(inst_id), cb_, user_data_));
+ new (std::nothrow) StubBaseComponent(std::move(comp_id),
+ std::move(inst_id), cb_, user_data_));
}
private:
- component_type_e type_;
base_component_lifecycle_callback_s cb_;
void* user_data_;
};
- StubBaseComponent(component_type_e type, std::string comp_id,
- std::string inst_id,
- base_component_lifecycle_callback_s cb,
- void* user_data)
- : component_based::Component((component_based::Component::Type)type,
- std::move(comp_id),
- std::move(inst_id)),
- cb_(cb),
- user_data_(user_data) {
+ StubBaseComponent(std::string comp_id,
+ std::string inst_id,
+ base_component_lifecycle_callback_s cb,
+ void* user_data)
+ : component_based::Component(std::move(comp_id), std::move(inst_id)),
+ cb_(cb), user_data_(user_data) {
}
~StubBaseComponent() = default;
component_based::Component* component =
static_cast<component_based::Component*>(context);
- if (component->GetType() != component_based::Component::Type::Frame) {
+ if (component->GetType()->GetHash() !=
+ component_based::FrameComponent::FrameType::Hash) {
LOGE("Invalid parameter");
return COMPONENT_ERROR_INVALID_PARAMETER;
}
}
::StubBaseComponent::Factory* factory =
- new (std::nothrow) ::StubBaseComponent::Factory(type, *callback, user_data);
+ new (std::nothrow) ::StubBaseComponent::Factory(*callback, user_data);
if (factory == nullptr) {
LOGE("Out of memory");
set_last_result(APP_ERROR_OUT_OF_MEMORY);
component_based::Component* component =
static_cast<component_based::Component*>(context);
- if (component->GetType() != component_based::Component::Type::Frame) {
+ if (component->GetType()->GetHash() !=
+ component_based::FrameComponent::FrameType::Hash) {
LOGE("Invalid parameter");
return COMPONENT_ERROR_INVALID_PARAMETER;
}
component_based::Component* component =
static_cast<component_based::Component*>(context);
- if (component->GetType() != component_based::Component::Type::Frame) {
+ if (component->GetType()->GetHash() !=
+ component_based::FrameComponent::FrameType::Hash) {
LOGE("Invalid parameter");
return COMPONENT_ERROR_INVALID_PARAMETER;
}
__fake_app_control_add_action_handler;
std::unique_ptr<component_based::Component> fc(
- new component_based::Component(component_based::Component::Type::Frame, std::string("comp_id"),
+ new component_based::Component(std::string("comp_id"),
std::string("inst_id")));
std::string cid = fc->GetComponentID();
std::string iid = fc->GetInstanceID();
EXPECT_EQ(iid, "inst_id");
- component_based::Component::Type type = fc->GetType();
- EXPECT_EQ(type, component_based::Component::Type::Frame);
+ auto type = fc->GetType();
+ EXPECT_EQ(type->GetName(), "base");
fc->Finish();
fc->RegisterAction(std::string("action"));