2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/event/common/thread-local-storage.h>
22 #include <dali/internal/common/core-impl.h>
23 #include <dali/public-api/common/dali-common.h>
24 #include <dali/internal/event/common/event-thread-services.h>
25 #include <dali/integration-api/processor-interface.h>
27 #if defined(DEBUG_ENABLED)
28 #include <dali/integration-api/debug.h>
29 Debug::Filter* gSingletonServiceLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_SINGLETON_SERVICE" );
31 // 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
32 #define DALI_LOG_SINGLETON_SERVICE_DIRECT(level, message) \
33 if(gSingletonServiceLogFilter && gSingletonServiceLogFilter->IsEnabledFor(level)) { std::string string(message); Dali::TizenPlatform::LogMessage( Debug::DebugInfo, string ); }
35 #define DALI_LOG_SINGLETON_SERVICE(level, format, ...) DALI_LOG_INFO(gSingletonServiceLogFilter, level, format, ## __VA_ARGS__ )
38 #define DALI_LOG_SINGLETON_SERVICE_DIRECT(level, message)
39 #define DALI_LOG_SINGLETON_SERVICE(level, format, ...)
51 thread_local ThreadLocalStorage* threadLocal = nullptr;
54 ThreadLocalStorage::ThreadLocalStorage(Core* core)
57 DALI_ASSERT_ALWAYS( threadLocal == nullptr && "Cannot create more than one ThreadLocalStorage object" );
62 ThreadLocalStorage::~ThreadLocalStorage() = default;
64 void ThreadLocalStorage::Remove()
66 threadLocal = nullptr;
69 ThreadLocalStorage& ThreadLocalStorage::Get()
71 DALI_ASSERT_ALWAYS(threadLocal);
76 Dali::SingletonService ThreadLocalStorage::GetSingletonService()
78 Dali::SingletonService singletonService;
81 singletonService = Dali::SingletonService( threadLocal );
83 return singletonService;
86 bool ThreadLocalStorage::Created()
88 // see if the TLS has been set yet
89 return (threadLocal != nullptr);
92 ThreadLocalStorage* ThreadLocalStorage::GetInternal()
97 Dali::Integration::PlatformAbstraction& ThreadLocalStorage::GetPlatformAbstraction()
99 return mCore->GetPlatform();
102 SceneGraph::UpdateManager& ThreadLocalStorage::GetUpdateManager()
104 return mCore->GetUpdateManager();
107 NotificationManager& ThreadLocalStorage::GetNotificationManager()
109 return mCore->GetNotificationManager();
112 ShaderFactory& ThreadLocalStorage::GetShaderFactory()
114 return mCore->GetShaderFactory();
117 StagePtr ThreadLocalStorage::GetCurrentStage()
119 return mCore->GetCurrentStage();
122 GestureEventProcessor& ThreadLocalStorage::GetGestureEventProcessor()
124 return mCore->GetGestureEventProcessor();
127 RelayoutController& ThreadLocalStorage::GetRelayoutController()
129 return mCore->GetRelayoutController();
132 ObjectRegistry& ThreadLocalStorage::GetObjectRegistry()
134 return mCore->GetObjectRegistry();
137 EventThreadServices& ThreadLocalStorage::GetEventThreadServices()
139 return mCore->GetEventThreadServices();
142 PropertyNotificationManager& ThreadLocalStorage::GetPropertyNotificationManager()
144 return mCore->GetPropertyNotificationManager();
147 AnimationPlaylist& ThreadLocalStorage::GetAnimationPlaylist()
149 return mCore->GetAnimationPlaylist();
152 void ThreadLocalStorage::AddScene( Scene* scene )
154 mCore->AddScene( scene );
157 void ThreadLocalStorage::RemoveScene( Scene* scene )
159 mCore->RemoveScene( scene );
162 void ThreadLocalStorage::Register( const std::type_info& info, BaseHandle singleton )
166 DALI_LOG_SINGLETON_SERVICE( Debug::General, "Singleton Added: %s\n", info.name() );
167 mSingletonContainer.push_back( SingletonPair( info.name(), singleton ) );
169 Integration::Processor* processor = dynamic_cast<Integration::Processor*>( &singleton.GetBaseObject() );
172 mCore->RegisterProcessor( *processor );
177 void ThreadLocalStorage::UnregisterAll( )
179 mSingletonContainer.clear();
182 BaseHandle ThreadLocalStorage::GetSingleton( const std::type_info& info ) const
186 const SingletonContainer::const_iterator end = mSingletonContainer.end();
187 for( SingletonContainer::const_iterator iter = mSingletonContainer.begin(); iter != end; ++iter )
189 // comparing the addresses as these are allocated statically per library
190 if( ( *iter ).first == info.name() )
192 object = ( *iter ).second;
199 } // namespace Internal