1 #ifndef __DALI_INTERNAL_MESSAGE_H__
2 #define __DALI_INTERNAL_MESSAGE_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 // http://floralicense.org/license/
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.
21 #include <dali/internal/common/buffer-index.h>
22 #include <dali/internal/common/type-abstraction.h>
23 #include <dali/internal/update/common/scene-graph-buffers.h>
32 * An abstract base class for messages queued across threads.
33 * Messages are only allowed to contain value objects, either copies of the parameters or pointers
34 * If message parameter type is & or const& the message will try to take a copy of the actual type
41 * Construct the message base.
50 virtual ~MessageBase()
55 * Called to process the message.
56 * @param [in] bufferIndex The current update/render buffer index (depending on which thread processes the message).
58 virtual void Process( BufferIndex bufferIndex ) = 0;
64 * Templated message which calls a member function of an object.
65 * This allows nodes etc. to be modified in a thread-safe manner, when the update occurs in a separate thread.
66 * The object lifetime must controlled i.e. not destroyed before the message is processed.
68 template< typename T >
69 class Message : public MessageBase
73 typedef void(T::*MemberFunction)();
77 * @note The object is expected to be const in the thread which sends this message.
78 * However it can be modified when Process() is called in a different thread.
79 * @param[in] obj The object to be updated in a separate thread.
80 * @param[in] member The member function of the object.
82 Message( const T* obj, MemberFunction member )
84 object( const_cast< T* >( obj ) ),
85 memberFunction( member )
97 * @copydoc MessageBase::Process
99 virtual void Process( BufferIndex /*bufferIndex*/ )
101 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
102 (object->*memberFunction)();
108 MemberFunction memberFunction;
113 * Templated message which calls a member function of an object.
114 * This overload passes one value-type parameter.
115 * Template parameters need to match the MemberFunction!
116 * The message will contain copy of the value (in case of & or const&)
118 template< typename T, typename P >
119 class MessageValue1 : public MessageBase
123 typedef void(T::*MemberFunction)( typename ParameterType< P >::PassingType );
127 * @note The object 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] obj The object.
130 * @param[in] member The member function of the object.
131 * @param[in] p1 The first value-type parameter to pass to the member function.
133 MessageValue1( const T* obj,
134 MemberFunction member,
135 typename ParameterType< P >::PassingType p1 )
137 object( const_cast< T* >( obj ) ),
138 memberFunction( member ),
146 virtual ~MessageValue1()
151 * @copydoc MessageBase::Process
153 virtual void Process( BufferIndex /*bufferIndex*/ )
155 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
156 (object->*memberFunction)( ParameterType< P >::PassObject( param1 ) );
162 MemberFunction memberFunction;
163 typename ParameterType< P >::HolderType param1;
168 * Templated message which calls a member function of an object.
169 * This overload passes two value-type parameters.
170 * Template parameters need to match the MemberFunction!
171 * The message will contain copy of the value (in case of & or const&)
174 template< typename T, typename P1, typename P2 >
175 class MessageValue2 : public MessageBase
179 typedef void(T::*MemberFunction)(
180 typename ParameterType< P1 >::PassingType,
181 typename ParameterType< P2 >::PassingType );
185 * @note The object is expected to be const in the thread which sends this message.
186 * However it can be modified when Process() is called in a different thread.
187 * @param[in] obj The object.
188 * @param[in] member The member function of the object.
189 * @param[in] p1 The first parameter to pass to the member function.
190 * @param[in] p2 The second parameter to pass to the member function.
192 MessageValue2( const T* obj,
193 MemberFunction member,
194 typename ParameterType< P1 >::PassingType p1,
195 typename ParameterType< P2 >::PassingType p2 )
197 object( const_cast< T* >( obj ) ),
198 memberFunction( member ),
207 virtual ~MessageValue2()
212 * @copydoc MessageBase::Process
214 virtual void Process( BufferIndex /*bufferIndex*/ )
216 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
217 (object->*memberFunction)(
218 ParameterType< P1 >::PassObject( param1 ),
219 ParameterType< P2 >::PassObject( param2 ) );
225 MemberFunction memberFunction;
226 typename ParameterType< P1 >::HolderType param1;
227 typename ParameterType< P2 >::HolderType param2;
232 * Templated message which calls a member function of an object.
233 * This overload passes three value-type parameters.
234 * Template parameters need to match the MemberFunction!
235 * The message will contain copy of the value (in case of & or const&)
237 template< typename T, typename P1, typename P2, typename P3 >
238 class MessageValue3 : public MessageBase
242 typedef void(T::*MemberFunction)(
243 typename ParameterType< P1 >::PassingType,
244 typename ParameterType< P2 >::PassingType,
245 typename ParameterType< P3 >::PassingType );
249 * @note The object is expected to be const in the thread which sends this message.
250 * However it can be modified when Process() is called in a different thread.
251 * @param[in] obj The object.
252 * @param[in] member The member function of the object.
253 * @param[in] p1 The first parameter to pass to the member function.
254 * @param[in] p2 The second parameter to pass to the member function.
255 * @param[in] p3 The third parameter to pass to the member function.
257 MessageValue3( const T* obj,
258 MemberFunction member,
259 typename ParameterType< P1 >::PassingType p1,
260 typename ParameterType< P2 >::PassingType p2,
261 typename ParameterType< P3 >::PassingType p3 )
263 object( const_cast< T* >( obj ) ),
264 memberFunction( member ),
274 virtual ~MessageValue3()
279 * @copydoc MessageBase::Process
281 virtual void Process( BufferIndex /*bufferIndex*/ )
283 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
284 (object->*memberFunction)(
285 ParameterType< P1 >::PassObject( param1 ),
286 ParameterType< P2 >::PassObject( param2 ),
287 ParameterType< P3 >::PassObject( param3 ) );
293 MemberFunction memberFunction;
294 typename ParameterType< P1 >::HolderType param1;
295 typename ParameterType< P2 >::HolderType param2;
296 typename ParameterType< P3 >::HolderType param3;
301 * Templated message which calls a member function of an object.
302 * This overload passes four value-type parameters.
303 * Template parameters need to match the MemberFunction!
304 * The message will contain copy of the value (in case of & or const&)
306 template< typename T, typename P1, typename P2, typename P3, typename P4 >
307 class MessageValue4 : public MessageBase
311 typedef void(T::*MemberFunction)(
312 typename ParameterType< P1 >::PassingType,
313 typename ParameterType< P2 >::PassingType,
314 typename ParameterType< P3 >::PassingType,
315 typename ParameterType< P4 >::PassingType );
319 * @note The object is expected to be const in the thread which sends this message.
320 * However it can be modified when Process() is called in a different thread.
321 * @param[in] obj The object.
322 * @param[in] member The member function of the object.
323 * @param[in] p1 The first parameter to pass to the member function.
324 * @param[in] p2 The second parameter to pass to the member function.
325 * @param[in] p3 The third parameter to pass to the member function.
326 * @param[in] p4 The fourth parameter to pass to the member function.
328 MessageValue4( const T* obj,
329 MemberFunction member,
330 typename ParameterType< P1 >::PassingType p1,
331 typename ParameterType< P2 >::PassingType p2,
332 typename ParameterType< P3 >::PassingType p3,
333 typename ParameterType< P4 >::PassingType p4 )
335 object( const_cast< T* >( obj ) ),
336 memberFunction( member ),
347 virtual ~MessageValue4()
352 * @copydoc MessageBase::Process
354 virtual void Process( BufferIndex /*bufferIndex*/ )
356 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
357 (object->*memberFunction)(
358 ParameterType< P1 >::PassObject( param1 ),
359 ParameterType< P2 >::PassObject( param2 ),
360 ParameterType< P3 >::PassObject( param3 ),
361 ParameterType< P4 >::PassObject( param4 ) );
367 MemberFunction memberFunction;
368 typename ParameterType< P1 >::HolderType param1;
369 typename ParameterType< P2 >::HolderType param2;
370 typename ParameterType< P3 >::HolderType param3;
371 typename ParameterType< P4 >::HolderType param4;
376 * Templated message which calls a member function of an object.
377 * This overload passes five value-type parameters.
378 * Template parameters need to match the MemberFunction!
379 * The message will contain copy of the value (in case of & or const&)
381 template< typename T, typename P1, typename P2, typename P3, typename P4, typename P5 >
382 class MessageValue5 : public MessageBase
386 typedef void(T::*MemberFunction)(
387 typename ParameterType< P1 >::PassingType,
388 typename ParameterType< P2 >::PassingType,
389 typename ParameterType< P3 >::PassingType,
390 typename ParameterType< P4 >::PassingType,
391 typename ParameterType< P5 >::PassingType );
395 * @note The object is expected to be const in the thread which sends this message.
396 * However it can be modified when Process() is called in a different thread.
397 * @param[in] obj The object.
398 * @param[in] member The member function of the object.
399 * @param[in] p1 The first parameter to pass to the member function.
400 * @param[in] p2 The second parameter to pass to the member function.
401 * @param[in] p3 The third parameter to pass to the member function.
402 * @param[in] p4 The fourth parameter to pass to the member function.
403 * @param[in] p5 The fifth parameter to pass to the member function.
405 MessageValue5( const T* obj,
406 MemberFunction member,
407 typename ParameterType< P1 >::PassingType p1,
408 typename ParameterType< P2 >::PassingType p2,
409 typename ParameterType< P3 >::PassingType p3,
410 typename ParameterType< P4 >::PassingType p4,
411 typename ParameterType< P5 >::PassingType p5 )
413 object( const_cast< T* >( obj ) ),
414 memberFunction( member ),
426 virtual ~MessageValue5()
431 * @copydoc MessageBase::Process
433 virtual void Process( BufferIndex /*bufferIndex*/ )
435 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
436 (object->*memberFunction)(
437 ParameterType< P1 >::PassObject( param1 ),
438 ParameterType< P2 >::PassObject( param2 ),
439 ParameterType< P3 >::PassObject( param3 ),
440 ParameterType< P4 >::PassObject( param4 ),
441 ParameterType< P5 >::PassObject( param5 ) );
448 MemberFunction memberFunction;
449 typename ParameterType< P1 >::HolderType param1;
450 typename ParameterType< P2 >::HolderType param2;
451 typename ParameterType< P3 >::HolderType param3;
452 typename ParameterType< P4 >::HolderType param4;
453 typename ParameterType< P5 >::HolderType param5;
458 * Templated message which calls a member function of an object.
459 * This overload passes a value-type to set a double-buffered property.
460 * Template parameters need to match the MemberFunction!
461 * The message will contain copy of the value (in case of & or const&)
463 template< typename T, typename P >
464 class MessageDoubleBuffered1 : public MessageBase
468 typedef void(T::*MemberFunction)(
470 typename ParameterType< P >::PassingType );
474 * @note The object is expected to be const in the thread which sends this message.
475 * However it can be modified when Process() is called in a different thread.
476 * @param[in] obj The object.
477 * @param[in] member The member function of the object.
478 * @param[in] p The second parameter to pass.
480 MessageDoubleBuffered1( const T* obj,
481 MemberFunction member,
482 typename ParameterType< P >::PassingType p )
484 object( const_cast< T* >( obj ) ),
485 memberFunction( member ),
493 virtual ~MessageDoubleBuffered1()
498 * @copydoc MessageBase::Process
500 virtual void Process( BufferIndex bufferIndex )
502 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
503 (object->*memberFunction)(
505 ParameterType< P >::PassObject( param ) );
511 MemberFunction memberFunction;
512 typename ParameterType< P >::HolderType param;
517 * Templated message which calls a member function of an object.
518 * This overload passes two value-types to set double-buffered properties.
519 * Template parameters need to match the MemberFunction!
520 * The message will contain copy of the value (in case of & or const&)
522 template< typename T, typename P2, typename P3 >
523 class MessageDoubleBuffered2 : public MessageBase
527 typedef void(T::*MemberFunction)(
529 typename ParameterType< P2 >::PassingType,
530 typename ParameterType< P3 >::PassingType );
534 * @note The object is expected to be const in the thread which sends this message.
535 * However it can be modified when Process() is called in a different thread.
536 * @param[in] obj The object.
537 * @param[in] member The member function of the object.
538 * @param[in] p2 The second parameter to pass to the function.
539 * @param[in] p3 The third parameter to pass to the function.
541 MessageDoubleBuffered2( const T* obj,
542 MemberFunction member,
543 typename ParameterType< P2 >::PassingType p2,
544 typename ParameterType< P3 >::PassingType p3 )
546 object( const_cast< T* >( obj ) ),
547 memberFunction( member ),
556 virtual ~MessageDoubleBuffered2()
561 * @copydoc MessageBase::Process
563 virtual void Process( BufferIndex bufferIndex )
565 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
566 (object->*memberFunction)(
568 ParameterType< P2 >::PassObject( param2 ),
569 ParameterType< P3 >::PassObject( param3 ) );
575 MemberFunction memberFunction;
576 typename ParameterType< P2 >::HolderType param2;
577 typename ParameterType< P3 >::HolderType param3;
583 * Templated message which calls a member function of an object.
584 * This overload passes three value-types to set double-buffered properties.
585 * Template parameters need to match the MemberFunction!
586 * The message will contain copy of the value (in case of & or const&)
588 template< typename T, typename P2, typename P3, typename P4 >
589 class MessageDoubleBuffered3 : public MessageBase
593 typedef void(T::*MemberFunction)(
595 typename ParameterType< P2 >::PassingType,
596 typename ParameterType< P3 >::PassingType,
597 typename ParameterType< P4 >::PassingType );
601 * @note The object is expected to be const in the thread which sends this message.
602 * However it can be modified when Process() is called in a different thread.
603 * @param[in] obj The object.
604 * @param[in] member The member function of the object.
605 * @param[in] p2 The second parameter to pass.
606 * @param[in] p3 The third parameter to pass.
607 * @param[in] p4 The forth parameter to pass.
609 MessageDoubleBuffered3( const T* obj,
610 MemberFunction member,
611 typename ParameterType< P2 >::PassingType p2,
612 typename ParameterType< P3 >::PassingType p3,
613 typename ParameterType< P4 >::PassingType p4 )
615 object( const_cast< T* >( obj ) ),
616 memberFunction( member ),
626 virtual ~MessageDoubleBuffered3()
631 * @copydoc MessageBase::Process
633 virtual void Process( BufferIndex bufferIndex )
635 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
636 (object->*memberFunction)(
638 ParameterType< P2 >::PassObject( param2 ),
639 ParameterType< P3 >::PassObject( param3 ),
640 ParameterType< P4 >::PassObject( param4 ) );
646 MemberFunction memberFunction;
647 typename ParameterType< P2 >::HolderType param2;
648 typename ParameterType< P3 >::HolderType param3;
649 typename ParameterType< P4 >::HolderType param4;
654 * Templated message which calls a member function of an object.
655 * This overload passes four value-types to set double-buffered properties.
656 * Template parameters need to match the MemberFunction!
657 * The message will contain copy of the value (in case of & or const&)
659 template< typename T, typename P2, typename P3, typename P4, typename P5 >
660 class MessageDoubleBuffered4 : public MessageBase
664 typedef void(T::*MemberFunction)(
666 typename ParameterType< P2 >::PassingType,
667 typename ParameterType< P3 >::PassingType,
668 typename ParameterType< P4 >::PassingType,
669 typename ParameterType< P5 >::PassingType );
673 * @note The object is expected to be const in the thread which sends this message.
674 * However it can be modified when Process() is called in a different thread.
675 * @param[in] obj The object.
676 * @param[in] member The member function of the object.
677 * @param[in] p2 The second parameter to pass.
678 * @param[in] p3 The third parameter to pass.
679 * @param[in] p4 The forth parameter to pass.
680 * @param[in] p5 The fifth parameter to pass.
682 MessageDoubleBuffered4( const T* obj,
683 MemberFunction member,
684 typename ParameterType< P2 >::PassingType p2,
685 typename ParameterType< P3 >::PassingType p3,
686 typename ParameterType< P4 >::PassingType p4,
687 typename ParameterType< P5 >::PassingType p5 )
689 object( const_cast< T* >( obj ) ),
690 memberFunction( member ),
701 virtual ~MessageDoubleBuffered4()
706 * @copydoc MessageBase::Process
708 virtual void Process( BufferIndex bufferIndex )
710 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
711 (object->*memberFunction)(
713 ParameterType< P2 >::PassObject( param2 ),
714 ParameterType< P3 >::PassObject( param3 ),
715 ParameterType< P4 >::PassObject( param4 ),
716 ParameterType< P5 >::PassObject( param5 ) );
722 MemberFunction memberFunction;
723 typename ParameterType< P2 >::HolderType param2;
724 typename ParameterType< P3 >::HolderType param3;
725 typename ParameterType< P4 >::HolderType param4;
726 typename ParameterType< P5 >::HolderType param5;
730 } // namespace Internal
734 #endif // __DALI_INTERNAL_MESSAGE_H__