Removed singletons from the type registry 07/57507/2
authorDavid Steele <david.steele@samsung.com>
Wed, 20 Jan 2016 13:04:46 +0000 (13:04 +0000)
committerDavid Steele <david.steele@samsung.com>
Wed, 20 Jan 2016 14:34:32 +0000 (14:34 +0000)
The type registry creation order is dependent on library load order, so it's possible for dali toolkit singletons to be created before adaptor singletons.

Have changed all adaptor singletons to register with the singleton
service in the Get() method, and removed unnecessary type registry
entries for them. Thus, they will be created when first required,
rather than when the type registry tries to create them.

Change-Id: I36281d86f5c769a05feb6c074b55375ddea9359b
Signed-off-by: David Steele <david.steele@samsung.com>
15 files changed:
adaptors/common/clipboard-event-notifier-impl.cpp
adaptors/common/lifecycle-controller-impl.cpp
adaptors/common/style-monitor-impl.cpp
adaptors/ecore/wayland/clipboard-impl-ecore-wl.cpp
adaptors/ecore/wayland/imf-manager-impl-ecore-wl.cpp
adaptors/mobile/accessibility-adaptor-impl-mobile.cpp
adaptors/mobile/mobile-color-controller-impl.cpp
adaptors/tizen/accessibility-adaptor-impl-tizen.cpp
adaptors/tizen/tts-player-impl-tizen.cpp
adaptors/ubuntu/accessibility-adaptor-impl-ubuntu.cpp
adaptors/ubuntu/tts-player-impl-ubuntu.cpp
adaptors/wayland/clipboard/clipboard-impl-wl.cpp
adaptors/wayland/imf/imf-manager-impl-wl.cpp
adaptors/x11/clipboard-impl-x.cpp
adaptors/x11/imf-manager-impl-x.cpp

