Clean up the code to build successfully on macOS
[platform/core/uifw/dali-core.git] / dali / internal / event / common / thread-local-storage.cpp
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/common/thread-local-storage.h>
20
21 // INTERNAL INCLUDES
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>
26
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" );
30
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 );  }
34
35 #define DALI_LOG_SINGLETON_SERVICE(level, format, ...) DALI_LOG_INFO(gSingletonServiceLogFilter, level, format, ## __VA_ARGS__ )
36 #else
37
38 #define DALI_LOG_SINGLETON_SERVICE_DIRECT(level, message)
39 #define DALI_LOG_SINGLETON_SERVICE(level, format, ...)
40
41 #endif
42
43 namespace Dali
44 {
45
46 namespace Internal
47 {
48
49 namespace
50 {
51 thread_local ThreadLocalStorage* threadLocal = nullptr;
52 }
53
54 ThreadLocalStorage::ThreadLocalStorage(Core* core)
55 : mCore( core )
56 {
57   DALI_ASSERT_ALWAYS( threadLocal == nullptr && "Cannot create more than one ThreadLocalStorage object" );
58
59   threadLocal = this;
60 }
61
62 ThreadLocalStorage::~ThreadLocalStorage()
63 {
64 }
65
66 void ThreadLocalStorage::Remove()
67 {
68   threadLocal = nullptr;
69 }
70
71 ThreadLocalStorage& ThreadLocalStorage::Get()
72 {
73   DALI_ASSERT_ALWAYS(threadLocal);
74
75   return *threadLocal;
76 }
77
78 Dali::SingletonService ThreadLocalStorage::GetSingletonService()
79 {
80   Dali::SingletonService singletonService;
81   if ( threadLocal )
82   {
83     singletonService = Dali::SingletonService( threadLocal );
84   }
85   return singletonService;
86 }
87
88 bool ThreadLocalStorage::Created()
89 {
90   // see if the TLS has been set yet
91   return (threadLocal != nullptr);
92 }
93
94 ThreadLocalStorage* ThreadLocalStorage::GetInternal()
95 {
96   return threadLocal;
97 }
98
99 Dali::Integration::PlatformAbstraction& ThreadLocalStorage::GetPlatformAbstraction()
100 {
101   return mCore->GetPlatform();
102 }
103
104 SceneGraph::UpdateManager& ThreadLocalStorage::GetUpdateManager()
105 {
106   return mCore->GetUpdateManager();
107 }
108
109 NotificationManager& ThreadLocalStorage::GetNotificationManager()
110 {
111   return mCore->GetNotificationManager();
112 }
113
114 ShaderFactory& ThreadLocalStorage::GetShaderFactory()
115 {
116   return mCore->GetShaderFactory();
117 }
118
119 StagePtr ThreadLocalStorage::GetCurrentStage()
120 {
121   return mCore->GetCurrentStage();
122 }
123
124 GestureEventProcessor& ThreadLocalStorage::GetGestureEventProcessor()
125 {
126   return mCore->GetGestureEventProcessor();
127 }
128
129 RelayoutController& ThreadLocalStorage::GetRelayoutController()
130 {
131   return mCore->GetRelayoutController();
132 }
133
134 ObjectRegistry& ThreadLocalStorage::GetObjectRegistry()
135 {
136   return mCore->GetObjectRegistry();
137 }
138
139 EventThreadServices& ThreadLocalStorage::GetEventThreadServices()
140 {
141   return mCore->GetEventThreadServices();
142 }
143
144 PropertyNotificationManager& ThreadLocalStorage::GetPropertyNotificationManager()
145 {
146   return mCore->GetPropertyNotificationManager();
147 }
148
149 AnimationPlaylist& ThreadLocalStorage::GetAnimationPlaylist()
150 {
151   return mCore->GetAnimationPlaylist();
152 }
153
154 void ThreadLocalStorage::AddScene( Scene* scene )
155 {
156   mCore->AddScene( scene );
157 }
158
159 void ThreadLocalStorage::RemoveScene( Scene* scene )
160 {
161   mCore->RemoveScene( scene );
162 }
163
164 void ThreadLocalStorage::Register( const std::type_info& info, BaseHandle singleton )
165 {
166   if( singleton )
167   {
168     DALI_LOG_SINGLETON_SERVICE( Debug::General, "Singleton Added: %s\n", info.name() );
169     mSingletonContainer.push_back( SingletonPair( info.name(), singleton ) );
170
171     Integration::Processor* processor = dynamic_cast<Integration::Processor*>( &singleton.GetBaseObject() );
172     if( processor )
173     {
174       mCore->RegisterProcessor( *processor );
175     }
176   }
177 }
178
179 void ThreadLocalStorage::UnregisterAll( )
180 {
181   mSingletonContainer.clear();
182 }
183
184 BaseHandle ThreadLocalStorage::GetSingleton( const std::type_info& info ) const
185 {
186   BaseHandle object;
187
188   const SingletonContainer::const_iterator end = mSingletonContainer.end();
189   for( SingletonContainer::const_iterator iter = mSingletonContainer.begin(); iter != end; ++iter )
190   {
191     // comparing the addresses as these are allocated statically per library
192     if( ( *iter ).first == info.name() )
193     {
194       object = ( *iter ).second;
195     }
196   }
197
198   return object;
199 }
200
201 } // namespace Internal
202
203 } // namespace Dali