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()
66 void ThreadLocalStorage::Remove()
68 threadLocal = nullptr;
71 ThreadLocalStorage& ThreadLocalStorage::Get()
73 DALI_ASSERT_ALWAYS(threadLocal);
78 Dali::SingletonService ThreadLocalStorage::GetSingletonService()
80 Dali::SingletonService singletonService;
83 singletonService = Dali::SingletonService( threadLocal );
85 return singletonService;
88 bool ThreadLocalStorage::Created()
90 // see if the TLS has been set yet
91 return (threadLocal != nullptr);
94 ThreadLocalStorage* ThreadLocalStorage::GetInternal()
99 Dali::Integration::PlatformAbstraction& ThreadLocalStorage::GetPlatformAbstraction()
101 return mCore->GetPlatform();
104 SceneGraph::UpdateManager& ThreadLocalStorage::GetUpdateManager()
106 return mCore->GetUpdateManager();
109 NotificationManager& ThreadLocalStorage::GetNotificationManager()
111 return mCore->GetNotificationManager();
114 ShaderFactory& ThreadLocalStorage::GetShaderFactory()
116 return mCore->GetShaderFactory();
119 StagePtr ThreadLocalStorage::GetCurrentStage()
121 return mCore->GetCurrentStage();
124 GestureEventProcessor& ThreadLocalStorage::GetGestureEventProcessor()
126 return mCore->GetGestureEventProcessor();
129 RelayoutController& ThreadLocalStorage::GetRelayoutController()
131 return mCore->GetRelayoutController();
134 ObjectRegistry& ThreadLocalStorage::GetObjectRegistry()
136 return mCore->GetObjectRegistry();
139 EventThreadServices& ThreadLocalStorage::GetEventThreadServices()
141 return mCore->GetEventThreadServices();
144 PropertyNotificationManager& ThreadLocalStorage::GetPropertyNotificationManager()
146 return mCore->GetPropertyNotificationManager();
149 AnimationPlaylist& ThreadLocalStorage::GetAnimationPlaylist()
151 return mCore->GetAnimationPlaylist();
154 void ThreadLocalStorage::AddScene( Scene* scene )
156 mCore->AddScene( scene );
159 void ThreadLocalStorage::RemoveScene( Scene* scene )
161 mCore->RemoveScene( scene );
164 void ThreadLocalStorage::Register( const std::type_info& info, BaseHandle singleton )
168 DALI_LOG_SINGLETON_SERVICE( Debug::General, "Singleton Added: %s\n", info.name() );
169 mSingletonContainer.push_back( SingletonPair( info.name(), singleton ) );
171 Integration::Processor* processor = dynamic_cast<Integration::Processor*>( &singleton.GetBaseObject() );
174 mCore->RegisterProcessor( *processor );
179 void ThreadLocalStorage::UnregisterAll( )
181 mSingletonContainer.clear();
184 BaseHandle ThreadLocalStorage::GetSingleton( const std::type_info& info ) const
188 const SingletonContainer::const_iterator end = mSingletonContainer.end();
189 for( SingletonContainer::const_iterator iter = mSingletonContainer.begin(); iter != end; ++iter )
191 // comparing the addresses as these are allocated statically per library
192 if( ( *iter ).first == info.name() )
194 object = ( *iter ).second;
201 } // namespace Internal