Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-core.git] / dali / internal / update / nodes / node-messages.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_NODE_MESSAGES_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_NODE_MESSAGES_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // INTERNAL INCLUDES
21 #include <dali/internal/common/buffer-index.h>
22 #include <dali/internal/common/message.h>
23 #include <dali/internal/update/nodes/node.h>
24 #include <dali/internal/update/manager/update-manager.h>
25
26 namespace Dali
27 {
28
29 namespace Internal
30 {
31
32 namespace SceneGraph
33 {
34
35 // Messages for Node
36
37 class NodePropertyMessageBase : public MessageBase
38 {
39 public:
40
41   /**
42    * Create a message.
43    */
44   NodePropertyMessageBase(UpdateManager& updateManager);
45
46   /**
47    * Virtual destructor
48    */
49   virtual ~NodePropertyMessageBase();
50
51 protected:
52
53   /**
54    * Inform UpdateManager that the Node is now active
55    */
56   void NotifyUpdateManager( Node* node );
57
58 private:
59
60   // Undefined
61   NodePropertyMessageBase(const NodePropertyMessageBase&);
62   NodePropertyMessageBase& operator=(const NodePropertyMessageBase& rhs);
63
64 protected:
65
66   UpdateManager& mUpdateManager;
67 };
68
69 /**
70  * Templated message which bakes a Node property.
71  */
72 template< typename P >
73 class NodePropertyMessage : public NodePropertyMessageBase
74 {
75 public:
76
77   typedef void(AnimatableProperty<P>::*MemberFunction)( BufferIndex, typename ParameterType< P >::PassingType );
78
79   /**
80    * Create a message.
81    * @note The node is expected to be const in the thread which sends this message.
82    * However it can be modified when Process() is called in a different thread.
83    * @param[in] updateManager The update-manager.
84    * @param[in] node The node.
85    * @param[in] property The property to bake.
86    * @param[in] member The member function of the object.
87    * @param[in] value The new value of the property.
88    */
89   static void Send( UpdateManager& updateManager,
90                     const Node* node,
91                     const AnimatableProperty<P>* property,
92                     MemberFunction member,
93                     typename ParameterType< P >::PassingType value )
94   {
95     // Reserve some memory inside the message queue
96     unsigned int* slot = updateManager.GetEventToUpdate().ReserveMessageSlot( sizeof( NodePropertyMessage ) );
97
98     // Construct message in the message queue memory; note that delete should not be called on the return value
99     new (slot) NodePropertyMessage( updateManager, node, property, member, value );
100   }
101
102   /**
103    * Virtual destructor
104    */
105   virtual ~NodePropertyMessage()
106   {
107   }
108
109   /**
110    * @copydoc MessageBase::Process
111    */
112   virtual void Process( BufferIndex updateBufferIndex )
113   {
114     (mProperty->*mMemberFunction)( updateBufferIndex, mParam );
115
116     if( ! mNode->IsActive() )
117     {
118       // Inform UpdateManager that the Node is now active
119       NotifyUpdateManager( mNode );
120     }
121   }
122
123 private:
124
125   /**
126    * Create a message.
127    * @note The node is expected to be const in the thread which sends this message.
128    * However it can be modified when Process() is called in a different thread.
129    * @param[in] updateManager The update-manager.
130    * @param[in] node The node.
131    * @param[in] property The property to bake.
132    * @param[in] member The member function of the object.
133    * @param[in] value The new value of the property.
134    */
135   NodePropertyMessage( UpdateManager& updateManager,
136                        const Node* node,
137                        const AnimatableProperty<P>* property,
138                        MemberFunction member,
139                        typename ParameterType< P >::PassingType value )
140   : NodePropertyMessageBase( updateManager ),
141     mNode( const_cast< Node* >( node ) ),
142     mProperty( const_cast< AnimatableProperty<P>* >( property ) ),
143     mMemberFunction( member ),
144     mParam( value )
145   {
146   }
147
148 private:
149
150   Node* mNode;
151   AnimatableProperty<P>* mProperty;
152   MemberFunction mMemberFunction;
153   typename ParameterType< P >::HolderType mParam;
154 };
155
156 /**
157  * Templated message which bakes a Node property.
158  */
159 template< typename P >
160 class NodePropertyComponentMessage : public NodePropertyMessageBase
161 {
162 public:
163
164   typedef void(AnimatableProperty<P>::*MemberFunction)( BufferIndex, float );
165
166   /**
167    * Send a message.
168    * @note The node is expected to be const in the thread which sends this message.
169    * However it can be modified when Process() is called in a different thread.
170    * @param[in] updateManager The update-manager.
171    * @param[in] node The node.
172    * @param[in] property The property to bake.
173    * @param[in] member The member function of the object.
174    * @param[in] value The new value of the X,Y,Z or W component.
175    */
176   static void Send( UpdateManager& updateManager,
177                     const Node* node,
178                     const AnimatableProperty<P>* property,
179                     MemberFunction member,
180                     float value )
181   {
182     // Reserve some memory inside the message queue
183     unsigned int* slot = updateManager.GetEventToUpdate().ReserveMessageSlot( sizeof( NodePropertyComponentMessage ) );
184
185     // Construct message in the message queue memory; note that delete should not be called on the return value
186     new (slot) NodePropertyComponentMessage( updateManager, node, property, member, value );
187   }
188
189   /**
190    * Virtual destructor
191    */
192   virtual ~NodePropertyComponentMessage()
193   {
194   }
195
196   /**
197    * @copydoc MessageBase::Process
198    */
199   virtual void Process( BufferIndex updateBufferIndex )
200   {
201     (mProperty->*mMemberFunction)( updateBufferIndex, mParam );
202
203     if( ! mNode->IsActive() )
204     {
205       // Inform UpdateManager that the Node is now active
206       NotifyUpdateManager( mNode );
207     }
208   }
209
210 private:
211
212   /**
213    * Create a message.
214    * @note The node is expected to be const in the thread which sends this message.
215    * However it can be modified when Process() is called in a different thread.
216    * @param[in] updateManager The update-manager.
217    * @param[in] node The node.
218    * @param[in] property The property to bake.
219    * @param[in] member The member function of the object.
220    * @param[in] value The new value of the X,Y,Z or W component.
221   */
222   NodePropertyComponentMessage( UpdateManager& updateManager,
223                                 const Node* node,
224                                 const AnimatableProperty<P>* property,
225                                 MemberFunction member,
226                                 float value )
227   : NodePropertyMessageBase( updateManager ),
228     mNode( const_cast< Node* >( node ) ),
229     mProperty( const_cast< AnimatableProperty<P>* >( property ) ),
230     mMemberFunction( member ),
231     mParam( value )
232   {
233   }
234
235 private:
236
237   Node* mNode;
238   AnimatableProperty<P>* mProperty;
239   MemberFunction mMemberFunction;
240   float mParam;
241 };
242
243 } // namespace SceneGraph
244
245 } // namespace Internal
246
247 } // namespace Dali
248
249 #endif // __DALI_INTERNAL_SCENE_GRAPH_NODE_MESSAGES_H__