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