#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"
: 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);
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)
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;
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;
}
void WidgetComponent::OnBaseDestroy() {
+ if (impl_->last_operation_ == "destroy")
+ impl_->DestroyProcess();
+ else
+ impl_->TerminateProcess();
}
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) {
} 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) {
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;
}
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() {