Using SingletonService instead of Adaptor 43/26943/2
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Mon, 1 Sep 2014 17:45:53 +0000 (18:45 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Mon, 8 Sep 2014 08:51:43 +0000 (09:51 +0100)
Change-Id: I4bb36595d48bb6441f1896975f73b6ce754231e1

12 files changed:
automated-tests/src/dali-toolkit-internal/CMakeLists.txt
automated-tests/src/dali-toolkit-unmanaged/CMakeLists.txt
automated-tests/src/dali-toolkit/CMakeLists.txt
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-adaptor.cpp
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-singleton-service.cpp [new file with mode: 0644]
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-singleton-service.h [new file with mode: 0644]
base/dali-toolkit/internal/controls/relayout-controller.cpp
base/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp
base/dali-toolkit/internal/styling/style-manager-impl.cpp
base/dali-toolkit/public-api/factory/localized-control-factory.cpp
base/dali-toolkit/public-api/focus-manager/focus-manager.cpp
base/dali-toolkit/public-api/focus-manager/keyinput-focus-manager.cpp

index da5110780cae3c926ee9ebf89b195de78ea524dc..ff683d5a9101c47668bac8f394bc1200dd22c9d5 100644 (file)
@@ -25,6 +25,7 @@ LIST(APPEND TC_SOURCES
    ../dali-toolkit/dali-toolkit-test-utils/toolkit-orientation.cpp
    ../dali-toolkit/dali-toolkit-test-utils/toolkit-physical-keyboard.cpp
    ../dali-toolkit/dali-toolkit-test-utils/toolkit-style-monitor.cpp
+   ../dali-toolkit/dali-toolkit-test-utils/toolkit-singleton-service.cpp
    ../dali-toolkit/dali-toolkit-test-utils/toolkit-timer.cpp
    ../dali-toolkit/dali-toolkit-test-utils/toolkit-clipboard-event-notifier.cpp
    ../dali-toolkit/dali-toolkit-test-utils/dummy-control.cpp
index a1e6c7f76b4e97e1cd32f3114d73013db7f81a6d..13c2d320b724092bb3bb003d53d28664709359cb 100644 (file)
@@ -61,6 +61,7 @@ LIST(APPEND TC_SOURCES
    ../dali-toolkit/dali-toolkit-test-utils/toolkit-imf-manager.cpp
    ../dali-toolkit/dali-toolkit-test-utils/toolkit-physical-keyboard.cpp
    ../dali-toolkit/dali-toolkit-test-utils/toolkit-style-monitor.cpp
+   ../dali-toolkit/dali-toolkit-test-utils/toolkit-singleton-service.cpp
    ../dali-toolkit/dali-toolkit-test-utils/toolkit-timer.cpp
    ../dali-toolkit/dali-toolkit-test-utils/toolkit-clipboard-event-notifier.cpp
    ../dali-toolkit/dali-toolkit-test-utils/dummy-control.cpp
index a476f28e10154bdc2b3072b3a829477876e9257f..52f83536a9562da1c091f537a81d64db11ba049d 100644 (file)
@@ -43,6 +43,7 @@ LIST(APPEND TC_SOURCES
    dali-toolkit-test-utils/toolkit-imf-manager.cpp
    dali-toolkit-test-utils/toolkit-physical-keyboard.cpp
    dali-toolkit-test-utils/toolkit-style-monitor.cpp
+   dali-toolkit-test-utils/toolkit-singleton-service.cpp
    dali-toolkit-test-utils/toolkit-timer.cpp
    dali-toolkit-test-utils/toolkit-clipboard-event-notifier.cpp
    dali-toolkit-test-utils/dummy-control.cpp
index 186fadd9671933d0d27ac4cb5a27424edf60cd7d..41acc41ec11adba40bcbc5aae479c9c7fd0a2d3c 100644 (file)
@@ -55,10 +55,6 @@ public:
 
   typedef SignalV2< void ( Adaptor& ) > AdaptorSignalV2;
 
-  typedef std::pair<std::string, Dali::BaseHandle> SingletonPair;
-  typedef std::map<std::string, Dali::BaseHandle>  SingletonContainer;
-  typedef SingletonContainer::const_iterator       SingletonConstIter;
-
 public:
 
   Adaptor(ToolkitAdaptor& toolkitAdaptor);
@@ -78,9 +74,6 @@ public:
   void RenderSync();
   RenderSurface& GetSurface();
 
-  void RegisterSingleton(const std::type_info& info, Dali::BaseHandle singleton);
-  Dali::BaseHandle GetSingleton(const std::type_info& info) const;
-
 public: // static methods
   static Adaptor& Get();
   static bool IsAvailable();
@@ -103,8 +96,6 @@ private:
   AdaptorSignalV2 mResizeSignal;
   TestRenderSurface mRenderSurface;
   ToolkitAdaptor& mToolkitAdaptor;
-
-  SingletonContainer mSingletonContainer;
 };
 
 namespace
@@ -206,31 +197,6 @@ bool Adaptor::IsAvailable()
   return available;
 }
 
-void Adaptor::RegisterSingleton(const std::type_info& info, Dali::BaseHandle singleton)
-{
-  mToolkitAdaptor.mFunctionsCalled.RegisterSingleton = true;
-
-  if(singleton)
-  {
-    mSingletonContainer.insert(SingletonPair(info.name(), singleton));
-  }
-}
-
-Dali::BaseHandle Adaptor::GetSingleton(const std::type_info& info) const
-{
-  mToolkitAdaptor.mFunctionsCalled.GetSingleton = true;
-
-  Dali::BaseHandle object = Dali::BaseHandle();
-
-  SingletonConstIter iter = mSingletonContainer.find(info.name());
-  if(iter != mSingletonContainer.end())
-  {
-    object = (*iter).second;
-  }
-
-  return object;
-}
-
 Adaptor::AdaptorSignalV2& Adaptor::SignalResize()
 {
   mToolkitAdaptor.mFunctionsCalled.SignalResize = true;
diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-singleton-service.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-singleton-service.cpp
new file mode 100644 (file)
index 0000000..d92eb15
--- /dev/null
@@ -0,0 +1,161 @@
+/*
+ * Copyright (c) 2014 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.
+ *
+ */
+
+#include "toolkit-singleton-service.h"
+
+#include <dali/public-api/common/dali-common.h>
+#include <dali/public-api/object/base-object.h>
+#include <dali/public-api/common/map-wrapper.h>
+#include <dali/public-api/signals/dali-signal-v2.h>
+
+namespace Dali
+{
+
+
+namespace Internal
+{
+namespace Adaptor
+{
+
+/**
+ * Stub for the SingletonService
+ */
+class SingletonService : public Dali::BaseObject
+{
+public:
+  static Dali::SingletonService New();
+  static Dali::SingletonService Get();
+  void Register( const std::type_info& info, BaseHandle singleton );
+  BaseHandle GetSingleton( const std::type_info& info ) const;
+
+private:
+  SingletonService();
+  virtual ~SingletonService();
+
+  // Undefined
+  SingletonService( const SingletonService& );
+  SingletonService& operator=( SingletonService& );
+
+private:
+
+  typedef std::pair<std::string, BaseHandle> SingletonPair;
+  typedef std::map<std::string, BaseHandle>  SingletonContainer;
+  typedef SingletonContainer::const_iterator SingletonConstIter;
+
+  SingletonContainer mSingletonContainer; ///< The container to look up singleton by its type name
+
+  static Dali::SingletonService mToolkitSingletonService;
+};
+
+Dali::SingletonService SingletonService::mToolkitSingletonService;
+
+Dali::SingletonService SingletonService::New()
+{
+  return Get();
+}
+
+Dali::SingletonService SingletonService::Get()
+{
+  if( ! mToolkitSingletonService )
+  {
+    mToolkitSingletonService = Dali::SingletonService( new Dali::Internal::Adaptor::SingletonService );
+  }
+  return mToolkitSingletonService;
+}
+
+void SingletonService::Register( const std::type_info& info, BaseHandle singleton )
+{
+  if( singleton )
+  {
+    mSingletonContainer.insert( SingletonPair( info.name(), singleton ) );
+  }
+}
+
+BaseHandle SingletonService::GetSingleton( const std::type_info& info ) const
+{
+  BaseHandle object;
+
+  SingletonConstIter iter = mSingletonContainer.find(info.name());
+  if( iter != mSingletonContainer.end() )
+  {
+    object = ( *iter ).second;
+  }
+
+  return object;
+}
+
+SingletonService::SingletonService()
+: mSingletonContainer()
+{
+}
+
+SingletonService::~SingletonService()
+{
+}
+
+} // namespace Adaptor
+} // namespace Internal
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+Internal::Adaptor::SingletonService& GetImplementation(Dali::SingletonService& player)
+{
+  DALI_ASSERT_ALWAYS( player && "SingletonService handle is empty" );
+
+  BaseObject& handle = player.GetBaseObject();
+
+  return static_cast<Internal::Adaptor::SingletonService&>(handle);
+}
+
+const Internal::Adaptor::SingletonService& GetImplementation(const Dali::SingletonService& player)
+{
+  DALI_ASSERT_ALWAYS( player && "SingletonService handle is empty" );
+
+  const BaseObject& handle = player.GetBaseObject();
+
+  return static_cast<const Internal::Adaptor::SingletonService&>(handle);
+}
+
+SingletonService::SingletonService()
+{
+}
+
+SingletonService SingletonService::Get()
+{
+  return Internal::Adaptor::SingletonService::Get();
+}
+
+SingletonService::~SingletonService()
+{
+}
+
+void SingletonService::Register( const std::type_info& info, BaseHandle singleton )
+{
+  GetImplementation( *this ).Register( info, singleton );
+}
+
+BaseHandle SingletonService::GetSingleton( const std::type_info& info ) const
+{
+  return GetImplementation( *this ).GetSingleton( info );
+}
+
+SingletonService::SingletonService( Internal::Adaptor::SingletonService* singletonService )
+: BaseHandle( singletonService )
+{
+}
+
+} // namespace Dali
diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-singleton-service.h b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-singleton-service.h
new file mode 100644 (file)
index 0000000..956925e
--- /dev/null
@@ -0,0 +1,55 @@
+#ifndef __DALI_TOOLKIT_TOOLKIT_SINGLETON_SERVICE_H__
+#define __DALI_TOOLKIT_TOOLKIT_SINGLETON_SERVICE_H__
+
+/*
+ * Copyright (c) 2014 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
+
+#define __DALI_SINGELTON_SERVICE_H__
+#include <typeinfo>
+#include <dali/public-api/object/base-handle.h>
+
+// INTERNAL INCLUDES
+
+namespace Dali
+{
+
+namespace Internal DALI_INTERNAL
+{
+namespace Adaptor
+{
+class SingletonService;
+}
+}
+
+class SingletonService : public BaseHandle
+{
+public:
+  SingletonService();
+  static SingletonService Get();
+  ~SingletonService();
+  void Register( const std::type_info& info, BaseHandle singleton );
+  BaseHandle GetSingleton( const std::type_info& info ) const;
+
+public: // Not intended for application developers
+  SingletonService( Internal::Adaptor::SingletonService* singletonService );
+};
+
+} // namespace Dali
+
+#endif // __DALI_TOOLKIT_TOOLKIT_SINGLETON_SERVICE_H__
index 8dce13a5ad25203f23fd89afec4cf87c730e6767..1a3a4e61faf1e7c12fe244598a4649e0ff2d610d 100644 (file)
@@ -67,24 +67,27 @@ void RelayoutController::Request()
     RelayoutController controller;
 
     // Check whether the RelayoutController is already created
-    Dali::Adaptor& adaptor = Dali::Adaptor::Get();
-    Dali::BaseHandle handle = adaptor.GetSingleton(typeid(RelayoutController));
-
-    if(handle)
+    SingletonService singletonService( SingletonService::Get() );
+    if ( singletonService )
     {
-      // If so, downcast the handle of singleton to RelayoutController
-      controller = RelayoutController(dynamic_cast<Internal::RelayoutControllerImpl*>(handle.GetObjectPtr()));
+      Dali::BaseHandle handle = singletonService.GetSingleton(typeid(RelayoutController));
+
+      if(handle)
+      {
+        // If so, downcast the handle of singleton to RelayoutController
+        controller = RelayoutController(dynamic_cast<Internal::RelayoutControllerImpl*>(handle.GetObjectPtr()));
+      }
+
+      if(!controller)
+      {
+        // If not, create the RelayoutController and register it as a singleton
+        controller = RelayoutController( new Internal::RelayoutControllerImpl(gRelayoutRequestPending) );
+        singletonService.Register( typeid(controller), controller );
+      }
+
+      GetImpl(controller).Request();
+      gRelayoutRequestPending = true;
     }
-
-    if(!controller)
-    {
-      // If not, create the RelayoutController and register it as a singleton
-      controller = RelayoutController( new Internal::RelayoutControllerImpl(gRelayoutRequestPending) );
-      adaptor.RegisterSingleton( typeid(controller), controller );
-    }
-
-    GetImpl(controller).Request();
-    gRelayoutRequestPending = true;
   }
 }
 
index a6ed055a77e86d16c93bfa5867c270c8f739df05..12b6748a7c82f95be6f2140740724477200cb284 100644 (file)
@@ -50,11 +50,15 @@ BaseHandle Create()
 {
   BaseHandle handle = KeyboardFocusManager::Get();
 
-  if ( !handle && Adaptor::IsAvailable() )
+  if ( !handle )
   {
-    Toolkit::KeyboardFocusManager manager = Toolkit::KeyboardFocusManager( new Internal::KeyboardFocusManager() );
-    Adaptor::Get().RegisterSingleton( typeid( manager ), manager );
-    handle = manager;
+    SingletonService singletonService( SingletonService::Get() );
+    if ( singletonService )
+    {
+      Toolkit::KeyboardFocusManager manager = Toolkit::KeyboardFocusManager( new Internal::KeyboardFocusManager() );
+      singletonService.Register( typeid( manager ), manager );
+      handle = manager;
+    }
   }
 
   return handle;
@@ -67,10 +71,11 @@ Toolkit::KeyboardFocusManager KeyboardFocusManager::Get()
 {
   Toolkit::KeyboardFocusManager manager;
 
-  if ( Adaptor::IsAvailable() )
+  SingletonService singletonService( SingletonService::Get() );
+  if ( singletonService )
   {
     // Check whether the keyboard focus manager is already created
-    Dali::BaseHandle handle = Dali::Adaptor::Get().GetSingleton( typeid( Toolkit::KeyboardFocusManager ) );
+    Dali::BaseHandle handle = singletonService.GetSingleton( typeid( Toolkit::KeyboardFocusManager ) );
     if(handle)
     {
       // If so, downcast the handle of singleton to keyboard focus manager
index 53c05cde0b129fcbc40aaa85573caf54b56310c9..57be231c242189fac6f7fdf3cafd7541ec868eba 100644 (file)
@@ -59,11 +59,15 @@ BaseHandle Create()
 {
   BaseHandle handle = StyleManager::Get();
 
-  if ( !handle && Adaptor::IsAvailable() )
+  if ( !handle )
   {
-    Toolkit::StyleManager manager = Toolkit::StyleManager( new Internal::StyleManager() );
-    Adaptor::Get().RegisterSingleton( typeid( manager ), manager );
-    handle = manager;
+    SingletonService singletonService( SingletonService::Get() );
+    if ( singletonService )
+    {
+      Toolkit::StyleManager manager = Toolkit::StyleManager( new Internal::StyleManager() );
+      singletonService.Register( typeid( manager ), manager );
+      handle = manager;
+    }
   }
 
   return handle;
@@ -88,10 +92,11 @@ Toolkit::StyleManager StyleManager::Get()
 {
   Toolkit::StyleManager manager;
 
-  if ( Adaptor::IsAvailable() )
+  SingletonService singletonService( SingletonService::Get() );
+  if ( singletonService )
   {
     // Check whether the style manager is already created
-    Dali::BaseHandle handle = Dali::Adaptor::Get().GetSingleton( typeid( Toolkit::StyleManager ) );
+    Dali::BaseHandle handle = singletonService.GetSingleton( typeid( Toolkit::StyleManager ) );
     if( handle )
     {
       // If so, downcast the handle of singleton
index 724c1f3dadcbfac12c0e6bd281bfe52d436fb4f6..d8999c1d0287e063c0ff40a618006d8fda1ebac4 100644 (file)
@@ -50,19 +50,22 @@ LocalizedControlFactory LocalizedControlFactory::Get()
   LocalizedControlFactory factory;
 
   // Check whether the focus factory is already created
-  Dali::Adaptor& adaptor = Dali::Adaptor::Get();
-  Dali::BaseHandle handle = adaptor.GetSingleton(typeid(LocalizedControlFactory));
-  if(handle)
+  SingletonService singletonService( SingletonService::Get() );
+  if ( singletonService )
   {
-    // If so, downcast the handle of singleton to focus factory
-    factory = LocalizedControlFactory(dynamic_cast<Internal::LocalizedControlFactory*>(handle.GetObjectPtr()));
-  }
-
-  if(!factory)
-  {
-    // If not, create the focus factory and register it as a singleton
-    factory = LocalizedControlFactory(new Internal::LocalizedControlFactory());
-    adaptor.RegisterSingleton(typeid(factory), factory);
+    Dali::BaseHandle handle = singletonService.GetSingleton(typeid(LocalizedControlFactory));
+    if(handle)
+    {
+      // If so, downcast the handle of singleton to focus factory
+      factory = LocalizedControlFactory(dynamic_cast<Internal::LocalizedControlFactory*>(handle.GetObjectPtr()));
+    }
+
+    if(!factory)
+    {
+      // If not, create the focus factory and register it as a singleton
+      factory = LocalizedControlFactory(new Internal::LocalizedControlFactory());
+      singletonService.Register(typeid(factory), factory);
+    }
   }
 
   return factory;
index f8e20607a74a8d3513e699db850c3d6fd2619aff..a4cddb1077cb8dd8eda71d0a8790dbbfa80adf8a 100644 (file)
@@ -48,19 +48,22 @@ FocusManager FocusManager::Get()
   FocusManager manager;
 
   // Check whether the focus manager is already created
-  Dali::Adaptor& adaptor = Dali::Adaptor::Get();
-  Dali::BaseHandle handle = adaptor.GetSingleton(typeid(FocusManager));
-  if(handle)
+  SingletonService singletonService( SingletonService::Get() );
+  if ( singletonService )
   {
-    // If so, downcast the handle of singleton to focus manager
-    manager = FocusManager(dynamic_cast<Internal::FocusManager*>(handle.GetObjectPtr()));
-  }
-
-  if(!manager)
-  {
-    // If not, create the focus manager and register it as a singleton
-    manager = FocusManager(new Internal::FocusManager());
-    adaptor.RegisterSingleton(typeid(manager), manager);
+    Dali::BaseHandle handle = singletonService.GetSingleton(typeid(FocusManager));
+    if(handle)
+    {
+      // If so, downcast the handle of singleton to focus manager
+      manager = FocusManager(dynamic_cast<Internal::FocusManager*>(handle.GetObjectPtr()));
+    }
+
+    if(!manager)
+    {
+      // If not, create the focus manager and register it as a singleton
+      manager = FocusManager(new Internal::FocusManager());
+      singletonService.Register(typeid(manager), manager);
+    }
   }
 
   return manager;
index f427283b07346ee7712b525adaaf41996dbb1159..b81e8071dcdaf587233fe527d95dbcceea65db63 100644 (file)
@@ -47,19 +47,22 @@ KeyInputFocusManager KeyInputFocusManager::Get()
   KeyInputFocusManager manager;
 
   // Check whether the focus manager is already created
-  Dali::Adaptor& adaptor = Dali::Adaptor::Get();
-  Dali::BaseHandle handle = adaptor.GetSingleton(typeid(KeyInputFocusManager));
-  if(handle)
+  SingletonService singletonService( SingletonService::Get() );
+  if ( singletonService )
   {
-    // If so, downcast the handle of singleton to focus manager
-    manager = KeyInputFocusManager(dynamic_cast<Internal::KeyInputFocusManager*>(handle.GetObjectPtr()));
-  }
-
-  if(!manager)
-  {
-    // If not, create the focus manager and register it as a singleton
-    manager = KeyInputFocusManager(new Internal::KeyInputFocusManager());
-    adaptor.RegisterSingleton(typeid(manager), manager);
+    Dali::BaseHandle handle = singletonService.GetSingleton(typeid(KeyInputFocusManager));
+    if(handle)
+    {
+      // If so, downcast the handle of singleton to focus manager
+      manager = KeyInputFocusManager(dynamic_cast<Internal::KeyInputFocusManager*>(handle.GetObjectPtr()));
+    }
+
+    if(!manager)
+    {
+      // If not, create the focus manager and register it as a singleton
+      manager = KeyInputFocusManager(new Internal::KeyInputFocusManager());
+      singletonService.Register(typeid(manager), manager);
+    }
   }
 
   return manager;