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