License conversion from Flora to Apache 2.0
[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 shortly before the observable object is destroyed.
63      */
64     virtual void PropertyOwnerDestroyed( PropertyOwner& owner ) = 0;
65   };
66
67   /**
68    * Create a property owner.
69    * @return A newly allocated object.
70    */
71   static PropertyOwner* New();
72
73   /**
74    * Virtual destructor; this is intended as a base class.
75    */
76   virtual ~PropertyOwner();
77
78   /**
79    * Add an observer.
80    * The observer is responsible for calling RemoveObserver(*this) during its own destruction.
81    * Connecting an actor-side object as an observer is not allowed, due to thread-safety issues.
82    * @param[in] observer The observer.
83    */
84   void AddObserver(Observer& observer);
85
86   /**
87    * Remove an observer.
88    * @param[in] observer The observer.
89    */
90   void RemoveObserver(Observer& observer);
91
92   /**
93    * This method can be used to determine if there is an animation or
94    * constraint that is using this property owner.
95    * @return true if there are observers.
96    */
97   bool IsObserved();
98
99   /**
100    * Disconnect all observers and remove constraints.
101    * This occurs when the object is disconnected from the scene-graph during UpdateManager::Update().
102    */
103   void DisconnectFromSceneGraph();
104
105   /**
106    * Install a custom property.
107    * @post The PropertyOwner takes ownership of the property.
108    * @param[in] property A pointer to a newly allocated property.
109    */
110   void InstallCustomProperty(PropertyBase* property);
111
112   /**
113    * Retrieve the custom properties owned by the object.
114    * @return A container of properties.
115    */
116   OwnedPropertyContainer& GetCustomProperties()
117   {
118     return mCustomProperties;
119   }
120
121   /**
122    * Retrieve the custom properties owned by the object.
123    * @return A container of properties.
124    */
125   const OwnedPropertyContainer& GetCustomProperties() const
126   {
127     return mCustomProperties;
128   }
129
130   /**
131    * Reset animatable properties to the corresponding base values.
132    * @param[in] currentBufferIndex The buffer to reset.
133    * @post The ResetDefaultProperties method is called, during which derived classes can reset default properties.
134    */
135   void ResetToBaseValues( BufferIndex updateBufferIndex );
136
137   // Constraints
138
139   /**
140    * Apply a constraint.
141    * @param[in] constraint The constraint to apply.
142    */
143   void ApplyConstraint( ConstraintBase* constraint );
144
145   /**
146    * Begin removal of constraints.
147    * @param[in] constraint The constraint to remove.
148    */
149   void RemoveConstraint( ConstraintBase* constraint );
150
151   /**
152    * Retrieve the constraints that are currently applied.
153    * @return A container of constraints.
154    */
155   ConstraintOwnerContainer& GetConstraints();
156
157 protected:
158
159   /**
160    * Protected constructor.
161    */
162   PropertyOwner();
163
164 private:
165
166   // Undefined
167   PropertyOwner(const PropertyOwner&);
168
169   // Undefined
170   PropertyOwner& operator=(const PropertyOwner& rhs);
171
172   /**
173    * Called after ResetToBaseValues; derived classes should reset any default properties.
174    * @param[in] currentBufferIndex The buffer to reset.
175    */
176   virtual void ResetDefaultProperties( BufferIndex updateBufferIndex ) {}
177
178 protected:
179
180   OwnedPropertyContainer mCustomProperties; ///< Properties provided with InstallCustomProperty()
181
182 private:
183
184   typedef Dali::Vector<PropertyOwner::Observer*> ObserverContainer;
185   typedef ObserverContainer::Iterator ObserverIter;
186   typedef ObserverContainer::ConstIterator ConstObserverIter;
187
188   ObserverContainer mObservers; ///< Container of observer raw-pointers (not owned)
189
190   ConstraintOwnerContainer mConstraints; ///< Container of owned constraints
191
192 };
193
194 } // namespace SceneGraph
195
196 } // namespace Internal
197
198 } // namespace Dali
199
200 #endif // __DALI_INTERNAL_SCENE_GRAPH_PROPERTY_OWNER_H__