2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/event/common/type-registry-impl.h>
22 #include <dali/internal/event/common/thread-local-storage.h>
23 #include <dali/public-api/object/type-registry.h>
24 #include <dali/public-api/object/base-handle.h>
25 #include <dali/internal/event/actors/custom-actor-internal.h>
26 #include <dali/internal/event/common/demangler.h>
28 #include <dali/integration-api/debug.h>
33 #if defined(DEBUG_ENABLED)
34 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_TYPE_REGISTRY");
42 extern std::string Demangle(const char* symbol);
47 TypeRegistry *TypeRegistry::Get()
49 static TypeRegistry *_reg(new TypeRegistry());
50 DALI_ASSERT_DEBUG(_reg);
54 TypeRegistry::TypeRegistry()
59 TypeRegistry::~TypeRegistry()
64 Dali::TypeInfo TypeRegistry::GetTypeInfo( const std::string &uniqueTypeName )
68 RegistryMap::iterator iter = mRegistryLut.find(uniqueTypeName);
70 if( iter != mRegistryLut.end() )
76 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Cannot find requested type '%s'\n", uniqueTypeName.c_str());
82 Dali::TypeInfo TypeRegistry::GetTypeInfo( const std::type_info& registerType )
86 std::string typeName = DemangleClassName(registerType.name());
88 RegistryMap::iterator iter = mRegistryLut.find(typeName);
90 if( iter != mRegistryLut.end() )
96 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Cannot find requested type '%s'\n", registerType.name());
102 size_t TypeRegistry::GetTypeNameCount() const
104 return mRegistryLut.size();
108 std::string TypeRegistry::GetTypeName(size_t index) const
112 if( index < mRegistryLut.size() )
114 RegistryMap::const_iterator iter = mRegistryLut.begin();
115 std::advance(iter, index);
123 bool TypeRegistry::Register( const std::type_info& theTypeInfo, const std::type_info& baseTypeInfo,
124 Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit )
126 std::string uniqueTypeName = DemangleClassName(theTypeInfo.name());
128 return Register( uniqueTypeName, baseTypeInfo, createInstance, callCreateOnInit );
131 bool TypeRegistry::Register( const std::string& uniqueTypeName, const std::type_info& baseTypeInfo,
132 Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit )
136 std::string baseTypeName = DemangleClassName(baseTypeInfo.name());
138 RegistryMap::iterator iter = mRegistryLut.find(uniqueTypeName);
140 if( iter == mRegistryLut.end() )
142 mRegistryLut[uniqueTypeName] = Dali::TypeInfo(new Internal::TypeInfo(uniqueTypeName, baseTypeName, createInstance));
144 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Type Registration %s(%s)\n", uniqueTypeName.c_str(), baseTypeName.c_str());
148 DALI_LOG_WARNING("Duplicate name for TypeRegistry for '%s'\n", + uniqueTypeName.c_str());
149 DALI_ASSERT_ALWAYS(!"Duplicate type name for Type Registation");
152 if( callCreateOnInit )
154 mInitFunctions.push_back(createInstance);
160 void TypeRegistry::CallInitFunctions(void) const
162 for( InitFunctions::const_iterator iter = mInitFunctions.begin(); iter != mInitFunctions.end(); ++iter)
168 std::string TypeRegistry::RegistrationName( const std::type_info& registerType )
170 return DemangleClassName( registerType.name() );
173 void TypeRegistry::RegisterSignal( TypeRegistration& typeRegistration, const std::string& name, Dali::TypeInfo::SignalConnectorFunction func )
175 RegistryMap::iterator iter = mRegistryLut.find( typeRegistration.RegisteredName() );
177 if( iter != mRegistryLut.end() )
179 DALI_ASSERT_DEBUG(iter->second);
181 GetImplementation(iter->second).AddConnectorFunction( name, func );
185 bool TypeRegistry::RegisterAction( TypeRegistration ®istered, const std::string &name, Dali::TypeInfo::ActionFunction f)
187 RegistryMap::iterator iter = mRegistryLut.find( registered.RegisteredName() );
189 if( iter != mRegistryLut.end() )
191 DALI_ASSERT_DEBUG(iter->second);
193 GetImplementation(iter->second).AddActionFunction( name, f );
203 bool TypeRegistry::RegisterProperty( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc )
205 RegistryMap::iterator iter = mRegistryLut.find( registered.RegisteredName() );
207 if( iter != mRegistryLut.end() )
209 DALI_ASSERT_DEBUG(iter->second);
211 GetImplementation(iter->second).AddProperty( name, index, type, setFunc, getFunc );
219 bool TypeRegistry::RegisterAnimatableProperty( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type )
221 RegistryMap::iterator iter = mRegistryLut.find( registered.RegisteredName() );
223 if( iter != mRegistryLut.end() )
225 DALI_ASSERT_DEBUG(iter->second);
227 GetImplementation(iter->second).AddAnimatableProperty( name, index, type );
235 bool TypeRegistry::RegisterAnimatablePropertyComponent( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Index baseIndex, unsigned int componentIndex )
237 RegistryMap::iterator iter = mRegistryLut.find( registered.RegisteredName() );
239 if( iter != mRegistryLut.end() )
241 DALI_ASSERT_DEBUG(iter->second);
243 GetImplementation(iter->second).AddAnimatablePropertyComponent( name, index, baseIndex, componentIndex );
251 bool TypeRegistry::DoActionTo( BaseObject * const object, const std::string &actionName, const Property::Map &properties)
255 Dali::TypeInfo type = GetTypeInfo( object );
259 if(GetImplementation(type).DoActionTo(object, actionName, properties))
264 type = GetTypeInfo( type.GetBaseName() );
270 bool TypeRegistry::ConnectSignal( BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor )
272 bool connected( false );
274 Dali::TypeInfo type = GetTypeInfo( object );
278 connected = GetImplementation(type).ConnectSignal( object, connectionTracker, signalName, functor );
283 type = GetTypeInfo( type.GetBaseName() );
288 // Ownership of functor was not passed to Dali::CallbackBase, so clean-up now
295 Dali::TypeInfo TypeRegistry::GetTypeInfo(const Dali::BaseObject * const pBaseObject)
299 // test for custom actor which has another indirection to get to the type hiearchy we're after
300 const Dali::Internal::CustomActor * const pCustom = dynamic_cast<const Dali::Internal::CustomActor*>(pBaseObject);
304 type = GetTypeInfo( typeid( pCustom->GetImplementation() ) );
308 type = GetTypeInfo( typeid( *pBaseObject ) );
314 } // namespace Internal