Merge "Klockwork: Remove unreachable code" into tizen
[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/internal/common/message.h>
26 #include <dali/internal/common/owner-container.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/animation/scene-graph-constraint-declarations.h>
30
31 namespace Dali
32 {
33
34 namespace Internal
35 {
36
37 namespace SceneGraph
38 {
39
40 class PropertyOwner;
41
42 typedef OwnerContainer< PropertyBase* > OwnedPropertyContainer;
43 typedef OwnedPropertyContainer::Iterator  OwnedPropertyIter;
44
45 /**
46  * An update-thread object which own properties.
47  * This allows observers to track the lifetime of the object & its properties.
48  */
49 class PropertyOwner
50 {
51 public:
52
53   class Observer
54   {
55   public:
56
57     /**
58      * Called when the observable object is disconnected from the scene graph.
59      * @param[in] currentBufferIndex The buffer to reset.
60      * @post The observer is automatically disconnected
61      * (observer will not receive the PropertyOwnerDestroyed callback after this)
62      */
63     virtual void PropertyOwnerDisconnected( BufferIndex updateBufferIndex, PropertyOwner& owner ) = 0;
64
65     /**
66      * Called shortly before the observable object is destroyed.
67      *
68      * @note Cleanup should be done in both this and PropertyOwnerDisconnected as PropertyOwnerDisconnected
69      * may not be called (i.e. when shutting down).
70      */
71     virtual void PropertyOwnerDestroyed( PropertyOwner& owner ) = 0;
72   };
73
74   /**
75    * Create a property owner.
76    * @return A newly allocated object.
77    */
78   static PropertyOwner* New();
79
80   /**
81    * Virtual destructor; this is intended as a base class.
82    */
83   virtual ~PropertyOwner();
84
85   /**
86    * Add an observer.
87    * The observer is responsible for calling RemoveObserver(*this) during its own destruction.
88    * Connecting an actor-side object as an observer is not allowed, due to thread-safety issues.
89    * @param[in] observer The observer.
90    */
91   void AddObserver(Observer& observer);
92
93   /**
94    * Remove an observer.
95    * @param[in] observer The observer.
96    */
97   void RemoveObserver(Observer& observer);
98
99   /**
100    * This method can be used to determine if there is an animation or
101    * constraint that is using this property owner.
102    * @return true if there are observers.
103    */
104   bool IsObserved();
105
106   /**
107    * Called just before destruction to disconnect all observers and remove constraints.
108    * This occurs when the object is in the process of being destroyed.
109    */
110   void Destroy();
111
112   /**
113    * Disconnect all observers and remove constraints.
114    * This occurs when the object is disconnected from the scene-graph during UpdateManager::Update().
115    * @param[in] currentBufferIndex The current update buffer.
116    */
117   void DisconnectFromSceneGraph( BufferIndex updateBufferIndex );
118
119   /**
120    * Install a custom property.
121    * @post The PropertyOwner takes ownership of the property.
122    * @param[in] property A pointer to a newly allocated property.
123    */
124   void InstallCustomProperty(PropertyBase* property);
125
126   /**
127    * Retrieve the custom properties owned by the object.
128    * @return A container of properties.
129    */
130   OwnedPropertyContainer& GetCustomProperties()
131   {
132     return mCustomProperties;
133   }
134
135   /**
136    * Retrieve the custom properties owned by the object.
137    * @return A container of properties.
138    */
139   const OwnedPropertyContainer& GetCustomProperties() const
140   {
141     return mCustomProperties;
142   }
143
144   /**
145    * Reset animatable properties to the corresponding base values.
146    * @param[in] currentBufferIndex The buffer to reset.
147    * @post The ResetDefaultProperties method is called, during which derived classes can reset default properties.
148    */
149   void ResetToBaseValues( BufferIndex updateBufferIndex );
150
151   // Constraints
152
153   /**
154    * Apply a constraint.
155    * @param[in] constraint The constraint to apply.
156    */
157   void ApplyConstraint( ConstraintBase* constraint );
158
159   /**
160    * Begin removal of constraints.
161    * @param[in] constraint The constraint to remove.
162    */
163   void RemoveConstraint( ConstraintBase* constraint );
164
165   /**
166    * Retrieve the constraints that are currently applied.
167    * @return A container of constraints.
168    */
169   ConstraintOwnerContainer& GetConstraints();
170
171 protected:
172
173   /**
174    * Protected constructor.
175    */
176   PropertyOwner();
177
178 private:
179
180   // Undefined
181   PropertyOwner(const PropertyOwner&);
182
183   // Undefined
184   PropertyOwner& operator=(const PropertyOwner& rhs);
185
186   /**
187    * Called after ResetToBaseValues; derived classes should reset any default properties.
188    * @param[in] currentBufferIndex The buffer to reset.
189    */
190   virtual void ResetDefaultProperties( BufferIndex updateBufferIndex ) {}
191
192 protected:
193
194   OwnedPropertyContainer mCustomProperties; ///< Properties provided with InstallCustomProperty()
195
196 private:
197
198   typedef Dali::Vector<PropertyOwner::Observer*> ObserverContainer;
199   typedef ObserverContainer::Iterator ObserverIter;
200   typedef ObserverContainer::ConstIterator ConstObserverIter;
201
202   ObserverContainer mObservers; ///< Container of observer raw-pointers (not owned)
203
204   ConstraintOwnerContainer mConstraints; ///< Container of owned constraints
205
206 };
207
208 } // namespace SceneGraph
209
210 } // namespace Internal
211
212 } // namespace Dali
213
214 #endif // __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H__