Formatted API
[platform/core/uifw/dali-core.git] / dali / public-api / object / object-registry.h
1 #ifndef DALI_OBJECT_REGISTRY_H
2 #define DALI_OBJECT_REGISTRY_H
3
4 /*
5  * Copyright (c) 2020 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/handle.h>
23 #include <dali/public-api/signals/dali-signal.h>
24
25 namespace Dali
26 {
27 /**
28  * @addtogroup dali_core_object
29  * @{
30  */
31
32 namespace Internal DALI_INTERNAL
33 {
34 class ObjectRegistry;
35 }
36
37 /**
38  * @brief The ObjectRegistry notifies it's observers when an object is created.
39  *
40  * Handle to the created Object is passed in the call back function.
41  * The Handle is passed as Dali::Object handle, which can be DownCast
42  * to the appropriate type.
43  *
44  * Care should be taken to not store the handle in the Observer, as this will
45  * have adverse effect on the life time of the Internal Object. The Handle
46  * should only be used to connect to signals.
47  *
48  * Usage:
49  * ObjectRegistry registry = Stage::GetObjectRegistry();
50  * registry.ObjectCreatedSignal().Connect( ObjectCreatedCallbackFunc );
51  *
52  * Signals
53  * | %Signal Name     | Method                       |
54  * |------------------|------------------------------|
55  * | objectCreated    | @ref ObjectCreatedSignal()   |
56  * | objectDestroyed  | @ref ObjectDestroyedSignal() |
57  * @SINCE_1_0.0
58  */
59 class DALI_CORE_API ObjectRegistry : public BaseHandle
60 {
61 public:
62   // Typedefs
63
64   /**
65    * @brief Object created signal.
66    * @SINCE_1_0.0
67    */
68   using ObjectCreatedSignalType = Signal<void(BaseHandle)>;
69
70   /**
71    * @brief Object destroyed signal.
72    * @SINCE_1_0.0
73    */
74   using ObjectDestroyedSignalType = Signal<void(const Dali::RefObject*)>;
75
76   /**
77    * @brief Allows the creation of an empty objectRegistry handle.
78    *
79    * To retrieve the current objectRegistry,
80    * this handle can be set using Stage::GetCurrent().GetObjectRegistry().
81    * @SINCE_1_0.0
82    */
83   ObjectRegistry();
84
85   /**
86    * @brief Destructor.
87    *
88    * This is non-virtual since derived Handle types must not contain data or virtual methods.
89    * @SINCE_1_0.0
90    */
91   ~ObjectRegistry();
92
93   /**
94    * @brief This copy constructor is required for (smart) pointer semantics.
95    *
96    * @SINCE_1_0.0
97    * @param[in] handle A reference to the copied handle
98    */
99   ObjectRegistry(const ObjectRegistry& handle);
100
101   /**
102    * @brief This assignment operator is required for (smart) pointer semantics.
103    *
104    * @SINCE_1_0.0
105    * @param[in] rhs A reference to the copied handle
106    * @return A reference to this
107    */
108   ObjectRegistry& operator=(const ObjectRegistry& rhs);
109
110   /**
111    * @brief Move constructor.
112    *
113    * @SINCE_1_9.22
114    * @param[in] rhs A reference to the moved handle
115    */
116   ObjectRegistry(ObjectRegistry&& rhs);
117
118   /**
119    * @brief Move assignment operator.
120    *
121    * @SINCE_1_9.22
122    * @param[in] rhs A reference to the moved handle
123    * @return A reference to this handle
124    */
125   ObjectRegistry& operator=(ObjectRegistry&& rhs);
126
127 public: // Signals
128   /**
129    * @brief This signal is emitted when an object is created.
130    *
131    * A callback of the following type may be connected:
132    * @code
133    *   void YourCallbackName(BaseHandle object);
134    * @endcode
135    * @SINCE_1_0.0
136    * @return The signal to connect to
137    * @pre The Object has been initialized.
138    */
139   ObjectCreatedSignalType& ObjectCreatedSignal();
140
141   /**
142    * @brief This signal is emitted when an object is destroyed.
143    *
144    * WARNING: Since this signal is emitted when the object is
145    * in the process of being destroyed, the RefObject pointer
146    * passed in the signal should not be modified in anyways.
147    * And should NOT be used to create an handle. which will
148    * affect the life time of this destroyed object and leads to
149    * undefined behaviour.
150    *
151    * The only intended use is for Toolkit controls which want to
152    * keep track of objects being created and destroyed for internal
153    * bookkeeping.
154    *
155    * A callback of the following type may be connected:
156    * @code
157    *   void YourCallbackName(const Dali::RefObject* objectPointer);
158    * @endcode
159    * @SINCE_1_0.0
160    * @return The signal to connect to
161    * @pre The Object has been initialized.
162    */
163   ObjectDestroyedSignalType& ObjectDestroyedSignal();
164
165 public: // Not intended for application developers
166   /// @cond internal
167   /**
168    * @brief This constructor is used by Dali Get() method.
169    *
170    * @SINCE_1_0.0
171    * @param[in] objectRegistry A pointer to a Dali resource
172    */
173   explicit DALI_INTERNAL ObjectRegistry(Internal::ObjectRegistry* objectRegistry);
174   /// @endcond
175 };
176
177 /**
178  * @}
179  */
180 } // namespace Dali
181
182 #endif // DALI_OBJECT_REGISTRY_H