From 5ca5e73746c15919a9acfd2c613c26d7450fa101 Mon Sep 17 00:00:00 2001 From: David Steele Date: Wed, 20 Jan 2016 13:04:46 +0000 Subject: [PATCH] Removed singletons from the type registry 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 --- adaptors/common/clipboard-event-notifier-impl.cpp | 28 ++-------- adaptors/common/lifecycle-controller-impl.cpp | 24 --------- adaptors/common/style-monitor-impl.cpp | 30 +++-------- adaptors/ecore/wayland/clipboard-impl-ecore-wl.cpp | 21 +++++--- .../ecore/wayland/imf-manager-impl-ecore-wl.cpp | 12 ----- .../mobile/accessibility-adaptor-impl-mobile.cpp | 45 ++++++---------- adaptors/mobile/mobile-color-controller-impl.cpp | 11 ---- .../tizen/accessibility-adaptor-impl-tizen.cpp | 45 ++++++---------- adaptors/tizen/tts-player-impl-tizen.cpp | 7 --- .../ubuntu/accessibility-adaptor-impl-ubuntu.cpp | 30 ++--------- adaptors/ubuntu/tts-player-impl-ubuntu.cpp | 12 ----- adaptors/wayland/clipboard/clipboard-impl-wl.cpp | 24 ++++++--- adaptors/wayland/imf/imf-manager-impl-wl.cpp | 12 ----- adaptors/x11/clipboard-impl-x.cpp | 60 +++++++--------------- adaptors/x11/imf-manager-impl-x.cpp | 7 --- 15 files changed, 95 insertions(+), 273 deletions(-) diff --git a/adaptors/common/clipboard-event-notifier-impl.cpp b/adaptors/common/clipboard-event-notifier-impl.cpp index 981ac46..ffd6a14 100644 --- a/adaptors/common/clipboard-event-notifier-impl.cpp +++ b/adaptors/common/clipboard-event-notifier-impl.cpp @@ -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; diff --git a/adaptors/common/lifecycle-controller-impl.cpp b/adaptors/common/lifecycle-controller-impl.cpp index 52b6c13..954a5f2 100644 --- a/adaptors/common/lifecycle-controller-impl.cpp +++ b/adaptors/common/lifecycle-controller-impl.cpp @@ -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; diff --git a/adaptors/common/style-monitor-impl.cpp b/adaptors/common/style-monitor-impl.cpp index df06e2f..ca9ec8f 100644 --- a/adaptors/common/style-monitor-impl.cpp +++ b/adaptors/common/style-monitor-impl.cpp @@ -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; diff --git a/adaptors/ecore/wayland/clipboard-impl-ecore-wl.cpp b/adaptors/ecore/wayland/clipboard-impl-ecore-wl.cpp index 6c1ff67..cea687c 100644 --- a/adaptors/ecore/wayland/clipboard-impl-ecore-wl.cpp +++ b/adaptors/ecore/wayland/clipboard-impl-ecore-wl.cpp @@ -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; diff --git a/adaptors/ecore/wayland/imf-manager-impl-ecore-wl.cpp b/adaptors/ecore/wayland/imf-manager-impl-ecore-wl.cpp index 99b3a0e..8673c2c 100644 --- a/adaptors/ecore/wayland/imf-manager-impl-ecore-wl.cpp +++ b/adaptors/ecore/wayland/imf-manager-impl-ecore-wl.cpp @@ -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; diff --git a/adaptors/mobile/accessibility-adaptor-impl-mobile.cpp b/adaptors/mobile/accessibility-adaptor-impl-mobile.cpp index c660087..01656e1 100644 --- a/adaptors/mobile/accessibility-adaptor-impl-mobile.cpp +++ b/adaptors/mobile/accessibility-adaptor-impl-mobile.cpp @@ -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() ) ); } } diff --git a/adaptors/mobile/mobile-color-controller-impl.cpp b/adaptors/mobile/mobile-color-controller-impl.cpp index 732d459..a6d97f7 100644 --- a/adaptors/mobile/mobile-color-controller-impl.cpp +++ b/adaptors/mobile/mobile-color-controller-impl.cpp @@ -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; diff --git a/adaptors/tizen/accessibility-adaptor-impl-tizen.cpp b/adaptors/tizen/accessibility-adaptor-impl-tizen.cpp index 70aa0ad..588cfae 100644 --- a/adaptors/tizen/accessibility-adaptor-impl-tizen.cpp +++ b/adaptors/tizen/accessibility-adaptor-impl-tizen.cpp @@ -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() ) ); } } diff --git a/adaptors/tizen/tts-player-impl-tizen.cpp b/adaptors/tizen/tts-player-impl-tizen.cpp index 976602e..9b9a2c6 100644 --- a/adaptors/tizen/tts-player-impl-tizen.cpp +++ b/adaptors/tizen/tts-player-impl-tizen.cpp @@ -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. diff --git a/adaptors/ubuntu/accessibility-adaptor-impl-ubuntu.cpp b/adaptors/ubuntu/accessibility-adaptor-impl-ubuntu.cpp index c1964d7..3a3bf85 100644 --- a/adaptors/ubuntu/accessibility-adaptor-impl-ubuntu.cpp +++ b/adaptors/ubuntu/accessibility-adaptor-impl-ubuntu.cpp @@ -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; diff --git a/adaptors/ubuntu/tts-player-impl-ubuntu.cpp b/adaptors/ubuntu/tts-player-impl-ubuntu.cpp index 12e5c55..961c66a 100644 --- a/adaptors/ubuntu/tts-player-impl-ubuntu.cpp +++ b/adaptors/ubuntu/tts-player-impl-ubuntu.cpp @@ -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 - diff --git a/adaptors/wayland/clipboard/clipboard-impl-wl.cpp b/adaptors/wayland/clipboard/clipboard-impl-wl.cpp index e759770..e207e6f 100644 --- a/adaptors/wayland/clipboard/clipboard-impl-wl.cpp +++ b/adaptors/wayland/clipboard/clipboard-impl-wl.cpp @@ -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; diff --git a/adaptors/wayland/imf/imf-manager-impl-wl.cpp b/adaptors/wayland/imf/imf-manager-impl-wl.cpp index f9a880c..8d5aa7a 100644 --- a/adaptors/wayland/imf/imf-manager-impl-wl.cpp +++ b/adaptors/wayland/imf/imf-manager-impl-wl.cpp @@ -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; diff --git a/adaptors/x11/clipboard-impl-x.cpp b/adaptors/x11/clipboard-impl-x.cpp index 2915a80..2f3e14e 100644 --- a/adaptors/x11/clipboard-impl-x.cpp +++ b/adaptors/x11/clipboard-impl-x.cpp @@ -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(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(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; diff --git a/adaptors/x11/imf-manager-impl-x.cpp b/adaptors/x11/imf-manager-impl-x.cpp index ec24338..efa6b52 100644 --- a/adaptors/x11/imf-manager-impl-x.cpp +++ b/adaptors/x11/imf-manager-impl-x.cpp @@ -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() -- 2.7.4