Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-core.git] / dali / internal / event / common / type-info-impl.h
1 #ifndef __DALI_INTERNAL_TYPE_INFO_H__
2 #define __DALI_INTERNAL_TYPE_INFO_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
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
10 //
11 //     http://floralicense.org/license/
12 //
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.
18 //
19
20 // EXTERNAL INCLUDES
21 #include <string>
22
23 // INTERNAL INCLUDES
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>
27
28 namespace Dali
29 {
30
31 namespace Internal
32 {
33
34 /**
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
39  * all base classes.
40  */
41 class TypeInfo : public BaseObject
42 {
43 public:
44   /**
45    * Create TypeInfo
46    * @param [name] the registered name
47    * @param [baseName] the base type registered name
48    * @param [creator] the creator function for this type
49    */
50   TypeInfo(const std::string &name, const std::string &baseName, Dali::TypeInfo::CreateFunction creator);
51
52   /**
53    *
54    */
55   ~TypeInfo();
56
57   /**
58    * @copydoc Dali::TypeInfo::GetName
59    */
60   const std::string& GetName();
61
62   /**
63    * @copydoc Dali::TypeInfo::GetBaseName
64    */
65   const std::string& GetBaseName();
66
67   /**
68    * @copydoc TypeInfo::CreateFunction
69    */
70   BaseHandle CreateInstance();
71
72   /**
73    * @copydoc Dali::TypeInfo::GetCreator
74    */
75   Dali::TypeInfo::CreateFunction GetCreator();
76
77   /**
78    * @copydoc Dali::TypeInfo::GetActions
79    */
80   Dali::TypeInfo::NameContainer GetActions();
81
82   /**
83    * @copydoc Dali::TypeInfo::GetSignals
84    */
85   Dali::TypeInfo::NameContainer GetSignals();
86
87   /**
88    * Adds the property indices to the container specified.
89    * @param[in/out] indices The container where the property indices are added.
90    */
91   void GetPropertyIndices( Property::IndexContainer& indices ) const;
92
93   /**
94    * @copydoc Dali::TypeInfo::GetPropertyName() const
95    */
96   const std::string& GetPropertyName( Property::Index index ) const;
97
98   /*
99    * Add an action function
100    */
101   void AddActionFunction( const std::string &actionName, Dali::TypeInfo::ActionFunction function );
102
103   /*
104    * Add a function for connecting a signal.
105    * @param[in] signalName The name of the signal.
106    * @param[in] function The function used for connecting to the signal.
107    */
108   void AddConnectorFunction( const std::string& signalName, Dali::TypeInfo::SignalConnectorFunctionV2 function );
109
110   /**
111    * Adds an event-thread only property to the type.
112    * @param[in] name The name of the property.
113    * @param[in] index The index of the property.
114    * @param[in] type The Property::Type.
115    * @param[in] setFunc The function to call to set the property (Can be NULL).
116    * @param[in] getFunc The function to call to retrieve the value of the property.
117    */
118   void AddProperty( const std::string& name, Property::Index index, Property::Type type, Dali::TypeInfo::SetPropertyFunction setFunc, Dali::TypeInfo::GetPropertyFunction getFunc );
119
120   /**
121    * Do an action on base object
122    * @param [in] object The base object to act upon
123    * @param [in] actionName The name of the desired action
124    * @param [in] properties The arguments of the action
125    * @return bool If the action could be executed
126    */
127   bool DoActionTo(BaseObject *object, const std::string &actionName, const std::vector<Property::Value> &properties);
128
129   /**
130    * Connects a callback function with the object's signals.
131    * @param[in] object The object providing the signal.
132    * @param[in] tracker Used to disconnect the signal.
133    * @param[in] signalName The signal to connect to.
134    * @param[in] functor A newly allocated FunctorDelegate.
135    * @return True if the signal was connected.
136    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
137    */
138   bool ConnectSignal( BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor );
139
140   /**
141    * Retrieve the property count for this type.
142    * @return The total number of properties.
143    */
144   unsigned int GetPropertyCount() const;
145
146   /**
147    * Given a property name, retrieve the index.
148    * @param[in] name The name of the property.
149    * @return The index associated with that name.
150    */
151   Property::Index GetPropertyIndex( const std::string& name ) const;
152
153   /**
154    * Checks if there is a setter for the property. If there is then it is writable.
155    * @param[in] index The property index.
156    * @return True, if writable, false otherwise.
157    */
158   bool IsPropertyWritable( Property::Index index ) const;
159
160   /**
161    * Retrieve the Property::Type of the property at the given index.
162    * @param[in] index The property index.
163    * @return The Property::Type at that index.
164    */
165   Property::Type GetPropertyType( Property::Index index ) const;
166
167   /**
168    * Sets the value of a property at the index specified for the given object.
169    * @param[in] object The object whose property is to be set.
170    * @param[in] index The property index.
171    * @param[in] value The value to set.
172    */
173   void SetProperty( BaseObject *object, Property::Index index, const Property::Value& value );
174
175   /**
176    * Sets the value of a property with the name specified for the given object.
177    * @param[in] object The object whose property is to be set.
178    * @param[in] name The property name.
179    * @param[in] value The value to set.
180    */
181   void SetProperty( BaseObject *object, const std::string& name, const Property::Value& value );
182
183   /**
184    * Retrieves the value of a property at the index specified for the given object.
185    * @param[in] object The object whose property is to be queried.
186    * @param[in] index The property index.
187    * @return The current value of the property.
188    */
189   Property::Value GetProperty( const BaseObject *object, Property::Index index );
190
191   /**
192    * Retrieves the value of a property with the name specified for the given object.
193    * @param[in] object The object whose property is to be queried.
194    * @param[in] name The property name.
195    * @return The current value of the property.
196    */
197   Property::Value GetProperty( const BaseObject *object, const std::string& name );
198
199 private:
200
201   struct RegisteredProperty
202   {
203     RegisteredProperty()
204     : type( Property::NONE ),
205       setFunc( NULL ),
206       getFunc( NULL ),
207       name()
208     {
209     }
210
211     RegisteredProperty( Property::Type propType, Dali::TypeInfo::SetPropertyFunction set, Dali::TypeInfo::GetPropertyFunction get, const std::string& propName )
212     : type( propType ),
213       setFunc( set ),
214       getFunc( get ),
215       name( propName )
216     {
217     }
218
219     Property::Type type;
220     Dali::TypeInfo::SetPropertyFunction setFunc;
221     Dali::TypeInfo::GetPropertyFunction getFunc;
222     std::string name;
223   };
224
225   typedef std::pair<std::string, Dali::TypeInfo::SignalConnectorFunctionV2 > ConnectionPairV2;
226   typedef std::pair<std::string, Dali::TypeInfo::ActionFunction > ActionPair;
227   typedef std::pair<Property::Index, RegisteredProperty> RegisteredPropertyPair;
228
229   typedef std::vector< ActionPair > ActionContainer;
230   typedef std::vector< ConnectionPairV2 > ConnectorContainerV2;
231   typedef std::vector< RegisteredPropertyPair > RegisteredPropertyContainer;
232
233   std::string mTypeName;
234   std::string mBaseTypeName;
235   Dali::TypeInfo::CreateFunction mCreate;
236   ActionContainer mActions;
237   ConnectorContainerV2 mSignalConnectors;
238   RegisteredPropertyContainer mRegisteredProperties;
239 };
240
241 } // namespace Internal
242
243 // Helpers for public-api forwarding methods
244
245 inline Internal::TypeInfo& GetImplementation(Dali::TypeInfo& typeInfo)
246 {
247   DALI_ASSERT_ALWAYS(typeInfo);
248
249   BaseObject& handle = typeInfo.GetBaseObject();
250
251   return static_cast<Internal::TypeInfo&>(handle);
252 }
253
254 inline const Internal::TypeInfo& GetImplementation(const Dali::TypeInfo& typeInfo)
255 {
256   DALI_ASSERT_ALWAYS(typeInfo);
257
258   const BaseObject& handle = typeInfo.GetBaseObject();
259
260   return static_cast<const Internal::TypeInfo&>(handle);
261 }
262
263 } // namespace Dali
264
265 #endif // header