1 #ifndef DALI_INTERNAL_THREAD_LOCAL_STORAGE_H
2 #define DALI_INTERNAL_THREAD_LOCAL_STORAGE_H
5 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/common/vector-wrapper.h>
25 #include <dali/devel-api/common/singleton-service.h>
26 #include <dali/internal/event/common/stage-def.h>
27 #include <dali/internal/event/common/scene-impl.h>
36 class PlatformAbstraction;
43 class NotificationManager;
45 class GestureEventProcessor;
46 class RelayoutController;
48 class EventThreadServices;
56 * Class to store a pointer to core in thread local storage.
59 class ThreadLocalStorage : public Dali::BaseObject
65 * Creates the TLS and adds a pointer to core
66 * @param [in] core reference to core
68 ThreadLocalStorage(Core* core);
71 * Remove core pointer.
72 * Prevents the core pointer being automatically deleted when the thread exits.
78 * @return reference to the TLS
80 static ThreadLocalStorage& Get();
83 * @copydoc Dali::SingletonService::Get()
85 static Dali::SingletonService GetSingletonService();
88 * Checks if the TLS has been created
89 * @return if the TLS has been created
91 static bool Created();
94 * Get a pointer to the TLS or NULL if not initialized
95 * @return pointer to the TLS
97 static ThreadLocalStorage* GetInternal();
100 * get platform abstraction
101 * @return reference to core
103 Dali::Integration::PlatformAbstraction& GetPlatformAbstraction();
106 * Retrieve the update manager
107 * @return reference to update manager
109 SceneGraph::UpdateManager& GetUpdateManager();
112 * Returns the Notification Manager
113 * @return reference to the Notification Manager
115 NotificationManager& GetNotificationManager();
118 * Returns the Shader Factory
119 * @return reference to the Shader Factory
121 ShaderFactory& GetShaderFactory();
124 * Returns the current stage.
125 * @return A pointer to the current stage.
127 StagePtr GetCurrentStage();
130 * Returns the gesture event processor.
131 * @return A reference to the gesture event processor.
133 GestureEventProcessor& GetGestureEventProcessor();
136 * Return the relayout controller
137 * @Return Return a reference to the relayout controller
139 RelayoutController& GetRelayoutController();
142 * Returns the Object registry.
143 * @return A reference to the Object registry
145 ObjectRegistry& GetObjectRegistry();
148 * @brief Gets the event thread services.
149 * @return A reference to the event thread services
151 EventThreadServices& GetEventThreadServices();
154 * @brief Gets the property notification manager.
155 * @return A reference to the property notification manager
157 PropertyNotificationManager& GetPropertyNotificationManager();
160 * @brief Gets the animation play list.
161 * @return A reference to the animation play list
163 AnimationPlaylist& GetAnimationPlaylist();
166 * Add a Scene to the Core.
167 * This is only used by the Scene to add itself to the core when the Scene is created.
168 * @param[in] scene The Scene.
170 void AddScene( Scene* scene );
173 * Remove a Scene from the Core.
174 * This is only used by the Scene to remove itself from the core when the Scene is destroyed.
175 * @param[in] scene The Scene.
177 void RemoveScene( Scene* scene );
180 * @copydoc Dali::SingletonService::Register()
182 void Register( const std::type_info& info, BaseHandle singleton );
185 * @copydoc Dali::SingletonService::UnregisterAll()
187 void UnregisterAll();
190 * @copydoc Dali::SingletonService::GetSingleton()
192 BaseHandle GetSingleton( const std::type_info& info ) const;
199 virtual ~ThreadLocalStorage();
202 ThreadLocalStorage( const ThreadLocalStorage& );
203 ThreadLocalStorage& operator=( ThreadLocalStorage& );
207 Core* mCore; ///< reference to core
209 // using the address of the type name string as compiler will allocate these once per library
210 // and we don't support un/re-loading of dali libraries while singleton service is alive
211 typedef std::pair< const char*, BaseHandle> SingletonPair;
212 typedef std::vector< SingletonPair > SingletonContainer;
213 typedef SingletonContainer::const_iterator SingletonConstIter;
215 SingletonContainer mSingletonContainer; ///< The container to look up singleton by its type name
219 } // namespace Internal
221 // Helpers for public-api forwarding methods
223 inline Internal::ThreadLocalStorage& GetImplementation(Dali::SingletonService& service)
225 DALI_ASSERT_ALWAYS( service && "SingletonService handle is empty" );
227 BaseObject& handle = service.GetBaseObject();
229 return static_cast<Internal::ThreadLocalStorage&>(handle);
232 inline const Internal::ThreadLocalStorage& GetImplementation(const Dali::SingletonService& service)
234 DALI_ASSERT_ALWAYS( service && "SingletonService handle is empty" );
236 const BaseObject& handle = service.GetBaseObject();
238 return static_cast<const Internal::ThreadLocalStorage&>(handle);
243 #endif // DALI_INTERNAL_THREAD_LOCAL_STORAGE_H