index 981ac46..ffd6a14 100644 (file)
@@ -33,29 +33,6 @@ namespace Internal
 namespace Adaptor
 {
 
-namespace
-{
-BaseHandle Create()
-{
-  BaseHandle handle( ClipboardEventNotifier::Get() );
-
-  if ( !handle )
-  {
-    Dali::SingletonService service( SingletonService::Get() );
-    if ( service )
-    {
-      Dali::ClipboardEventNotifier notifier( ClipboardEventNotifier::New() );
-      service.Register( typeid( notifier ), notifier );
-      handle = notifier;
-    }
-  }
-
-  return handle;
-}
-TypeRegistration CLIPBOARD_EVENT_NOTIFIER_TYPE( typeid(Dali::ClipboardEventNotifier), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
-
-} // unnamed namespace
-
 Dali::ClipboardEventNotifier ClipboardEventNotifier::New()
 {
   Dali::ClipboardEventNotifier notifier = Dali::ClipboardEventNotifier(new ClipboardEventNotifier());
@@ -77,6 +54,11 @@ Dali::ClipboardEventNotifier ClipboardEventNotifier::Get()
       // If so, downcast the handle
       notifier = Dali::ClipboardEventNotifier( dynamic_cast< ClipboardEventNotifier* >( handle.GetObjectPtr() ) );
     }
+    else
+    {
+      notifier = Dali::ClipboardEventNotifier( ClipboardEventNotifier::New() );
+      service.Register( typeid( notifier ), notifier );
+    }
   }
 
   return notifier;
index 52b6c13..954a5f2 100644 (file)
@@ -34,30 +34,6 @@ namespace Internal
 namespace Adaptor
 {
 
-namespace
-{
-
-BaseHandle Create()
-{
-  BaseHandle handle( LifecycleController::Get() );
-
-  if ( !handle && Adaptor::IsAvailable() )
-  {
-    Dali::SingletonService service( SingletonService::Get() );
-    if ( service )
-    {
-      Dali::LifecycleController lifecycleController = Dali::LifecycleController( new LifecycleController() );
-      service.Register( typeid( lifecycleController ), lifecycleController );
-      handle = lifecycleController;
-    }
-  }
-
-  return handle;
-}
-TypeRegistration LIFECYCLE_CONTROLLER_TYPE( typeid(Dali::LifecycleController), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
-
-} // unnamed namespace
-
 Dali::LifecycleController LifecycleController::Get()
 {
   Dali::LifecycleController lifecycleController;
index df06e2f..ca9ec8f 100644 (file)
@@ -44,26 +44,6 @@ namespace
 Dali::Integration::Log::Filter* gLogFilter = Dali::Integration::Log::Filter::New(Debug::NoLogging, false, "LOG_STYLE_MONITOR");
 #endif
 
-BaseHandle Create()
-{
-  BaseHandle handle( StyleMonitor::Get() );
-
-  if ( !handle && Adaptor::IsAvailable() )
-  {
-    Dali::SingletonService service( SingletonService::Get() );
-    if ( service )
-    {
-      Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );
-      Dali::StyleMonitor styleMonitor = Dali::StyleMonitor( new StyleMonitor( adaptorImpl.GetPlatformAbstraction() ) );
-      service.Register( typeid( styleMonitor ), styleMonitor );
-      handle = styleMonitor;
-    }
-  }
-
-  return handle;
-}
-TypeRegistration STYLE_MONITOR_TYPE( typeid(Dali::StyleMonitor), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
-
 /**
  * Use font client to get the system default font family
  * @param[in] fontClient handle to font client
@@ -86,15 +66,21 @@ Dali::StyleMonitor StyleMonitor::Get()
   Dali::StyleMonitor styleMonitor;
 
   Dali::SingletonService service( SingletonService::Get() );
-  if ( service )
+  if( service )
   {
     // Check whether the singleton is already created
     Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::StyleMonitor ) );
-    if(handle)
+    if( handle )
     {
       // If so, downcast the handle
       styleMonitor = Dali::StyleMonitor( dynamic_cast< StyleMonitor* >( handle.GetObjectPtr() ) );
     }
+    else
+    {
+      Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );
+      styleMonitor = Dali::StyleMonitor( new StyleMonitor( adaptorImpl.GetPlatformAbstraction() ) );
+      service.Register( typeid( styleMonitor ), styleMonitor );
+    }
   }
 
   return styleMonitor;
index 6c1ff67..cea687c 100644 (file)
@@ -53,17 +53,15 @@ namespace Internal
 namespace Adaptor
 {
 
-namespace
+struct Clipboard::Impl
 {
-BaseHandle Create()
-{
-  BaseHandle handle( Clipboard::Get() );
+  // Put implementation here.
+};
 
-  return handle;
+Clipboard::Clipboard(Impl* impl)
+: mImpl(impl)
+{
 }
-TypeRegistration CLIPBOARD_TYPE( typeid(Dali::Clipboard), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
-
-} // unnamed namespace
 
 Clipboard::~Clipboard()
 {
@@ -83,10 +81,17 @@ Dali::Clipboard Clipboard::Get()
       // If so, downcast the handle
       clipboard = Dali::Clipboard( dynamic_cast< Clipboard* >( handle.GetObjectPtr() ) );
     }
+    else
+    {
+      Clipboard::Impl* impl( new Clipboard::Impl() );
+      clipboard = Dali::Clipboard( new Clipboard(impl) );
+      service.Register( typeid(Dali::Clipboard), clipboard );
+    }
   }
 
   return clipboard;
 }
+
 bool Clipboard::SetItem(const std::string &itemData )
 {
   return true;
index 99b3a0e..8673c2c 100644 (file)
@@ -39,18 +39,6 @@ namespace Internal
 namespace Adaptor
 {
 
-namespace
-{
-
-BaseHandle Create()
-{
-  return ImfManager::Get();
-}
-
-TypeRegistration IMF_MANAGER_TYPE( typeid(Dali::ImfManager), typeid(Dali::BaseHandle), Create );
-
-} // unnamed namespace
-
 bool ImfManager::IsAvailable()
 {
   return false;
index c660087..01656e1 100644 (file)
@@ -91,16 +91,25 @@ void AccessibilityOnOffNotification(keynode_t* node, void* data)
   }
 }
 
-BaseHandle Create()
+} // unnamed namespace
+
+Dali::AccessibilityAdaptor AccessibilityAdaptor::Get()
 {
-  BaseHandle handle( AccessibilityAdaptor::Get() );
+  Dali::AccessibilityAdaptor adaptor;
 
-  if ( !handle )
+  Dali::SingletonService service( SingletonService::Get() );
+  if ( service )
   {
-    Dali::SingletonService service( SingletonService::Get() );
-    if ( service )
+    // Check whether the singleton is already created
+    Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::AccessibilityAdaptor ) );
+    if(handle)
     {
-      Dali::AccessibilityAdaptor adaptor = Dali::AccessibilityAdaptor( new AccessibilityAdaptorMobile() );
+      // If so, downcast the handle
+      adaptor = Dali::AccessibilityAdaptor( dynamic_cast< AccessibilityAdaptor* >( handle.GetObjectPtr() ) );
+    }
+    else
+    {
+      adaptor = Dali::AccessibilityAdaptor( new AccessibilityAdaptorMobile() );
       AccessibilityAdaptorMobile& adaptorImpl = AccessibilityAdaptorMobile::GetImplementation( adaptor );
 
       bool isEnabled = GetEnabledVConf();
@@ -115,30 +124,6 @@ BaseHandle Create()
       vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, AccessibilityOnOffNotification, &adaptorImpl );
 
       service.Register( typeid( adaptor ), adaptor );
-      handle = adaptor;
-    }
-  }
-
-  return handle;
-}
-
-TypeRegistration ACCESSIBILITY_ADAPTOR_TYPE( typeid(Dali::AccessibilityAdaptor), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
-
-} // unnamed namespace
-
-Dali::AccessibilityAdaptor AccessibilityAdaptor::Get()
-{
-  Dali::AccessibilityAdaptor adaptor;
-
-  Dali::SingletonService service( SingletonService::Get() );
-  if ( service )
-  {
-    // Check whether the singleton is already created
-    Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::AccessibilityAdaptor ) );
-    if(handle)
-    {
-      // If so, downcast the handle
-      adaptor = Dali::AccessibilityAdaptor( dynamic_cast< AccessibilityAdaptor* >( handle.GetObjectPtr() ) );
     }
   }
 
index 732d459..a6d97f7 100644 (file)
@@ -34,17 +34,6 @@ namespace Internal
 namespace Adaptor
 {
 
-namespace
-{
-
-BaseHandle Create()
-{
-  return ColorController::Get();
-}
-Dali::TypeRegistration COLOR_CONTROLLER_TYPE( typeid(Dali::ColorController), typeid(Dali::BaseHandle), Create );
-
-}
-
 Dali::ColorController ColorController::Get()
 {
   Dali::ColorController colorController;
index 70aa0ad..588cfae 100644 (file)
@@ -77,16 +77,25 @@ void AccessibilityOnOffNotification(keynode_t* node, void* data)
   }
 }
 
-BaseHandle Create()
+} // unnamed namespace
+
+Dali::AccessibilityAdaptor AccessibilityAdaptor::Get()
 {
-  BaseHandle handle( AccessibilityAdaptor::Get() );
+  Dali::AccessibilityAdaptor adaptor;
 
-  if ( !handle )
+  Dali::SingletonService service( SingletonService::Get() );
+  if ( service )
   {
-    Dali::SingletonService service( SingletonService::Get() );
-    if ( service )
+    // Check whether the singleton is already created
+    Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::AccessibilityAdaptor ) );
+    if(handle)
     {
-      Dali::AccessibilityAdaptor adaptor = Dali::AccessibilityAdaptor( new AccessibilityAdaptor() );
+      // If so, downcast the handle
+      adaptor = Dali::AccessibilityAdaptor( dynamic_cast< AccessibilityAdaptor* >( handle.GetObjectPtr() ) );
+    }
+    else
+    {
+      adaptor = Dali::AccessibilityAdaptor( new AccessibilityAdaptor() );
       AccessibilityAdaptor& adaptorImpl = AccessibilityAdaptor::GetImplementation( adaptor );
 
       bool isEnabled = GetEnabledVConf();
@@ -101,30 +110,6 @@ BaseHandle Create()
       vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, AccessibilityOnOffNotification, &adaptorImpl );
 
       service.Register( typeid( adaptor ), adaptor );
-      handle = adaptor;
-    }
-  }
-
-  return handle;
-}
-
-TypeRegistration ACCESSIBILITY_ADAPTOR_TYPE( typeid(Dali::AccessibilityAdaptor), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
-
-} // unnamed namespace
-
-Dali::AccessibilityAdaptor AccessibilityAdaptor::Get()
-{
-  Dali::AccessibilityAdaptor adaptor;
-
-  Dali::SingletonService service( SingletonService::Get() );
-  if ( service )
-  {
-    // Check whether the singleton is already created
-    Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::AccessibilityAdaptor ) );
-    if(handle)
-    {
-      // If so, downcast the handle
-      adaptor = Dali::AccessibilityAdaptor( dynamic_cast< AccessibilityAdaptor* >( handle.GetObjectPtr() ) );
     }
   }
 
index 976602e..9b9a2c6 100644 (file)
@@ -36,13 +36,6 @@ namespace Adaptor
 
 namespace // unnamed namespace
 {
-// Type Registration
-Dali::BaseHandle Create()
-{
-  return Dali::TtsPlayer::Get() ;
-}
-
-Dali::TypeRegistration mType( typeid(Dali::TtsPlayer), typeid(Dali::BaseHandle), Create );
 
 /**
  * Helper function to convert Tizen-specific TTS state to external state.
index c1964d7..3a3bf85 100644 (file)
@@ -33,31 +33,6 @@ namespace Internal
 namespace Adaptor
 {
 
-namespace // unnamed namespace
-{
-
-BaseHandle Create()
-{
-  BaseHandle handle( AccessibilityAdaptor::Get() );
-
-  if ( !handle )
-  {
-    Dali::SingletonService service( SingletonService::Get() );
-    if ( service )
-    {
-      Dali::AccessibilityAdaptor adaptor = Dali::AccessibilityAdaptor( new AccessibilityAdaptor() );
-      service.Register( typeid( adaptor ), adaptor );
-      handle = adaptor;
-    }
-  }
-
-  return handle;
-}
-
-TypeRegistration ACCESSIBILITY_ADAPTOR_TYPE( typeid(Dali::AccessibilityAdaptor), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
-
-} // unnamed namespace
-
 Dali::AccessibilityAdaptor AccessibilityAdaptor::Get()
 {
   Dali::AccessibilityAdaptor adaptor;
@@ -72,6 +47,11 @@ Dali::AccessibilityAdaptor AccessibilityAdaptor::Get()
       // If so, downcast the handle
       adaptor = Dali::AccessibilityAdaptor( dynamic_cast< AccessibilityAdaptor* >( handle.GetObjectPtr() ) );
     }
+    else
+    {
+      adaptor = Dali::AccessibilityAdaptor( new AccessibilityAdaptor() );
+      service.Register( typeid( adaptor ), adaptor );
+    }
   }
 
   return adaptor;
index 12e5c55..961c66a 100644 (file)
@@ -31,17 +31,6 @@ namespace Internal
 namespace Adaptor
 {
 
-namespace // unnamed namespace
-{
-// Type Registration
-Dali::BaseHandle Create()
-{
-  return Dali::TtsPlayer::Get() ;
-}
-
-Dali::TypeRegistration mType( typeid(Dali::TtsPlayer), typeid(Dali::BaseHandle), Create ) ;
-} // unnamed namespace
-
 #if defined(DEBUG_ENABLED)
 Debug::Filter* TtsPlayer::gLogFilter = Debug::Filter::New(Debug::Concise, false, "LOG_TTS_PLAYER");
 #endif
@@ -94,4 +83,3 @@ Dali::TtsPlayer::StateChangedSignalType& TtsPlayer::StateChangedSignal()
 } // namespace Internal
 
 } // namespace Dali
-
index e759770..e207e6f 100644 (file)
@@ -39,17 +39,19 @@ namespace Internal
 namespace Adaptor
 {
 
-namespace
+struct Clipboard::Impl
 {
-BaseHandle Create()
-{
-  BaseHandle handle( Clipboard::Get() );
+  Impl()
+  {
+  }
 
-  return handle;
-}
-TypeRegistration CLIPBOARD_TYPE( typeid(Dali::Clipboard), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
+  // Put implementation here.
+};
 
-} // unnamed namespace
+Clipboard::Clipboard(Impl* impl)
+: mImpl(impl)
+{
+}
 
 Clipboard::~Clipboard()
 {
@@ -69,6 +71,12 @@ Dali::Clipboard Clipboard::Get()
       // If so, downcast the handle
       clipboard = Dali::Clipboard( dynamic_cast< Clipboard* >( handle.GetObjectPtr() ) );
     }
+    else
+    {
+      Clipboard::Impl* impl( new Clipboard::Impl() );
+      clipboard = Dali::Clipboard( new Clipboard(impl) );
+      service.Register( typeid(Dali::Clipboard), clipboard );
+    }
   }
 
   return clipboard;
index f9a880c..8d5aa7a 100644 (file)
@@ -32,18 +32,6 @@ namespace Internal
 namespace Adaptor
 {
 
-namespace
-{
-
-BaseHandle Create()
-{
-  return ImfManager::Get();
-}
-
-TypeRegistration IMF_MANAGER_TYPE( typeid(Dali::ImfManager), typeid(Dali::BaseHandle), Create );
-
-} // unnamed namespace
-
 bool ImfManager::IsAvailable()
 {
   return false;
index 2915a80..2f3e14e 100644 (file)
@@ -64,48 +64,6 @@ struct Clipboard::Impl
   Ecore_X_Window mApplicationWindow;
 };
 
-namespace // unnamed namespace
-{
-
-BaseHandle Create()
-{
-  BaseHandle handle( Clipboard::Get() );
-
-  if ( !handle && Adaptor::IsAvailable() )
-  {
-    Dali::SingletonService service( SingletonService::Get() );
-    if ( service )
-    {
-      Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );
-      Any nativewindow = adaptorImpl.GetNativeWindowHandle();
-
-      // The Ecore_X_Window needs to use the Clipboard.
-      // Only when the render surface is window, we can get the Ecore_X_Window.
-      Ecore_X_Window ecoreXwin( AnyCast<Ecore_X_Window>(nativewindow) );
-      if (ecoreXwin)
-      {
-        // If we fail to get Ecore_X_Window, we can't use the Clipboard correctly.
-        // Thus you have to call "ecore_imf_context_client_window_set" somewhere.
-        // In EvasPlugIn, this function is called in EvasPlugin::ConnectEcoreEvent().
-        Clipboard::Impl* impl( new Clipboard::Impl( ecoreXwin ) );
-        Dali::Clipboard clipboard = Dali::Clipboard( new Clipboard( impl ) );
-        service.Register( typeid( clipboard ), clipboard );
-        handle = clipboard;
-      }
-      else
-      {
-        DALI_LOG_ERROR("Failed to get native window handle");
-      }
-    }
-  }
-
-  return handle;
-}
-
-TypeRegistration CLIPBOARD_TYPE( typeid(Dali::Clipboard), typeid(Dali::BaseHandle), Create, true /* Create Instance At Startup */ );
-
-} // unnamed namespace
-
 Clipboard::Clipboard(Impl* impl)
 : mImpl( impl )
 {
@@ -130,6 +88,24 @@ Dali::Clipboard Clipboard::Get()
       // If so, downcast the handle
       clipboard = Dali::Clipboard( dynamic_cast< Clipboard* >( handle.GetObjectPtr() ) );
     }
+    else
+    {
+      Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );
+      Any nativewindow = adaptorImpl.GetNativeWindowHandle();
+
+      // The Ecore_X_Window needs to use the Clipboard.
+      // Only when the render surface is window, we can get the Ecore_X_Window.
+      Ecore_X_Window ecoreXwin( AnyCast<Ecore_X_Window>(nativewindow) );
+      if (ecoreXwin)
+      {
+        // If we fail to get Ecore_X_Window, we can't use the Clipboard correctly.
+        // Thus you have to call "ecore_imf_context_client_window_set" somewhere.
+        // In EvasPlugIn, this function is called in EvasPlugin::ConnectEcoreEvent().
+        Clipboard::Impl* impl( new Clipboard::Impl( ecoreXwin ) );
+        clipboard = Dali::Clipboard( new Clipboard( impl ) );
+        service.Register( typeid( clipboard ), clipboard );
+      }
+    }
   }
 
   return clipboard;
index ec24338..efa6b52 100644 (file)
@@ -116,13 +116,6 @@ void ImfDeleteSurrounding( void *data, Ecore_IMF_Context *imfContext, void *even
   }
 }
 
-BaseHandle Create()
-{
-  return ImfManager::Get();
-}
-
-TypeRegistration IMF_MANAGER_TYPE( typeid(Dali::ImfManager), typeid(Dali::BaseHandle), Create );
-
 } // unnamed namespace
 
 bool ImfManager::IsAvailable()