use modern construct 'override' in the derive class.
[platform/core/uifw/dali-core.git] / dali / internal / event / common / thread-local-storage.h
index ff3b114..f994a12 100644 (file)
@@ -1,24 +1,30 @@
-#ifndef __DALI_INTERNAL_THREAD_LOCAL_STORAGE_H__
-#define __DALI_INTERNAL_THREAD_LOCAL_STORAGE_H__
-
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+#ifndef DALI_INTERNAL_THREAD_LOCAL_STORAGE_H
+#define DALI_INTERNAL_THREAD_LOCAL_STORAGE_H
+
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/common/vector-wrapper.h>
 
 // INTERNAL INCLUDES
-#include <dali/internal/event/common/stage-impl.h>
+#include <dali/devel-api/common/singleton-service.h>
+#include <dali/internal/event/common/stage-def.h>
+#include <dali/internal/event/common/scene-impl.h>
 
 namespace Dali
 {
@@ -35,15 +41,11 @@ namespace Internal
 
 class Core;
 class NotificationManager;
-class ResourceClient;
-class ResourceManager;
-class ImageFactory;
-class ModelFactory;
-class FontFactory;
 class ShaderFactory;
-class EventToUpdate;
 class GestureEventProcessor;
-class EmojiFactory;
+class RelayoutController;
+class ObjectRegistry;
+class EventThreadServices;
 
 namespace SceneGraph
 {
@@ -54,7 +56,7 @@ class UpdateManager;
  * Class to store a pointer to core in thread local storage.
  *
  */
-class ThreadLocalStorage
+class ThreadLocalStorage : public Dali::BaseObject
 {
 public:
 
@@ -66,11 +68,6 @@ public:
   ThreadLocalStorage(Core* core);
 
   /**
-   * Destructor.
-   */
-  ~ThreadLocalStorage();
-
-  /**
    * Remove core pointer.
    * Prevents the core pointer being automatically deleted when the thread exits.
    */
@@ -83,12 +80,23 @@ public:
   static ThreadLocalStorage& Get();
 
   /**
+   * @copydoc Dali::SingletonService::Get()
+   */
+  static Dali::SingletonService GetSingletonService();
+
+  /**
    * Checks if the TLS has been created
    * @return if the TLS has been created
    */
   static bool Created();
 
   /**
+   * Get a pointer to the TLS or NULL if not initialized
+   * @return pointer to the TLS
+   */
+  static ThreadLocalStorage* GetInternal();
+
+  /**
    * get platform abstraction
    * @return reference to core
    */
@@ -107,73 +115,129 @@ public:
   NotificationManager& GetNotificationManager();
 
   /**
-   * Returns the Resource Manager
-   * @return reference to the Resource Manager
+   * Returns the Shader Factory
+   * @return reference to the Shader Factory
    */
-  ResourceManager& GetResourceManager();
+  ShaderFactory& GetShaderFactory();
 
   /**
-   * Returns the Resource Client
-   * @return reference to the Resource Client
+   * Returns the current stage.
+   * @return A pointer to the current stage.
    */
-  ResourceClient& GetResourceClient();
+  StagePtr GetCurrentStage();
 
   /**
-   * Returns the Image Factory
-   * @return reference to the Image Factory
+   * Returns the gesture event processor.
+   * @return A reference to the gesture event processor.
    */
-  ImageFactory& GetImageFactory();
+  GestureEventProcessor& GetGestureEventProcessor();
 
   /**
-   * Returns the Model Factory
-   * @return reference to the Image Factory
+   * Return the relayout controller
+   * @Return Return a reference to the relayout controller
    */
-  ModelFactory& GetModelFactory();
+  RelayoutController& GetRelayoutController();
 
   /**
-   * Returns the Font Factory
-   * @return reference to the Font Factory
+   * Returns the Object registry.
+   * @return A reference to the Object registry
    */
-  FontFactory& GetFontFactory();
+  ObjectRegistry& GetObjectRegistry();
 
   /**
-   * Returns the Shader Factory
-   * @return reference to the Shader Factory
+   * @brief Gets the event thread services.
+   * @return A reference to the event thread services
    */
-  ShaderFactory& GetShaderFactory();
+  EventThreadServices& GetEventThreadServices();
 
   /**
-   * Returns the current stage.
-   * @return A smart-pointer to the current stage.
+   * @brief Gets the property notification manager.
+   * @return A reference to the property notification manager
    */
-  StagePtr GetCurrentStage();
+  PropertyNotificationManager& GetPropertyNotificationManager();
 
   /**
-   * Return the message controller
-   * @return A reference to the message controller
+   * @brief Gets the animation play list.
+   * @return A reference to the animation play list
    */
-  EventToUpdate& GetEventToUpdate();
+  AnimationPlaylist& GetAnimationPlaylist();
 
   /**
-   * Returns the gesture event processor.
-   * @return A reference to the gesture event processor.
+   * Add a Scene to the Core.
+   * This is only used by the Scene to add itself to the core when the Scene is created.
+   * @param[in] scene The Scene.
    */
-  GestureEventProcessor& GetGestureEventProcessor();
+  void AddScene( Scene* scene );
+
+  /**
+   * Remove a Scene from the Core.
+   * This is only used by the Scene to remove itself from the core when the Scene is destroyed.
+   * @param[in] scene The Scene.
+   */
+  void RemoveScene( Scene* scene );
+
+  /**
+   * @copydoc Dali::SingletonService::Register()
+   */
+  void Register( const std::type_info& info, BaseHandle singleton );
+
+  /**
+   * @copydoc Dali::SingletonService::UnregisterAll()
+   */
+  void UnregisterAll();
+
+  /**
+   * @copydoc Dali::SingletonService::GetSingleton()
+   */
+  BaseHandle GetSingleton( const std::type_info& info ) const;
+
+private:
 
   /**
-   * Returns the Emoji factory.
-   * @return a reference to the Emoji factory.
+   * Virtual Destructor
    */
-  EmojiFactory& GetEmojiFactory();
+  ~ThreadLocalStorage() override;
+
+  // Undefined
+  ThreadLocalStorage( const ThreadLocalStorage& );
+  ThreadLocalStorage& operator=( ThreadLocalStorage& );
 
 private:
 
-  Core* mCore;                            ///< reference to core
+  Core* mCore;                                              ///< reference to core
+
+  // using the address of the type name string as compiler will allocate these once per library
+  // and we don't support un/re-loading of dali libraries while singleton service is alive
+  using SingletonPair      = std::pair<const char*, BaseHandle>;
+  using SingletonContainer = std::vector<SingletonPair>;
+  using SingletonConstIter = SingletonContainer::const_iterator;
+
+  SingletonContainer mSingletonContainer; ///< The container to look up singleton by its type name
 
 };
 
 } // namespace Internal
 
+// Helpers for public-api forwarding methods
+
+inline Internal::ThreadLocalStorage& GetImplementation(Dali::SingletonService& service)
+{
+  DALI_ASSERT_ALWAYS( service && "SingletonService handle is empty" );
+
+  BaseObject& handle = service.GetBaseObject();
+
+  return static_cast<Internal::ThreadLocalStorage&>(handle);
+}
+
+inline const Internal::ThreadLocalStorage& GetImplementation(const Dali::SingletonService& service)
+{
+  DALI_ASSERT_ALWAYS( service && "SingletonService handle is empty" );
+
+  const BaseObject& handle = service.GetBaseObject();
+
+  return static_cast<const Internal::ThreadLocalStorage&>(handle);
+}
+
 } // namespace Dali
 
-#endif // __DALI_INTERNAL_THREAD_LOCAL_STORAGE_H__
+#endif // DALI_INTERNAL_THREAD_LOCAL_STORAGE_H