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