1 #ifndef __DALI_INTERNAL_TYPE_INFO_H__
2 #define __DALI_INTERNAL_TYPE_INFO_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.0 (the License);
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://floralicense.org/license/
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an AS IS BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
24 #include <dali/public-api/object/base-handle.h>
25 #include <dali/public-api/object/base-object.h>
26 #include <dali/public-api/object/type-info.h>
35 * A TypeInfo class to support registered type creation, and introspection of available
36 * actions and signal connection.
37 * It also supports doing actions and connecting signal handlers. Note this is properly
38 * conducted through the BaseHandle interface which uses the TypeRegistry to walk
41 class TypeInfo : public BaseObject
46 * @param [name] the registered name
47 * @param [baseName] the base type registered name
48 * @param [creator] the creator function for this type
50 TypeInfo(const std::string &name, const std::string &baseName, Dali::TypeInfo::CreateFunction creator);
58 * @copydoc Dali::TypeInfo::GetName
60 const std::string& GetName();
63 * @copydoc Dali::TypeInfo::GetBaseName
65 const std::string& GetBaseName();
68 * @copydoc TypeInfo::CreateFunction
70 BaseHandle CreateInstance();
73 * @copydoc Dali::TypeInfo::GetCreator
75 Dali::TypeInfo::CreateFunction GetCreator();
78 * @copydoc Dali::TypeInfo::GetActions
80 Dali::TypeInfo::NameContainer GetActions();
83 * @copydoc Dali::TypeInfo::GetSignals
85 Dali::TypeInfo::NameContainer GetSignals();
88 * Add an action function
90 void AddActionFunction( const std::string &actionName, Dali::TypeInfo::ActionFunction function );
93 * Add a function for connecting a signal.
94 * @param[in] signalName The name of the signal.
95 * @param[in] function The function used for connecting to the signal.
97 void AddConnectorFunction( const std::string& signalName, Dali::TypeInfo::SignalConnectorFunctionV2 function );
100 * Do an action on base object
101 * @param [in] object The base object to act upon
102 * @param [in] actionName The name of the desired action
103 * @param [in] properties The arguments of the action
104 * @return bool If the action could be executed
106 bool DoActionTo(BaseObject *object, const std::string &actionName, const std::vector<Property::Value> &properties);
109 * Connects a callback function with the object's signals.
110 * @param[in] object The object providing the signal.
111 * @param[in] tracker Used to disconnect the signal.
112 * @param[in] signalName The signal to connect to.
113 * @param[in] functor A newly allocated FunctorDelegate.
114 * @return True if the signal was connected.
115 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
117 bool ConnectSignal( BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor );
121 typedef std::pair<std::string, Dali::TypeInfo::SignalConnectorFunctionV2 > ConnectionPairV2;
122 typedef std::pair<std::string, Dali::TypeInfo::ActionFunction > ActionPair;
124 typedef std::vector< ActionPair > ActionContainer;
125 typedef std::vector< ConnectionPairV2 > ConnectorContainerV2;
127 std::string mTypeName;
128 std::string mBaseTypeName;
129 Dali::TypeInfo::CreateFunction mCreate;
130 ActionContainer mActions;
131 ConnectorContainerV2 mSignalConnectors;
134 } // namespace Internal
136 // Helpers for public-api forwarding methods
138 inline Internal::TypeInfo& GetImplementation(Dali::TypeInfo& typeInfo)
140 DALI_ASSERT_ALWAYS(typeInfo);
142 BaseObject& handle = typeInfo.GetBaseObject();
144 return static_cast<Internal::TypeInfo&>(handle);
147 inline const Internal::TypeInfo& GetImplementation(const Dali::TypeInfo& typeInfo)
149 DALI_ASSERT_ALWAYS(typeInfo);
151 const BaseObject& handle = typeInfo.GetBaseObject();
153 return static_cast<const Internal::TypeInfo&>(handle);