../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
../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
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
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);
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();
AdaptorSignalV2 mResizeSignal;
TestRenderSurface mRenderSurface;
ToolkitAdaptor& mToolkitAdaptor;
-
- SingletonContainer mSingletonContainer;
};
namespace
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;
--- /dev/null
+/*
+ * 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
--- /dev/null
+#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__
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;
}
}
{
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;
{
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
{
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;
{
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
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;
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;
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;