[4.0] Enhance application device signal 45/153345/1
authorJinho, Lee <jeano.lee@samsung.com>
Thu, 28 Sep 2017 08:12:02 +0000 (17:12 +0900)
committerJinho, Lee <jeano.lee@samsung.com>
Thu, 28 Sep 2017 08:51:22 +0000 (17:51 +0900)
This reverts commit e9fe045a302d16a1372317c7ec7ff77ff25fcefc.

Change-Id: I19862a56c40922806f60c1bc711c5f9d25d9211e

adaptors/common/application-impl.cpp
adaptors/common/application-impl.h
adaptors/common/framework.h
adaptors/devel-api/adaptor-framework/application-devel.cpp
adaptors/devel-api/adaptor-framework/application-devel.h
adaptors/public-api/adaptor-framework/application.h
adaptors/tizen/framework-tizen-3.cpp
adaptors/tizen/framework-tizen.cpp
adaptors/ubuntu/framework-ubuntu.cpp

index 5e73d5e..c44cdfb 100644 (file)
@@ -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;
index 621facc..b7e4bb2 100644 (file)
@@ -24,6 +24,7 @@
 
 // INTERNAL INCLUDES
 #include <application.h>
+#include <application-devel.h>
 #include <singleton-service.h>
 
 #include <framework.h>
@@ -125,6 +126,16 @@ public:
   Dali::Window GetWindow();
 
   /**
+   * @copydoc Dali::DevelApplication::GetRegion();
+   */
+  std::string GetRegion();
+
+  /**
+   * @copydoc Dali::DevelApplication::GetLanguage();
+   */
+  std::string GetLanguage();
+
+  /**
    * @copydoc Dali::Application::ReplaceWindow();
    */
   void ReplaceWindow( const PositionSize& positionSize, const std::string& name);
@@ -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;
 
index 36115f2..7dcbdbc 100644 (file)
@@ -20,6 +20,7 @@
 
 // EXTERNAL INCLUDES
 #include <string>
+#include <application-devel.h>
 #include <dali/public-api/signals/callback.h>
 #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:
index 51b379c..c597354 100644 (file)
@@ -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
index d29c487..76e1c83 100644 (file)
@@ -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
index 9e215c9..d36416b 100644 (file)
@@ -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
index aeb25c5..be71dff 100644 (file)
@@ -291,8 +291,7 @@ struct Framework::Impl
   static void AppLanguageChanged(app_event_info_h event, void *data)
   {
     Observer *observer = &static_cast<Framework*>(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<Framework*>(data)->mObserver;
-
-    observer->OnRegionChanged();
+    observer->OnRegionChanged("");
   }
 
   static void AppBatteryLow(app_event_info_h event, void *data)
   {
     Observer *observer = &static_cast<Framework*>(data)->mObserver;
-
-    observer->OnBatteryLow();
+    observer->OnBatteryLow(Dali::DevelApplication::BatteryStatus::NORMAL);
   }
 
   static void AppMemoryLow(app_event_info_h event, void *data)
   {
     Observer *observer = &static_cast<Framework*>(data)->mObserver;
-
-    observer->OnMemoryLow();
+    observer->OnMemoryLow(Dali::DevelApplication::MemoryStatus::NORMAL);
   }
 
 private:
index 013435a..7ff0c32 100644 (file)
@@ -383,8 +383,8 @@ struct Framework::Impl
   static void AppLanguageChanged(AppCore::AppEventInfoPtr event, void *data)
   {
     Observer *observer = &static_cast<Framework*>(data)->mObserver;
-
-    observer->OnLanguageChanged();
+    std::string language( static_cast<const char *>(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<Framework*>(data)->mObserver;
-
-    observer->OnRegionChanged();
+    std::string region( static_cast<const char *>(event->value) );
+    observer->OnRegionChanged(region);
   }
 
   static void AppBatteryLow(AppCore::AppEventInfoPtr event, void *data)
   {
     Observer *observer = &static_cast<Framework*>(data)->mObserver;
+    int status = *static_cast<int *>(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<Framework*>(data)->mObserver;
-
-    observer->OnMemoryLow();
+    int status = *static_cast<int *>(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<Framework*>(data)->mObserver;
-
-    observer->OnLanguageChanged();
-  }
-
-  static void WatchAppRegionChanged(app_event_info_h event, void *data)
-  {
-    Observer *observer = &static_cast<Framework*>(data)->mObserver;
-
-    observer->OnRegionChanged();
-  }
-
-  static void WatchAppBatteryLow(app_event_info_h event, void *data)
-  {
-    Observer *observer = &static_cast<Framework*>(data)->mObserver;
-
-    observer->OnBatteryLow();
-  }
-
-  static void WatchAppMemoryLow(app_event_info_h event, void *data)
-  {
-    Observer *observer = &static_cast<Framework*>(data)->mObserver;
-
-    observer->OnMemoryLow();
-  }
-
   static void WatchAppControl(app_control_h app_control, void *data)
   {
     Framework* framework = static_cast<Framework*>(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
index 22203cc..1df4c3d 100644 (file)
@@ -255,7 +255,7 @@ bool Framework::AppStatusHandler(int type, void *bundleData)
       break;
 
     case APP_LANGUAGE_CHANGE:
-      mObserver.OnLanguageChanged();
+      mObserver.OnLanguageChanged("");
       break;
 
     default: