2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
18 #include <dali/internal/event/common/type-registry-impl.h>
25 #include <dali/internal/event/common/thread-local-storage.h>
26 #include <dali/public-api/object/type-registry.h>
27 #include <dali/public-api/object/base-handle.h>
28 #include <dali/internal/event/actors/custom-actor-internal.h>
29 #include <dali/internal/event/common/demangler.h>
31 #include <dali/integration-api/debug.h>
36 #if defined(DEBUG_ENABLED)
37 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_TYPE_REGISTRY");
45 extern std::string Demangle(const char* symbol);
50 TypeRegistry *TypeRegistry::Get()
52 static TypeRegistry *_reg(new TypeRegistry());
53 DALI_ASSERT_DEBUG(_reg);
57 TypeRegistry::TypeRegistry()
62 TypeRegistry::~TypeRegistry()
67 Dali::TypeInfo TypeRegistry::GetTypeInfo( const std::string &uniqueTypeName )
71 RegistryMap::iterator iter = mRegistryLut.find(uniqueTypeName);
73 if( iter != mRegistryLut.end() )
79 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Cannot find requested type '%s'\n", uniqueTypeName.c_str());
85 Dali::TypeInfo TypeRegistry::GetTypeInfo( const std::type_info& registerType )
89 std::string typeName = DemangleClassName(registerType.name());
91 RegistryMap::iterator iter = mRegistryLut.find(typeName);
93 if( iter != mRegistryLut.end() )
99 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Cannot find requested type '%s'\n", registerType.name());
105 Dali::TypeRegistry::NameContainer TypeRegistry::GetTypeNames() const
107 Dali::TypeRegistry::NameContainer ret;
109 for(RegistryMap::const_iterator iter = mRegistryLut.begin(); iter != mRegistryLut.end(); ++iter)
111 ret.push_back(iter->first);
117 bool TypeRegistry::Register( const std::type_info& theTypeInfo, const std::type_info& baseTypeInfo,
118 Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit )
120 std::string uniqueTypeName = DemangleClassName(theTypeInfo.name());
122 return Register( uniqueTypeName, baseTypeInfo, createInstance, callCreateOnInit );
125 bool TypeRegistry::Register( const std::string& uniqueTypeName, const std::type_info& baseTypeInfo,
126 Dali::TypeInfo::CreateFunction createInstance, bool callCreateOnInit )
130 std::string baseTypeName = DemangleClassName(baseTypeInfo.name());
132 RegistryMap::iterator iter = mRegistryLut.find(uniqueTypeName);
134 if( iter == mRegistryLut.end() )
136 mRegistryLut[uniqueTypeName] = Dali::TypeInfo(new Internal::TypeInfo(uniqueTypeName, baseTypeName, createInstance));
138 DALI_LOG_INFO( gLogFilter, Debug::Concise, "Type Registration %s(%s)\n", uniqueTypeName.c_str(), baseTypeName.c_str());
142 DALI_LOG_WARNING("Duplicate name for TypeRegistry for '%s'\n", + uniqueTypeName.c_str());
143 DALI_ASSERT_ALWAYS(!"Duplicate type name for Type Registation");
146 if( callCreateOnInit )
148 mInitFunctions.push_back(createInstance);
154 void TypeRegistry::CallInitFunctions(void) const
156 for( InitFunctions::const_iterator iter = mInitFunctions.begin(); iter != mInitFunctions.end(); ++iter)
162 std::string TypeRegistry::RegistrationName( const std::type_info& registerType )
164 return DemangleClassName( registerType.name() );
167 void TypeRegistry::RegisterSignal( TypeRegistration& typeRegistration, const std::string& name, Dali::TypeInfo::SignalConnectorFunctionV2 func )
169 RegistryMap::iterator iter = mRegistryLut.find( typeRegistration.RegisteredName() );
171 if( iter != mRegistryLut.end() )
173 DALI_ASSERT_DEBUG(iter->second);
175 GetImplementation(iter->second).AddConnectorFunction( name, func );
179 bool TypeRegistry::RegisterAction( TypeRegistration ®istered, const std::string &name, Dali::TypeInfo::ActionFunction f)
181 RegistryMap::iterator iter = mRegistryLut.find( registered.RegisteredName() );
183 if( iter != mRegistryLut.end() )
185 DALI_ASSERT_DEBUG(iter->second);
187 GetImplementation(iter->second).AddActionFunction( name, f );
197 bool TypeRegistry::RegisterProperty( TypeRegistration& registered, const std::string& name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc )
199 RegistryMap::iterator iter = mRegistryLut.find( registered.RegisteredName() );
201 if( iter != mRegistryLut.end() )
203 DALI_ASSERT_DEBUG(iter->second);
205 GetImplementation(iter->second).AddProperty( name, index, type, setFunc, getFunc );
213 bool TypeRegistry::DoActionTo( BaseObject * const object, const std::string &actionName, const std::vector<Property::Value> &properties)
217 Dali::TypeInfo type = GetTypeInfo( object );
221 if(GetImplementation(type).DoActionTo(object, actionName, properties))
226 type = GetTypeInfo( type.GetBaseName() );
232 bool TypeRegistry::ConnectSignal( BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor )
234 bool connected( false );
236 Dali::TypeInfo type = GetTypeInfo( object );
240 connected = GetImplementation(type).ConnectSignal( object, connectionTracker, signalName, functor );
245 type = GetTypeInfo( type.GetBaseName() );
250 // Ownership of functor was not passed to Dali::CallbackBase, so clean-up now
257 Dali::TypeInfo TypeRegistry::GetTypeInfo(const Dali::BaseObject * const pBaseObject)
261 // test for custom actor which has another indirection to get to the type hiearchy we're after
262 const Dali::Internal::CustomActor * const pCustom = dynamic_cast<const Dali::Internal::CustomActor*>(pBaseObject);
266 type = GetTypeInfo( typeid( pCustom->GetImplementation() ) );
270 type = GetTypeInfo( typeid( *pBaseObject ) );
276 } // namespace Internal