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-info-impl.h>
21 #include <algorithm> // std::find_if
23 #include <dali/public-api/object/type-registry.h>
26 #include <dali/integration-api/debug.h>
34 * Functor to find by name for vector of pairs
37 struct PairNameListFinder
39 PairNameListFinder(const std::string &find)
46 return p.first == mFind;
51 const std::string& mFind;
62 TypeInfo::TypeInfo(const std::string &name, const std::string &baseTypeName, Dali::TypeInfo::CreateFunction creator)
63 : mTypeName(name), mBaseTypeName(baseTypeName), mCreate(creator)
65 DALI_ASSERT_ALWAYS(!name.empty() && "Type info construction must have a name");
66 DALI_ASSERT_ALWAYS(!baseTypeName.empty() && "Type info construction must have a base type name");
73 BaseHandle TypeInfo::CreateInstance()
84 bool TypeInfo::DoActionTo(BaseObject *object, const std::string &actionName, const std::vector<Property::Value> &properties)
88 ActionContainer::iterator iter = find_if(mActions.begin(), mActions.end(), PairNameListFinder<ActionPair>(actionName));
90 if( iter != mActions.end() )
92 done = (iter->second)(object, actionName, properties);
96 DALI_LOG_WARNING("Type '%s' cannot do action '%s'\n", mTypeName.c_str(), actionName.c_str());
101 Dali::TypeInfo base = Dali::TypeRegistry::Get().GetTypeInfo( mBaseTypeName );
104 done = GetImplementation(base).DoActionTo(object, actionName, properties);
109 base = Dali::TypeRegistry::Get().GetTypeInfo( base.GetBaseName() );
116 bool TypeInfo::ConnectSignal( BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor )
118 bool connected( false );
120 ConnectorContainerV2::iterator iter = find_if( mSignalConnectors.begin(), mSignalConnectors.end(),
121 PairNameListFinder<ConnectionPairV2>(signalName) );
123 if( iter != mSignalConnectors.end() )
125 connected = (iter->second)( object, connectionTracker, signalName, functor );
131 const std::string& TypeInfo::GetName()
136 const std::string& TypeInfo::GetBaseName()
138 return mBaseTypeName;
141 Dali::TypeInfo::CreateFunction TypeInfo::GetCreator()
146 Dali::TypeInfo::NameContainer TypeInfo::GetActions()
148 Dali::TypeInfo::NameContainer ret;
150 for(ActionContainer::iterator iter = mActions.begin(); iter != mActions.end(); ++iter)
152 ret.push_back(iter->first);
155 Dali::TypeInfo base = Dali::TypeRegistry::Get().GetTypeInfo( mBaseTypeName );
158 for(ActionContainer::iterator iter = GetImplementation(base).mActions.begin();
159 iter != GetImplementation(base).mActions.end(); ++iter)
161 ret.push_back(iter->first);
164 base = Dali::TypeRegistry::Get().GetTypeInfo( base.GetBaseName() );
170 Dali::TypeInfo::NameContainer TypeInfo::GetSignals()
172 Dali::TypeInfo::NameContainer ret;
174 for(ConnectorContainerV2::iterator iter = mSignalConnectors.begin(); iter != mSignalConnectors.end(); ++iter)
176 ret.push_back(iter->first);
179 Dali::TypeInfo base = Dali::TypeRegistry::Get().GetTypeInfo( mBaseTypeName );
182 for(ConnectorContainerV2::iterator iter = GetImplementation(base).mSignalConnectors.begin();
183 iter != GetImplementation(base).mSignalConnectors.end(); ++iter)
185 ret.push_back(iter->first);
188 base = Dali::TypeRegistry::Get().GetTypeInfo( base.GetBaseName() );
194 void TypeInfo::AddActionFunction( const std::string &actionName, Dali::TypeInfo::ActionFunction function )
196 if( NULL == function)
198 DALI_LOG_WARNING("Action function is empty\n");
202 ActionContainer::iterator iter = std::find_if(mActions.begin(), mActions.end(),
203 PairNameListFinder<ActionPair>(actionName));
205 if( iter == mActions.end() )
207 mActions.push_back( ActionPair( actionName, function ) );
211 DALI_LOG_WARNING("Action already exists in TypeRegistry Type", actionName.c_str());
216 void TypeInfo::AddConnectorFunction( const std::string& signalName, Dali::TypeInfo::SignalConnectorFunctionV2 function )
218 if( NULL == function)
220 DALI_LOG_WARNING("Connector function is empty\n");
224 ConnectorContainerV2::iterator iter = find_if( mSignalConnectors.begin(), mSignalConnectors.end(),
225 PairNameListFinder<ConnectionPairV2>(signalName) );
227 if( iter == mSignalConnectors.end() )
229 mSignalConnectors.push_back( ConnectionPairV2( signalName, function ) );
233 DALI_LOG_WARNING("Signal name already exists in TypeRegistry Type for signal connector function", signalName.c_str());
238 } // namespace Internal