Revert "[Tizen] Not execute the remove callback"
[platform/core/uifw/dali-core.git] / dali / internal / event / common / thread-local-storage.h
1 #ifndef DALI_INTERNAL_THREAD_LOCAL_STORAGE_H
2 #define DALI_INTERNAL_THREAD_LOCAL_STORAGE_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/common/vector-wrapper.h>
23
24 // INTERNAL INCLUDES
25 #include <dali/devel-api/common/singleton-service.h>
26 #include <dali/internal/event/common/scene-impl.h>
27 #include <dali/internal/event/common/stage-def.h>
28
29 namespace Dali
30 {
31 struct Vector2;
32
33 namespace Integration
34 {
35 class PlatformAbstraction;
36 }
37
38 namespace Internal
39 {
40 class Core;
41 class NotificationManager;
42 class ShaderFactory;
43 class GestureEventProcessor;
44 class RelayoutController;
45 class ObjectRegistry;
46 class EventThreadServices;
47 class PropertyNotificationManager;
48 class AnimationPlaylist;
49
50 namespace SceneGraph
51 {
52 class UpdateManager;
53 }
54
55 /**
56  * Class to store a pointer to core in thread local storage.
57  *
58  */
59 class ThreadLocalStorage : public Dali::BaseObject
60 {
61 public:
62   /**
63    * Constructor
64    * Creates the TLS and adds a pointer to core
65    * @param [in] core reference to core
66    */
67   ThreadLocalStorage(Core* core);
68
69   /**
70    * Remove core pointer.
71    * Prevents the core pointer being automatically deleted when the thread exits.
72    */
73   void Remove();
74
75   /**
76    * Get the TLS
77    * @return reference to the TLS
78    */
79   static ThreadLocalStorage& Get();
80
81   /**
82    * @copydoc Dali::SingletonService::Get()
83    */
84   static Dali::SingletonService GetSingletonService();
85
86   /**
87    * Checks if the TLS has been created
88    * @return if the TLS has been created
89    */
90   static bool Created();
91
92   /**
93    * Get a pointer to the TLS or NULL if not initialized
94    * @return pointer to the TLS
95    */
96   static ThreadLocalStorage* GetInternal();
97
98   /**
99    * get platform abstraction
100    * @return reference to core
101    */
102   Dali::Integration::PlatformAbstraction& GetPlatformAbstraction();
103
104   /**
105    * Retrieve the update manager
106    * @return reference to update manager
107    */
108   SceneGraph::UpdateManager& GetUpdateManager();
109
110   /**
111    * Returns the Notification Manager
112    * @return reference to the Notification Manager
113    */
114   NotificationManager& GetNotificationManager();
115
116   /**
117    * Returns the Shader Factory
118    * @return reference to the Shader Factory
119    */
120   ShaderFactory& GetShaderFactory();
121
122   /**
123    * Returns the current stage.
124    * @return A pointer to the current stage.
125    */
126   StagePtr GetCurrentStage();
127
128   /**
129    * Returns the gesture event processor.
130    * @return A reference to the gesture event processor.
131    */
132   GestureEventProcessor& GetGestureEventProcessor();
133
134   /**
135    * Return the relayout controller
136    * @Return Return a reference to the relayout controller
137    */
138   RelayoutController& GetRelayoutController();
139
140   /**
141    * Returns the Object registry.
142    * @return A reference to the Object registry
143    */
144   ObjectRegistry& GetObjectRegistry();
145
146   /**
147    * @brief Gets the event thread services.
148    * @return A reference to the event thread services
149    */
150   EventThreadServices& GetEventThreadServices();
151
152   /**
153    * @brief Gets the property notification manager.
154    * @return A reference to the property notification manager
155    */
156   PropertyNotificationManager& GetPropertyNotificationManager();
157
158   /**
159    * @brief Gets the animation play list.
160    * @return A reference to the animation play list
161    */
162   AnimationPlaylist& GetAnimationPlaylist();
163
164   /**
165    * @brief Returns whether the blend equation is supported in the system or not.
166    * @param[in] blendEquation blend equation to be checked.
167    * @return True if the blend equation supported.
168    */
169   bool IsBlendEquationSupported(DevelBlendEquation::Type blendEquation);
170
171   /**
172    * @brief Returns shader prefix of shading language version.
173    */
174   std::string GetShaderVersionPrefix();
175
176   /**
177    * @brief Returns vertex shader prefix including shading language version.
178    */
179   std::string GetVertexShaderPrefix();
180
181   /**
182    * @brief Returns fragment shader prefix including shading language version and extension information.
183    */
184   std::string GetFragmentShaderPrefix();
185
186   /**
187    * Add a Scene to the Core.
188    * This is only used by the Scene to add itself to the core when the Scene is created.
189    * @param[in] scene The Scene.
190    */
191   void AddScene(Scene* scene);
192
193   /**
194    * Remove a Scene from the Core.
195    * This is only used by the Scene to remove itself from the core when the Scene is destroyed.
196    * @param[in] scene The Scene.
197    */
198   void RemoveScene(Scene* scene);
199
200   /**
201    * @copydoc Dali::SingletonService::Register()
202    */
203   void Register(const std::type_info& info, BaseHandle singleton);
204
205   /**
206    * @copydoc Dali::SingletonService::UnregisterAll()
207    */
208   void UnregisterAll();
209
210   /**
211    * @copydoc Dali::SingletonService::GetSingleton()
212    */
213   BaseHandle GetSingleton(const std::type_info& info) const;
214
215 private:
216   /**
217    * Virtual Destructor
218    */
219   ~ThreadLocalStorage() override;
220
221   // Undefined
222   ThreadLocalStorage(const ThreadLocalStorage&);
223   ThreadLocalStorage& operator=(ThreadLocalStorage&);
224
225 private:
226   Core* mCore; ///< reference to core
227
228   // using the address of the type name string as compiler will allocate these once per library
229   // and we don't support un/re-loading of dali libraries while singleton service is alive
230   using SingletonPair      = std::pair<const char*, BaseHandle>;
231   using SingletonContainer = std::vector<SingletonPair>;
232   using SingletonConstIter = SingletonContainer::const_iterator;
233
234   SingletonContainer mSingletonContainer; ///< The container to look up singleton by its type name
235 };
236
237 } // namespace Internal
238
239 // Helpers for public-api forwarding methods
240
241 inline Internal::ThreadLocalStorage& GetImplementation(Dali::SingletonService& service)
242 {
243   DALI_ASSERT_ALWAYS(service && "SingletonService handle is empty");
244
245   BaseObject& handle = service.GetBaseObject();
246
247   return static_cast<Internal::ThreadLocalStorage&>(handle);
248 }
249
250 inline const Internal::ThreadLocalStorage& GetImplementation(const Dali::SingletonService& service)
251 {
252   DALI_ASSERT_ALWAYS(service && "SingletonService handle is empty");
253
254   const BaseObject& handle = service.GetBaseObject();
255
256   return static_cast<const Internal::ThreadLocalStorage&>(handle);
257 }
258
259 } // namespace Dali
260
261 #endif // DALI_INTERNAL_THREAD_LOCAL_STORAGE_H