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),
typedef Dali::Adaptor::AdaptorSignalV2 AdaptorSignalV2;
- typedef std::pair<std::string, BaseHandle> SingletonPair;
- typedef std::map<std::string, BaseHandle> SingletonContainer;
- typedef SingletonContainer::const_iterator SingletonConstIter;
-
/**
* Creates a New Adaptor
* @param[in] surface A render surface can be one of the following
*/
virtual bool CallFromMainLoop(boost::function<void(void)> 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:
/**
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
// INTERNAL INCLUDES
#include <command-line-options.h>
#include <common/adaptor-impl.h>
+#include <singleton-service-impl.h>
namespace Dali
{
const unsigned int DEFAULT_WINDOW_HEIGHT = 800;
const float DEFAULT_HORIZONTAL_DPI = 220;
const float DEFAULT_VERTICAL_DPI = 217;
-
-boost::thread_specific_ptr<Application> gThreadLocalApplication;
}
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);
delete mCommandLineOptions;
delete mAdaptor;
mWindow.Reset();
- gThreadLocalApplication.release();
}
void Application::CreateWindow()
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();
// INTERNAL INCLUDES
#include <application.h>
+#include <singleton-service.h>
#include <framework.h>
#include <window-impl.h>
namespace Dali
{
-class Window;
class Adaptor;
+class Window;
namespace Internal
{
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
Dali::Window GetWindow();
/**
- * @copydoc Dali::Application::Get();
- */
- static Dali::Application Get();
-
- /**
* @copydoc Dali::Application::GetTheme();
*/
const std::string& GetTheme();
CommandLineOptions* mCommandLineOptions;
+ Dali::SingletonService mSingletonService;
Dali::Adaptor* mAdaptor;
Dali::Window mWindow;
Dali::Application::WINDOW_MODE mWindowMode;
#include <dali/public-api/dali-core.h>
// INTERNAL INCLUDES
-#include <adaptor-impl.h>
+#include <singleton-service-impl.h>
namespace Dali
{
{
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;
{
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
$(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 \
#include <dali/public-api/object/type-registry.h>
// INTERNAL INCLUDES
-#include <adaptor-impl.h>
+#include <singleton-service-impl.h>
namespace Dali
{
{
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
}
else
{
- Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );
player = Dali::HapticPlayer( New() );
- adaptorImpl.RegisterSingleton( typeid( player ), player );
+ service.Register( typeid( player ), player );
}
}
#include <physical-keyboard-impl.h>
// INTERNAL INCLUDES
-#include <adaptor-impl.h>
+#include <singleton-service-impl.h>
namespace Dali
{
{
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;
{
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
--- /dev/null
+/*
+ * 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 <singleton-service-impl.h>
+
+// EXTERNAL INCLUDES
+#include <boost/thread/tss.hpp>
+#include <dali/integration-api/debug.h>
+
+// INTERNAL INCLUDES
+
+#if defined(DEBUG_ENABLED)
+#include <slp-logging.h>
+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
--- /dev/null
+#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 <dali/public-api/object/base-object.h>
+#include <dali/public-api/common/map-wrapper.h>
+
+// INTERNAL INCLUDES
+#include <singleton-service.h>
+
+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<std::string, BaseHandle> SingletonPair;
+ typedef std::map<std::string, BaseHandle> 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<Internal::Adaptor::SingletonService&>(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<const Internal::Adaptor::SingletonService&>(handle);
+}
+
+} // namespace Dali
+
+#endif // __DALI_INTERNAL_SINGLETON_SERVICE_H__
#include <dali/public-api/object/type-registry.h>
// INTERNAL INCLUDES
-#include <adaptor-impl.h>
+#include <singleton-service-impl.h>
namespace Dali
{
{
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
}
else
{
- Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );
player = Dali::SoundPlayer( New() );
- adaptorImpl.RegisterSingleton( typeid( player ), player );
+ service.Register( typeid( player ), player );
}
}
// INTERNAL INCLUDES
#include <dali/public-api/object/type-registry.h>
#include <adaptor-impl.h>
+#include <singleton-service-impl.h>
namespace Dali
{
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;
{
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
#include <efl_assist_theme.h>
// INTERNAL INCLUDES
-#include <common/adaptor-impl.h>
+#include <singleton-service-impl.h>
namespace Dali
{
{
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
}
else
{
- Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );
colorController = Dali::ColorController( new ColorController( ) );
- adaptorImpl.RegisterSingleton( typeid( colorController ), colorController );
+ service.Register( typeid( colorController ), colorController );
}
}
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();
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
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 );
*/
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
/**
--- /dev/null
+/*
+ * 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 <singleton-service.h>
+
+// INTERNAL INCLUDES
+#include <singleton-service-impl.h>
+
+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
--- /dev/null
+#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 <typeinfo>
+#include <dali/public-api/object/base-handle.h>
+
+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__
#include <dali/public-api/adaptor-framework/physical-keyboard.h>
#include <dali/public-api/adaptor-framework/pixmap-image.h>
#include <dali/public-api/adaptor-framework/render-surface.h>
+#include <dali/public-api/adaptor-framework/singleton-service.h>
#include <dali/public-api/adaptor-framework/sound-player.h>
#include <dali/public-api/adaptor-framework/style-change.h>
#include <dali/public-api/adaptor-framework/style-monitor.h>
$(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 \
$(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 \
#include <dali/integration-api/debug.h>
#include <dali/integration-api/events/touch-event-integ.h>
#include <dali/integration-api/events/gesture-requests.h>
-#include "system-settings.h"
+
+// INTERNAL INCLUDES
+#include <singleton-service-impl.h>
+#include <system-settings.h>
namespace Dali
{
{
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;
{
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
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 );
+ }
}
}
#include <dali/integration-api/debug.h>
// INTERNAL INCLUDES
-#include <adaptor-impl.h>
+#include <singleton-service-impl.h>
#ifdef __arm__
#define SENSOR_ENABLED
{
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
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;
}
}
#include <dali/integration-api/debug.h>
#include <dali/integration-api/events/touch-event-integ.h>
#include <dali/integration-api/events/gesture-requests.h>
+
+// INTERNAL INCLUDES
+#include <singleton-service-impl.h>
#include "system-settings.h"
namespace Dali
{
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;
{
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
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 );
+ }
}
}
#include <dali/integration-api/debug.h>
// INTERNAL INCLUDES
-#include <adaptor-impl.h>
+#include <singleton-service-impl.h>
namespace // unnamed namespace
{
{
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
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;
}
}
#include <dali/integration-api/debug.h>
// INTERNAL INCLUDES
-#include <adaptor.h>
#include <dali/public-api/object/any.h>
-#include <adaptor-impl.h>
+#include <singleton-service-impl.h>
namespace //unnamed namespace
{
{
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
// INTERNAL INCLUDES
#include <window-render-surface.h>
#include <adaptor-impl.h>
+#include <singleton-service-impl.h>
#include <virtual-keyboard-impl.h>
namespace Dali
{
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
#include <dali/integration-api/debug.h>
// INTERNAL INCLUDES
-#include <adaptor.h>
#include <dali/public-api/object/any.h>
#include <adaptor-impl.h>
#include <ecore-x-window-interface.h>
+#include <singleton-service-impl.h>
namespace //unnamed namespace
{
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;
{
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
// INTERNAL INCLUDES
#include <window-render-surface.h>
#include <adaptor-impl.h>
+#include <singleton-service-impl.h>
#include <virtual-keyboard-impl.h>
namespace Dali
{
BaseHandle handle( ImfManager::Get() );
- if ( !handle && Adaptor::IsAvailable() )
+ Dali::SingletonService service( SingletonService::Get() );
+ if ( !handle && Adaptor::IsAvailable() && service )
{
Adaptor& adaptorImpl( Adaptor::GetImplementation( Adaptor::Get() ) );
// 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;
}
{
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