[dali_1.9.14] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / event / common / thread-local-storage.cpp
index 8ce6c11..2424d41 100644 (file)
 #include <dali/internal/common/core-impl.h>
 #include <dali/public-api/common/dali-common.h>
 #include <dali/internal/event/common/event-thread-services.h>
+#include <dali/integration-api/processor-interface.h>
+
+#if defined(DEBUG_ENABLED)
+#include <dali/integration-api/debug.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::TizenPlatform::LogMessage( Debug::DebugInfo, string );  }
+
+#define DALI_LOG_SINGLETON_SERVICE(level, format, ...) DALI_LOG_INFO(gSingletonServiceLogFilter, level, format, ## __VA_ARGS__ )
+#else
+
+#define DALI_LOG_SINGLETON_SERVICE_DIRECT(level, message)
+#define DALI_LOG_SINGLETON_SERVICE(level, format, ...)
+
+#endif
 
 namespace Dali
 {
@@ -58,6 +75,16 @@ ThreadLocalStorage& ThreadLocalStorage::Get()
   return *threadLocal;
 }
 
+Dali::SingletonService ThreadLocalStorage::GetSingletonService()
+{
+  Dali::SingletonService singletonService;
+  if ( threadLocal )
+  {
+    singletonService = Dali::SingletonService( threadLocal );
+  }
+  return singletonService;
+}
+
 bool ThreadLocalStorage::Created()
 {
   // see if the TLS has been set yet
@@ -134,6 +161,43 @@ void ThreadLocalStorage::RemoveScene( Scene* scene )
   mCore->RemoveScene( scene );
 }
 
+void ThreadLocalStorage::Register( const std::type_info& info, BaseHandle singleton )
+{
+  if( singleton )
+  {
+    DALI_LOG_SINGLETON_SERVICE( Debug::General, "Singleton Added: %s\n", info.name() );
+    mSingletonContainer.push_back( SingletonPair( info.name(), singleton ) );
+
+    Integration::Processor* processor = dynamic_cast<Integration::Processor*>( &singleton.GetBaseObject() );
+    if( processor )
+    {
+      mCore->RegisterProcessor( *processor );
+    }
+  }
+}
+
+void ThreadLocalStorage::UnregisterAll( )
+{
+  mSingletonContainer.clear();
+}
+
+BaseHandle ThreadLocalStorage::GetSingleton( const std::type_info& info ) const
+{
+  BaseHandle object;
+
+  const SingletonContainer::const_iterator end = mSingletonContainer.end();
+  for( SingletonContainer::const_iterator iter = mSingletonContainer.begin(); iter != end; ++iter )
+  {
+    // comparing the addresses as these are allocated statically per library
+    if( ( *iter ).first == info.name() )
+    {
+      object = ( *iter ).second;
+    }
+  }
+
+  return object;
+}
+
 } // namespace Internal
 
 } // namespace Dali