Merge "Added option to test harness execution to only summarize failures" into devel...
[platform/core/uifw/dali-adaptor.git] / adaptors / common / singleton-service-impl.cpp
index 63e7dfb..5ee6180 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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.
 #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>
+#include <tizen-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 );  }
+    if(gSingletonServiceLogFilter && gSingletonServiceLogFilter->IsEnabledFor(level)) { std::string string(message); Dali::TizenPlatform::LogMessage( Debug::DebugInfo, string );  }
 
 #define DALI_LOG_SINGLETON_SERVICE(level, format, args...) DALI_LOG_INFO(gSingletonServiceLogFilter, level, format, ## args )
 
@@ -52,22 +50,7 @@ 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* service )
-{
-  if ( service )
-  {
-    service->UnregisterAll();
-  }
-}
-
-boost::thread_specific_ptr< SingletonService > gSingletonService( &DummyCleanup );
+thread_local SingletonService * gSingletonService = 0;
 } // unnamed namespace
 
 Dali::SingletonService SingletonService::New()
@@ -79,9 +62,9 @@ Dali::SingletonService SingletonService::New()
 Dali::SingletonService SingletonService::Get()
 {
   Dali::SingletonService singletonService;
-  if ( gSingletonService.get() )
+  if ( gSingletonService )
   {
-    singletonService = Dali::SingletonService( gSingletonService.get() );
+    singletonService = Dali::SingletonService( gSingletonService );
   }
   return singletonService;
 }
@@ -91,7 +74,7 @@ void SingletonService::Register( const std::type_info& info, BaseHandle singleto
   if( singleton )
   {
     DALI_LOG_SINGLETON_SERVICE( Debug::General, "Singleton Added: %s\n", info.name() );
-    mSingletonContainer.insert( SingletonPair( info.name(), singleton ) );
+    mSingletonContainer.push_back( SingletonPair( info.name(), singleton ) );
   }
 }
 
@@ -104,10 +87,14 @@ BaseHandle SingletonService::GetSingleton( const std::type_info& info ) const
 {
   BaseHandle object;
 
-  SingletonConstIter iter = mSingletonContainer.find(info.name());
-  if( iter != mSingletonContainer.end() )
+  const SingletonContainer::const_iterator end = mSingletonContainer.end();
+  for( SingletonContainer::const_iterator iter = mSingletonContainer.begin(); iter != end; ++iter )
   {
-    object = ( *iter ).second;
+    // comparing the addresses as these are allocated statically per library
+    if( ( *iter ).first == info.name() )
+    {
+      object = ( *iter ).second;
+    }
   }
 
   return object;
@@ -117,16 +104,17 @@ SingletonService::SingletonService()
 : mSingletonContainer()
 {
   // Can only have one instance of SingletonService
-  DALI_ASSERT_ALWAYS( !gSingletonService.get() && "Only one instance of SingletonService is allowed");
+  DALI_ASSERT_ALWAYS( !gSingletonService && "Only one instance of SingletonService is allowed");
 
-  gSingletonService.reset( this );
+  gSingletonService = this;
 
   DALI_LOG_SINGLETON_SERVICE_DIRECT( Debug::Concise, "SingletonService Created\n" );
 }
 
 SingletonService::~SingletonService()
 {
-  gSingletonService.release();
+  gSingletonService = 0;
+
   DALI_LOG_SINGLETON_SERVICE_DIRECT( Debug::Concise, "SingletonService Destroyed\n" );
 }
 
@@ -135,3 +123,4 @@ SingletonService::~SingletonService()
 } // namespace Internal
 
 } // namespace Dali
+