From: hyunho Date: Thu, 17 Dec 2020 09:05:57 +0000 (+0900) Subject: Seperate widget-component from other components X-Git-Tag: submit/tizen/20201231.025220~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3fd978c3aa5e1e6d592e179b44a4ecab2b0c0d2d;p=platform%2Fcore%2Fappfw%2Fcomponent-based-application.git Seperate widget-component from other components Change-Id: I68399db1c3e7688acb0f11dc879d537bd9efa157 Signed-off-by: hyunho --- diff --git a/component_based/CMakeLists.txt b/component_based/CMakeLists.txt index 376f143..4c72b7f 100644 --- a/component_based/CMakeLists.txt +++ b/component_based/CMakeLists.txt @@ -4,7 +4,11 @@ ADD_SUBDIRECTORY(uri) ADD_SUBDIRECTORY(app_control) ADD_SUBDIRECTORY(base) ADD_SUBDIRECTORY(efl_base) +ADD_SUBDIRECTORY(widget_base) +ADD_SUBDIRECTORY(efl_widget_base) ADD_DEPENDENCIES(component-based-app-control component-based-uri) ADD_DEPENDENCIES(component-based-core-base component-based-app-control) ADD_DEPENDENCIES(component-based-application component-based-core-base) +ADD_DEPENDENCIES(component-based-core-widget-base component-based-core-base) +ADD_DEPENDENCIES(component-based-widget-application component-based-core-widget-base) diff --git a/component_based/base/CMakeLists.txt b/component_based/base/CMakeLists.txt index 9b3645e..ec231f6 100644 --- a/component_based/base/CMakeLists.txt +++ b/component_based/base/CMakeLists.txt @@ -9,9 +9,8 @@ SET(INCLUDEDIR "\${prefix}/include") SET(VERSION ${FULLVER}) INCLUDE(FindPkgConfig) -SET(requires "glib-2.0 bundle dlog ecore-wl2 appcore-multiwindow capi-appfw-app-control aul capi-appfw-app-common widget_service screen_connector_provider") -SET(pc_requires "ecore-wl2 appcore-multiwindow capi-appfw-app-control component-based-app-control aul widget_service screen_connector_provider -") +SET(requires "glib-2.0 bundle dlog ecore-wl2 appcore-multiwindow capi-appfw-app-control aul capi-appfw-app-common") +SET(pc_requires "ecore-wl2 appcore-multiwindow capi-appfw-app-control component-based-app-control aul") pkg_check_modules(component-based-core-base REQUIRED ${requires}) diff --git a/component_based/base/component.cc b/component_based/base/component.cc index 7b3862e..a8cc61c 100644 --- a/component_based/base/component.cc +++ b/component_based/base/component.cc @@ -24,6 +24,7 @@ #include "component_based/common/exception.h" #include "component_based/base/component.h" #include "component_based/base/component_implementation.h" +#include "component_based/base/component_manager_internal.h" #include "component_based/base/dlog_internal.h" namespace component_based { @@ -376,4 +377,8 @@ AppControl Component::Send(AppControl control) { } } +IComponentManager& Component::GetComponentManager() { + return internal::ComponentManager::GetInst(); +} + } // namespace component_based diff --git a/component_based/base/component.h b/component_based/base/component.h index 2f0b24e..a4de4a5 100644 --- a/component_based/base/component.h +++ b/component_based/base/component.h @@ -27,6 +27,7 @@ #include "component_based/base/low_battery.h" #include "component_based/base/low_memory.h" #include "component_based/base/suspended_state.h" +#include "component_based/base/component_manager_interface.h" #ifndef EXPORT_API #define EXPORT_API __attribute__((visibility("default"))) @@ -94,6 +95,7 @@ class EXPORT_API Component { bool DeregisterAction(std::string app_control_name); void SendAsync(AppControl control, AppControl::IEventListener* ev); AppControl Send(AppControl control); + IComponentManager& GetComponentManager(); protected: State GetState(); diff --git a/component_based/base/component_manager_interface.h b/component_based/base/component_manager_interface.h new file mode 100644 index 0000000..1e47244 --- /dev/null +++ b/component_based/base/component_manager_interface.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef COMPONENT_BASED_BASE_COMPONENT_MANAGER_INTERFACE_H_ +#define COMPONENT_BASED_BASE_COMPONENT_MANAGER_INTERFACE_H_ + +#include + +#ifndef EXPORT_API +#define EXPORT_API __attribute__((visibility("default"))) +#endif + +namespace component_based { + +class EXPORT_API IComponentManager { + public: + virtual bool IsResumed(const std::string& inst_id) = 0; +}; + +} // namespace component_based + +#endif // COMPONENT_BASED_BASE_COMPONENT_MANAGER_INTERFACE_H_ diff --git a/component_based/base/component_manager_internal.cc b/component_based/base/component_manager_internal.cc index 5e3e3d4..fd34a22 100644 --- a/component_based/base/component_manager_internal.cc +++ b/component_based/base/component_manager_internal.cc @@ -19,7 +19,6 @@ #include #include #include -#include #include #include @@ -190,29 +189,6 @@ bool ComponentManager::Bind(const std::string& inst_id, return true; } -bool ComponentManager::BindWidget(const std::string& inst_id, - std::unique_ptr win) { - appcore_multiwindow_base_instance_h context = - appcore_multiwindow_base_instance_find(inst_id.c_str()); - if (!context) { - LOGE("Failed to find instance(%s)", inst_id.c_str()); - return false; - } - - win_map_[inst_id] = std::move(win); - Ecore_Wl2_Window* wl_win = GetWl2Window(inst_id); - if (!wl_win) { - LOGE("Failed to get wayland window(%s)", inst_id.c_str()); - return false; - } - - struct wl_surface* surface = ecore_wl2_window_surface_get(wl_win); - screen_connector_provider_remote_enable(inst_id.c_str(), surface); - appcore_multiwindow_base_window_bind(context, wl_win); - LOGI("Bind instance(%s)", inst_id.c_str()); - return true; -} - void ComponentManager::Unbind(const std::string& inst_id) { auto win_iter = win_map_.find(inst_id); if (win_iter == win_map_.end()) { diff --git a/component_based/base/component_manager_internal.h b/component_based/base/component_manager_internal.h index c95aa81..be5470e 100644 --- a/component_based/base/component_manager_internal.h +++ b/component_based/base/component_manager_internal.h @@ -26,11 +26,12 @@ #include "component_based/base/component.h" #include "component_based/base/window_interface.h" +#include "component_based/base/window_component_manager_interface.h" namespace component_based { namespace internal { -class ComponentManager { +class ComponentManager : public IWindowComponentManager { private: ComponentManager() = default; ~ComponentManager() = default; @@ -59,17 +60,16 @@ class ComponentManager { void Start(const std::string& comp_id, const std::string& inst_id, bundle* b); void Resume(const std::string& inst_id); void Pause(const std::string& inst_id); - bool IsResumed(const std::string& inst_id); + bool IsResumed(const std::string& inst_id) override; void Stop(const std::string& inst_id); void Exit(const std::string& inst_id); void ExitAtIdle(const std::string& inst_id); void ExitAll(); - bool Bind(const std::string& inst_id, std::unique_ptr win); - bool BindWidget(const std::string& inst_id, std::unique_ptr win); + bool Bind(const std::string& inst_id, std::unique_ptr win) override; void Unbind(const std::string& inst_id); std::string GetInstanceID(int win_id); - const IWindow* GetWindow(const std::string& inst_id); + const IWindow* GetWindow(const std::string& inst_id) override; void AddGroup(const std::string& inst_id, int surf_id); void RemoveGroup(const std::string& inst_id); bool IsEmpty(); diff --git a/component_based/base/frame_component.cc b/component_based/base/frame_component.cc index d000872..399aa7e 100644 --- a/component_based/base/frame_component.cc +++ b/component_based/base/frame_component.cc @@ -47,8 +47,10 @@ FrameComponent::DisplayStatus FrameComponent::GetDisplayStatus() { } const IWindow* FrameComponent::GetWindow() { - auto& mgr = internal::ComponentManager::GetInst(); - return mgr.GetWindow(GetInstanceID()); + IComponentManager& manager = GetComponentManager(); + IWindowComponentManager& w_manager = + static_cast(manager); + return w_manager.GetWindow(GetInstanceID()); } bool FrameComponent::OnBaseCreate() { @@ -58,8 +60,10 @@ bool FrameComponent::OnBaseCreate() { return false; } - auto& mgr = internal::ComponentManager::GetInst(); - if (!mgr.Bind(GetInstanceID(), std::move(win))) { + IComponentManager& manager = GetComponentManager(); + IWindowComponentManager& w_manager = + static_cast(manager); + if (!w_manager.Bind(GetInstanceID(), std::move(win))) { LOGE("Bind window fail"); return false; } diff --git a/component_based/base/widget_component.cc b/component_based/base/widget_component.cc deleted file mode 100644 index 5a2cf44..0000000 --- a/component_based/base/widget_component.cc +++ /dev/null @@ -1,353 +0,0 @@ -/* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "component_based/base/component_manager_internal.h" -#include "component_based/base/dlog_internal.h" -#include "component_based/base/widget_component.h" -#include "component_based/base/widget_component_implementation.h" - -#define STATUS_FOREGROUND "fg" -#define STATUS_BACKGROUND "bg" - -namespace component_based { - -WidgetComponent::Impl::Impl(WidgetComponent* parent) - : parent_(parent) { -} - -WidgetComponent::WidgetComponent(std::string comp_id, std::string inst_id, - tizen_base::Bundle& start_data) - : 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); - - 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); - - if (!width_str.empty()) { - impl_->width_ = std::stoi(width_str); - impl_->height_ = std::stoi(height_str); - } - - std::vector period_v = start_data.GetByte("__WIDGET_PERIOD__"); - if (period_v.size() > 0) { - impl_->period_ = *reinterpret_cast(&period_v[0]); - impl_->period_timer_ = g_timeout_add_seconds( - impl_->period_, impl_->PeriodTimeoutCb, this); - } -} - -WidgetComponent::~WidgetComponent() { - if (impl_->period_timer_) - g_source_remove(impl_->period_timer_); -} - -const IWindow* WidgetComponent::GetWindow() { - auto& mgr = internal::ComponentManager::GetInst(); - return mgr.GetWindow(GetInstanceID()); -} - -bool WidgetComponent::Impl::SendStatus(int status, tizen_base::Bundle extra) { - int lifecycle; - int ret = aul_widget_send_status_to_viewer(parent_->GetComponentID().c_str(), - parent_->GetInstanceID().c_str(), viewer_endpoint_.c_str(), - status, -1, extra.GetCount() != 0 ? extra.GetHandle() : nullptr); - if (ret != 0) - return false; - - 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(), - pkgid_.c_str(), lifecycle); - if (ret != 0) - return false; - } - return true; -} - -void WidgetComponent::Impl::SetPendingUpdate(bool pending) { - pending_update_ = pending; -} - -bool WidgetComponent::Impl::GetPendingUpdate() { - return pending_update_; -} - -void WidgetComponent::Impl::ClearUpdateTimer() { - g_source_remove(period_timer_); - period_timer_ = 0; -} - -gboolean WidgetComponent::Impl::PeriodTimeoutCb(gpointer user_data) { - WidgetComponent* wc = static_cast(user_data); - if (!wc) { - LOGE("Can't find the instance"); - return G_SOURCE_REMOVE; - } - if (wc->GetState() != State::Running) { - wc->impl_->SetPendingUpdate(true); - wc->impl_->ClearUpdateTimer(); - } else { - tizen_base::Bundle data; - wc->OnUpdate(data, false); - } - - return G_SOURCE_CONTINUE; -} - -bool WidgetComponent::OnBaseCreate() { - screen_connector_provider_init(); - std::unique_ptr win = OnCreate(impl_->width_, impl_->height_); - if (win == nullptr) { - LOGE("OnCreate() returns nullptr"); - impl_->SendStatus(WIDGET_INSTANCE_EVENT_CREATE_ABORTED); - return false; - } - - auto& mgr = internal::ComponentManager::GetInst(); - if (!mgr.BindWidget(GetInstanceID(), std::move(win))) { - LOGE("Bind window fail"); - if (!impl_->SendStatus(WIDGET_INSTANCE_EVENT_CREATE_ABORTED)) - LOGE("Fail to send abort event"); - return false; - } - - LOGD("%s is created", GetInstanceID().c_str()); - if (!impl_->SendStatus(WIDGET_INSTANCE_EVENT_CREATE)) { - LOGE("Fail to send create event"); - return false; - } - return true; -} - -void WidgetComponent::OnBaseDestroy() { -} - -void WidgetComponent::Impl::ResizeProcess(tizen_base::Bundle data) { - std::string width_str = data.GetString(WIDGET_K_WIDTH); - std::string height_str = data.GetString(WIDGET_K_HEIGHT); - - if (!width_str.empty()) { - width_ = std::stoi(width_str); - height_ = std::stoi(height_str); - } - parent_->OnResize(width_, height_); - SendStatus(WIDGET_INSTANCE_EVENT_SIZE_CHANGED); -} - -void WidgetComponent::Impl::UpdateProcess(tizen_base::Bundle data) { - std::string force = data.GetString("__WIDGET_FORCE__"); - std::string update_data = data.GetString("__WIDGET_CONTENT_INFO__"); - if (parent_->GetState() != State::Running) { - pending_update_data_ = update_data; - pending_update_ = true; - } else { - tizen_base::Bundle data(update_data); - parent_->OnUpdate(data, force == "true"); - SendStatus(WIDGET_INSTANCE_EVENT_UPDATE); - } -} - -void WidgetComponent::Impl::DestroyProcess(tizen_base::Bundle data) { - parent_->OnDestroy(false); - aul_widget_instance_del(parent_->GetComponentID().c_str(), - parent_->GetInstanceID().c_str()); - SendStatus(WIDGET_INSTANCE_EVENT_DESTROY); - parent_->Finish(); -} - -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::PeriodProcess(tizen_base::Bundle data) { - ClearUpdateTimer(); - std::vector period_v = data.GetByte("__WIDGET_PERIOD__"); - if (period_v.size() > 0) { - period_ = *reinterpret_cast(&period_v[0]); - period_timer_ = g_timeout_add_seconds( - period_, PeriodTimeoutCb, this); - } -} - -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_->ResizeProcess(data); - return; - } else if (op == "update") { - impl_->UpdateProcess(data); - return; - } else if (op == "destroy") { - impl_->DestroyProcess(data); - return; - } else if (op == "terminate") { - impl_->TerminateProcess(data); - return; - } else if (op == "resume") { - OnBaseResume(); - return; - } else if (op == "pause") { - OnBasePause(); - return; - } else if (op == "period") { - impl_->PeriodProcess(data); - return; - } - std::string content_str = data.GetString("__WIDGET_CONTENT_INFO__"); - if (!content_str.empty()) { - tizen_base::Bundle content(content_str); - OnBaseRestoreContent(content); - } else { - OnBaseRestoreContent(GetContent()); - } - OnStart(restarted); -} - -void WidgetComponent::OnBaseResume() { - if (GetState() == State::Paused || - GetState() == State::Started || - GetState() == State::Stopped) { - if (impl_->pending_update_) { - tizen_base::Bundle update_data; - 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); - 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); - } -} - -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); - } - OnBaseStop(); -} - -void WidgetComponent::OnBaseStop() { - OnStop(); - tizen_base::Bundle content = GetContent(); - OnBaseSaveContent(content); - SetContent(std::move(content)); -} - -void WidgetComponent::OnBaseRestoreContent(tizen_base::Bundle content) { -} - -void WidgetComponent::OnBaseSaveContent(tizen_base::Bundle& content) { -} - -// LCOV_EXCL_START -void WidgetComponent::OnBaseAction(std::string action, AppControl app_control) { -} -// LCOV_EXCL_STOP - -// LCOV_EXCL_START -void WidgetComponent::OnBaseDeviceOrientationChanged( - DeviceOrientation::Orientation orientation) { -} -// LCOV_EXCL_STOP - -// LCOV_EXCL_START -void WidgetComponent::OnBaseLanguageChanged(std::string language) { -} -// LCOV_EXCL_STOP - -// LCOV_EXCL_START -void WidgetComponent::OnBaseRegionFormatChanged(std::string region) { -} -// LCOV_EXCL_STOP - -// LCOV_EXCL_START -void WidgetComponent::OnBaseLowBattery(LowBattery::Status status) { -} -// LCOV_EXCL_STOP - -// LCOV_EXCL_START -void WidgetComponent::OnBaseLowMemory(LowMemory::Status status) { -} -// LCOV_EXCL_STOP - -// LCOV_EXCL_START -void WidgetComponent::OnBaseSuspendedStateChanged(SuspendedState::State state) { -} -// LCOV_EXCL_STOP - -std::unique_ptr WidgetComponent::OnCreate(int width, int height) { - return nullptr; -} - -void WidgetComponent::OnStart(bool restarted) { -} - -void WidgetComponent::OnResume() { -} - -void WidgetComponent::OnPause() { -} - -void WidgetComponent::OnStop() { -} - -void WidgetComponent::OnDestroy(bool permanent) { -} - -void WidgetComponent::OnUpdate(tizen_base::Bundle data, bool force) { -} - -void WidgetComponent::OnResize(int w, int h) { -} - -} // namespace component_based diff --git a/component_based/base/widget_component.h b/component_based/base/widget_component.h deleted file mode 100644 index 93d973f..0000000 --- a/component_based/base/widget_component.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef COMPONENT_BASED_BASE_WIDGET_COMPONENT_H_ -#define COMPONENT_BASED_BASE_WIDGET_COMPONENT_H_ - -#include - -#include "component_based/base/component.h" -#include "component_based/base/window_interface.h" - -#ifndef EXPORT_API -#define EXPORT_API __attribute__((visibility("default"))) -#endif - -namespace component_based { - -class EXPORT_API WidgetComponent : public Component { - public: - class Factory : public Component::Factory { - public: - std::unique_ptr Create(std::string comp_id, - std::string inst_id, - tizen_base::Bundle& start_data) override { - return std::unique_ptr( - new (std::nothrow) WidgetComponent( - std::move(comp_id), std::move(inst_id), start_data)); - } - }; - - enum class DisplayStatus { - Unknown, - On, - Off, - }; - - class WidgetType : public Type { - public: - enum { - Hash = 0x3333 - }; - - int GetHash() const override { - return Hash; - } - - std::string GetName() const override { - return "widget"; - } - }; - - std::unique_ptr GetType() const override { - return std::unique_ptr(new WidgetType()); - } - - WidgetComponent(std::string comp_id, std::string inst_id, - tizen_base::Bundle& start_data); - virtual ~WidgetComponent(); - - 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(int w, int h); - virtual void OnStart(bool restarted); - virtual void OnResume(); - virtual void OnPause(); - virtual void OnStop(); - virtual void OnDestroy(bool permanent); - virtual void OnUpdate(tizen_base::Bundle data, bool force); - virtual void OnResize(int width, int height); - - int GetWidth(); - int GetHeight(); - - private: - class Impl; - std::unique_ptr impl_; -}; - -} // namespace component_based - -#endif // COMPONENT_BASED_BASE_WIDGET_COMPONENT_H_ diff --git a/component_based/base/widget_component_implementation.h b/component_based/base/widget_component_implementation.h deleted file mode 100644 index 9bdc59f..0000000 --- a/component_based/base/widget_component_implementation.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef COMPONENT_BASED_BASE_WIDGET_COMPONENT_IMPLEMENTATION_H_ -#define COMPONENT_BASED_BASE_WIDGET_COMPONENT_IMPLEMENTATION_H_ - -#include -#include - -#include -#include -#include - -#include "component_based/base/widget_component.h" - -namespace component_based { - -class WidgetComponent::Impl { - public: - virtual ~Impl() = default; - - private: - friend class WidgetComponent; - Impl(WidgetComponent* parent); - - private: - 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 PeriodProcess(tizen_base::Bundle data); - bool SendStatus(int status, tizen_base::Bundle extra = tizen_base::Bundle()); - void SetPendingUpdate(bool update); - bool GetPendingUpdate(); - void ClearUpdateTimer(); - - private: - WidgetComponent* parent_; - int width_; - int height_; - std::string viewer_endpoint_; - std::string pkgid_; - int period_; - guint period_timer_; - bool pending_update_; - std::string pending_update_data_; -}; - -} // namespace component_base - -#endif // COMPONENT_BASED_BASE_WIDGET_COMPONENT_IMPLEMENTATION_H_ diff --git a/component_based/base/window_component_manager_interface.h b/component_based/base/window_component_manager_interface.h new file mode 100644 index 0000000..1fd6a97 --- /dev/null +++ b/component_based/base/window_component_manager_interface.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef COMPONENT_BASED_BASE_WINDOW_COMPONENT_MANAGER_INTERFACE_H_ +#define COMPONENT_BASED_BASE_WINDOW_COMPONENT_MANAGER_INTERFACE_H_ + +#include +#include + +#include "component_based/base/window_interface.h" +#include "component_based/base/component_manager_interface.h" + +#ifndef EXPORT_API +#define EXPORT_API __attribute__((visibility("default"))) +#endif + +namespace component_based { + +class EXPORT_API IWindowComponentManager : public IComponentManager { + public: + virtual bool Bind(const std::string& inst_id, + std::unique_ptr win) = 0; + + virtual const IWindow* GetWindow(const std::string& inst_id) = 0; +}; + +} // namespace component_based + +#endif // COMPONENT_BASED_BASE_WINDOW_COMPONENT_MANAGER_INTERFACE_H_ diff --git a/component_based/efl_base/elm_widget_window.cc b/component_based/efl_base/elm_widget_window.cc deleted file mode 100644 index d6b6d69..0000000 --- a/component_based/efl_base/elm_widget_window.cc +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include - -#include "elm_widget_window.h" - -namespace component_based { - -ElmWidgetWindow::ElmWidgetWindow(std::string id) - : ElmWindow::ElmWindow(id) { - int rots[3] = {0}; - Evas_Object* win = static_cast(GetRaw()); - elm_win_wm_rotation_preferred_rotation_set(win, -1); - elm_win_wm_rotation_available_rotations_set(win, rots, 1); - Ecore_Wl2_Window* wl_win = ecore_evas_wayland2_window_get( - ecore_evas_ecore_evas_get(evas_object_evas_get(win))); - ecore_wl2_window_class_set(wl_win, id.c_str()); - elm_win_aux_hint_add(win, "wm.policy.win.user.geometry", "1"); - - std::string plug_id = id + ":" + std::to_string(getpid()); - evas_object_data_set(win, "___PLUGID", strdup(plug_id.c_str())); - evas_object_event_callback_add( - win, EVAS_CALLBACK_DEL, WinDelCb, NULL); -} - -ElmWidgetWindow::ElmWidgetWindow(Evas_Object* win) - : ElmWindow::ElmWindow(win) { -} - -ElmWidgetWindow::~ElmWidgetWindow() = default; - -void ElmWidgetWindow::WinDelCb(void* data, Evas* e, - Evas_Object* obj, void* event_info) { - char* plug_id; - plug_id = static_cast(evas_object_data_del(obj, "___PLUGID")); - free(plug_id); -} - -} // namespace component_based diff --git a/component_based/efl_base/elm_widget_window.h b/component_based/efl_base/elm_widget_window.h deleted file mode 100644 index 887183c..0000000 --- a/component_based/efl_base/elm_widget_window.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef COMPONENT_BASED_EFL_BASE_ELM_WIDGET_WINDOW_H_ -#define COMPONENT_BASED_EFL_BASE_ELM_WIDGET_WINDOW_H_ - -#include - -#include - -#include "elm_window.h" - -#ifndef EXPORT_API -#define EXPORT_API __attribute__((visibility("default"))) -#endif - -namespace component_based { - -class EXPORT_API ElmWidgetWindow : public ElmWindow { - public: - ElmWidgetWindow(std::string id); - ElmWidgetWindow(Evas_Object* win); - virtual ~ElmWidgetWindow(); - private: - static void WinDelCb(void* data, Evas* e, Evas_Object* obj, void* event_info); -}; - -} // namespace component_based - -#endif // COMPONENT_BASED_EFL_BASE_ELM_WIDGET_WINDOW_H_ diff --git a/component_based/efl_widget_base/CMakeLists.txt b/component_based/efl_widget_base/CMakeLists.txt new file mode 100644 index 0000000..e1f3a3b --- /dev/null +++ b/component_based/efl_widget_base/CMakeLists.txt @@ -0,0 +1,54 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +PROJECT(component-based-widget-application CXX) + +SET(PREFIX "${CMAKE_INSTALL_PREFIX}") +SET(EXEC_PREFIX "\${prefix}") +SET(PROJECT_NAME "${PROJECT_NAME}") +SET(LIBDIR ${LIB_INSTALL_DIR}) +SET(INCLUDEDIR "\${prefix}/include") +SET(VERSION ${FULLVER}) + +INCLUDE(FindPkgConfig) +SET(requires "glib-2.0 bundle dlog ecore-wl2 elementary capi-appfw-app-control") +SET(pc_requires "elementary component-based-core-widget-base") +pkg_check_modules(component-based-widget-application REQUIRED ${requires}) + +FOREACH(flag ${component-based-widget-application_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Werror -Winline -std=c++11") + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_CXX_FLAGS_RELEASE "-O2") + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../base/) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../base/api/) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/api/) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/) + +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCES) +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SOURCES}) + +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${MAJORVER}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${FULLVER}) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${component-based-widget-application_LDFLAGS} component-based-core-widget-base) + +SET(PC_NAME component-based-widget-application) +SET(PC_REQUIRED ${pc_requires}) + +CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) +SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${PROJECT_NAME}.pc") + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) +INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ + DESTINATION ${INCLUDE_INSTALL_DIR}/component_based/efl_widget_base + FILES_MATCHING PATTERN "*.h") +INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/api + DESTINATION ${INCLUDE_INSTALL_DIR}/component_based/efl_widget_base + FILES_MATCHING PATTERN "*.h") + + diff --git a/component_based/efl_widget_base/api/widget_component.h b/component_based/efl_widget_base/api/widget_component.h new file mode 100644 index 0000000..8a3a656 --- /dev/null +++ b/component_based/efl_widget_base/api/widget_component.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __TIZEN_COMPONENT_BASED_WIDGET_COMPONENT_H__ +#define __TIZEN_COMPONENT_BASED_WIDGET_COMPONENT_H__ + +#include +#include +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup COMPONENT_BASED_WIDGET_COMPONENT_MODULE + * @{ + */ + +// TODO(CAPI) CAPI should be implemented to support C# APIs. + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __TIZEN_COMPONENT_BASED_WIDGET_COMPONENT_H__ */ + diff --git a/component_based/efl_widget_base/component-based-widget-application.pc.in b/component_based/efl_widget_base/component-based-widget-application.pc.in new file mode 100644 index 0000000..2e57c72 --- /dev/null +++ b/component_based/efl_widget_base/component-based-widget-application.pc.in @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +exec_prefix=@EXEC_PREFIX@ +libdir=@LIB_INSTALL_DIR@ +includedir=@INCLUDE_INSTALL_DIR@ + +Name: @PC_NAME@ +Description: Support development of the Tizen Extensive App Model +Version: @VERSION@ +Requires: @PC_REQUIRED@ +Libs: -L${libdir} -lcomponent-based-core-widget-base -lcomponent-based-widget-application +Cflags: -I${includedir} -I${includedir}/appfw -I${includedir}/component_based -I${includedir}/component_based/api -I${includedir}/component_based/efl_base -I${includedir}/component_based/efl_base/api -I${includedir}/component_based/widget_base -I${includedir}/component_based/widget_base/api -I${includedir}/component_based/efl_widget_base -I${includedir}/component_based/efl_widget_base/api diff --git a/component_based/efl_widget_base/elm_widget_window.cc b/component_based/efl_widget_base/elm_widget_window.cc new file mode 100644 index 0000000..b3e35d2 --- /dev/null +++ b/component_based/efl_widget_base/elm_widget_window.cc @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include + +#include "elm_widget_window.h" + +namespace component_based { + +ElmWidgetWindow::ElmWidgetWindow(std::string id) { + int rots[3] = {0}; + win_ = elm_win_add(nullptr, id.c_str(), ELM_WIN_BASIC); + elm_win_wm_rotation_preferred_rotation_set(win_, -1); + elm_win_wm_rotation_available_rotations_set(win_, rots, 1); + Ecore_Wl2_Window* wl_win = ecore_evas_wayland2_window_get( + ecore_evas_ecore_evas_get(evas_object_evas_get(win_))); + ecore_wl2_window_class_set(wl_win, id.c_str()); + elm_win_aux_hint_add(win_, "wm.policy.win.user.geometry", "1"); + + std::string plug_id = id + ":" + std::to_string(getpid()); + evas_object_data_set(win_, "___PLUGID", strdup(plug_id.c_str())); + evas_object_event_callback_add( + win_, EVAS_CALLBACK_DEL, WinDelCb, NULL); +} + +ElmWidgetWindow::ElmWidgetWindow(Evas_Object* win) + : win_(win) { +} + +ElmWidgetWindow::~ElmWidgetWindow() { + if (win_ != nullptr) + evas_object_del(win_); +} + +int ElmWidgetWindow::GetResID() const { + Evas* evas = evas_object_evas_get(win_); + Ecore_Evas* ecore_evas = ecore_evas_ecore_evas_get(evas); + Ecore_Wl2_Window* wl_win = ecore_evas_wayland2_window_get(ecore_evas); + return ecore_wl2_window_id_get(wl_win); +} + +void* ElmWidgetWindow::GetRaw() { + return win_; +} + +void ElmWidgetWindow::WinDelCb(void* data, Evas* e, + Evas_Object* obj, void* event_info) { + char* plug_id; + plug_id = static_cast(evas_object_data_del(obj, "___PLUGID")); + free(plug_id); +} + +} // namespace component_based diff --git a/component_based/efl_widget_base/elm_widget_window.h b/component_based/efl_widget_base/elm_widget_window.h new file mode 100644 index 0000000..6c5bf60 --- /dev/null +++ b/component_based/efl_widget_base/elm_widget_window.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef COMPONENT_BASED_EFL_BASE_ELM_WIDGET_WINDOW_H_ +#define COMPONENT_BASED_EFL_BASE_ELM_WIDGET_WINDOW_H_ + +#include + +#include + +#include "component_based/base/window_interface.h" + +#ifndef EXPORT_API +#define EXPORT_API __attribute__((visibility("default"))) +#endif + +namespace component_based { + +class EXPORT_API ElmWidgetWindow : public IWindow { + public: + ElmWidgetWindow(std::string id); + ElmWidgetWindow(Evas_Object* win); + virtual ~ElmWidgetWindow(); + + int GetResID() const override; + void* GetRaw() override; + + private: + static void WinDelCb(void* data, Evas* e, Evas_Object* obj, void* event_info); + Evas_Object* win_ = nullptr; +}; + +} // namespace component_based + +#endif // COMPONENT_BASED_EFL_BASE_ELM_WIDGET_WINDOW_H_ diff --git a/component_based/widget_base/CMakeLists.txt b/component_based/widget_base/CMakeLists.txt new file mode 100644 index 0000000..5175100 --- /dev/null +++ b/component_based/widget_base/CMakeLists.txt @@ -0,0 +1,53 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +PROJECT(component-based-core-widget-base CXX) + +SET(PREFIX "${CMAKE_INSTALL_PREFIX}") +SET(EXEC_PREFIX "\${prefix}") +SET(PROJECT_NAME "${PROJECT_NAME}") +SET(LIBDIR ${LIB_INSTALL_DIR}) +SET(INCLUDEDIR "\${prefix}/include") +SET(VERSION ${FULLVER}) + +INCLUDE(FindPkgConfig) +SET(requires "glib-2.0 bundle dlog ecore-wl2 appcore-multiwindow elementary capi-appfw-app-control widget_service screen_connector_provider") +SET(pc_requires "elementary component-based-core-base appcore-multiwindow widget_service screen_connector_provider") +pkg_check_modules(component-based-core-widget-base REQUIRED ${requires}) + +FOREACH(flag ${component-based-core-widget-base_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Werror -Winline -std=c++11") + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_CXX_FLAGS_RELEASE "-O2") + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../base/) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../base/api/) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/api/) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/) + +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCES) +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SOURCES}) + +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${MAJORVER}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${FULLVER}) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${component-based-core-widget-base_LDFLAGS} component-based-core-base) + +SET(PC_NAME component-based-core-widget-base) +SET(PC_REQUIRED ${pc_requires}) + +CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) +SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${PROJECT_NAME}.pc") + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) +INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ + DESTINATION ${INCLUDE_INSTALL_DIR}/component_based/widget_base + FILES_MATCHING PATTERN "*.h") +INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/api + DESTINATION ${INCLUDE_INSTALL_DIR}/component_based/widget_base + FILES_MATCHING PATTERN "*.h") + diff --git a/component_based/widget_base/api/base_widget_component.h b/component_based/widget_base/api/base_widget_component.h new file mode 100644 index 0000000..ce82a44 --- /dev/null +++ b/component_based/widget_base/api/base_widget_component.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __TIZEN_COMPONENT_BASED_BASE_WIDGET_COMPONENT_H__ +#define __TIZEN_COMPONENT_BASED_BASE_WIDGET_COMPONENT_H__ + +#include +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif +// TODO(CAPI) CAPI should be implemented to support C# APIs. + +#ifdef __cplusplus +} +#endif + +#endif /* __TIZEN_COMPONENT_BASED_BASE_WIDGET_COMPONENT_H__ */ + diff --git a/component_based/widget_base/component-based-core-widget-base.pc.in b/component_based/widget_base/component-based-core-widget-base.pc.in new file mode 100644 index 0000000..6cdc981 --- /dev/null +++ b/component_based/widget_base/component-based-core-widget-base.pc.in @@ -0,0 +1,11 @@ +prefix=@PREFIX@ +exec_prefix=@EXEC_PREFIX@ +libdir=@LIB_INSTALL_DIR@ +includedir=@INCLUDE_INSTALL_DIR@ + +Name: @PC_NAME@ +Description: Support development of the Tizen Component-based App Model +Version: @VERSION@ +Requires: @PC_REQUIRED@ +Libs: -L${libdir} -lcomponent-based-core-base -lcomponent-based-core-widget-base +Cflags: -I${includedir} -I${includedir}/appfw -I${includedir}/component_based -I${includedir}/component_based/api -I${includedir}/component_based/widget_base/api -I${includedir}/component_based/widget_base diff --git a/component_based/widget_base/widget_component.cc b/component_based/widget_base/widget_component.cc new file mode 100644 index 0000000..deac412 --- /dev/null +++ b/component_based/widget_base/widget_component.cc @@ -0,0 +1,363 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "component_based/base/component_manager_internal.h" +#include "component_based/base/dlog_internal.h" +#include "component_based/widget_base/widget_component.h" +#include "component_based/widget_base/widget_component_implementation.h" + +#define STATUS_FOREGROUND "fg" +#define STATUS_BACKGROUND "bg" + +namespace component_based { + +WidgetComponent::Impl::Impl(WidgetComponent* parent) + : parent_(parent) { +} + +WidgetComponent::WidgetComponent(std::string comp_id, std::string inst_id, + tizen_base::Bundle& start_data) + : 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); + + 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); + + if (!width_str.empty()) { + impl_->width_ = std::stoi(width_str); + impl_->height_ = std::stoi(height_str); + } + + std::vector period_v = start_data.GetByte("__WIDGET_PERIOD__"); + if (period_v.size() > 0) { + impl_->period_ = *reinterpret_cast(&period_v[0]); + impl_->period_timer_ = g_timeout_add_seconds( + impl_->period_, impl_->PeriodTimeoutCb, this); + } +} + +WidgetComponent::~WidgetComponent() { + if (impl_->period_timer_) + g_source_remove(impl_->period_timer_); +} + +const IWindow* WidgetComponent::GetWindow() { + IComponentManager& manager = GetComponentManager(); + IWindowComponentManager& w_manager = + static_cast(manager); + return w_manager.GetWindow(GetInstanceID()); +} + +bool WidgetComponent::Impl::SendStatus(int status, tizen_base::Bundle extra) { + int lifecycle; + int ret = aul_widget_send_status_to_viewer(parent_->GetComponentID().c_str(), + parent_->GetInstanceID().c_str(), viewer_endpoint_.c_str(), + status, -1, extra.GetCount() != 0 ? extra.GetHandle() : nullptr); + if (ret != 0) + return false; + + 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(), + pkgid_.c_str(), lifecycle); + if (ret != 0) + return false; + } + return true; +} + +void WidgetComponent::Impl::SetPendingUpdate(bool pending) { + pending_update_ = pending; +} + +bool WidgetComponent::Impl::GetPendingUpdate() { + return pending_update_; +} + +void WidgetComponent::Impl::ClearUpdateTimer() { + g_source_remove(period_timer_); + period_timer_ = 0; +} + +gboolean WidgetComponent::Impl::PeriodTimeoutCb(gpointer user_data) { + WidgetComponent* wc = static_cast(user_data); + if (!wc) { + LOGE("Can't find the instance"); + return G_SOURCE_REMOVE; + } + if (wc->GetState() != State::Running) { + wc->impl_->SetPendingUpdate(true); + wc->impl_->ClearUpdateTimer(); + } else { + tizen_base::Bundle data; + wc->OnUpdate(data, false); + } + + return G_SOURCE_CONTINUE; +} + +bool WidgetComponent::OnBaseCreate() { + screen_connector_provider_init(); + std::unique_ptr win = OnCreate(impl_->width_, impl_->height_); + if (win == nullptr) { + LOGE("OnCreate() returns nullptr"); + impl_->SendStatus(WIDGET_INSTANCE_EVENT_CREATE_ABORTED); + return false; + } + + IComponentManager& manager = GetComponentManager(); + IWindowComponentManager& w_manager = + static_cast(manager); + if (!w_manager.Bind(GetInstanceID(), std::move(win))) { + LOGE("Bind window fail"); + if (!impl_->SendStatus(WIDGET_INSTANCE_EVENT_CREATE_ABORTED)) + LOGE("Fail to send abort event"); + return false; + } + + int win_id = GetWindow()->GetResID(); + 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); + + LOGD("%s is created", GetInstanceID().c_str()); + if (!impl_->SendStatus(WIDGET_INSTANCE_EVENT_CREATE)) { + LOGE("Fail to send create event"); + return false; + } + return true; +} + +void WidgetComponent::OnBaseDestroy() { +} + +void WidgetComponent::Impl::ResizeProcess(tizen_base::Bundle data) { + std::string width_str = data.GetString(WIDGET_K_WIDTH); + std::string height_str = data.GetString(WIDGET_K_HEIGHT); + + if (!width_str.empty()) { + width_ = std::stoi(width_str); + height_ = std::stoi(height_str); + } + parent_->OnResize(width_, height_); + SendStatus(WIDGET_INSTANCE_EVENT_SIZE_CHANGED); +} + +void WidgetComponent::Impl::UpdateProcess(tizen_base::Bundle data) { + std::string force = data.GetString("__WIDGET_FORCE__"); + std::string update_data = data.GetString("__WIDGET_CONTENT_INFO__"); + if (parent_->GetState() != State::Running) { + pending_update_data_ = update_data; + pending_update_ = true; + } else { + tizen_base::Bundle data(update_data); + parent_->OnUpdate(data, force == "true"); + SendStatus(WIDGET_INSTANCE_EVENT_UPDATE); + } +} + +void WidgetComponent::Impl::DestroyProcess(tizen_base::Bundle data) { + parent_->OnDestroy(false); + aul_widget_instance_del(parent_->GetComponentID().c_str(), + parent_->GetInstanceID().c_str()); + SendStatus(WIDGET_INSTANCE_EVENT_DESTROY); + parent_->Finish(); +} + +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::PeriodProcess(tizen_base::Bundle data) { + ClearUpdateTimer(); + std::vector period_v = data.GetByte("__WIDGET_PERIOD__"); + if (period_v.size() > 0) { + period_ = *reinterpret_cast(&period_v[0]); + period_timer_ = g_timeout_add_seconds( + period_, PeriodTimeoutCb, this); + } +} + +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_->ResizeProcess(data); + return; + } else if (op == "update") { + impl_->UpdateProcess(data); + return; + } else if (op == "destroy") { + impl_->DestroyProcess(data); + return; + } else if (op == "terminate") { + impl_->TerminateProcess(data); + return; + } else if (op == "resume") { + OnBaseResume(); + return; + } else if (op == "pause") { + OnBasePause(); + return; + } else if (op == "period") { + impl_->PeriodProcess(data); + return; + } + std::string content_str = data.GetString("__WIDGET_CONTENT_INFO__"); + if (!content_str.empty()) { + tizen_base::Bundle content(content_str); + OnBaseRestoreContent(content); + } else { + OnBaseRestoreContent(GetContent()); + } + OnStart(restarted); +} + +void WidgetComponent::OnBaseResume() { + if (GetState() == State::Paused || + GetState() == State::Started || + GetState() == State::Stopped) { + if (impl_->pending_update_) { + tizen_base::Bundle update_data; + 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); + 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); + } +} + +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); + } + OnBaseStop(); +} + +void WidgetComponent::OnBaseStop() { + OnStop(); + tizen_base::Bundle content = GetContent(); + OnBaseSaveContent(content); + SetContent(std::move(content)); +} + +void WidgetComponent::OnBaseRestoreContent(tizen_base::Bundle content) { +} + +void WidgetComponent::OnBaseSaveContent(tizen_base::Bundle& content) { +} + +// LCOV_EXCL_START +void WidgetComponent::OnBaseAction(std::string action, AppControl app_control) { +} +// LCOV_EXCL_STOP + +// LCOV_EXCL_START +void WidgetComponent::OnBaseDeviceOrientationChanged( + DeviceOrientation::Orientation orientation) { +} +// LCOV_EXCL_STOP + +// LCOV_EXCL_START +void WidgetComponent::OnBaseLanguageChanged(std::string language) { +} +// LCOV_EXCL_STOP + +// LCOV_EXCL_START +void WidgetComponent::OnBaseRegionFormatChanged(std::string region) { +} +// LCOV_EXCL_STOP + +// LCOV_EXCL_START +void WidgetComponent::OnBaseLowBattery(LowBattery::Status status) { +} +// LCOV_EXCL_STOP + +// LCOV_EXCL_START +void WidgetComponent::OnBaseLowMemory(LowMemory::Status status) { +} +// LCOV_EXCL_STOP + +// LCOV_EXCL_START +void WidgetComponent::OnBaseSuspendedStateChanged(SuspendedState::State state) { +} +// LCOV_EXCL_STOP + +std::unique_ptr WidgetComponent::OnCreate(int width, int height) { + return nullptr; +} + +void WidgetComponent::OnStart(bool restarted) { +} + +void WidgetComponent::OnResume() { +} + +void WidgetComponent::OnPause() { +} + +void WidgetComponent::OnStop() { +} + +void WidgetComponent::OnDestroy(bool permanent) { +} + +void WidgetComponent::OnUpdate(tizen_base::Bundle data, bool force) { +} + +void WidgetComponent::OnResize(int w, int h) { +} + +} // namespace component_based diff --git a/component_based/widget_base/widget_component.h b/component_based/widget_base/widget_component.h new file mode 100644 index 0000000..93d973f --- /dev/null +++ b/component_based/widget_base/widget_component.h @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef COMPONENT_BASED_BASE_WIDGET_COMPONENT_H_ +#define COMPONENT_BASED_BASE_WIDGET_COMPONENT_H_ + +#include + +#include "component_based/base/component.h" +#include "component_based/base/window_interface.h" + +#ifndef EXPORT_API +#define EXPORT_API __attribute__((visibility("default"))) +#endif + +namespace component_based { + +class EXPORT_API WidgetComponent : public Component { + public: + class Factory : public Component::Factory { + public: + std::unique_ptr Create(std::string comp_id, + std::string inst_id, + tizen_base::Bundle& start_data) override { + return std::unique_ptr( + new (std::nothrow) WidgetComponent( + std::move(comp_id), std::move(inst_id), start_data)); + } + }; + + enum class DisplayStatus { + Unknown, + On, + Off, + }; + + class WidgetType : public Type { + public: + enum { + Hash = 0x3333 + }; + + int GetHash() const override { + return Hash; + } + + std::string GetName() const override { + return "widget"; + } + }; + + std::unique_ptr GetType() const override { + return std::unique_ptr(new WidgetType()); + } + + WidgetComponent(std::string comp_id, std::string inst_id, + tizen_base::Bundle& start_data); + virtual ~WidgetComponent(); + + 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(int w, int h); + virtual void OnStart(bool restarted); + virtual void OnResume(); + virtual void OnPause(); + virtual void OnStop(); + virtual void OnDestroy(bool permanent); + virtual void OnUpdate(tizen_base::Bundle data, bool force); + virtual void OnResize(int width, int height); + + int GetWidth(); + int GetHeight(); + + private: + class Impl; + std::unique_ptr impl_; +}; + +} // namespace component_based + +#endif // COMPONENT_BASED_BASE_WIDGET_COMPONENT_H_ diff --git a/component_based/widget_base/widget_component_implementation.h b/component_based/widget_base/widget_component_implementation.h new file mode 100644 index 0000000..0154d57 --- /dev/null +++ b/component_based/widget_base/widget_component_implementation.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef COMPONENT_BASED_BASE_WIDGET_COMPONENT_IMPLEMENTATION_H_ +#define COMPONENT_BASED_BASE_WIDGET_COMPONENT_IMPLEMENTATION_H_ + +#include +#include + +#include +#include +#include + +#include "component_based/widget_base/widget_component.h" + +namespace component_based { + +class WidgetComponent::Impl { + public: + virtual ~Impl() = default; + + private: + friend class WidgetComponent; + Impl(WidgetComponent* parent); + + private: + 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 PeriodProcess(tizen_base::Bundle data); + bool SendStatus(int status, tizen_base::Bundle extra = tizen_base::Bundle()); + void SetPendingUpdate(bool update); + bool GetPendingUpdate(); + void ClearUpdateTimer(); + + private: + WidgetComponent* parent_; + int width_; + int height_; + std::string viewer_endpoint_; + std::string pkgid_; + int period_; + guint period_timer_; + bool pending_update_; + std::string pending_update_data_; +}; + +} // namespace component_base + +#endif // COMPONENT_BASED_BASE_WIDGET_COMPONENT_IMPLEMENTATION_H_ diff --git a/packaging/component-based-widget-application.manifest b/packaging/component-based-widget-application.manifest new file mode 100644 index 0000000..97e8c31 --- /dev/null +++ b/packaging/component-based-widget-application.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/component-based-widget.manifest b/packaging/component-based-widget.manifest new file mode 100644 index 0000000..97e8c31 --- /dev/null +++ b/packaging/component-based-widget.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/component-based.spec b/packaging/component-based.spec index 38ab548..1ac6832 100644 --- a/packaging/component-based.spec +++ b/packaging/component-based.spec @@ -7,6 +7,8 @@ License: Apache-2.0 Source0: %{name}-%{version}.tar.gz Source1001: %{name}.manifest Source1002: %{name}-application.manifest +Source1003: %{name}-widget.manifest +Source1004: %{name}-widget-application.manifest Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig @@ -67,6 +69,48 @@ Requires: %{name}-application = %{version}-%{release} %description -n %{name}-application-devel Header & package configuration files to support development of the component-based application. + + +################################################# +# component-based-widget +################################################# +%package -n %{name}-widget +Summary: Library for developing the component-based widget application +Group: Application Framework/Core +License: Apache-2.0 + +%description -n %{name}-widget +Provider APIs to develop the component-based widget application + +%package -n %{name}-widget-devel +Summary: Component-based widget application development library (dev) +Group: Development/Libraries +Requires: %{name}-widget = %{version}-%{release} + +%description -n %{name}-widget-devel +Header & package configuration files to support development of the component-based widget + + +################################################# +# component-based-widget-application +################################################# +%package -n %{name}-widget-application +Summary: Library for developing the component-based efl widget application +Group: Application Framework/Core +License: Apache-2.0 + +%description -n %{name}-widget-application +Provider APIs to develop the component-based efl widget application + +%package -n %{name}-widget-application-devel +Summary: Component-based efl widget application development library (dev) +Group: Development/Libraries +Requires: %{name}-widget-application = %{version}-%{release} + +%description -n %{name}-widget-application-devel +Header & package configuration files to support development of the component-based efl widget application. + + ################################################# # unittests ################################################# @@ -94,6 +138,8 @@ Component-based library gcov objects %setup -q cp %{SOURCE1001} . cp %{SOURCE1002} . +cp %{SOURCE1003} . +cp %{SOURCE1004} . %build %if 0%{?gcov:1} @@ -147,12 +193,21 @@ install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj %postun -n %{name}-application /sbin/ldconfig + +%post -n %{name}-widget -p /sbin/ldconfig +%postun -n %{name}-widget -p /sbin/ldconfig + +%post -n %{name}-widget-application -p /sbin/ldconfig +%postun -n %{name}-widget-application -p /sbin/ldconfig + + %post unittests %if 0%{?gcov:1} %{_bindir}/component-based_unittests %endif -%files + +%files -n %{name} %manifest %{name}.manifest %license LICENSE %defattr(-,root,root,-) @@ -160,7 +215,7 @@ install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj %{_libdir}/libcomponent-based-app-control.so.* %{_libdir}/libcomponent-based-uri.so.* -%files devel +%files -n %{name}-devel %{_includedir}/component_based/base/*.h %{_includedir}/component_based/base/api/*.h %{_includedir}/component_based/app_control/*.h @@ -186,6 +241,36 @@ install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj %{_libdir}/pkgconfig/component-based-application.pc %{_libdir}/libcomponent-based-application.so + +################################################# +# component-based-widget +################################################# +%files -n %{name}-widget +%license LICENSE +%manifest %{name}-widget.manifest +%attr(0644,root,root) %{_libdir}/libcomponent-based-core-widget-base.so.* + +%files -n %{name}-widget-devel +%{_includedir}/component_based/widget_base/*.h +%{_includedir}/component_based/widget_base/api/*.h +%{_libdir}/pkgconfig/component-based-core-widget-base.pc +%{_libdir}/libcomponent-based-core-widget-base.so + + +################################################# +# component-based-widget-application +################################################# +%files -n %{name}-widget-application +%license LICENSE +%manifest %{name}-widget-application.manifest +%attr(0644,root,root) %{_libdir}/libcomponent-based-widget-application.so.* + +%files -n %{name}-widget-application-devel +%{_includedir}/component_based/efl_widget_base/*.h +%{_includedir}/component_based/efl_widget_base/api/*.h +%{_libdir}/pkgconfig/component-based-widget-application.pc +%{_libdir}/libcomponent-based-widget-application.so + ################################################# # unittests #################################################