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