[SRUK] Initial copy from Tizen 2.2 version
[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    * Add an action function
89    */
90   void AddActionFunction( const std::string &actionName, Dali::TypeInfo::ActionFunction function );
91
92   /*
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.
96    */
97   void AddConnectorFunction( const std::string& signalName, Dali::TypeInfo::SignalConnectorFunctionV2 function );
98
99   /**
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
105    */
106   bool DoActionTo(BaseObject *object, const std::string &actionName, const std::vector<Property::Value> &properties);
107
108   /**
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.
116    */
117   bool ConnectSignal( BaseObject* object, ConnectionTrackerInterface* connectionTracker, const std::string& signalName, FunctorDelegate* functor );
118
119 private:
120
121   typedef std::pair<std::string, Dali::TypeInfo::SignalConnectorFunctionV2 > ConnectionPairV2;
122   typedef std::pair<std::string, Dali::TypeInfo::ActionFunction > ActionPair;
123
124   typedef std::vector< ActionPair > ActionContainer;
125   typedef std::vector< ConnectionPairV2 > ConnectorContainerV2;
126
127   std::string mTypeName;
128   std::string mBaseTypeName;
129   Dali::TypeInfo::CreateFunction mCreate;
130   ActionContainer mActions;
131   ConnectorContainerV2 mSignalConnectors;
132 };
133
134 } // namespace Internal
135
136 // Helpers for public-api forwarding methods
137
138 inline Internal::TypeInfo& GetImplementation(Dali::TypeInfo& typeInfo)
139 {
140   DALI_ASSERT_ALWAYS(typeInfo);
141
142   BaseObject& handle = typeInfo.GetBaseObject();
143
144   return static_cast<Internal::TypeInfo&>(handle);
145 }
146
147 inline const Internal::TypeInfo& GetImplementation(const Dali::TypeInfo& typeInfo)
148 {
149   DALI_ASSERT_ALWAYS(typeInfo);
150
151   const BaseObject& handle = typeInfo.GetBaseObject();
152
153   return static_cast<const Internal::TypeInfo&>(handle);
154 }
155
156 } // namespace Dali
157
158 #endif // header