Enable -Wnon-virtual-dtor to avoid incorrect C++ code sneaking in
[platform/core/uifw/dali-core.git] / dali / internal / update / common / property-owner.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_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
23 // INTERNAL INCLUDES
24 #include <dali/public-api/common/dali-vector.h>
25 #include <dali/devel-api/common/owner-container.h>
26 #include <dali/internal/common/message.h>
27 #include <dali/internal/update/common/property-base.h>
28 #include <dali/internal/update/common/scene-graph-buffers.h>
29 #include <dali/internal/update/common/uniform-map.h>
30 #include <dali/internal/update/animation/scene-graph-constraint-declarations.h>
31
32
33 namespace Dali
34 {
35
36 namespace Internal
37 {
38
39 namespace SceneGraph
40 {
41
42 class PropertyOwner;
43
44 typedef OwnerContainer< PropertyBase* > OwnedPropertyContainer;
45 typedef OwnedPropertyContainer::Iterator  OwnedPropertyIter;
46
47 /**
48  * An update-thread object which own properties.
49  * This allows observers to track the lifetime of the object & its properties.
50  */
51 class PropertyOwner
52 {
53 public:
54
55   class Observer
56   {
57   public:
58
59     /**
60      * Called when the observable object is connected to the scene graph.
61      * @param[in] owner A reference to the connected PropertyOwner
62      */
63     virtual void PropertyOwnerConnected( PropertyOwner& owner ) = 0;
64
65     /**
66      * Called when the observable object is disconnected from the scene graph.
67      * @param[in] currentBufferIndex The buffer to reset.
68      * @param[in] owner A reference to the disconnected PropertyOwner
69      */
70     virtual void PropertyOwnerDisconnected( BufferIndex updateBufferIndex, PropertyOwner& owner ) = 0;
71
72     /**
73      * Called shortly before the observable object is destroyed.
74      *
75      * @note Cleanup should be done in both this and PropertyOwnerDisconnected as PropertyOwnerDisconnected
76      * may not be called (i.e. when shutting down).
77      */
78     virtual void PropertyOwnerDestroyed( PropertyOwner& owner ) = 0;
79
80   protected:
81
82     /**
83      * Virtual destructor, no deletion through this interface
84      */
85     virtual ~Observer() {}
86
87   };
88
89   /**
90    * Create a property owner.
91    * @return A newly allocated object.
92    */
93   static PropertyOwner* New();
94
95   /**
96    * Virtual destructor; this is intended as a base class.
97    */
98   virtual ~PropertyOwner();
99
100   /**
101    * Add an observer.
102    * The observer is responsible for calling RemoveObserver(*this) during its own destruction.
103    * Connecting an actor-side object as an observer is not allowed, due to thread-safety issues.
104    * @param[in] observer The observer.
105    */
106   void AddObserver(Observer& observer);
107
108   /**
109    * Remove an observer.
110    * @param[in] observer The observer.
111    */
112   void RemoveObserver(Observer& observer);
113
114   /**
115    * This method can be used to determine if there is an animation or
116    * constraint that is using this property owner.
117    * @return true if there are observers.
118    */
119   bool IsObserved();
120
121   /**
122    * Called just before destruction to disconnect all observers and remove constraints.
123    * This occurs when the object is in the process of being destroyed.
124    */
125   void Destroy();
126
127   /**
128    * Notify all observers that the object has been connected
129    * This occurs when the object is connected to the scene-graph during UpdateManager::Update().
130    */
131   void ConnectToSceneGraph();
132
133   /**
134    * Notify all observers that the object has been disconnected and remove constraints.
135    * This occurs when the object is disconnected from the scene-graph during UpdateManager::Update().
136    * @param[in] currentBufferIndex The current update buffer.
137    */
138   void DisconnectFromSceneGraph( BufferIndex updateBufferIndex );
139
140   /**
141    * Install a custom property.
142    * @post The PropertyOwner takes ownership of the property.
143    * @param[in] property A pointer to a newly allocated property.
144    */
145   void InstallCustomProperty(PropertyBase* property);
146
147   /**
148    * Retrieve the custom properties owned by the object.
149    * @return A container of properties.
150    */
151   OwnedPropertyContainer& GetCustomProperties()
152   {
153     return mCustomProperties;
154   }
155
156   /**
157    * Retrieve the custom properties owned by the object.
158    * @return A container of properties.
159    */
160   const OwnedPropertyContainer& GetCustomProperties() const
161   {
162     return mCustomProperties;
163   }
164
165   /**
166    * Reset animatable properties to the corresponding base values.
167    * @param[in] currentBufferIndex The buffer to reset.
168    * @post The ResetDefaultProperties method is called, during which derived classes can reset default properties.
169    */
170   void ResetToBaseValues( BufferIndex updateBufferIndex );
171
172   // Constraints
173
174   /**
175    * Apply a constraint.
176    * @param[in] constraint The constraint to apply.
177    */
178   void ApplyConstraint( ConstraintBase* constraint );
179
180   /**
181    * Begin removal of constraints.
182    * @param[in] constraint The constraint to remove.
183    */
184   void RemoveConstraint( ConstraintBase* constraint );
185
186   /**
187    * Retrieve the constraints that are currently applied.
188    * @return A container of constraints.
189    */
190   ConstraintOwnerContainer& GetConstraints();
191
192   /**
193    * @copydoc UniformMap::Add
194    */
195   virtual void AddUniformMapping( UniformPropertyMapping* map );
196
197   /**
198    * @copydoc UniformMap::Remove
199    */
200   virtual void RemoveUniformMapping( const std::string& uniformName );
201
202   /**
203    * Get the mappings table
204    */
205   const UniformMap& GetUniformMap() const;
206
207   /**
208    * @copydoc UniformMap::AddUniformMapObserver
209    */
210   void AddUniformMapObserver( UniformMap::Observer& observer );
211
212   /**
213    * @copydoc UniformMap::RemoveUniformMapObserver
214    */
215   void RemoveUniformMapObserver( UniformMap::Observer& observer );
216
217
218 protected:
219
220   /**
221    * Protected constructor.
222    */
223   PropertyOwner();
224
225 private:
226
227   // Undefined
228   PropertyOwner(const PropertyOwner&);
229
230   // Undefined
231   PropertyOwner& operator=(const PropertyOwner& rhs);
232
233   /**
234    * Called after ResetToBaseValues; derived classes should reset any default properties.
235    * @param[in] currentBufferIndex The buffer to reset.
236    */
237   virtual void ResetDefaultProperties( BufferIndex updateBufferIndex ) {}
238
239 protected:
240
241   OwnedPropertyContainer mCustomProperties; ///< Properties provided with InstallCustomProperty()
242   UniformMap mUniformMaps; ///< Container of owned uniform maps
243
244 private:
245
246   typedef Dali::Vector<PropertyOwner::Observer*> ObserverContainer;
247   typedef ObserverContainer::Iterator ObserverIter;
248   typedef ObserverContainer::ConstIterator ConstObserverIter;
249
250   ObserverContainer mObservers; ///< Container of observer raw-pointers (not owned)
251
252   ConstraintOwnerContainer mConstraints; ///< Container of owned constraints
253 };
254
255 } // namespace SceneGraph
256
257 } // namespace Internal
258
259 } // namespace Dali
260
261 #endif // __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H__