1 #ifndef __DALI_INTERNAL_MESSAGE_H__
2 #define __DALI_INTERNAL_MESSAGE_H__
5 * Copyright (c) 2017 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)( 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)( param1, param2 );
224 MemberFunction memberFunction;
225 typename ParameterType< P1 >::HolderType param1;
226 typename ParameterType< P2 >::HolderType param2;
231 * Templated message which calls a member function of an object.
232 * This overload passes three value-type parameters.
233 * Template parameters need to match the MemberFunction!
234 * The message will contain copy of the value (in case of & or const&)
236 template< typename T, typename P1, typename P2, typename P3 >
237 class MessageValue3 : public MessageBase
241 typedef void(T::*MemberFunction)(
242 typename ParameterType< P1 >::PassingType,
243 typename ParameterType< P2 >::PassingType,
244 typename ParameterType< P3 >::PassingType );
248 * @note The object is expected to be const in the thread which sends this message.
249 * However it can be modified when Process() is called in a different thread.
250 * @param[in] obj The object.
251 * @param[in] member The member function of the object.
252 * @param[in] p1 The first parameter to pass to the member function.
253 * @param[in] p2 The second parameter to pass to the member function.
254 * @param[in] p3 The third parameter to pass to the member function.
256 MessageValue3( const T* obj,
257 MemberFunction member,
258 typename ParameterType< P1 >::PassingType p1,
259 typename ParameterType< P2 >::PassingType p2,
260 typename ParameterType< P3 >::PassingType p3 )
262 object( const_cast< T* >( obj ) ),
263 memberFunction( member ),
273 virtual ~MessageValue3()
278 * @copydoc MessageBase::Process
280 virtual void Process( BufferIndex /*bufferIndex*/ )
282 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
283 (object->*memberFunction)( param1, param2, param3 );
289 MemberFunction memberFunction;
290 typename ParameterType< P1 >::HolderType param1;
291 typename ParameterType< P2 >::HolderType param2;
292 typename ParameterType< P3 >::HolderType param3;
297 * Templated message which calls a member function of an object.
298 * This overload passes four value-type parameters.
299 * Template parameters need to match the MemberFunction!
300 * The message will contain copy of the value (in case of & or const&)
302 template< typename T, typename P1, typename P2, typename P3, typename P4 >
303 class MessageValue4 : public MessageBase
307 typedef void(T::*MemberFunction)(
308 typename ParameterType< P1 >::PassingType,
309 typename ParameterType< P2 >::PassingType,
310 typename ParameterType< P3 >::PassingType,
311 typename ParameterType< P4 >::PassingType );
315 * @note The object is expected to be const in the thread which sends this message.
316 * However it can be modified when Process() is called in a different thread.
317 * @param[in] obj The object.
318 * @param[in] member The member function of the object.
319 * @param[in] p1 The first parameter to pass to the member function.
320 * @param[in] p2 The second parameter to pass to the member function.
321 * @param[in] p3 The third parameter to pass to the member function.
322 * @param[in] p4 The fourth parameter to pass to the member function.
324 MessageValue4( const T* obj,
325 MemberFunction member,
326 typename ParameterType< P1 >::PassingType p1,
327 typename ParameterType< P2 >::PassingType p2,
328 typename ParameterType< P3 >::PassingType p3,
329 typename ParameterType< P4 >::PassingType p4 )
331 object( const_cast< T* >( obj ) ),
332 memberFunction( member ),
343 virtual ~MessageValue4()
348 * @copydoc MessageBase::Process
350 virtual void Process( BufferIndex /*bufferIndex*/ )
352 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
353 (object->*memberFunction)( param1, param2, param3, param4 );
359 MemberFunction memberFunction;
360 typename ParameterType< P1 >::HolderType param1;
361 typename ParameterType< P2 >::HolderType param2;
362 typename ParameterType< P3 >::HolderType param3;
363 typename ParameterType< P4 >::HolderType param4;
368 * Templated message which calls a member function of an object.
369 * This overload passes five value-type parameters.
370 * Template parameters need to match the MemberFunction!
371 * The message will contain copy of the value (in case of & or const&)
373 template< typename T, typename P1, typename P2, typename P3, typename P4, typename P5 >
374 class MessageValue5 : public MessageBase
378 typedef void(T::*MemberFunction)(
379 typename ParameterType< P1 >::PassingType,
380 typename ParameterType< P2 >::PassingType,
381 typename ParameterType< P3 >::PassingType,
382 typename ParameterType< P4 >::PassingType,
383 typename ParameterType< P5 >::PassingType );
387 * @note The object is expected to be const in the thread which sends this message.
388 * However it can be modified when Process() is called in a different thread.
389 * @param[in] obj The object.
390 * @param[in] member The member function of the object.
391 * @param[in] p1 The first parameter to pass to the member function.
392 * @param[in] p2 The second parameter to pass to the member function.
393 * @param[in] p3 The third parameter to pass to the member function.
394 * @param[in] p4 The fourth parameter to pass to the member function.
395 * @param[in] p5 The fifth parameter to pass to the member function.
397 MessageValue5( const T* obj,
398 MemberFunction member,
399 typename ParameterType< P1 >::PassingType p1,
400 typename ParameterType< P2 >::PassingType p2,
401 typename ParameterType< P3 >::PassingType p3,
402 typename ParameterType< P4 >::PassingType p4,
403 typename ParameterType< P5 >::PassingType p5 )
405 object( const_cast< T* >( obj ) ),
406 memberFunction( member ),
418 virtual ~MessageValue5()
423 * @copydoc MessageBase::Process
425 virtual void Process( BufferIndex /*bufferIndex*/ )
427 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
428 (object->*memberFunction)( param1, param2, param3, param4, param5 );
435 MemberFunction memberFunction;
436 typename ParameterType< P1 >::HolderType param1;
437 typename ParameterType< P2 >::HolderType param2;
438 typename ParameterType< P3 >::HolderType param3;
439 typename ParameterType< P4 >::HolderType param4;
440 typename ParameterType< P5 >::HolderType param5;
445 * Templated message which calls a member function of an object.
446 * This overload passes six value-type parameters.
447 * Template parameters need to match the MemberFunction!
448 * The message will contain copy of the value (in case of & or const&)
450 template< typename T, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6 >
451 class MessageValue6 : public MessageBase
455 typedef void(T::*MemberFunction)(
456 typename ParameterType< P1 >::PassingType,
457 typename ParameterType< P2 >::PassingType,
458 typename ParameterType< P3 >::PassingType,
459 typename ParameterType< P4 >::PassingType,
460 typename ParameterType< P5 >::PassingType,
461 typename ParameterType< P6 >::PassingType );
465 * @note The object is expected to be const in the thread which sends this message.
466 * However it can be modified when Process() is called in a different thread.
467 * @param[in] obj The object.
468 * @param[in] member The member function of the object.
469 * @param[in] p1 The first parameter to pass to the member function.
470 * @param[in] p2 The second parameter to pass to the member function.
471 * @param[in] p3 The third parameter to pass to the member function.
472 * @param[in] p4 The fourth parameter to pass to the member function.
473 * @param[in] p5 The fifth parameter to pass to the member function.
474 * @param[in] p6 The sixth parameter to pass to the member function.
476 MessageValue6( const T* obj,
477 MemberFunction member,
478 typename ParameterType< P1 >::PassingType p1,
479 typename ParameterType< P2 >::PassingType p2,
480 typename ParameterType< P3 >::PassingType p3,
481 typename ParameterType< P4 >::PassingType p4,
482 typename ParameterType< P5 >::PassingType p5,
483 typename ParameterType< P6 >::PassingType p6 )
485 object( const_cast< T* >( obj ) ),
486 memberFunction( member ),
499 virtual ~MessageValue6()
504 * @copydoc MessageBase::Process
506 virtual void Process( BufferIndex /*bufferIndex*/ )
508 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
509 (object->*memberFunction)( param1, param2, param3, param4, param5, param6 );
516 MemberFunction memberFunction;
517 typename ParameterType< P1 >::HolderType param1;
518 typename ParameterType< P2 >::HolderType param2;
519 typename ParameterType< P3 >::HolderType param3;
520 typename ParameterType< P4 >::HolderType param4;
521 typename ParameterType< P5 >::HolderType param5;
522 typename ParameterType< P6 >::HolderType param6;
527 * Templated message which calls a member function of an object.
528 * This overload passes just the buffer index to the method, no parameters.
530 template< typename T >
531 class MessageDoubleBuffered0 : public MessageBase
535 typedef void(T::*MemberFunction)( BufferIndex );
539 * @note The object is expected to be const in the thread which sends this message.
540 * However it can be modified when Process() is called in a different thread.
541 * @param[in] obj The object.
542 * @param[in] member The member function of the object.
544 MessageDoubleBuffered0( const T* obj, MemberFunction member )
546 object( const_cast< T* >( obj ) ),
547 memberFunction( member )
554 virtual ~MessageDoubleBuffered0()
559 * @copydoc MessageBase::Process
561 virtual void Process( BufferIndex bufferIndex )
563 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
564 (object->*memberFunction)( bufferIndex );
570 MemberFunction memberFunction;
576 * Templated message which calls a member function of an object.
577 * This overload passes a value-type to set a double-buffered property.
578 * Template parameters need to match the MemberFunction!
579 * The message will contain copy of the value (in case of & or const&)
581 template< typename T, typename P >
582 class MessageDoubleBuffered1 : public MessageBase
586 typedef void(T::*MemberFunction)(
588 typename ParameterType< P >::PassingType );
592 * @note The object is expected to be const in the thread which sends this message.
593 * However it can be modified when Process() is called in a different thread.
594 * @param[in] obj The object.
595 * @param[in] member The member function of the object.
596 * @param[in] p The second parameter to pass.
598 MessageDoubleBuffered1( const T* obj,
599 MemberFunction member,
600 typename ParameterType< P >::PassingType p )
602 object( const_cast< T* >( obj ) ),
603 memberFunction( member ),
611 virtual ~MessageDoubleBuffered1()
616 * @copydoc MessageBase::Process
618 virtual void Process( BufferIndex bufferIndex )
620 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
621 (object->*memberFunction)( bufferIndex, param );
627 MemberFunction memberFunction;
628 typename ParameterType< P >::HolderType param;
633 * Templated message which calls a member function of an object.
634 * This overload passes two value-types to set double-buffered properties.
635 * Template parameters need to match the MemberFunction!
636 * The message will contain copy of the value (in case of & or const&)
638 template< typename T, typename P2, typename P3 >
639 class MessageDoubleBuffered2 : public MessageBase
643 typedef void(T::*MemberFunction)(
645 typename ParameterType< P2 >::PassingType,
646 typename ParameterType< P3 >::PassingType );
650 * @note The object is expected to be const in the thread which sends this message.
651 * However it can be modified when Process() is called in a different thread.
652 * @param[in] obj The object.
653 * @param[in] member The member function of the object.
654 * @param[in] p2 The second parameter to pass to the function.
655 * @param[in] p3 The third parameter to pass to the function.
657 MessageDoubleBuffered2( const T* obj,
658 MemberFunction member,
659 typename ParameterType< P2 >::PassingType p2,
660 typename ParameterType< P3 >::PassingType p3 )
662 object( const_cast< T* >( obj ) ),
663 memberFunction( member ),
672 virtual ~MessageDoubleBuffered2()
677 * @copydoc MessageBase::Process
679 virtual void Process( BufferIndex bufferIndex )
681 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
682 (object->*memberFunction)(
683 bufferIndex, param2, param3 );
689 MemberFunction memberFunction;
690 typename ParameterType< P2 >::HolderType param2;
691 typename ParameterType< P3 >::HolderType param3;
697 * Templated message which calls a member function of an object.
698 * This overload passes three value-types to set double-buffered properties.
699 * Template parameters need to match the MemberFunction!
700 * The message will contain copy of the value (in case of & or const&)
702 template< typename T, typename P2, typename P3, typename P4 >
703 class MessageDoubleBuffered3 : public MessageBase
707 typedef void(T::*MemberFunction)(
709 typename ParameterType< P2 >::PassingType,
710 typename ParameterType< P3 >::PassingType,
711 typename ParameterType< P4 >::PassingType );
715 * @note The object is expected to be const in the thread which sends this message.
716 * However it can be modified when Process() is called in a different thread.
717 * @param[in] obj The object.
718 * @param[in] member The member function of the object.
719 * @param[in] p2 The second parameter to pass.
720 * @param[in] p3 The third parameter to pass.
721 * @param[in] p4 The forth parameter to pass.
723 MessageDoubleBuffered3( const T* obj,
724 MemberFunction member,
725 typename ParameterType< P2 >::PassingType p2,
726 typename ParameterType< P3 >::PassingType p3,
727 typename ParameterType< P4 >::PassingType p4 )
729 object( const_cast< T* >( obj ) ),
730 memberFunction( member ),
740 virtual ~MessageDoubleBuffered3()
745 * @copydoc MessageBase::Process
747 virtual void Process( BufferIndex bufferIndex )
749 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
750 (object->*memberFunction)( bufferIndex, param2, param3, param4 );
756 MemberFunction memberFunction;
757 typename ParameterType< P2 >::HolderType param2;
758 typename ParameterType< P3 >::HolderType param3;
759 typename ParameterType< P4 >::HolderType param4;
764 * Templated message which calls a member function of an object.
765 * This overload passes four value-types to set double-buffered properties.
766 * Template parameters need to match the MemberFunction!
767 * The message will contain copy of the value (in case of & or const&)
769 template< typename T, typename P2, typename P3, typename P4, typename P5 >
770 class MessageDoubleBuffered4 : public MessageBase
774 typedef void(T::*MemberFunction)(
776 typename ParameterType< P2 >::PassingType,
777 typename ParameterType< P3 >::PassingType,
778 typename ParameterType< P4 >::PassingType,
779 typename ParameterType< P5 >::PassingType );
783 * @note The object is expected to be const in the thread which sends this message.
784 * However it can be modified when Process() is called in a different thread.
785 * @param[in] obj The object.
786 * @param[in] member The member function of the object.
787 * @param[in] p2 The second parameter to pass.
788 * @param[in] p3 The third parameter to pass.
789 * @param[in] p4 The forth parameter to pass.
790 * @param[in] p5 The fifth parameter to pass.
792 MessageDoubleBuffered4( const T* obj,
793 MemberFunction member,
794 typename ParameterType< P2 >::PassingType p2,
795 typename ParameterType< P3 >::PassingType p3,
796 typename ParameterType< P4 >::PassingType p4,
797 typename ParameterType< P5 >::PassingType p5 )
799 object( const_cast< T* >( obj ) ),
800 memberFunction( member ),
811 virtual ~MessageDoubleBuffered4()
816 * @copydoc MessageBase::Process
818 virtual void Process( BufferIndex bufferIndex )
820 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
821 (object->*memberFunction)( bufferIndex, param2, param3, param4, param5 );
827 MemberFunction memberFunction;
828 typename ParameterType< P2 >::HolderType param2;
829 typename ParameterType< P3 >::HolderType param3;
830 typename ParameterType< P4 >::HolderType param4;
831 typename ParameterType< P5 >::HolderType param5;
835 } // namespace Internal
839 #endif // __DALI_INTERNAL_MESSAGE_H__