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