2 * Copyright (c) 2016 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 bool TypeRegistry::Register( const std::string& uniqueTypeName, const std::type_info& baseTypeInfo,
161 Dali::CSharpTypeInfo::CreateFunction createInstance )
166 std::string baseTypeName = DemangleClassName(baseTypeInfo.name());
168 RegistryMap::iterator iter = mRegistryLut.find(uniqueTypeName);
170 if( iter == mRegistryLut.end() )
172 mRegistryLut[uniqueTypeName] = Dali::TypeInfo(new Internal::TypeInfo(uniqueTypeName, baseTypeName, createInstance));
174 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Type Registration %s(%s)\n", uniqueTypeName.c_str(), baseTypeName.c_str());
178 DALI_LOG_WARNING("Duplicate name for TypeRegistry for '%s'\n", + uniqueTypeName.c_str());
179 DALI_ASSERT_ALWAYS(!"Duplicate type name for Type Registation");
186 void TypeRegistry::CallInitFunctions(void) const
188 for( InitFunctions::const_iterator iter = mInitFunctions.begin(); iter != mInitFunctions.end(); ++iter)
194 std::string TypeRegistry::RegistrationName( const std::type_info& registerType )
196 return DemangleClassName( registerType.name() );
199 void TypeRegistry::RegisterSignal( TypeRegistration& typeRegistration, const std::string& name, Dali::TypeInfo::SignalConnectorFunction func )
201 RegistryMap::iterator iter = mRegistryLut.find( typeRegistration.RegisteredName() );
203 if( iter != mRegistryLut.end() )
205 DALI_ASSERT_DEBUG(iter->second);
207 GetImplementation(iter->second).AddConnectorFunction( name, func );
211 bool TypeRegistry::RegisterAction( TypeRegistration ®istered, const std::string &name, Dali::TypeInfo::ActionFunction f)
213 RegistryMap::iterator iter = mRegistryLut.find( registered.RegisteredName() );
215 if( iter != mRegistryLut.end() )
217 DALI_ASSERT_DEBUG(iter->second);
219 GetImplementation(iter->second).AddActionFunction( name, f );
229 bool TypeRegistry::RegisterProperty( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc )
231 RegistryMap::iterator iter = mRegistryLut.find( registered.RegisteredName() );
233 if( iter != mRegistryLut.end() )
235 DALI_ASSERT_DEBUG(iter->second);
237 GetImplementation(iter->second).AddProperty( name, index, type, setFunc, getFunc );
245 bool TypeRegistry::RegisterProperty( const std::string& objectName, const std::string& name, Property::Index index, Property::Type type, Dali::CSharpTypeInfo::SetPropertyFunction setFunc, Dali::CSharpTypeInfo::GetPropertyFunction getFunc )
247 RegistryMap::iterator iter = mRegistryLut.find( objectName );
249 if( iter != mRegistryLut.end() )
251 DALI_ASSERT_DEBUG(iter->second);
253 GetImplementation(iter->second).AddProperty( name, index, type, setFunc, getFunc );
263 bool TypeRegistry::RegisterAnimatableProperty( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type )
265 RegistryMap::iterator iter = mRegistryLut.find( registered.RegisteredName() );
267 if( iter != mRegistryLut.end() )
269 DALI_ASSERT_DEBUG(iter->second);
271 GetImplementation(iter->second).AddAnimatableProperty( name, index, type );
279 bool TypeRegistry::RegisterAnimatableProperty( TypeRegistration& registered, const std::string& name, Property::Index index, const Property::Value& value )
281 RegistryMap::iterator iter = mRegistryLut.find( registered.RegisteredName() );
283 if( iter != mRegistryLut.end() )
285 DALI_ASSERT_DEBUG(iter->second);
287 GetImplementation(iter->second).AddAnimatableProperty( name, index, value );
295 bool TypeRegistry::RegisterAnimatablePropertyComponent( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Index baseIndex, unsigned int componentIndex )
297 RegistryMap::iterator iter = mRegistryLut.find( registered.RegisteredName() );
299 if( iter != mRegistryLut.end() )
301 DALI_ASSERT_DEBUG(iter->second);
303 GetImplementation(iter->second).AddAnimatablePropertyComponent( name, index, baseIndex, componentIndex );
311 bool TypeRegistry::RegisterChildProperty( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type )
313 RegistryMap::iterator iter = mRegistryLut.find( registered.RegisteredName() );
315 if( iter != mRegistryLut.end() )
317 DALI_ASSERT_DEBUG(iter->second);
319 GetImplementation(iter->second).AddChildProperty( name, index, type );
327 bool TypeRegistry::DoActionTo( BaseObject * const object, const std::string &actionName, const Property::Map &properties)
331 Dali::TypeInfo type = GetTypeInfo( object );
335 if(GetImplementation(type).DoActionTo(object, actionName, properties))
340 type = GetTypeInfo( type.GetBaseName() );
346 bool TypeRegistry::ConnectSignal( BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor )
348 bool connected( false );
350 Dali::TypeInfo type = GetTypeInfo( object );
354 connected = GetImplementation(type).ConnectSignal( object, connectionTracker, signalName, functor );
359 type = GetTypeInfo( type.GetBaseName() );
364 // Ownership of functor was not passed to Dali::CallbackBase, so clean-up now
371 Dali::TypeInfo TypeRegistry::GetTypeInfo(const Dali::BaseObject * const pBaseObject)
375 // test for custom actor which has another indirection to get to the type hiearchy we're after
376 const Dali::Internal::CustomActor * const pCustom = dynamic_cast<const Dali::Internal::CustomActor*>(pBaseObject);
380 const Dali::CustomActorImpl& custom = pCustom->GetImplementation();
381 type = GetTypeInfo( typeid( custom ) );
385 type = GetTypeInfo( typeid( *pBaseObject ) );
391 } // namespace Internal