From 84369ca2f8558dc7dc47a7b1234c7185474c73e9 Mon Sep 17 00:00:00 2001 From: Daekwang Ryu Date: Wed, 22 Jun 2022 11:46:46 +0900 Subject: [PATCH] Apply app-core-ui-cpp This is a prerequisite to applying the Ui Thread app model. Change-Id: I194b283f8503fdc9cb48abfa86ae1cdbb20e3284 --- build/tizen/deps-check.cmake | 2 +- .../adaptor/tizen-wayland/framework-tizen.cpp | 434 +++++++++++++++------ packaging/dali-adaptor.spec | 2 +- 3 files changed, 316 insertions(+), 122 deletions(-) diff --git a/build/tizen/deps-check.cmake b/build/tizen/deps-check.cmake index a13dc7d..3ed1b62 100755 --- a/build/tizen/deps-check.cmake +++ b/build/tizen/deps-check.cmake @@ -103,7 +103,7 @@ CHECK_MODULE_AND_SET( SCREENCONNECTORPROVIDER screen_connector_provider [] ) CHECK_MODULE_AND_SET( APPFW_WATCH capi-appfw-watch-application watch_available ) CHECK_MODULE_AND_SET( APPCORE_WATCH appcore-watch [] ) -CHECK_MODULE_AND_SET( CAPI_APPFW_APPLICATION appcore-ui [] ) +CHECK_MODULE_AND_SET( CAPI_APPFW_APPLICATION app-core-ui-cpp [] ) CHECK_MODULE_AND_SET( CAPI_APPFW_WIDGET_BASE appcore-widget-base [] ) CHECK_MODULE_AND_SET( CAPI_APPFW_COMMON capi-appfw-app-common [] ) CHECK_MODULE_AND_SET( CAPI_APPFW_CONTROL capi-appfw-app-control [] ) diff --git a/dali/internal/adaptor/tizen-wayland/framework-tizen.cpp b/dali/internal/adaptor/tizen-wayland/framework-tizen.cpp index 8198a80..7db93c7 100644 --- a/dali/internal/adaptor/tizen-wayland/framework-tizen.cpp +++ b/dali/internal/adaptor/tizen-wayland/framework-tizen.cpp @@ -21,14 +21,13 @@ // EXTERNAL INCLUDES #include #include -#include #include -#include - #include #include #include #include +#include +#include // CONDITIONAL INCLUDES #ifdef APPCORE_WATCH_AVAILABLE #include @@ -50,6 +49,9 @@ // INTERNAL INCLUDES #include +#include + +using namespace tizen_cpp; namespace Dali { @@ -169,6 +171,44 @@ int AppAddEventHandler(AppEventHandlerPtr* eventHandler, AppEventType eventType, } } +DeviceStatus::Memory::Status GetMemoryStatus(app_event_low_memory_status_e memoryStatus) +{ + switch(memoryStatus) + { + case APP_EVENT_LOW_MEMORY_SOFT_WARNING: // 0x02 + { + return Dali::DeviceStatus::Memory::Status::LOW; + } + case APP_EVENT_LOW_MEMORY_HARD_WARNING: // 0x04 + { + return Dali::DeviceStatus::Memory::Status::CRITICALLY_LOW; + } + default: // APP_EVENT_LOW_MEMORY_NORMAL 0x01 + { + return Dali::DeviceStatus::Memory::Status::NORMAL; + } + } +} + +DeviceStatus::Battery::Status GetBatteryStatus(app_event_low_battery_status_e batteryStatus) +{ + switch(batteryStatus) + { + case APP_EVENT_LOW_BATTERY_POWER_OFF: // 1 + { + return Dali::DeviceStatus::Battery::Status::POWER_OFF; + } + case APP_EVENT_LOW_BATTERY_CRITICAL_LOW: // 2 + { + return Dali::DeviceStatus::Battery::Status::CRITICALLY_LOW; + } + default: + { + return Dali::DeviceStatus::Battery::Status::NORMAL; + } + } +} + } // namespace AppCore /** @@ -176,6 +216,243 @@ int AppAddEventHandler(AppEventHandlerPtr* eventHandler, AppEventType eventType, */ struct Framework::Impl { + class UiAppContext : public AppCoreUiBase + { + public: + explicit UiAppContext(unsigned int hint, Framework* framework) + : AppCoreUiBase(hint), + mFramework(framework) + { + mLanguageChanged = std::make_shared(IAppCore::IEvent::Type::LANG_CHANGE, OnLanguageChanged, this); + AddEvent(mLanguageChanged); + + mDeviceOrientationChanged = std::make_shared(IAppCore::IEvent::Type::DEVICE_ORIENTATION_CHANGED, OnDeviceOrientationChanged, this); + AddEvent(mDeviceOrientationChanged); + + mRegionFormatChanged = std::make_shared(IAppCore::IEvent::Type::REGION_CHANGE, OnRegionFormatChanged, this); + AddEvent(mRegionFormatChanged); + + mLowMemory = std::make_shared(IAppCore::IEvent::Type::LOW_MEMORY, OnLowMemory, this); + AddEvent(mLowMemory); + + mLowBattery = std::make_shared(IAppCore::IEvent::Type::LOW_BATTERY, OnLowBattery, this); + AddEvent(mLowBattery); + } + + virtual ~UiAppContext() + { + RemoveEvent(mLowBattery); + RemoveEvent(mLowMemory); + RemoveEvent(mRegionFormatChanged); + RemoveEvent(mDeviceOrientationChanged); + RemoveEvent(mLanguageChanged); + } + + int OnCreate() override + { + AppCoreUiBase::OnCreate(); + mFramework->Create(); + return 0; + } + + int OnTerminate() override + { + AppCoreUiBase::OnTerminate(); + auto* observer = &mFramework->mObserver; + observer->OnTerminate(); + return 0; + } + + int OnPause() override + { + AppCoreUiBase::OnPause(); + auto* observer = &mFramework->mObserver; + observer->OnPause(); + return 0; + } + + int OnResume() override + { + AppCoreUiBase::OnResume(); + auto* observer = &mFramework->mObserver; + observer->OnResume(); + return 0; + } + + int OnControl(tizen_base::Bundle b) override + { + AppCoreUiBase::OnControl(b); + + app_control_h appControl = nullptr; + + auto* bundleData = b.GetHandle(); + if(bundleData) + { + if(app_control_create_event(bundleData, &appControl) != TIZEN_ERROR_NONE) + { + DALI_LOG_ERROR("Failed to create an app_control handle"); + return 0; + } + } + else + { + if(app_control_create(&appControl) != TIZEN_ERROR_NONE) + { + DALI_LOG_ERROR("Failed to create an app_control handle"); + return 0; + } + } + + auto* observer = &mFramework->mObserver; + ProcessBundle(mFramework, bundleData); + observer->OnReset(); + observer->OnAppControl(appControl); + app_control_destroy(appControl); + return 0; + } + + void OnLoopInit(int argc, char** argv) override + { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wold-style-cast" + ecore_init(); + ecore_app_args_set(argc, (const char**)argv); +#pragma GCC diagnostic pop + +#ifdef DALI_ELDBUS_AVAILABLE + // Initialize ElDBus. + DALI_LOG_INFO(gDBusLogging, Debug::General, "Starting DBus Initialization\n"); + eldbus_init(); +#endif + } + + void OnLoopFinish() override + { + ecore_shutdown(); + + if(getenv("AUL_LOADER_INIT")) + { + setenv("AUL_LOADER_INIT", "0", 1); + ecore_shutdown(); + } + +#ifdef DALI_ELDBUS_AVAILABLE + // Shutdown ELDBus. + DALI_LOG_INFO(gDBusLogging, Debug::General, "Shutting down DBus\n"); + eldbus_shutdown(); +#endif + } + + void OnLoopRun() override + { + ecore_main_loop_begin(); + } + + void OnLoopExit() override + { + ecore_main_loop_quit(); + } + + private: + static void OnLanguageChanged(app_event_info_h event_info, void* user_data) + { + auto* context = static_cast(user_data); + auto* framework = context->mFramework; + Observer* observer = &framework->mObserver; + + char* lang = nullptr; + app_event_get_language(event_info, &lang); + if(lang) + { + framework->SetLanguage(std::string(lang)); + observer->OnLanguageChanged(); + free(lang); + } + else + { + DALI_LOG_ERROR("NULL pointer in Language changed event\n"); + } + } + + static void OnDeviceOrientationChanged(app_event_info_h event_info, void* user_data) + { + } + + static void OnRegionFormatChanged(app_event_info_h event_info, void* user_data) + { + auto* context = static_cast(user_data); + auto* framework = context->mFramework; + Observer* observer = &framework->mObserver; + + char* region = nullptr; + app_event_get_region_format(event_info, ®ion); + if(region) + { + framework->SetRegion(std::string(region)); + observer->OnRegionChanged(); + free(region); + } + else + { + DALI_LOG_ERROR("NULL pointer in Region changed event\n"); + } + } + + static void OnLowBattery(app_event_info_h event_info, void* user_data) + { + auto* context = static_cast(user_data); + auto* framework = context->mFramework; + Observer* observer = &framework->mObserver; + + app_event_low_battery_status_e status; + app_event_get_low_battery_status(event_info, &status); + Dali::DeviceStatus::Battery::Status result = AppCore::GetBatteryStatus(status); + observer->OnBatteryLow(result); + } + + static void OnLowMemory(app_event_info_h event_info, void* user_data) + { + auto* context = static_cast(user_data); + auto* framework = context->mFramework; + Observer* observer = &framework->mObserver; + + app_event_low_memory_status_e status; + app_event_get_low_memory_status(event_info, &status); + Dali::DeviceStatus::Memory::Status result = AppCore::GetMemoryStatus(status); + observer->OnMemoryLow(result); + } + + void ProcessBundle(Framework* framework, bundle* bundleData) + { + if(bundleData == nullptr) + { + return; + } + + // get bundle name + char* bundleName = const_cast(bundle_get_val(bundleData, "name")); + if(bundleName != nullptr) + { + framework->SetBundleName(bundleName); + } + + // get bundle? id + char* bundleId = const_cast(bundle_get_val(bundleData, "id")); + if(bundleId != nullptr) + { + framework->SetBundleId(bundleId); + } + } + + private: + Framework* mFramework; + std::shared_ptr mLanguageChanged; + std::shared_ptr mDeviceOrientationChanged; + std::shared_ptr mRegionFormatChanged; + std::shared_ptr mLowBattery; + std::shared_ptr mLowMemory; + }; + // Constructor Impl(void* data, Type type) : mAbortCallBack(NULL), @@ -209,6 +486,7 @@ struct Framework::Impl int AppMain() { + // TODO: The app-core-cpp has to be applied to the other app types. int ret; switch(mApplicationType) { @@ -316,49 +594,14 @@ struct Framework::Impl std::string mLanguage{}; std::string mRegion{}; - Framework* mFramework; - AppCore::AppEventHandlerPtr handlers[5]; + Framework* mFramework; + AppCore::AppEventHandlerPtr handlers[5]; + std::unique_ptr mUiAppContext; #ifdef APPCORE_WATCH_AVAILABLE watch_app_lifecycle_callback_s mWatchCallback; app_event_handler_h watchHandlers[5]; #endif - static int AppCreate(void* data) - { - appcore_ui_base_on_create(); - return static_cast(static_cast(data)->Create()); - } - - static int AppTerminate(void* data) - { - appcore_ui_base_on_terminate(); - Observer* observer = &static_cast(data)->mObserver; - - observer->OnTerminate(); - - return 0; - } - - static int AppPause(void* data) - { - appcore_ui_base_on_pause(); - Observer* observer = &static_cast(data)->mObserver; - - observer->OnPause(); - - return 0; - } - - static int AppResume(void* data) - { - appcore_ui_base_on_resume(); - Observer* observer = &static_cast(data)->mObserver; - - observer->OnResume(); - - return 0; - } - static void ProcessBundle(Framework* framework, bundle* bundleData) { if(bundleData == NULL) @@ -381,53 +624,19 @@ struct Framework::Impl } } - /** - * Called by AppCore when the application is launched from another module (e.g. homescreen). - * @param[in] b the bundle data which the launcher module sent - */ - static int AppControl(bundle* bundleData, void* data) - { - app_control_h appControl = NULL; - - appcore_ui_base_on_control(bundleData); - - if(bundleData) - { - if(app_control_create_event(bundleData, &appControl) != TIZEN_ERROR_NONE) - { - DALI_LOG_ERROR("Failed to create an app_control handle"); - } - } - else - { - if(app_control_create(&appControl) != TIZEN_ERROR_NONE) - { - DALI_LOG_ERROR("Failed to create an app_control handle"); - } - } - - Framework* framework = static_cast(data); - Observer* observer = &framework->mObserver; - - ProcessBundle(framework, bundleData); - - observer->OnReset(); - observer->OnAppControl(appControl); - - app_control_destroy(appControl); - - return 0; - } - static void AppInit(int argc, char** argv, void* data) { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wold-style-cast" - ecore_init(); ecore_app_args_set(argc, (const char**)argv); - #pragma GCC diagnostic pop + +#ifdef DALI_ELDBUS_AVAILABLE + // Initialize ElDBus. + DALI_LOG_INFO(gDBusLogging, Debug::General, "Starting DBus Initialization\n"); + eldbus_init(); +#endif } static void AppFinish(void) @@ -439,6 +648,12 @@ struct Framework::Impl setenv("AUL_LOADER_INIT", "0", 1); ecore_shutdown(); } + +#ifdef DALI_ELDBUS_AVAILABLE + // Shutdown ELDBus. + DALI_LOG_INFO(gDBusLogging, Debug::General, "Shutting down DBus\n"); + eldbus_shutdown(); +#endif } static void AppRun(void* data) @@ -544,40 +759,29 @@ struct Framework::Impl int AppNormalMain() { - int ret; - - AppCore::AppAddEventHandler(&handlers[AppCore::LOW_BATTERY], AppCore::LOW_BATTERY, AppBatteryLow, mFramework); - AppCore::AppAddEventHandler(&handlers[AppCore::LOW_MEMORY], AppCore::LOW_MEMORY, AppMemoryLow, mFramework); - AppCore::AppAddEventHandler(&handlers[AppCore::DEVICE_ORIENTATION_CHANGED], AppCore::DEVICE_ORIENTATION_CHANGED, AppDeviceRotated, mFramework); - AppCore::AppAddEventHandler(&handlers[AppCore::LANGUAGE_CHANGED], AppCore::LANGUAGE_CHANGED, AppLanguageChanged, mFramework); - AppCore::AppAddEventHandler(&handlers[AppCore::REGION_FORMAT_CHANGED], AppCore::REGION_FORMAT_CHANGED, AppRegionChanged, mFramework); - - appcore_ui_base_ops ops = appcore_ui_base_get_default_ops(); - - /* override methods */ - ops.base.create = AppCreate; - ops.base.control = AppControl; - ops.base.terminate = AppTerminate; - ops.pause = AppPause; - ops.resume = AppResume; - ops.base.init = AppInit; - ops.base.finish = AppFinish; - ops.base.run = AppRun; - ops.base.exit = AppExit; - - ret = appcore_ui_base_init(ops, *mFramework->mArgc, *mFramework->mArgv, mFramework, APPCORE_UI_BASE_HINT_WINDOW_GROUP_CONTROL | APPCORE_UI_BASE_HINT_WINDOW_STACK_CONTROL | APPCORE_UI_BASE_HINT_BG_LAUNCH_CONTROL | APPCORE_UI_BASE_HINT_HW_ACC_CONTROL | APPCORE_UI_BASE_HINT_WINDOW_AUTO_CONTROL); - - if(ret != TIZEN_ERROR_NONE) - return ret; + if(mUiAppContext.get() == nullptr) + { + unsigned int hint = AppCoreUiBase::HINT_WINDOW_GROUP_CONTROL | + AppCoreUiBase::HINT_WINDOW_STACK_CONTROL | + AppCoreUiBase::HINT_BG_LAUNCH_CONTROL | + AppCoreUiBase::HINT_HW_ACC_CONTROL | + AppCoreUiBase::HINT_WINDOW_AUTO_CONTROL; - appcore_ui_base_fini(); + mUiAppContext = std::make_unique(hint, mFramework); + } + mUiAppContext->Run(*mFramework->mArgc, *mFramework->mArgv); return TIZEN_ERROR_NONE; } void AppNormalExit() { - appcore_ui_base_exit(); + if(mUiAppContext.get() == nullptr) + { + return; + } + + mUiAppContext->Exit(); } void AppWidgetExit() @@ -803,11 +1007,7 @@ Framework::Framework(Framework::Observer& observer, int* argc, char*** argv, Typ { set_last_result(TIZEN_ERROR_NOT_SUPPORTED); } -#ifdef DALI_ELDBUS_AVAILABLE - // Initialize ElDBus. - DALI_LOG_INFO(gDBusLogging, Debug::General, "Starting DBus Initialization\n"); - eldbus_init(); -#endif + InitThreads(); mImpl = new Impl(this, type); @@ -820,12 +1020,6 @@ Framework::~Framework() Quit(); } -#ifdef DALI_ELDBUS_AVAILABLE - // Shutdown ELDBus. - DALI_LOG_INFO(gDBusLogging, Debug::General, "Shutting down DBus\n"); - eldbus_shutdown(); -#endif - delete mImpl; } @@ -906,7 +1100,7 @@ std::string Framework::GetResourcePath() resourcePath += "/"; } -#endif //TIZEN_PLATFORM_CONFIG_SUPPORTED +#endif // TIZEN_PLATFORM_CONFIG_SUPPORTED return resourcePath; } diff --git a/packaging/dali-adaptor.spec b/packaging/dali-adaptor.spec index 144b9f6..fb762c6 100644 --- a/packaging/dali-adaptor.spec +++ b/packaging/dali-adaptor.spec @@ -95,7 +95,7 @@ BuildRequires: pkgconfig(ecore-wayland) BuildRequires: pkgconfig(libtbm) # for the adaptor -BuildRequires: pkgconfig(appcore-ui) +BuildRequires: pkgconfig(app-core-ui-cpp) BuildRequires: pkgconfig(appcore-widget-base) BuildRequires: pkgconfig(bundle) BuildRequires: pkgconfig(capi-appfw-app-common) -- 2.7.4