Tizen 2.4.0 rev3 SDK Public Release
[framework/graphics/dali.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) 2015 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  * @since_tizen 2.4
53  */
54 class DALI_IMPORT_API ObjectRegistry : public BaseHandle
55 {
56 public:
57
58   // Typedefs
59
60   /**
61    * @brief Object created signal
62    * @since_tizen 2.4
63    */
64   typedef Signal< void ( BaseHandle ) > ObjectCreatedSignalType;
65
66   /**
67    * @brief Object destroyed signal
68    * @since_tizen 2.4
69    */
70   typedef Signal< void ( const Dali::RefObject* ) > ObjectDestroyedSignalType;
71
72   /**
73    * @brief Allows the creation of an empty objectRegistry handle.
74    *
75    * To retrieve the current objectRegistry,
76    * this handle can be set using Stage::GetCurrent().GetObjectRegistry().
77    * @since_tizen 2.4
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    * @since_tizen 2.4
86    */
87   ~ObjectRegistry();
88
89   /**
90    * @brief This copy constructor is required for (smart) pointer semantics.
91    *
92    * @since_tizen 2.4
93    * @param [in] handle A reference to the copied handle
94    */
95   ObjectRegistry(const ObjectRegistry& handle);
96
97   /**
98    * @brief This assignment operator is required for (smart) pointer semantics.
99    *
100    * @since_tizen 2.4
101    * @param [in] rhs  A reference to the copied handle
102    * @return A reference to this
103    */
104   ObjectRegistry& operator=(const ObjectRegistry& rhs);
105
106 public: // Signals
107
108   /**
109    * @brief This signal is emitted when an object is created.
110    *
111    * A callback of the following type may be connected:
112    * @code
113    *   void YourCallbackName(BaseHandle object);
114    * @endcode
115    * @since_tizen 2.4
116    * @return The signal to connect to.
117    * @pre The Object has been initialized.
118    */
119   ObjectCreatedSignalType& ObjectCreatedSignal();
120
121   /**
122    * @brief This signal is emitted when an object is destroyed.
123    *
124    * WARNING: Since this signal is emitted when the object is
125    * in the process of being destroyed, the RefObject pointer
126    * passed in the signal should not be modified in anyways.
127    * And should NOT be used to create an handle. which will
128    * affect the life time of this destroyed object and leads to
129    * undefined behaviour.
130    *
131    * The only intended use is for Toolkit controls which want to
132    * keep track of objects being created and destroyed for internal
133    * bookkeeping.
134    *
135    * A callback of the following type may be connected:
136    * @code
137    *   void YourCallbackName(const RefObject* objectPointer);
138    * @endcode
139    * @since_tizen 2.4
140    * @return The signal to connect to.
141    * @pre The Object has been initialized.
142    */
143   ObjectDestroyedSignalType& ObjectDestroyedSignal();
144
145 public: // Not intended for application developers
146
147   /**
148    * @brief This constructor is used by Dali Get() method.
149    *
150    * @since_tizen 2.4
151    * @param [in] objectRegistry A pointer to a Dali resource
152    */
153   explicit DALI_INTERNAL ObjectRegistry(Internal::ObjectRegistry* objectRegistry);
154 };
155
156 /**
157  * @}
158  */
159 } // namespace Dali
160
161 #endif // __DALI_OBJECT_REGISTRY_H__