From ae37a5866286d97378c956ff9b55efb0e8c565e8 Mon Sep 17 00:00:00 2001 From: "minho.sun" Date: Fri, 8 Sep 2017 16:02:29 +0900 Subject: [PATCH] Enhance application device signal Currently, DALi developer cannot get any information about device events like LanguageChangedSignal. To make user can use these kind of signals fully, 1) Add Language / Region information getter api. - api : GetLanguage() / GetRegion() 2) Add new signal type and new signal for Battery / Memory status. - signal type : LowBatterySignalType / LowMemorySignalType - signal : LowBatterySignal / LowMemorySignalType - enum : BatteryStatus / MemoryStatus Change-Id: I86db387985d37013d44d9641aaca4848c00bdd2d Signed-off-by: minho.sun --- adaptors/common/application-impl.cpp | 23 +++-- adaptors/common/application-impl.h | 75 ++++++++++------ adaptors/common/framework.h | 9 +- .../adaptor-framework/application-devel.cpp | 20 +++++ .../adaptor-framework/application-devel.h | 82 +++++++++++++++++ .../adaptor-framework/application.h | 8 +- adaptors/tizen/framework-tizen-3.cpp | 12 +-- adaptors/tizen/framework-tizen.cpp | 90 +++++++++++-------- adaptors/ubuntu/framework-ubuntu.cpp | 2 +- 9 files changed, 236 insertions(+), 85 deletions(-) diff --git a/adaptors/common/application-impl.cpp b/adaptors/common/application-impl.cpp index 5e73d5e87..c44cdfb3e 100644 --- a/adaptors/common/application-impl.cpp +++ b/adaptors/common/application-impl.cpp @@ -326,31 +326,34 @@ void Application::OnAppControl(void *data) mAppControlSignal.Emit( application , data ); } -void Application::OnLanguageChanged() +void Application::OnLanguageChanged( const std::string& language ) { + mLanguage = language; DoLanguageChange(); Dali::Application application(this); mLanguageChangedSignal.Emit( application ); } -void Application::OnRegionChanged() +void Application::OnRegionChanged( const std::string& region ) { + mRegion = region; Dali::Application application(this); mRegionChangedSignal.Emit( application ); } -void Application::OnBatteryLow() +void Application::OnBatteryLow( Dali::DevelApplication::BatteryStatus::Type status ) { Dali::Application application(this); mBatteryLowSignal.Emit( application ); + mLowBatterySignal.Emit( status ); } -void Application::OnMemoryLow() +void Application::OnMemoryLow( Dali::DevelApplication::MemoryStatus::Type status ) { Dali::Application application(this); mMemoryLowSignal.Emit( application ); + mLowMemorySignal.Emit( status ); } - void Application::OnResize(Dali::Adaptor& adaptor) { Dali::Application application(this); @@ -362,6 +365,16 @@ bool Application::AddIdle( CallbackBase* callback ) return mAdaptor->AddIdle( callback ); } +std::string Application::GetRegion() +{ + return mRegion; +} + +std::string Application::GetLanguage() +{ + return mLanguage; +} + Dali::Adaptor& Application::GetAdaptor() { return *mAdaptor; diff --git a/adaptors/common/application-impl.h b/adaptors/common/application-impl.h index 621facce5..b7e4bb262 100644 --- a/adaptors/common/application-impl.h +++ b/adaptors/common/application-impl.h @@ -24,6 +24,7 @@ // INTERNAL INCLUDES #include +#include #include #include @@ -124,6 +125,16 @@ public: */ Dali::Window GetWindow(); + /** + * @copydoc Dali::DevelApplication::GetRegion(); + */ + std::string GetRegion(); + + /** + * @copydoc Dali::DevelApplication::GetLanguage(); + */ + std::string GetLanguage(); + /** * @copydoc Dali::Application::ReplaceWindow(); */ @@ -231,22 +242,22 @@ public: // From Framework::Observer /** * Called when the framework informs the application that the language of the device has changed. */ - virtual void OnLanguageChanged(); + virtual void OnLanguageChanged( const std::string& language ); /** * Called when the framework informs the application that the region of the device has changed. */ - virtual void OnRegionChanged(); + virtual void OnRegionChanged( const std::string& region ); /** * Called when the framework informs the application that the battery level of the device is low. */ - virtual void OnBatteryLow(); + virtual void OnBatteryLow( Dali::DevelApplication::BatteryStatus::Type status ); /** * Called when the framework informs the application that the memory level of the device is low. */ - virtual void OnMemoryLow(); + virtual void OnMemoryLow( Dali::DevelApplication::MemoryStatus::Type status ); public: @@ -320,6 +331,16 @@ public: // Signals */ Dali::Application::AppSignalType& MemoryLowSignal() { return mMemoryLowSignal; } + /** + * @copydoc Dali::DevelApplication::LowBatterySignal() + */ + Dali::DevelApplication::LowBatterySignalType& LowBatterySignal() { return mLowBatterySignal; } + + /** + * @copydoc Dali::DevelApplication:::LowMemorySignal() + */ + Dali::DevelApplication::LowMemorySignalType& LowMemorySignal() { return mLowMemorySignal; } + protected: /** @@ -360,17 +381,19 @@ protected: private: - AppSignalType mInitSignal; - AppSignalType mTerminateSignal; - AppSignalType mPauseSignal; - AppSignalType mResumeSignal; - AppSignalType mResetSignal; - AppSignalType mResizeSignal; - AppControlSignalType mAppControlSignal; - AppSignalType mLanguageChangedSignal; - AppSignalType mRegionChangedSignal; - AppSignalType mBatteryLowSignal; - AppSignalType mMemoryLowSignal; + AppSignalType mInitSignal; + AppSignalType mTerminateSignal; + AppSignalType mPauseSignal; + AppSignalType mResumeSignal; + AppSignalType mResetSignal; + AppSignalType mResizeSignal; + AppControlSignalType mAppControlSignal; + AppSignalType mLanguageChangedSignal; + AppSignalType mRegionChangedSignal; + AppSignalType mBatteryLowSignal; + AppSignalType mMemoryLowSignal; + Dali::DevelApplication::LowBatterySignalType mLowBatterySignal; + Dali::DevelApplication::LowMemorySignalType mLowMemorySignal; EventLoop* mEventLoop; Framework* mFramework; @@ -378,16 +401,18 @@ private: Dali::Configuration::ContextLoss mContextLossConfiguration; CommandLineOptions* mCommandLineOptions; - Dali::SingletonService mSingletonService; - Dali::Adaptor* mAdaptor; - Dali::Window mWindow; - Dali::Application::WINDOW_MODE mWindowMode; - std::string mName; - std::string mStylesheet; - EnvironmentOptions mEnvironmentOptions; - PositionSize mWindowPositionSize; - Launchpad::State mLaunchpadState; - bool mUseRemoteSurface; + Dali::SingletonService mSingletonService; + Dali::Adaptor* mAdaptor; + Dali::Window mWindow; + Dali::Application::WINDOW_MODE mWindowMode; + std::string mName; + std::string mStylesheet; + std::string mLanguage; + std::string mRegion; + EnvironmentOptions mEnvironmentOptions; + PositionSize mWindowPositionSize; + Launchpad::State mLaunchpadState; + bool mUseRemoteSurface; SlotDelegate< Application > mSlotDelegate; diff --git a/adaptors/common/framework.h b/adaptors/common/framework.h index 36115f226..7dcbdbc0e 100644 --- a/adaptors/common/framework.h +++ b/adaptors/common/framework.h @@ -20,6 +20,7 @@ // EXTERNAL INCLUDES #include +#include #include #ifdef APPCORE_WATCH_AVAILABLE #include "wearable/watch/watch-application.h" @@ -113,22 +114,22 @@ public: /** * Invoked when the language of the device is changed. */ - virtual void OnLanguageChanged() {} + virtual void OnLanguageChanged( const std::string& language ) {} /** * Invoked when the region is changed. */ - virtual void OnRegionChanged() {} + virtual void OnRegionChanged( const std::string& region ) {} /** * Invoked when the battery level of the device is low. */ - virtual void OnBatteryLow() {} + virtual void OnBatteryLow( Dali::DevelApplication::BatteryStatus::Type status ) {} /** * Invoked when the memory level of the device is low. */ - virtual void OnMemoryLow() {} + virtual void OnMemoryLow( Dali::DevelApplication::MemoryStatus::Type status ) {} }; public: diff --git a/adaptors/devel-api/adaptor-framework/application-devel.cpp b/adaptors/devel-api/adaptor-framework/application-devel.cpp index 51b379ce3..c59735445 100644 --- a/adaptors/devel-api/adaptor-framework/application-devel.cpp +++ b/adaptors/devel-api/adaptor-framework/application-devel.cpp @@ -55,6 +55,26 @@ void PreInitialize( int* argc, char** argv[] ) Internal::Adaptor::Application::PreInitialize( argc, argv ); } +std::string GetRegion( Application application ) +{ + return Internal::Adaptor::GetImplementation( application ).GetRegion(); +} + +std::string GetLanguage( Application application ) +{ + return Internal::Adaptor::GetImplementation( application ).GetLanguage(); +} + +LowBatterySignalType& LowBatterySignal( Application application ) +{ + return Internal::Adaptor::GetImplementation( application ).LowBatterySignal(); +} + +LowMemorySignalType& LowMemorySignal( Application application ) +{ + return Internal::Adaptor::GetImplementation( application ).LowMemorySignal(); +} + } // namespace DevelApplication } // namespace Dali diff --git a/adaptors/devel-api/adaptor-framework/application-devel.h b/adaptors/devel-api/adaptor-framework/application-devel.h index d29c48781..76e1c830e 100644 --- a/adaptors/devel-api/adaptor-framework/application-devel.h +++ b/adaptors/devel-api/adaptor-framework/application-devel.h @@ -31,6 +31,59 @@ namespace Dali namespace DevelApplication { +/* + * @brief An enum of memory status. + */ +struct MemoryStatus +{ + enum Type + { + /* + * Normal status. + */ + NORMAL, + + /* + * Soft warning status. + */ + SOFT_WARNING, + + /* + * Hard warning status. + */ + HARD_WARNING + }; +}; + +/* + * @brief An enum of battery status. + */ +struct BatteryStatus +{ + enum Type + { + /* + * Normal status. + * Battery status is over 5%. + */ + NORMAL, + + /* + * Battery status is under 5%. + */ + CRITICAL_LOW, + + /* + * Device can be turned off anytime. + * Battery status is under 1%. + */ + POWER_OFF + }; +}; + +typedef Signal< void (BatteryStatus::Type) > LowBatterySignalType; +typedef Signal< void (MemoryStatus::Type) > LowMemorySignalType; + /** * @brief This is the constructor for applications. * @@ -55,6 +108,35 @@ DALI_IMPORT_API Application New( int* argc, char **argv[], const std::string& st */ DALI_IMPORT_API void PreInitialize( int* argc, char** argv[] ); +/** + * @brief This is used to get region information from device. + * + * @return Region information + */ +DALI_IMPORT_API std::string GetRegion( Application application ); + +/** + * @brief This is used to get language information from device. + * + * @return Language information + */ +DALI_IMPORT_API std::string GetLanguage( Application application ); + +/** + * @brief This signal is emitted when the battery level of the device is low. + * @SINCE_1_0.0 + * @return The signal to connect to + */ +DALI_IMPORT_API LowBatterySignalType& LowBatterySignal( Application application ); + +/** + * @brief This signal is emitted when the memory level of the device is low. + * @SINCE_1_0.0 + * @return The signal to connect to + */ +DALI_IMPORT_API LowMemorySignalType& LowMemorySignal( Application application ); + + } // namespace DevelApplication } // namespace Dali diff --git a/adaptors/public-api/adaptor-framework/application.h b/adaptors/public-api/adaptor-framework/application.h index 9e215c982..d36416ba1 100644 --- a/adaptors/public-api/adaptor-framework/application.h +++ b/adaptors/public-api/adaptor-framework/application.h @@ -108,6 +108,7 @@ class DALI_IMPORT_API Application : public BaseHandle { public: + typedef Signal< void (Application&) > AppSignalType; ///< Application lifecycle signal and system signal callback type @SINCE_1_0.0 typedef Signal< void (Application&, void *) > AppControlSignalType; ///< Application control signal callback type @SINCE_1_0.0 @@ -284,7 +285,6 @@ public: */ static std::string GetResourcePath(); - public: // Stereoscopy /** @@ -393,18 +393,20 @@ public: // Signals AppSignalType& RegionChangedSignal(); /** + * @DEPRECATED_1_2.58 Use LowBatterySignal() instead. * @brief This signal is emitted when the battery level of the device is low. * @SINCE_1_0.0 * @return The signal to connect to */ - AppSignalType& BatteryLowSignal(); + AppSignalType& BatteryLowSignal() DALI_DEPRECATED_API; /** + * @DEPRECATED_1_2.58 Use LowMemorySignal() instead. * @brief This signal is emitted when the memory level of the device is low. * @SINCE_1_0.0 * @return The signal to connect to */ - AppSignalType& MemoryLowSignal(); + AppSignalType& MemoryLowSignal() DALI_DEPRECATED_API; public: // Not intended for application developers /// @cond internal diff --git a/adaptors/tizen/framework-tizen-3.cpp b/adaptors/tizen/framework-tizen-3.cpp index aeb25c59d..be71dffcf 100644 --- a/adaptors/tizen/framework-tizen-3.cpp +++ b/adaptors/tizen/framework-tizen-3.cpp @@ -291,8 +291,7 @@ struct Framework::Impl static void AppLanguageChanged(app_event_info_h event, void *data) { Observer *observer = &static_cast(data)->mObserver; - - observer->OnLanguageChanged(); + observer->OnLanguageChanged(""); } static void AppDeviceRotated(app_event_info_h event_info, void *data) @@ -302,22 +301,19 @@ struct Framework::Impl static void AppRegionChanged(app_event_info_h event, void *data) { Observer *observer = &static_cast(data)->mObserver; - - observer->OnRegionChanged(); + observer->OnRegionChanged(""); } static void AppBatteryLow(app_event_info_h event, void *data) { Observer *observer = &static_cast(data)->mObserver; - - observer->OnBatteryLow(); + observer->OnBatteryLow(Dali::DevelApplication::BatteryStatus::NORMAL); } static void AppMemoryLow(app_event_info_h event, void *data) { Observer *observer = &static_cast(data)->mObserver; - - observer->OnMemoryLow(); + observer->OnMemoryLow(Dali::DevelApplication::MemoryStatus::NORMAL); } private: diff --git a/adaptors/tizen/framework-tizen.cpp b/adaptors/tizen/framework-tizen.cpp index 013435a7e..7ff0c3292 100644 --- a/adaptors/tizen/framework-tizen.cpp +++ b/adaptors/tizen/framework-tizen.cpp @@ -383,8 +383,8 @@ struct Framework::Impl static void AppLanguageChanged(AppCore::AppEventInfoPtr event, void *data) { Observer *observer = &static_cast(data)->mObserver; - - observer->OnLanguageChanged(); + std::string language( static_cast(event->value) ); + observer->OnLanguageChanged(language); } static void AppDeviceRotated(AppCore::AppEventInfoPtr event_info, void *data) @@ -394,22 +394,62 @@ struct Framework::Impl static void AppRegionChanged(AppCore::AppEventInfoPtr event, void *data) { Observer *observer = &static_cast(data)->mObserver; - - observer->OnRegionChanged(); + std::string region( static_cast(event->value) ); + observer->OnRegionChanged(region); } static void AppBatteryLow(AppCore::AppEventInfoPtr event, void *data) { Observer *observer = &static_cast(data)->mObserver; + int status = *static_cast(event->value); + Dali::DevelApplication::BatteryStatus::Type result = Dali::DevelApplication::BatteryStatus::NORMAL; - observer->OnBatteryLow(); + // convert to dali battery status + switch( status ) + { + case 1: + { + result = Dali::DevelApplication::BatteryStatus::POWER_OFF; + break; + } + case 2: + { + result = Dali::DevelApplication::BatteryStatus::CRITICAL_LOW; + break; + } + default : + break; + } + observer->OnBatteryLow(result); } static void AppMemoryLow(AppCore::AppEventInfoPtr event, void *data) { Observer *observer = &static_cast(data)->mObserver; - - observer->OnMemoryLow(); + int status = *static_cast(event->value); + Dali::DevelApplication::MemoryStatus::Type result = Dali::DevelApplication::MemoryStatus::NORMAL; + // convert to dali memmory status + switch( status ) + { + case 1: + { + result = Dali::DevelApplication::MemoryStatus::NORMAL; + break; + } + case 2: + { + result = Dali::DevelApplication::MemoryStatus::SOFT_WARNING; + break; + } + case 4: + { + result = Dali::DevelApplication::MemoryStatus::HARD_WARNING; + break; + } + default : + break; + } + observer->OnMemoryLow(result); } @@ -1097,34 +1137,6 @@ struct Framework::Impl observer->OnAmbientChanged(ambient); } - static void WatchAppLanguageChanged(app_event_info_h event, void *data) - { - Observer *observer = &static_cast(data)->mObserver; - - observer->OnLanguageChanged(); - } - - static void WatchAppRegionChanged(app_event_info_h event, void *data) - { - Observer *observer = &static_cast(data)->mObserver; - - observer->OnRegionChanged(); - } - - static void WatchAppBatteryLow(app_event_info_h event, void *data) - { - Observer *observer = &static_cast(data)->mObserver; - - observer->OnBatteryLow(); - } - - static void WatchAppMemoryLow(app_event_info_h event, void *data) - { - Observer *observer = &static_cast(data)->mObserver; - - observer->OnMemoryLow(); - } - static void WatchAppControl(app_control_h app_control, void *data) { Framework* framework = static_cast(data); @@ -1174,10 +1186,10 @@ struct Framework::Impl mWatchCallback.ambient_tick = WatchAppAmbientTick; mWatchCallback.ambient_changed = WatchAppAmbientChanged; - watch_app_add_event_handler(&watchHandlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, WatchAppBatteryLow, mFramework); - watch_app_add_event_handler(&watchHandlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, WatchAppMemoryLow, mFramework); - watch_app_add_event_handler(&watchHandlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, WatchAppLanguageChanged, mFramework); - watch_app_add_event_handler(&watchHandlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, WatchAppRegionChanged, mFramework); + 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::LANGUAGE_CHANGED], AppCore::LANGUAGE_CHANGED, AppLanguageChanged, mFramework); + AppCore::AppAddEventHandler(&handlers[AppCore::REGION_FORMAT_CHANGED], AppCore::REGION_FORMAT_CHANGED, AppRegionChanged, mFramework); ret = watch_app_main(*mFramework->mArgc, *mFramework->mArgv, &mWatchCallback, mFramework); #endif diff --git a/adaptors/ubuntu/framework-ubuntu.cpp b/adaptors/ubuntu/framework-ubuntu.cpp index 22203ccba..1df4c3d88 100644 --- a/adaptors/ubuntu/framework-ubuntu.cpp +++ b/adaptors/ubuntu/framework-ubuntu.cpp @@ -255,7 +255,7 @@ bool Framework::AppStatusHandler(int type, void *bundleData) break; case APP_LANGUAGE_CHANGE: - mObserver.OnLanguageChanged(); + mObserver.OnLanguageChanged(""); break; default: -- 2.34.1