From: Adeel Kazmi Date: Mon, 1 Sep 2014 17:45:12 +0000 (+0100) Subject: Added SingletonService, removed Singleton APIs from Adaptor & removed Application... X-Git-Tag: dali_1.0.8~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=12acf51f394123980eec1e6fff504971745a741c;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git Added SingletonService, removed Singleton APIs from Adaptor & removed Application::Get Change-Id: I09191b12dfb40c54e68f3bfa811bd61b70248780 --- diff --git a/adaptors/common/adaptor-impl.cpp b/adaptors/common/adaptor-impl.cpp index 3482250..05aae0d 100644 --- a/adaptors/common/adaptor-impl.cpp +++ b/adaptors/common/adaptor-impl.cpp @@ -819,27 +819,6 @@ void Adaptor::ProcessCoreEventsFromIdle() mNotificationOnIdleInstalled = false; } -void Adaptor::RegisterSingleton(const std::type_info& info, BaseHandle singleton) -{ - if(singleton) - { - mSingletonContainer.insert(SingletonPair(info.name(), singleton)); - } -} - -BaseHandle Adaptor::GetSingleton(const std::type_info& info) const -{ - BaseHandle object = Dali::BaseHandle(); - - SingletonConstIter iter = mSingletonContainer.find(info.name()); - if(iter != mSingletonContainer.end()) - { - object = (*iter).second; - } - - return object; -} - Adaptor::Adaptor(Dali::Adaptor& adaptor, RenderSurface* surface, const DeviceLayout& baseLayout) : mAdaptor(adaptor), mState(READY), diff --git a/adaptors/common/adaptor-impl.h b/adaptors/common/adaptor-impl.h index fa068e2..942bab9 100644 --- a/adaptors/common/adaptor-impl.h +++ b/adaptors/common/adaptor-impl.h @@ -90,10 +90,6 @@ public: typedef Dali::Adaptor::AdaptorSignalV2 AdaptorSignalV2; - typedef std::pair SingletonPair; - typedef std::map SingletonContainer; - typedef SingletonContainer::const_iterator SingletonConstIter; - /** * Creates a New Adaptor * @param[in] surface A render surface can be one of the following @@ -201,16 +197,6 @@ public: // AdaptorInternalServices implementation */ virtual bool CallFromMainLoop(boost::function callBack); - /** - * @copydoc Dali::Adaptor::RegisterSingleton() - */ - virtual void RegisterSingleton(const std::type_info& info, BaseHandle singleton); - - /** - * @copydoc Dali::Adaptor::GetSingleton() - */ - virtual BaseHandle GetSingleton(const std::type_info& info) const; - public: /** @@ -517,7 +503,6 @@ private: // Data size_t mVDpi; ///< Override vertical DPI FeedbackPluginProxy* mDaliFeedbackPlugin; ///< Used to access feedback support FeedbackController* mFeedbackController; ///< Plays feedback effects for Dali-Toolkit UI Controls. - SingletonContainer mSingletonContainer; ///< The container to look up singleton by its type name Dali::TtsPlayer mTtsPlayers[Dali::TtsPlayer::MODE_NUM]; ///< Provides TTS support ObserverContainer mObservers; ///< A list of adaptor observer pointers DragAndDropDetectorPtr mDragAndDropDetector; ///< The Drag & Drop detector diff --git a/adaptors/common/application-impl.cpp b/adaptors/common/application-impl.cpp index 79a666a..aeee4d3 100644 --- a/adaptors/common/application-impl.cpp +++ b/adaptors/common/application-impl.cpp @@ -25,6 +25,7 @@ // INTERNAL INCLUDES #include #include +#include namespace Dali { @@ -52,8 +53,6 @@ const unsigned int DEFAULT_WINDOW_WIDTH = 480; const unsigned int DEFAULT_WINDOW_HEIGHT = 800; const float DEFAULT_HORIZONTAL_DPI = 220; const float DEFAULT_VERTICAL_DPI = 217; - -boost::thread_specific_ptr gThreadLocalApplication; } ApplicationPtr Application::New( @@ -67,28 +66,26 @@ ApplicationPtr Application::New( return application; } -Application::Application( - int* argc, - char** argv[], - const std::string& name, - const DeviceLayout& baseLayout, - Dali::Application::WINDOW_MODE windowMode) -: mFramework(NULL), - mCommandLineOptions(NULL), - mAdaptor(NULL), +Application::Application( int* argc, char** argv[], const std::string& name, const DeviceLayout& baseLayout, Dali::Application::WINDOW_MODE windowMode) +: mInitSignalV2(), + mTerminateSignalV2(), + mPauseSignalV2(), + mResumeSignalV2(), + mResetSignalV2(), + mResizeSignalV2(), + mLanguageChangedSignalV2(), + mEventLoop( NULL ), + mFramework( NULL ), + mCommandLineOptions( NULL ), + mSingletonService( SingletonService::New() ), + mAdaptor( NULL ), mWindow(), mWindowMode( windowMode ), - mName(name), - mInitialized(false), - mBaseLayout(baseLayout), + mName( name ), + mInitialized( false ), + mBaseLayout( baseLayout ), mSlotDelegate( this ) { - // make sure we don't create the local thread application instance twice - DALI_ASSERT_ALWAYS(gThreadLocalApplication.get() == NULL && "Cannot create more than one Application per thread" ); - - // reset is used to store a new value associated with this thread - gThreadLocalApplication.reset(this); - mCommandLineOptions = new CommandLineOptions(argc, argv); mFramework = new Framework(*this, argc, argv, name); @@ -100,7 +97,6 @@ Application::~Application() delete mCommandLineOptions; delete mAdaptor; mWindow.Reset(); - gThreadLocalApplication.release(); } void Application::CreateWindow() @@ -266,15 +262,6 @@ Dali::Window Application::GetWindow() return mWindow; } -Dali::Application Application::Get() -{ - DALI_ASSERT_ALWAYS( gThreadLocalApplication.get() != NULL && "Application not instantiated" ); - - Dali::Application application(gThreadLocalApplication.get()); - - return application; -} - const std::string& Application::GetTheme() { return Dali::StyleMonitor::Get().GetTheme(); diff --git a/adaptors/common/application-impl.h b/adaptors/common/application-impl.h index 44d4362..8301f00 100644 --- a/adaptors/common/application-impl.h +++ b/adaptors/common/application-impl.h @@ -28,14 +28,15 @@ // INTERNAL INCLUDES #include +#include #include #include namespace Dali { -class Window; class Adaptor; +class Window; namespace Internal { @@ -72,7 +73,7 @@ public: const DeviceLayout& baseLayout, Dali::Application::WINDOW_MODE windowMode); - Application(int* argc, char **argv[], const std::string& name, const DeviceLayout& baseLayout, Dali::Application::WINDOW_MODE windowMode ); + Application( int* argc, char **argv[], const std::string& name, const DeviceLayout& baseLayout, Dali::Application::WINDOW_MODE windowMode ); /** * Destructor @@ -112,11 +113,6 @@ public: Dali::Window GetWindow(); /** - * @copydoc Dali::Application::Get(); - */ - static Dali::Application Get(); - - /** * @copydoc Dali::Application::GetTheme(); */ const std::string& GetTheme(); @@ -262,6 +258,7 @@ private: CommandLineOptions* mCommandLineOptions; + Dali::SingletonService mSingletonService; Dali::Adaptor* mAdaptor; Dali::Window mWindow; Dali::Application::WINDOW_MODE mWindowMode; diff --git a/adaptors/common/clipboard-event-notifier-impl.cpp b/adaptors/common/clipboard-event-notifier-impl.cpp index 3f509e8..c28dcf0 100644 --- a/adaptors/common/clipboard-event-notifier-impl.cpp +++ b/adaptors/common/clipboard-event-notifier-impl.cpp @@ -22,7 +22,7 @@ #include // INTERNAL INCLUDES -#include +#include namespace Dali { @@ -39,12 +39,15 @@ BaseHandle Create() { BaseHandle handle( ClipboardEventNotifier::Get() ); - if ( !handle && Adaptor::IsAvailable() ) + if ( !handle ) { - Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) ); - Dali::ClipboardEventNotifier notifier( ClipboardEventNotifier::New() ); - adaptorImpl.RegisterSingleton( typeid( notifier ), notifier ); - handle = notifier; + Dali::SingletonService service( SingletonService::Get() ); + if ( service ) + { + Dali::ClipboardEventNotifier notifier( ClipboardEventNotifier::New() ); + service.Register( typeid( notifier ), notifier ); + handle = notifier; + } } return handle; @@ -64,10 +67,11 @@ Dali::ClipboardEventNotifier ClipboardEventNotifier::Get() { Dali::ClipboardEventNotifier notifier; - if ( Adaptor::IsAvailable() ) + Dali::SingletonService service( SingletonService::Get() ); + if ( service ) { // Check whether the singleton is already created - Dali::BaseHandle handle = Adaptor::Get().GetSingleton( typeid( Dali::ClipboardEventNotifier ) ); + Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::ClipboardEventNotifier ) ); if(handle) { // If so, downcast the handle diff --git a/adaptors/common/file.list b/adaptors/common/file.list index 91ff562..96f7ed6 100644 --- a/adaptors/common/file.list +++ b/adaptors/common/file.list @@ -20,6 +20,7 @@ adaptor_common_internal_src_files = \ $(adaptor_common_dir)/render-surface-impl.cpp \ $(adaptor_common_dir)/server-connection.cpp \ $(adaptor_common_dir)/shared-file.cpp \ + $(adaptor_common_dir)/singleton-service-impl.cpp \ $(adaptor_common_dir)/sound-player-impl.cpp \ $(adaptor_common_dir)/style-monitor-impl.cpp \ $(adaptor_common_dir)/timer-impl.cpp \ diff --git a/adaptors/common/haptic-player-impl.cpp b/adaptors/common/haptic-player-impl.cpp index 23a3023..9df0ded 100644 --- a/adaptors/common/haptic-player-impl.cpp +++ b/adaptors/common/haptic-player-impl.cpp @@ -22,7 +22,7 @@ #include // INTERNAL INCLUDES -#include +#include namespace Dali { @@ -56,10 +56,11 @@ Dali::HapticPlayer HapticPlayer::Get() { Dali::HapticPlayer player; - if ( Adaptor::IsAvailable() ) + Dali::SingletonService service( SingletonService::Get() ); + if ( service ) { // Check whether the singleton is already created - Dali::BaseHandle handle = Adaptor::Get().GetSingleton( typeid( Dali::HapticPlayer ) ); + Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::HapticPlayer ) ); if ( handle ) { // If so, downcast the handle @@ -67,9 +68,8 @@ Dali::HapticPlayer HapticPlayer::Get() } else { - Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) ); player = Dali::HapticPlayer( New() ); - adaptorImpl.RegisterSingleton( typeid( player ), player ); + service.Register( typeid( player ), player ); } } diff --git a/adaptors/common/physical-keyboard-impl.cpp b/adaptors/common/physical-keyboard-impl.cpp index 0f7ca87..8cb8a66 100644 --- a/adaptors/common/physical-keyboard-impl.cpp +++ b/adaptors/common/physical-keyboard-impl.cpp @@ -21,7 +21,7 @@ #include // INTERNAL INCLUDES -#include +#include namespace Dali { @@ -36,11 +36,11 @@ Dali::PhysicalKeyboard PhysicalKeyboard::New() { Dali::PhysicalKeyboard keyboardHandle; - if ( Adaptor::IsAvailable() ) + Dali::SingletonService service( SingletonService::Get() ); + if ( service ) { - Dali::Adaptor& adaptor = Adaptor::Get(); keyboardHandle = Dali::PhysicalKeyboard( new PhysicalKeyboard() ); - adaptor.RegisterSingleton( typeid( keyboardHandle ), keyboardHandle ); + service.Register( typeid( keyboardHandle ), keyboardHandle ); } return keyboardHandle; @@ -50,12 +50,10 @@ Dali::PhysicalKeyboard PhysicalKeyboard::Get() { Dali::PhysicalKeyboard keyboardHandle; - // Ensure the adaptor has been created - if ( Adaptor::IsAvailable() ) + Dali::SingletonService service = SingletonService::Get(); + if ( service ) { - Dali::Adaptor& adaptor = Adaptor::Get(); - - BaseHandle handle = adaptor.GetSingleton( typeid( Dali::PhysicalKeyboard ) ); + BaseHandle handle = service.GetSingleton( typeid( Dali::PhysicalKeyboard ) ); if( handle ) { // If so, downcast the handle of singleton to focus manager diff --git a/adaptors/common/singleton-service-impl.cpp b/adaptors/common/singleton-service-impl.cpp new file mode 100644 index 0000000..1faedb5 --- /dev/null +++ b/adaptors/common/singleton-service-impl.cpp @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// CLASS HEADER +#include + +// EXTERNAL INCLUDES +#include +#include + +// INTERNAL INCLUDES + +#if defined(DEBUG_ENABLED) +#include +Debug::Filter* gSingletonServiceLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_SINGLETON_SERVICE" ); + +// Need to define own macro as the log function is not installed when this object is created so no logging is shown with DALI_LOG_INFO at construction and destruction +#define DALI_LOG_SINGLETON_SERVICE_DIRECT(level, message) \ + if(gSingletonServiceLogFilter && gSingletonServiceLogFilter->IsEnabledFor(level)) { std::string string(message); Dali::SlpPlatform::LogMessage( Debug::DebugInfo, string ); } + +#define DALI_LOG_SINGLETON_SERVICE(level, format, args...) DALI_LOG_INFO(gSingletonServiceLogFilter, level, format, ## args ) + +#else + +#define DALI_LOG_SINGLETON_SERVICE_DIRECT(level, message) +#define DALI_LOG_SINGLETON_SERVICE(level, format, args...) + +#endif + +namespace Dali +{ + +namespace Internal +{ + +namespace Adaptor +{ + +namespace +{ + +/* + * Dummy cleanup function required as boost::thread_specific_ptr requires access to destructor but + * we should not make the destructor of SingletonService public as it is a ref-counted object. + * + * We do not expect this to be called as we only release the pointer, and not reset. + */ +void DummyCleanup( SingletonService* ) +{ +} + +boost::thread_specific_ptr< SingletonService > gSingletonService( &DummyCleanup ); +} // unnamed namespace + +Dali::SingletonService SingletonService::New() +{ + Dali::SingletonService singletonService( new SingletonService ); + return singletonService; +} + +Dali::SingletonService SingletonService::Get() +{ + Dali::SingletonService singletonService; + if ( gSingletonService.get() ) + { + singletonService = Dali::SingletonService( gSingletonService.get() ); + } + return singletonService; +} + +void SingletonService::Register( const std::type_info& info, BaseHandle singleton ) +{ + if( singleton ) + { + DALI_LOG_SINGLETON_SERVICE( Debug::General, "Singleton Added: %s\n", info.name() ); + mSingletonContainer.insert( SingletonPair( info.name(), singleton ) ); + } +} + +BaseHandle SingletonService::GetSingleton( const std::type_info& info ) const +{ + BaseHandle object; + + SingletonConstIter iter = mSingletonContainer.find(info.name()); + if( iter != mSingletonContainer.end() ) + { + object = ( *iter ).second; + } + + return object; +} + +SingletonService::SingletonService() +: mSingletonContainer() +{ + // Can only have one instance of SingletonService + DALI_ASSERT_ALWAYS( !gSingletonService.get() && "Only one instance of SingletonService is allowed"); + + gSingletonService.reset( this ); + + DALI_LOG_SINGLETON_SERVICE_DIRECT( Debug::Concise, "SingletonService Created\n" ); +} + +SingletonService::~SingletonService() +{ + gSingletonService.release(); + DALI_LOG_SINGLETON_SERVICE_DIRECT( Debug::Concise, "SingletonService Destroyed\n" ); +} + +} // namespace Adaptor + +} // namespace Internal + +} // namespace Dali diff --git a/adaptors/common/singleton-service-impl.h b/adaptors/common/singleton-service-impl.h new file mode 100644 index 0000000..b86fc0e --- /dev/null +++ b/adaptors/common/singleton-service-impl.h @@ -0,0 +1,115 @@ +#ifndef __DALI_INTERNAL_SINGLETON_SERVICE_H__ +#define __DALI_INTERNAL_SINGLETON_SERVICE_H__ + +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// EXTERNAL INCLUDES +#include +#include + +// INTERNAL INCLUDES +#include + +namespace Dali +{ + +namespace Internal +{ + +namespace Adaptor +{ + +class SingletonService : public Dali::BaseObject +{ +public: + + /** + * Create a SingletonService. + * This should only be called once by the Application class. + * @return A newly created SingletonService. + */ + static Dali::SingletonService New() DALI_IMPORT_API; + + /** + * @copydoc Dali::SingletonService::Get() + */ + static Dali::SingletonService Get(); + + /** + * @copydoc Dali::SingletonService::Register() + */ + void Register( const std::type_info& info, BaseHandle singleton ); + + /** + * @copydoc Dali::SingletonService::GetSingleton() + */ + BaseHandle GetSingleton( const std::type_info& info ) const; + +private: + + /** + * Private Constructor + * @see SingletonService::New() + */ + SingletonService(); + + /** + * Virtual Destructor + */ + virtual ~SingletonService(); + + // Undefined + SingletonService( const SingletonService& ); + SingletonService& operator=( SingletonService& ); + +private: + + typedef std::pair SingletonPair; + typedef std::map SingletonContainer; + typedef SingletonContainer::const_iterator SingletonConstIter; + + SingletonContainer mSingletonContainer; ///< The container to look up singleton by its type name +}; + +} // namespace Adaptor + +} // namespace Internal + +// Helpers for public-api forwarding methods + +inline Internal::Adaptor::SingletonService& GetImplementation(Dali::SingletonService& player) +{ + DALI_ASSERT_ALWAYS( player && "SingletonService handle is empty" ); + + BaseObject& handle = player.GetBaseObject(); + + return static_cast(handle); +} + +inline const Internal::Adaptor::SingletonService& GetImplementation(const Dali::SingletonService& player) +{ + DALI_ASSERT_ALWAYS( player && "SingletonService handle is empty" ); + + const BaseObject& handle = player.GetBaseObject(); + + return static_cast(handle); +} + +} // namespace Dali + +#endif // __DALI_INTERNAL_SINGLETON_SERVICE_H__ diff --git a/adaptors/common/sound-player-impl.cpp b/adaptors/common/sound-player-impl.cpp index 83654f0..7215a73 100644 --- a/adaptors/common/sound-player-impl.cpp +++ b/adaptors/common/sound-player-impl.cpp @@ -22,7 +22,7 @@ #include // INTERNAL INCLUDES -#include +#include namespace Dali { @@ -58,10 +58,11 @@ Dali::SoundPlayer SoundPlayer::Get() { Dali::SoundPlayer player; - if ( Adaptor::IsAvailable() ) + Dali::SingletonService service( SingletonService::Get() ); + if ( service ) { // Check whether the singleton is already created - Dali::BaseHandle handle = Adaptor::Get().GetSingleton( typeid( Dali::SoundPlayer ) ); + Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::SoundPlayer ) ); if ( handle ) { // If so, downcast the handle @@ -69,9 +70,8 @@ Dali::SoundPlayer SoundPlayer::Get() } else { - Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) ); player = Dali::SoundPlayer( New() ); - adaptorImpl.RegisterSingleton( typeid( player ), player ); + service.Register( typeid( player ), player ); } } diff --git a/adaptors/common/style-monitor-impl.cpp b/adaptors/common/style-monitor-impl.cpp index ef701d5..58e02e2 100644 --- a/adaptors/common/style-monitor-impl.cpp +++ b/adaptors/common/style-monitor-impl.cpp @@ -21,6 +21,7 @@ // INTERNAL INCLUDES #include #include +#include namespace Dali { @@ -40,10 +41,14 @@ BaseHandle Create() if ( !handle && Adaptor::IsAvailable() ) { - Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) ); - Dali::StyleMonitor styleMonitor = Dali::StyleMonitor( new StyleMonitor( adaptorImpl.GetPlatformAbstraction() ) ); - adaptorImpl.RegisterSingleton( typeid( styleMonitor ), styleMonitor ); - handle = styleMonitor; + 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; @@ -56,10 +61,11 @@ Dali::StyleMonitor StyleMonitor::Get() { Dali::StyleMonitor styleMonitor; - if ( Adaptor::IsAvailable() ) + Dali::SingletonService service( SingletonService::Get() ); + if ( service ) { // Check whether the singleton is already created - Dali::BaseHandle handle = Dali::Adaptor::Get().GetSingleton( typeid( Dali::StyleMonitor ) ); + Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::StyleMonitor ) ); if(handle) { // If so, downcast the handle diff --git a/adaptors/mobile/mobile-color-controller-impl.cpp b/adaptors/mobile/mobile-color-controller-impl.cpp index 20b1e1a..2a0a0e0 100644 --- a/adaptors/mobile/mobile-color-controller-impl.cpp +++ b/adaptors/mobile/mobile-color-controller-impl.cpp @@ -24,7 +24,7 @@ #include // INTERNAL INCLUDES -#include +#include namespace Dali { @@ -50,10 +50,11 @@ Dali::ColorController ColorController::Get() { Dali::ColorController colorController; - if ( Adaptor::IsAvailable() ) + Dali::SingletonService service( SingletonService::Get() ); + if ( service ) { // Check whether the singleton is already created - Dali::BaseHandle handle = Dali::Adaptor::Get().GetSingleton( typeid( Dali::ColorController ) ); + Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::ColorController ) ); if(handle) { // If so, downcast the handle @@ -61,9 +62,8 @@ Dali::ColorController ColorController::Get() } else { - Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) ); colorController = Dali::ColorController( new ColorController( ) ); - adaptorImpl.RegisterSingleton( typeid( colorController ), colorController ); + service.Register( typeid( colorController ), colorController ); } } diff --git a/adaptors/public-api/adaptor-framework/adaptor.cpp b/adaptors/public-api/adaptor-framework/adaptor.cpp index 1f54f67..136267f 100644 --- a/adaptors/public-api/adaptor-framework/adaptor.cpp +++ b/adaptors/public-api/adaptor-framework/adaptor.cpp @@ -101,16 +101,6 @@ bool Adaptor::IsAvailable() return Internal::Adaptor::Adaptor::IsAvailable(); } -void Adaptor::RegisterSingleton(const std::type_info& info, BaseHandle singleton) -{ - mImpl->RegisterSingleton(info, singleton); -} - -BaseHandle Adaptor::GetSingleton(const std::type_info& info) const -{ - return mImpl->GetSingleton(info); -} - void Adaptor::NotifyLanguageChanged() { mImpl->NotifyLanguageChanged(); diff --git a/adaptors/public-api/adaptor-framework/adaptor.h b/adaptors/public-api/adaptor-framework/adaptor.h index 0f8c255..692185a 100644 --- a/adaptors/public-api/adaptor-framework/adaptor.h +++ b/adaptors/public-api/adaptor-framework/adaptor.h @@ -189,26 +189,6 @@ public: static bool IsAvailable(); /** - * @brief Registers the singleton of Dali handle with its type info. - * - * The singleton will be kept alive for the life time of the - * adaptor. - * @note This is not intended for application developers. - * @param[in] info The type info of the Dali handle generated by the compiler. - * @param[in] singleton The Dali handle to be registered - */ - void RegisterSingleton(const std::type_info& info, BaseHandle singleton); - - /** - * @brief Gets the singleton for the given type. - * - * @note This is not intended for application developers. - * @param[in] info The type info of the given type. - * @return the Dali handle if it is registered as a singleton or an uninitialized handle. - */ - BaseHandle GetSingleton(const std::type_info& info) const; - - /** * @brief Call this method to notify Dali when the system language changes. * * Use this only when NOT using Dali::Application, As Application created using diff --git a/adaptors/public-api/adaptor-framework/application.cpp b/adaptors/public-api/adaptor-framework/application.cpp index 5e87bac..586d596 100644 --- a/adaptors/public-api/adaptor-framework/application.cpp +++ b/adaptors/public-api/adaptor-framework/application.cpp @@ -112,11 +112,6 @@ Window Application::GetWindow() return Internal::Adaptor::GetImplementation(*this).GetWindow(); } -Application Application::Get() -{ - return Internal::Adaptor::Application::Get(); -} - void Application::SetViewMode( ViewMode viewMode ) { Internal::Adaptor::GetImplementation(*this).SetViewMode( viewMode ); diff --git a/adaptors/public-api/adaptor-framework/application.h b/adaptors/public-api/adaptor-framework/application.h index b07d9be..fb6c6b7 100644 --- a/adaptors/public-api/adaptor-framework/application.h +++ b/adaptors/public-api/adaptor-framework/application.h @@ -229,14 +229,6 @@ public: */ Window GetWindow(); - /** - * Returns the local thread's instance of the Application class. - * @return A reference to the local thread's Application class instance. - * @pre The Application class has been initialised. - * @note This is only valid in the main thread. - */ - static Application Get(); - public: // Stereoscopy /** diff --git a/adaptors/public-api/adaptor-framework/singleton-service.cpp b/adaptors/public-api/adaptor-framework/singleton-service.cpp new file mode 100644 index 0000000..9ef7fcb --- /dev/null +++ b/adaptors/public-api/adaptor-framework/singleton-service.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// CLASS HEADER +#include + +// INTERNAL INCLUDES +#include + +namespace Dali DALI_IMPORT_API +{ + +SingletonService::SingletonService() +{ +} + +SingletonService SingletonService::Get() +{ + return Internal::Adaptor::SingletonService::Get(); +} + +SingletonService::~SingletonService() +{ +} + +void SingletonService::Register( const std::type_info& info, BaseHandle singleton ) +{ + GetImplementation( *this ).Register( info, singleton ); +} + +BaseHandle SingletonService::GetSingleton( const std::type_info& info ) const +{ + return GetImplementation( *this ).GetSingleton( info ); +} + +SingletonService::SingletonService( Internal::Adaptor::SingletonService* singletonService ) +: BaseHandle( singletonService ) +{ +} + +} // namespace Dali diff --git a/adaptors/public-api/adaptor-framework/singleton-service.h b/adaptors/public-api/adaptor-framework/singleton-service.h new file mode 100644 index 0000000..06cc717 --- /dev/null +++ b/adaptors/public-api/adaptor-framework/singleton-service.h @@ -0,0 +1,100 @@ +#ifndef __DALI_SINGELTON_SERVICE_H__ +#define __DALI_SINGELTON_SERVICE_H__ + +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// EXTERNAL INCLUDES +#include +#include + +namespace Dali DALI_IMPORT_API +{ + +namespace Internal DALI_INTERNAL +{ +namespace Adaptor +{ +class SingletonService; +} +} + +/** + * @brief Allows the registration of a class as a singleton + * + * @note This class is created by the Application class and is destroyed when the Application class is destroyed. + * + * @see Application + */ +class SingletonService : public BaseHandle +{ +public: + + /** + * @brief Create an uninitialized handle. + * + * This can be initialized by calling SingletonService::Get(). + */ + SingletonService(); + + /** + * @brief Retrieves a handle to the SingletonService. + * + * @return A handle to the SingletonService if it is available. This will be an empty handle if + * the service is not available. + */ + static SingletonService Get(); + + /** + * @brief Destructor + * + * This is non-virtual since derived Handle types must not contain data or virtual methods. + */ + ~SingletonService(); + + /** + * @brief Registers the singleton of Dali handle with its type info. + * + * The singleton will be kept alive for the life time of the service. + * + * @note This is not intended for application developers. + * @param[in] info The type info of the Dali handle generated by the compiler. + * @param[in] singleton The Dali handle to be registered + */ + void Register( const std::type_info& info, BaseHandle singleton ); + + /** + * @brief Gets the singleton for the given type. + * + * @note This is not intended for application developers. + * @param[in] info The type info of the given type. + * @return the Dali handle if it is registered as a singleton or an uninitialized handle. + */ + BaseHandle GetSingleton( const std::type_info& info ) const; + +public: // Not intended for application developers + + /** + * @brief This constructor is used by SingletonService::Get(). + * @param[in] singletonService A pointer to the internal singleton-service object. + */ + SingletonService( Internal::Adaptor::SingletonService* singletonService ); +}; + +} // namespace Dali + +#endif // __DALI_SINGELTON_SERVICE_H__ diff --git a/adaptors/public-api/dali.h b/adaptors/public-api/dali.h index 4b1d86a..a82c4ab 100644 --- a/adaptors/public-api/dali.h +++ b/adaptors/public-api/dali.h @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include diff --git a/adaptors/public-api/file.list b/adaptors/public-api/file.list index ff9f234..0a0dd23 100644 --- a/adaptors/public-api/file.list +++ b/adaptors/public-api/file.list @@ -16,6 +16,7 @@ public_api_src_files = \ $(adaptor_public_api_dir)/adaptor-framework/physical-keyboard.cpp \ $(adaptor_public_api_dir)/adaptor-framework/pixmap-image.cpp \ $(adaptor_public_api_dir)/adaptor-framework/render-surface.cpp \ + $(adaptor_public_api_dir)/adaptor-framework/singleton-service.cpp \ $(adaptor_public_api_dir)/adaptor-framework/sound-player.cpp \ $(adaptor_public_api_dir)/adaptor-framework/style-monitor.cpp \ $(adaptor_public_api_dir)/adaptor-framework/tilt-sensor.cpp \ @@ -52,6 +53,7 @@ public_api_adaptor_framework_header_files = \ $(adaptor_public_api_dir)/adaptor-framework/physical-keyboard.h \ $(adaptor_public_api_dir)/adaptor-framework/pixmap-image.h \ $(adaptor_public_api_dir)/adaptor-framework/render-surface.h \ + $(adaptor_public_api_dir)/adaptor-framework/singleton-service.h \ $(adaptor_public_api_dir)/adaptor-framework/sound-player.h \ $(adaptor_public_api_dir)/adaptor-framework/style-change.h \ $(adaptor_public_api_dir)/adaptor-framework/style-monitor.h \ diff --git a/adaptors/tizen/accessibility-manager-impl-tizen.cpp b/adaptors/tizen/accessibility-manager-impl-tizen.cpp index 9cd164f..feb5551 100644 --- a/adaptors/tizen/accessibility-manager-impl-tizen.cpp +++ b/adaptors/tizen/accessibility-manager-impl-tizen.cpp @@ -25,7 +25,10 @@ #include #include #include -#include "system-settings.h" + +// INTERNAL INCLUDES +#include +#include namespace Dali { @@ -64,12 +67,15 @@ BaseHandle Create() { BaseHandle handle( AccessibilityManager::Get() ); - if ( !handle && Adaptor::IsAvailable() ) + if ( !handle ) { - Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) ); - Dali::AccessibilityManager manager = Dali::AccessibilityManager( new AccessibilityManager() ); - adaptorImpl.RegisterSingleton( typeid( manager ), manager ); - handle = manager; + Dali::SingletonService service( SingletonService::Get() ); + if ( service ) + { + Dali::AccessibilityManager manager = Dali::AccessibilityManager( new AccessibilityManager() ); + service.Register( typeid( manager ), manager ); + handle = manager; + } } return handle; @@ -82,10 +88,11 @@ Dali::AccessibilityManager AccessibilityManager::Get() { Dali::AccessibilityManager manager; - if ( Adaptor::IsAvailable() ) + Dali::SingletonService service( SingletonService::Get() ); + if ( service ) { // Check whether the singleton is already created - Dali::BaseHandle handle = Dali::Adaptor::Get().GetSingleton( typeid( Dali::AccessibilityManager ) ); + Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::AccessibilityManager ) ); if(handle) { // If so, downcast the handle @@ -262,8 +269,11 @@ void AccessibilityManager::DisableAccessibility() mStatusChangedSignalV2.Emit( handle ); // Destroy the TtsPlayer if exists. - Dali::Adaptor& adaptor = Dali::Adaptor::Get(); - Adaptor::GetImplementation(adaptor).DestroyTtsPlayer(Dali::TtsPlayer::SCREEN_READER); + if ( Adaptor::IsAvailable() ) + { + Dali::Adaptor& adaptor = Dali::Adaptor::Get(); + Adaptor::GetImplementation( adaptor ).DestroyTtsPlayer( Dali::TtsPlayer::SCREEN_READER ); + } } } diff --git a/adaptors/tizen/tilt-sensor-impl-tizen.cpp b/adaptors/tizen/tilt-sensor-impl-tizen.cpp index d171c6a..5a93b11 100644 --- a/adaptors/tizen/tilt-sensor-impl-tizen.cpp +++ b/adaptors/tizen/tilt-sensor-impl-tizen.cpp @@ -30,7 +30,7 @@ #include // INTERNAL INCLUDES -#include +#include #ifdef __arm__ #define SENSOR_ENABLED @@ -75,10 +75,11 @@ Dali::TiltSensor TiltSensor::Get() { Dali::TiltSensor sensor; - if ( Adaptor::IsAvailable() ) + Dali::SingletonService service( SingletonService::Get() ); + if ( service ) { // Check whether the keyboard focus manager is already created - Dali::BaseHandle handle = Dali::Adaptor::Get().GetSingleton( typeid( Dali::TiltSensor ) ); + Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::TiltSensor ) ); if(handle) { // If so, downcast the handle of singleton to keyboard focus manager @@ -87,9 +88,8 @@ Dali::TiltSensor TiltSensor::Get() else { // Create a singleton instance - Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) ); sensor = TiltSensor::New(); - adaptorImpl.RegisterSingleton( typeid( sensor ), sensor ); + service.Register( typeid( sensor ), sensor ); handle = sensor; } } diff --git a/adaptors/ubuntu/accessibility-manager-impl-ubuntu.cpp b/adaptors/ubuntu/accessibility-manager-impl-ubuntu.cpp index cb8fc21..8c4214a 100644 --- a/adaptors/ubuntu/accessibility-manager-impl-ubuntu.cpp +++ b/adaptors/ubuntu/accessibility-manager-impl-ubuntu.cpp @@ -24,6 +24,9 @@ #include #include #include + +// INTERNAL INCLUDES +#include #include "system-settings.h" namespace Dali @@ -45,12 +48,15 @@ BaseHandle Create() { BaseHandle handle( AccessibilityManager::Get() ); - if ( !handle && Adaptor::IsAvailable() ) + if ( !handle ) { - Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) ); - Dali::AccessibilityManager manager = Dali::AccessibilityManager( new AccessibilityManager() ); - adaptorImpl.RegisterSingleton( typeid( manager ), manager ); - handle = manager; + Dali::SingletonService service( SingletonService::Get() ); + if ( service ) + { + Dali::AccessibilityManager manager = Dali::AccessibilityManager( new AccessibilityManager() ); + service.Register( typeid( manager ), manager ); + handle = manager; + } } return handle; @@ -63,10 +69,11 @@ Dali::AccessibilityManager AccessibilityManager::Get() { Dali::AccessibilityManager manager; - if ( Adaptor::IsAvailable() ) + Dali::SingletonService service( SingletonService::Get() ); + if ( service ) { // Check whether the singleton is already created - Dali::BaseHandle handle = Dali::Adaptor::Get().GetSingleton( typeid( Dali::AccessibilityManager ) ); + Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::AccessibilityManager ) ); if(handle) { // If so, downcast the handle @@ -243,8 +250,11 @@ void AccessibilityManager::DisableAccessibility() mStatusChangedSignalV2.Emit( handle ); // Destroy the TtsPlayer if exists. - Dali::Adaptor& adaptor = Dali::Adaptor::Get(); - Adaptor::GetImplementation(adaptor).DestroyTtsPlayer(Dali::TtsPlayer::SCREEN_READER); + if ( Adaptor::IsAvailable() ) + { + Dali::Adaptor& adaptor = Dali::Adaptor::Get(); + Adaptor::GetImplementation( adaptor ).DestroyTtsPlayer( Dali::TtsPlayer::SCREEN_READER ); + } } } diff --git a/adaptors/ubuntu/tilt-sensor-impl-ubuntu.cpp b/adaptors/ubuntu/tilt-sensor-impl-ubuntu.cpp index b30b0de..86aa653 100644 --- a/adaptors/ubuntu/tilt-sensor-impl-ubuntu.cpp +++ b/adaptors/ubuntu/tilt-sensor-impl-ubuntu.cpp @@ -25,7 +25,7 @@ #include // INTERNAL INCLUDES -#include +#include namespace // unnamed namespace { @@ -66,10 +66,11 @@ Dali::TiltSensor TiltSensor::Get() { Dali::TiltSensor sensor; - if ( Adaptor::IsAvailable() ) + Dali::SingletonService service( SingletonService::Get() ); + if ( service ) { // Check whether the keyboard focus manager is already created - Dali::BaseHandle handle = Dali::Adaptor::Get().GetSingleton( typeid( Dali::TiltSensor ) ); + Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::TiltSensor ) ); if(handle) { // If so, downcast the handle of singleton to keyboard focus manager @@ -78,9 +79,8 @@ Dali::TiltSensor TiltSensor::Get() else { // Create a singleton instance - Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) ); sensor = TiltSensor::New(); - adaptorImpl.RegisterSingleton( typeid( sensor ), sensor ); + service.Register( typeid( sensor ), sensor ); handle = sensor; } } diff --git a/adaptors/wayland/clipboard-impl-wl.cpp b/adaptors/wayland/clipboard-impl-wl.cpp index 987530e..90fdcdc 100644 --- a/adaptors/wayland/clipboard-impl-wl.cpp +++ b/adaptors/wayland/clipboard-impl-wl.cpp @@ -25,9 +25,8 @@ #include // INTERNAL INCLUDES -#include #include -#include +#include namespace //unnamed namespace { @@ -74,10 +73,11 @@ Dali::Clipboard Clipboard::Get() { Dali::Clipboard clipboard; - if ( Adaptor::IsAvailable() ) + Dali::SingletonService service( SingletonService::Get() ); + if ( service ) { // Check whether the singleton is already created - Dali::BaseHandle handle = Adaptor::Get().GetSingleton( typeid( Dali::Clipboard ) ); + Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::Clipboard ) ); if(handle) { // If so, downcast the handle diff --git a/adaptors/wayland/imf-manager-impl-wl.cpp b/adaptors/wayland/imf-manager-impl-wl.cpp index 5a6c3f4..3c0a841 100644 --- a/adaptors/wayland/imf-manager-impl-wl.cpp +++ b/adaptors/wayland/imf-manager-impl-wl.cpp @@ -28,6 +28,7 @@ // INTERNAL INCLUDES #include #include +#include #include namespace Dali @@ -131,10 +132,11 @@ Dali::ImfManager ImfManager::Get() { Dali::ImfManager manager; - if ( Adaptor::IsAvailable() ) + Dali::SingletonService service( SingletonService::Get() ); + if ( service ) { // Check whether the singleton is already created - Dali::BaseHandle handle = Dali::Adaptor::Get().GetSingleton( typeid( Dali::ImfManager ) ); + Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::ImfManager ) ); if(handle) { // If so, downcast the handle diff --git a/adaptors/x11/clipboard-impl-x.cpp b/adaptors/x11/clipboard-impl-x.cpp index dfa2786..3d0f0f9 100644 --- a/adaptors/x11/clipboard-impl-x.cpp +++ b/adaptors/x11/clipboard-impl-x.cpp @@ -24,10 +24,10 @@ #include // INTERNAL INCLUDES -#include #include #include #include +#include namespace //unnamed namespace { @@ -62,23 +62,27 @@ BaseHandle Create() if ( !handle && Adaptor::IsAvailable() ) { - Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) ); - - // 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( 0 ); - Dali::RenderSurface& surface( adaptorImpl.GetSurface() ); - if( surface.GetType() == Dali::RenderSurface::WINDOW ) + Dali::SingletonService service( SingletonService::Get() ); + if ( service ) { - ecoreXwin = AnyCast< Ecore_X_Window >( adaptorImpl.GetSurface().GetSurface() ); + Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) ); + + // 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( 0 ); + Dali::RenderSurface& surface( adaptorImpl.GetSurface() ); + if( surface.GetType() == Dali::RenderSurface::WINDOW ) + { + ecoreXwin = AnyCast< Ecore_X_Window >( adaptorImpl.GetSurface().GetSurface() ); + } + + // 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(). + Dali::Clipboard clipboard = Dali::Clipboard( new Clipboard( ecoreXwin ) ); + service.Register( typeid( clipboard ), clipboard ); + handle = clipboard; } - - // 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(). - Dali::Clipboard clipboard = Dali::Clipboard( new Clipboard( ecoreXwin ) ); - adaptorImpl.RegisterSingleton( typeid( clipboard ), clipboard ); - handle = clipboard; } return handle; @@ -100,10 +104,11 @@ Dali::Clipboard Clipboard::Get() { Dali::Clipboard clipboard; - if ( Adaptor::IsAvailable() ) + Dali::SingletonService service( SingletonService::Get() ); + if ( service ) { // Check whether the singleton is already created - Dali::BaseHandle handle = Adaptor::Get().GetSingleton( typeid( Dali::Clipboard ) ); + Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::Clipboard ) ); if(handle) { // If so, downcast the handle diff --git a/adaptors/x11/imf-manager-impl-x.cpp b/adaptors/x11/imf-manager-impl-x.cpp index 2f7db66..3e681b0 100644 --- a/adaptors/x11/imf-manager-impl-x.cpp +++ b/adaptors/x11/imf-manager-impl-x.cpp @@ -28,6 +28,7 @@ // INTERNAL INCLUDES #include #include +#include #include namespace Dali @@ -120,7 +121,8 @@ BaseHandle Create() { BaseHandle handle( ImfManager::Get() ); - if ( !handle && Adaptor::IsAvailable() ) + Dali::SingletonService service( SingletonService::Get() ); + if ( !handle && Adaptor::IsAvailable() && service ) { Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) ); @@ -138,7 +140,7 @@ BaseHandle Create() // In EvasPlugIn, this function is called in EvasPlugin::ConnectEcoreEvent(). Dali::ImfManager manager = Dali::ImfManager( new ImfManager( ecoreXwin ) ); - adaptorImpl.RegisterSingleton( typeid( manager ), manager ); + service.Register( typeid( manager ), manager ); handle = manager; } @@ -153,10 +155,11 @@ Dali::ImfManager ImfManager::Get() { Dali::ImfManager manager; - if ( Adaptor::IsAvailable() ) + Dali::SingletonService service( SingletonService::Get() ); + if ( service ) { // Check whether the singleton is already created - Dali::BaseHandle handle = Dali::Adaptor::Get().GetSingleton( typeid( Dali::ImfManager ) ); + Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::ImfManager ) ); if(handle) { // If so, downcast the handle