Added object sizes to platform abstraction in profiling section
[platform/core/uifw/dali-core.git] / dali / internal / event / common / object-registry-impl.h
1 #ifndef __DALI_INTERNAL_OBJECT_REGISTRY_H__
2 #define __DALI_INTERNAL_OBJECT_REGISTRY_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 // INTERNAL INCLUDES
21 #ifdef DEBUG_ENABLED
22 #include <dali/public-api/common/set-wrapper.h>
23 #endif
24 #include <dali/public-api/object/ref-object.h>
25 #include <dali/public-api/object/object-registry.h>
26 #include <dali/public-api/object/base-object.h>
27
28 namespace Dali
29 {
30
31 struct Vector2;
32
33 namespace Internal
34 {
35
36 namespace SceneGraph
37 {
38 class UpdateManager;
39 }
40
41 class ObjectRegistry;
42
43 typedef IntrusivePtr<ObjectRegistry> ObjectRegistryPtr;
44
45 /**
46  * The ObjectRegistry notifies it's observers when an object is created.
47  * There is a single instance of Object registry for each Dali-core instance.
48  * All Dali Objects need to register with ObjectRegistry to be observed by
49  * feedback plugin's and other observers.
50  */
51 class ObjectRegistry : public BaseObject
52 {
53 public:
54
55   /**
56    * Create the objectRegistry
57    */
58   static ObjectRegistryPtr New();
59
60   /**
61    * Registers the Object into the Object Registry, which notifies
62    * about this object creation to its observers using signals. As
63    * the signals use a BaseHandle, the object must already have a
64    * ref-count > 0, otherwise it will get deleted on signal completion.
65    * @pre The object is not already registered.
66    * @pre the object is ref counted (held in an intrusive pointer)
67    * @param[in] object Pointer to the object.
68    */
69   void RegisterObject( Dali::BaseObject* object );
70
71   /**
72    * Unregisters the Object from the Object Registry, Which notifies
73    * about this object destruction to its observers.
74    * @pre The object is already registered.
75    * @param[in] object Pointer to the object.
76    */
77   void UnregisterObject( Dali::BaseObject* object );
78
79   /**
80    * @copydoc Dali::ObjectRegistry::ObjectCreatedSignal()
81    */
82   Dali::ObjectRegistry::ObjectCreatedSignalV2& ObjectCreatedSignal()
83   {
84     return mObjectCreatedSignalV2;
85   }
86
87   /**
88    * @copydoc Dali::ObjectRegistry::ObjectDestroyedSignal()
89    */
90   Dali::ObjectRegistry::ObjectDestroyedSignalV2& ObjectDestroyedSignal()
91   {
92     return mObjectDestroyedSignalV2;
93   }
94
95   /**
96    * Connects a callback function with the object registry signals.
97    * @param[in] object The object providing the signal.
98    * @param[in] tracker Used to disconnect the signal.
99    * @param[in] signalName The signal to connect to.
100    * @param[in] functor A newly allocated FunctorDelegate.
101    * @return True if the signal was connected.
102    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
103    */
104   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
105
106 private:
107
108   /**
109    * Protected constructor; see also ObjectRegistry::New()
110    */
111   ObjectRegistry();
112
113   /**
114    * A reference counted object may only be deleted by calling Unreference()
115    */
116   ~ObjectRegistry();
117
118 private:
119
120   Dali::ObjectRegistry::ObjectCreatedSignalV2 mObjectCreatedSignalV2;
121   Dali::ObjectRegistry::ObjectDestroyedSignalV2 mObjectDestroyedSignalV2;
122
123 #ifdef DEBUG_ENABLED
124   std::set< Dali::BaseObject* > mDebugRegistry; ///< This allows us to assert that an object is only registered once (debug builds only)
125 #endif
126
127 };
128
129 } // namespace Internal
130
131 // Helpers for public-api forwarding methods
132
133 inline Internal::ObjectRegistry& GetImplementation(Dali::ObjectRegistry& objectRegistry)
134 {
135   DALI_ASSERT_ALWAYS( objectRegistry && "ObjectRegistry handle is empty" );
136
137   BaseObject& handle = objectRegistry.GetBaseObject();
138
139   return static_cast<Internal::ObjectRegistry&>(handle);
140 }
141
142 inline const Internal::ObjectRegistry& GetImplementation(const Dali::ObjectRegistry& objectRegistry)
143 {
144   DALI_ASSERT_ALWAYS( objectRegistry && "ObjectRegistry handle is empty" );
145
146   const BaseObject& handle = objectRegistry.GetBaseObject();
147
148   return static_cast<const Internal::ObjectRegistry&>(handle);
149 }
150
151 } // namespace Dali
152
153 #endif // __DALI_INTERNAL_OBJECT_REGISTRY_H__