1 #ifndef __DALI_INTERNAL_MESSAGE_H__
2 #define __DALI_INTERNAL_MESSAGE_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/internal/common/buffer-index.h>
23 #include <dali/internal/common/type-abstraction.h>
24 #include <dali/internal/update/common/scene-graph-buffers.h>
33 * An abstract base class for messages queued across threads.
34 * Messages are only allowed to contain value objects, either copies of the parameters or pointers
35 * If message parameter type is & or const& the message will try to take a copy of the actual type
42 * Construct the message base.
51 virtual ~MessageBase()
56 * Called to process the message.
57 * @param [in] bufferIndex The current update/render buffer index (depending on which thread processes the message).
59 virtual void Process( BufferIndex bufferIndex ) = 0;
65 * Templated message which calls a member function of an object.
66 * This allows nodes etc. to be modified in a thread-safe manner, when the update occurs in a separate thread.
67 * The object lifetime must controlled i.e. not destroyed before the message is processed.
69 template< typename T >
70 class Message : public MessageBase
74 typedef void(T::*MemberFunction)();
78 * @note The object is expected to be const in the thread which sends this message.
79 * However it can be modified when Process() is called in a different thread.
80 * @param[in] obj The object to be updated in a separate thread.
81 * @param[in] member The member function of the object.
83 Message( const T* obj, MemberFunction member )
85 object( const_cast< T* >( obj ) ),
86 memberFunction( member )
98 * @copydoc MessageBase::Process
100 virtual void Process( BufferIndex /*bufferIndex*/ )
102 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
103 (object->*memberFunction)();
109 MemberFunction memberFunction;
114 * Templated message which calls a member function of an object.
115 * This overload passes one value-type parameter.
116 * Template parameters need to match the MemberFunction!
117 * The message will contain copy of the value (in case of & or const&)
119 template< typename T, typename P >
120 class MessageValue1 : public MessageBase
124 typedef void(T::*MemberFunction)( typename ParameterType< P >::PassingType );
128 * @note The object is expected to be const in the thread which sends this message.
129 * However it can be modified when Process() is called in a different thread.
130 * @param[in] obj The object.
131 * @param[in] member The member function of the object.
132 * @param[in] p1 The first value-type parameter to pass to the member function.
134 MessageValue1( const T* obj,
135 MemberFunction member,
136 typename ParameterType< P >::PassingType p1 )
138 object( const_cast< T* >( obj ) ),
139 memberFunction( member ),
147 virtual ~MessageValue1()
152 * @copydoc MessageBase::Process
154 virtual void Process( BufferIndex /*bufferIndex*/ )
156 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
157 (object->*memberFunction)( ParameterType< P >::PassObject( param1 ) );
163 MemberFunction memberFunction;
164 typename ParameterType< P >::HolderType param1;
169 * Templated message which calls a member function of an object.
170 * This overload passes two value-type parameters.
171 * Template parameters need to match the MemberFunction!
172 * The message will contain copy of the value (in case of & or const&)
175 template< typename T, typename P1, typename P2 >
176 class MessageValue2 : public MessageBase
180 typedef void(T::*MemberFunction)(
181 typename ParameterType< P1 >::PassingType,
182 typename ParameterType< P2 >::PassingType );
186 * @note The object is expected to be const in the thread which sends this message.
187 * However it can be modified when Process() is called in a different thread.
188 * @param[in] obj The object.
189 * @param[in] member The member function of the object.
190 * @param[in] p1 The first parameter to pass to the member function.
191 * @param[in] p2 The second parameter to pass to the member function.
193 MessageValue2( const T* obj,
194 MemberFunction member,
195 typename ParameterType< P1 >::PassingType p1,
196 typename ParameterType< P2 >::PassingType p2 )
198 object( const_cast< T* >( obj ) ),
199 memberFunction( member ),
208 virtual ~MessageValue2()
213 * @copydoc MessageBase::Process
215 virtual void Process( BufferIndex /*bufferIndex*/ )
217 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
218 (object->*memberFunction)(
219 ParameterType< P1 >::PassObject( param1 ),
220 ParameterType< P2 >::PassObject( param2 ) );
226 MemberFunction memberFunction;
227 typename ParameterType< P1 >::HolderType param1;
228 typename ParameterType< P2 >::HolderType param2;
233 * Templated message which calls a member function of an object.
234 * This overload passes three value-type parameters.
235 * Template parameters need to match the MemberFunction!
236 * The message will contain copy of the value (in case of & or const&)
238 template< typename T, typename P1, typename P2, typename P3 >
239 class MessageValue3 : public MessageBase
243 typedef void(T::*MemberFunction)(
244 typename ParameterType< P1 >::PassingType,
245 typename ParameterType< P2 >::PassingType,
246 typename ParameterType< P3 >::PassingType );
250 * @note The object is expected to be const in the thread which sends this message.
251 * However it can be modified when Process() is called in a different thread.
252 * @param[in] obj The object.
253 * @param[in] member The member function of the object.
254 * @param[in] p1 The first parameter to pass to the member function.
255 * @param[in] p2 The second parameter to pass to the member function.
256 * @param[in] p3 The third parameter to pass to the member function.
258 MessageValue3( const T* obj,
259 MemberFunction member,
260 typename ParameterType< P1 >::PassingType p1,
261 typename ParameterType< P2 >::PassingType p2,
262 typename ParameterType< P3 >::PassingType p3 )
264 object( const_cast< T* >( obj ) ),
265 memberFunction( member ),
275 virtual ~MessageValue3()
280 * @copydoc MessageBase::Process
282 virtual void Process( BufferIndex /*bufferIndex*/ )
284 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
285 (object->*memberFunction)(
286 ParameterType< P1 >::PassObject( param1 ),
287 ParameterType< P2 >::PassObject( param2 ),
288 ParameterType< P3 >::PassObject( param3 ) );
294 MemberFunction memberFunction;
295 typename ParameterType< P1 >::HolderType param1;
296 typename ParameterType< P2 >::HolderType param2;
297 typename ParameterType< P3 >::HolderType param3;
302 * Templated message which calls a member function of an object.
303 * This overload passes four value-type parameters.
304 * Template parameters need to match the MemberFunction!
305 * The message will contain copy of the value (in case of & or const&)
307 template< typename T, typename P1, typename P2, typename P3, typename P4 >
308 class MessageValue4 : public MessageBase
312 typedef void(T::*MemberFunction)(
313 typename ParameterType< P1 >::PassingType,
314 typename ParameterType< P2 >::PassingType,
315 typename ParameterType< P3 >::PassingType,
316 typename ParameterType< P4 >::PassingType );
320 * @note The object is expected to be const in the thread which sends this message.
321 * However it can be modified when Process() is called in a different thread.
322 * @param[in] obj The object.
323 * @param[in] member The member function of the object.
324 * @param[in] p1 The first parameter to pass to the member function.
325 * @param[in] p2 The second parameter to pass to the member function.
326 * @param[in] p3 The third parameter to pass to the member function.
327 * @param[in] p4 The fourth parameter to pass to the member function.
329 MessageValue4( const T* obj,
330 MemberFunction member,
331 typename ParameterType< P1 >::PassingType p1,
332 typename ParameterType< P2 >::PassingType p2,
333 typename ParameterType< P3 >::PassingType p3,
334 typename ParameterType< P4 >::PassingType p4 )
336 object( const_cast< T* >( obj ) ),
337 memberFunction( member ),
348 virtual ~MessageValue4()
353 * @copydoc MessageBase::Process
355 virtual void Process( BufferIndex /*bufferIndex*/ )
357 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
358 (object->*memberFunction)(
359 ParameterType< P1 >::PassObject( param1 ),
360 ParameterType< P2 >::PassObject( param2 ),
361 ParameterType< P3 >::PassObject( param3 ),
362 ParameterType< P4 >::PassObject( param4 ) );
368 MemberFunction memberFunction;
369 typename ParameterType< P1 >::HolderType param1;
370 typename ParameterType< P2 >::HolderType param2;
371 typename ParameterType< P3 >::HolderType param3;
372 typename ParameterType< P4 >::HolderType param4;
377 * Templated message which calls a member function of an object.
378 * This overload passes five value-type parameters.
379 * Template parameters need to match the MemberFunction!
380 * The message will contain copy of the value (in case of & or const&)
382 template< typename T, typename P1, typename P2, typename P3, typename P4, typename P5 >
383 class MessageValue5 : public MessageBase
387 typedef void(T::*MemberFunction)(
388 typename ParameterType< P1 >::PassingType,
389 typename ParameterType< P2 >::PassingType,
390 typename ParameterType< P3 >::PassingType,
391 typename ParameterType< P4 >::PassingType,
392 typename ParameterType< P5 >::PassingType );
396 * @note The object is expected to be const in the thread which sends this message.
397 * However it can be modified when Process() is called in a different thread.
398 * @param[in] obj The object.
399 * @param[in] member The member function of the object.
400 * @param[in] p1 The first parameter to pass to the member function.
401 * @param[in] p2 The second parameter to pass to the member function.
402 * @param[in] p3 The third parameter to pass to the member function.
403 * @param[in] p4 The fourth parameter to pass to the member function.
404 * @param[in] p5 The fifth parameter to pass to the member function.
406 MessageValue5( const T* obj,
407 MemberFunction member,
408 typename ParameterType< P1 >::PassingType p1,
409 typename ParameterType< P2 >::PassingType p2,
410 typename ParameterType< P3 >::PassingType p3,
411 typename ParameterType< P4 >::PassingType p4,
412 typename ParameterType< P5 >::PassingType p5 )
414 object( const_cast< T* >( obj ) ),
415 memberFunction( member ),
427 virtual ~MessageValue5()
432 * @copydoc MessageBase::Process
434 virtual void Process( BufferIndex /*bufferIndex*/ )
436 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
437 (object->*memberFunction)(
438 ParameterType< P1 >::PassObject( param1 ),
439 ParameterType< P2 >::PassObject( param2 ),
440 ParameterType< P3 >::PassObject( param3 ),
441 ParameterType< P4 >::PassObject( param4 ),
442 ParameterType< P5 >::PassObject( param5 ) );
449 MemberFunction memberFunction;
450 typename ParameterType< P1 >::HolderType param1;
451 typename ParameterType< P2 >::HolderType param2;
452 typename ParameterType< P3 >::HolderType param3;
453 typename ParameterType< P4 >::HolderType param4;
454 typename ParameterType< P5 >::HolderType param5;
459 * Templated message which calls a member function of an object.
460 * This overload passes six value-type parameters.
461 * Template parameters need to match the MemberFunction!
462 * The message will contain copy of the value (in case of & or const&)
464 template< typename T, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6 >
465 class MessageValue6 : public MessageBase
469 typedef void(T::*MemberFunction)(
470 typename ParameterType< P1 >::PassingType,
471 typename ParameterType< P2 >::PassingType,
472 typename ParameterType< P3 >::PassingType,
473 typename ParameterType< P4 >::PassingType,
474 typename ParameterType< P5 >::PassingType,
475 typename ParameterType< P6 >::PassingType );
479 * @note The object is expected to be const in the thread which sends this message.
480 * However it can be modified when Process() is called in a different thread.
481 * @param[in] obj The object.
482 * @param[in] member The member function of the object.
483 * @param[in] p1 The first parameter to pass to the member function.
484 * @param[in] p2 The second parameter to pass to the member function.
485 * @param[in] p3 The third parameter to pass to the member function.
486 * @param[in] p4 The fourth parameter to pass to the member function.
487 * @param[in] p5 The fifth parameter to pass to the member function.
488 * @param[in] p6 The sixth parameter to pass to the member function.
490 MessageValue6( const T* obj,
491 MemberFunction member,
492 typename ParameterType< P1 >::PassingType p1,
493 typename ParameterType< P2 >::PassingType p2,
494 typename ParameterType< P3 >::PassingType p3,
495 typename ParameterType< P4 >::PassingType p4,
496 typename ParameterType< P5 >::PassingType p5,
497 typename ParameterType< P6 >::PassingType p6 )
499 object( const_cast< T* >( obj ) ),
500 memberFunction( member ),
513 virtual ~MessageValue6()
518 * @copydoc MessageBase::Process
520 virtual void Process( BufferIndex /*bufferIndex*/ )
522 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
523 (object->*memberFunction)(
524 ParameterType< P1 >::PassObject( param1 ),
525 ParameterType< P2 >::PassObject( param2 ),
526 ParameterType< P3 >::PassObject( param3 ),
527 ParameterType< P4 >::PassObject( param4 ),
528 ParameterType< P5 >::PassObject( param5 ),
529 ParameterType< P6 >::PassObject( param6 ) );
536 MemberFunction memberFunction;
537 typename ParameterType< P1 >::HolderType param1;
538 typename ParameterType< P2 >::HolderType param2;
539 typename ParameterType< P3 >::HolderType param3;
540 typename ParameterType< P4 >::HolderType param4;
541 typename ParameterType< P5 >::HolderType param5;
542 typename ParameterType< P6 >::HolderType param6;
547 * Templated message which calls a member function of an object.
548 * This overload passes a value-type to set a double-buffered property.
549 * Template parameters need to match the MemberFunction!
550 * The message will contain copy of the value (in case of & or const&)
552 template< typename T, typename P >
553 class MessageDoubleBuffered1 : public MessageBase
557 typedef void(T::*MemberFunction)(
559 typename ParameterType< P >::PassingType );
563 * @note The object is expected to be const in the thread which sends this message.
564 * However it can be modified when Process() is called in a different thread.
565 * @param[in] obj The object.
566 * @param[in] member The member function of the object.
567 * @param[in] p The second parameter to pass.
569 MessageDoubleBuffered1( const T* obj,
570 MemberFunction member,
571 typename ParameterType< P >::PassingType p )
573 object( const_cast< T* >( obj ) ),
574 memberFunction( member ),
582 virtual ~MessageDoubleBuffered1()
587 * @copydoc MessageBase::Process
589 virtual void Process( BufferIndex bufferIndex )
591 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
592 (object->*memberFunction)(
594 ParameterType< P >::PassObject( param ) );
600 MemberFunction memberFunction;
601 typename ParameterType< P >::HolderType param;
606 * Templated message which calls a member function of an object.
607 * This overload passes two value-types to set double-buffered properties.
608 * Template parameters need to match the MemberFunction!
609 * The message will contain copy of the value (in case of & or const&)
611 template< typename T, typename P2, typename P3 >
612 class MessageDoubleBuffered2 : public MessageBase
616 typedef void(T::*MemberFunction)(
618 typename ParameterType< P2 >::PassingType,
619 typename ParameterType< P3 >::PassingType );
623 * @note The object is expected to be const in the thread which sends this message.
624 * However it can be modified when Process() is called in a different thread.
625 * @param[in] obj The object.
626 * @param[in] member The member function of the object.
627 * @param[in] p2 The second parameter to pass to the function.
628 * @param[in] p3 The third parameter to pass to the function.
630 MessageDoubleBuffered2( const T* obj,
631 MemberFunction member,
632 typename ParameterType< P2 >::PassingType p2,
633 typename ParameterType< P3 >::PassingType p3 )
635 object( const_cast< T* >( obj ) ),
636 memberFunction( member ),
645 virtual ~MessageDoubleBuffered2()
650 * @copydoc MessageBase::Process
652 virtual void Process( BufferIndex bufferIndex )
654 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
655 (object->*memberFunction)(
657 ParameterType< P2 >::PassObject( param2 ),
658 ParameterType< P3 >::PassObject( param3 ) );
664 MemberFunction memberFunction;
665 typename ParameterType< P2 >::HolderType param2;
666 typename ParameterType< P3 >::HolderType param3;
672 * Templated message which calls a member function of an object.
673 * This overload passes three value-types to set double-buffered properties.
674 * Template parameters need to match the MemberFunction!
675 * The message will contain copy of the value (in case of & or const&)
677 template< typename T, typename P2, typename P3, typename P4 >
678 class MessageDoubleBuffered3 : public MessageBase
682 typedef void(T::*MemberFunction)(
684 typename ParameterType< P2 >::PassingType,
685 typename ParameterType< P3 >::PassingType,
686 typename ParameterType< P4 >::PassingType );
690 * @note The object is expected to be const in the thread which sends this message.
691 * However it can be modified when Process() is called in a different thread.
692 * @param[in] obj The object.
693 * @param[in] member The member function of the object.
694 * @param[in] p2 The second parameter to pass.
695 * @param[in] p3 The third parameter to pass.
696 * @param[in] p4 The forth parameter to pass.
698 MessageDoubleBuffered3( const T* obj,
699 MemberFunction member,
700 typename ParameterType< P2 >::PassingType p2,
701 typename ParameterType< P3 >::PassingType p3,
702 typename ParameterType< P4 >::PassingType p4 )
704 object( const_cast< T* >( obj ) ),
705 memberFunction( member ),
715 virtual ~MessageDoubleBuffered3()
720 * @copydoc MessageBase::Process
722 virtual void Process( BufferIndex bufferIndex )
724 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
725 (object->*memberFunction)(
727 ParameterType< P2 >::PassObject( param2 ),
728 ParameterType< P3 >::PassObject( param3 ),
729 ParameterType< P4 >::PassObject( param4 ) );
735 MemberFunction memberFunction;
736 typename ParameterType< P2 >::HolderType param2;
737 typename ParameterType< P3 >::HolderType param3;
738 typename ParameterType< P4 >::HolderType param4;
743 * Templated message which calls a member function of an object.
744 * This overload passes four value-types to set double-buffered properties.
745 * Template parameters need to match the MemberFunction!
746 * The message will contain copy of the value (in case of & or const&)
748 template< typename T, typename P2, typename P3, typename P4, typename P5 >
749 class MessageDoubleBuffered4 : public MessageBase
753 typedef void(T::*MemberFunction)(
755 typename ParameterType< P2 >::PassingType,
756 typename ParameterType< P3 >::PassingType,
757 typename ParameterType< P4 >::PassingType,
758 typename ParameterType< P5 >::PassingType );
762 * @note The object is expected to be const in the thread which sends this message.
763 * However it can be modified when Process() is called in a different thread.
764 * @param[in] obj The object.
765 * @param[in] member The member function of the object.
766 * @param[in] p2 The second parameter to pass.
767 * @param[in] p3 The third parameter to pass.
768 * @param[in] p4 The forth parameter to pass.
769 * @param[in] p5 The fifth parameter to pass.
771 MessageDoubleBuffered4( const T* obj,
772 MemberFunction member,
773 typename ParameterType< P2 >::PassingType p2,
774 typename ParameterType< P3 >::PassingType p3,
775 typename ParameterType< P4 >::PassingType p4,
776 typename ParameterType< P5 >::PassingType p5 )
778 object( const_cast< T* >( obj ) ),
779 memberFunction( member ),
790 virtual ~MessageDoubleBuffered4()
795 * @copydoc MessageBase::Process
797 virtual void Process( BufferIndex bufferIndex )
799 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
800 (object->*memberFunction)(
802 ParameterType< P2 >::PassObject( param2 ),
803 ParameterType< P3 >::PassObject( param3 ),
804 ParameterType< P4 >::PassObject( param4 ),
805 ParameterType< P5 >::PassObject( param5 ) );
811 MemberFunction memberFunction;
812 typename ParameterType< P2 >::HolderType param2;
813 typename ParameterType< P3 >::HolderType param3;
814 typename ParameterType< P4 >::HolderType param4;
815 typename ParameterType< P5 >::HolderType param5;
819 } // namespace Internal
823 #endif // __DALI_INTERNAL_MESSAGE_H__