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