2 * Copyright (c) 2014 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>
26 #include <dali/internal/event/common/thread-local-storage.h>
27 #include <dali/public-api/object/type-registry.h>
28 #include <dali/public-api/object/base-handle.h>
29 #include <dali/internal/event/actors/custom-actor-internal.h>
30 #include <dali/internal/event/common/demangler.h>
32 #include <dali/integration-api/debug.h>
37 #if defined(DEBUG_ENABLED)
38 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_TYPE_REGISTRY");
46 extern std::string Demangle(const char* symbol);
51 TypeRegistry *TypeRegistry::Get()
53 static TypeRegistry *_reg(new TypeRegistry());
54 DALI_ASSERT_DEBUG(_reg);
58 TypeRegistry::TypeRegistry()
63 TypeRegistry::~TypeRegistry()
68 Dali::TypeInfo TypeRegistry::GetTypeInfo( const std::string &uniqueTypeName )
72 RegistryMap::iterator iter = mRegistryLut.find(uniqueTypeName);
74 if( iter != mRegistryLut.end() )
80 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Cannot find requested type '%s'\n", uniqueTypeName.c_str());
86 Dali::TypeInfo TypeRegistry::GetTypeInfo( const std::type_info& registerType )
90 std::string typeName = DemangleClassName(registerType.name());
92 RegistryMap::iterator iter = mRegistryLut.find(typeName);
94 if( iter != mRegistryLut.end() )
100 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Cannot find requested type '%s'\n", registerType.name());
106 Dali::TypeRegistry::NameContainer TypeRegistry::GetTypeNames() const
108 Dali::TypeRegistry::NameContainer ret;
110 for(RegistryMap::const_iterator iter = mRegistryLut.begin(); iter != mRegistryLut.end(); ++iter)
112 ret.push_back(iter->first);
118 bool TypeRegistry::Register( const std::type_info& theTypeInfo, const std::type_info& baseTypeInfo,
119 Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit )
121 std::string uniqueTypeName = DemangleClassName(theTypeInfo.name());
123 return Register( uniqueTypeName, baseTypeInfo, createInstance, callCreateOnInit );
126 bool TypeRegistry::Register( const std::string& uniqueTypeName, const std::type_info& baseTypeInfo,
127 Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit )
131 std::string baseTypeName = DemangleClassName(baseTypeInfo.name());
133 RegistryMap::iterator iter = mRegistryLut.find(uniqueTypeName);
135 if( iter == mRegistryLut.end() )
137 mRegistryLut[uniqueTypeName] = Dali::TypeInfo(new Internal::TypeInfo(uniqueTypeName, baseTypeName, createInstance));
139 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Type Registration %s(%s)\n", uniqueTypeName.c_str(), baseTypeName.c_str());
143 DALI_LOG_WARNING("Duplicate name for TypeRegistry for '%s'\n", + uniqueTypeName.c_str());
144 DALI_ASSERT_ALWAYS(!"Duplicate type name for Type Registation");
147 if( callCreateOnInit )
149 mInitFunctions.push_back(createInstance);
155 void TypeRegistry::CallInitFunctions(void) const
157 for( InitFunctions::const_iterator iter = mInitFunctions.begin(); iter != mInitFunctions.end(); ++iter)
163 std::string TypeRegistry::RegistrationName( const std::type_info& registerType )
165 return DemangleClassName( registerType.name() );
168 void TypeRegistry::RegisterSignal( TypeRegistration& typeRegistration, const std::string& name, Dali::TypeInfo::SignalConnectorFunction func )
170 RegistryMap::iterator iter = mRegistryLut.find( typeRegistration.RegisteredName() );
172 if( iter != mRegistryLut.end() )
174 DALI_ASSERT_DEBUG(iter->second);
176 GetImplementation(iter->second).AddConnectorFunction( name, func );
180 bool TypeRegistry::RegisterAction( TypeRegistration ®istered, const std::string &name, Dali::TypeInfo::ActionFunction f)
182 RegistryMap::iterator iter = mRegistryLut.find( registered.RegisteredName() );
184 if( iter != mRegistryLut.end() )
186 DALI_ASSERT_DEBUG(iter->second);
188 GetImplementation(iter->second).AddActionFunction( name, f );
198 bool TypeRegistry::RegisterProperty( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc )
200 RegistryMap::iterator iter = mRegistryLut.find( registered.RegisteredName() );
202 if( iter != mRegistryLut.end() )
204 DALI_ASSERT_DEBUG(iter->second);
206 GetImplementation(iter->second).AddProperty( name, index, type, setFunc, getFunc );
214 bool TypeRegistry::DoActionTo( BaseObject * const object, const std::string &actionName, const std::vector<Property::Value> &properties)
218 Dali::TypeInfo type = GetTypeInfo( object );
222 if(GetImplementation(type).DoActionTo(object, actionName, properties))
227 type = GetTypeInfo( type.GetBaseName() );
233 bool TypeRegistry::ConnectSignal( BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor )
235 bool connected( false );
237 Dali::TypeInfo type = GetTypeInfo( object );
241 connected = GetImplementation(type).ConnectSignal( object, connectionTracker, signalName, functor );
246 type = GetTypeInfo( type.GetBaseName() );
251 // Ownership of functor was not passed to Dali::CallbackBase, so clean-up now
258 Dali::TypeInfo TypeRegistry::GetTypeInfo(const Dali::BaseObject * const pBaseObject)
262 // test for custom actor which has another indirection to get to the type hiearchy we're after
263 const Dali::Internal::CustomActor * const pCustom = dynamic_cast<const Dali::Internal::CustomActor*>(pBaseObject);
267 type = GetTypeInfo( typeid( pCustom->GetImplementation() ) );
271 type = GetTypeInfo( typeid( *pBaseObject ) );
277 } // namespace Internal