1 #ifndef DALI_INTERNAL_MESSAGE_H
2 #define DALI_INTERNAL_MESSAGE_H
5 * Copyright (c) 2019 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 )
88 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
99 * @copydoc MessageBase::Process
101 virtual void Process( BufferIndex /*bufferIndex*/ )
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 ),
142 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
148 virtual ~MessageValue1()
153 * @copydoc MessageBase::Process
155 virtual void Process( BufferIndex /*bufferIndex*/ )
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 ),
203 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
209 virtual ~MessageValue2()
214 * @copydoc MessageBase::Process
216 virtual void Process( BufferIndex /*bufferIndex*/ )
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 ),
268 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
274 virtual ~MessageValue3()
279 * @copydoc MessageBase::Process
281 virtual void Process( BufferIndex /*bufferIndex*/ )
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 ),
338 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
344 virtual ~MessageValue4()
349 * @copydoc MessageBase::Process
351 virtual void Process( BufferIndex /*bufferIndex*/ )
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 ),
413 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
419 virtual ~MessageValue5()
424 * @copydoc MessageBase::Process
426 virtual void Process( BufferIndex /*bufferIndex*/ )
428 (object->*memberFunction)( param1, param2, param3, param4, param5 );
434 MemberFunction memberFunction;
435 typename ParameterType< P1 >::HolderType param1;
436 typename ParameterType< P2 >::HolderType param2;
437 typename ParameterType< P3 >::HolderType param3;
438 typename ParameterType< P4 >::HolderType param4;
439 typename ParameterType< P5 >::HolderType param5;
444 * Templated message which calls a member function of an object.
445 * This overload passes six value-type parameters.
446 * Template parameters need to match the MemberFunction!
447 * The message will contain copy of the value (in case of & or const&)
449 template< typename T, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6 >
450 class MessageValue6 : public MessageBase
454 typedef void(T::*MemberFunction)(
455 typename ParameterType< P1 >::PassingType,
456 typename ParameterType< P2 >::PassingType,
457 typename ParameterType< P3 >::PassingType,
458 typename ParameterType< P4 >::PassingType,
459 typename ParameterType< P5 >::PassingType,
460 typename ParameterType< P6 >::PassingType );
464 * @note The object is expected to be const in the thread which sends this message.
465 * However it can be modified when Process() is called in a different thread.
466 * @param[in] obj The object.
467 * @param[in] member The member function of the object.
468 * @param[in] p1 The first parameter to pass to the member function.
469 * @param[in] p2 The second parameter to pass to the member function.
470 * @param[in] p3 The third parameter to pass to the member function.
471 * @param[in] p4 The fourth parameter to pass to the member function.
472 * @param[in] p5 The fifth parameter to pass to the member function.
473 * @param[in] p6 The sixth parameter to pass to the member function.
475 MessageValue6( const T* obj,
476 MemberFunction member,
477 typename ParameterType< P1 >::PassingType p1,
478 typename ParameterType< P2 >::PassingType p2,
479 typename ParameterType< P3 >::PassingType p3,
480 typename ParameterType< P4 >::PassingType p4,
481 typename ParameterType< P5 >::PassingType p5,
482 typename ParameterType< P6 >::PassingType p6 )
484 object( const_cast< T* >( obj ) ),
485 memberFunction( member ),
493 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
499 virtual ~MessageValue6()
504 * @copydoc MessageBase::Process
506 virtual void Process( BufferIndex /*bufferIndex*/ )
508 (object->*memberFunction)( param1, param2, param3, param4, param5, param6 );
514 MemberFunction memberFunction;
515 typename ParameterType< P1 >::HolderType param1;
516 typename ParameterType< P2 >::HolderType param2;
517 typename ParameterType< P3 >::HolderType param3;
518 typename ParameterType< P4 >::HolderType param4;
519 typename ParameterType< P5 >::HolderType param5;
520 typename ParameterType< P6 >::HolderType param6;
525 * Templated message which calls a member function of an object.
526 * This overload passes just the buffer index to the method, no parameters.
528 template< typename T >
529 class MessageDoubleBuffered0 : public MessageBase
533 typedef void(T::*MemberFunction)( BufferIndex );
537 * @note The object is expected to be const in the thread which sends this message.
538 * However it can be modified when Process() is called in a different thread.
539 * @param[in] obj The object.
540 * @param[in] member The member function of the object.
542 MessageDoubleBuffered0( const T* obj, MemberFunction member )
544 object( const_cast< T* >( obj ) ),
545 memberFunction( member )
547 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
553 virtual ~MessageDoubleBuffered0()
558 * @copydoc MessageBase::Process
560 virtual void Process( BufferIndex bufferIndex )
562 (object->*memberFunction)( bufferIndex );
568 MemberFunction memberFunction;
574 * Templated message which calls a member function of an object.
575 * This overload passes a value-type to set a double-buffered property.
576 * Template parameters need to match the MemberFunction!
577 * The message will contain copy of the value (in case of & or const&)
579 template< typename T, typename P >
580 class MessageDoubleBuffered1 : public MessageBase
584 typedef void(T::*MemberFunction)(
586 typename ParameterType< P >::PassingType );
590 * @note The object is expected to be const in the thread which sends this message.
591 * However it can be modified when Process() is called in a different thread.
592 * @param[in] obj The object.
593 * @param[in] member The member function of the object.
594 * @param[in] p The second parameter to pass.
596 MessageDoubleBuffered1( const T* obj,
597 MemberFunction member,
598 typename ParameterType< P >::PassingType p )
600 object( const_cast< T* >( obj ) ),
601 memberFunction( member ),
604 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
610 virtual ~MessageDoubleBuffered1()
615 * @copydoc MessageBase::Process
617 virtual void Process( BufferIndex bufferIndex )
619 (object->*memberFunction)( bufferIndex, param );
625 MemberFunction memberFunction;
626 typename ParameterType< P >::HolderType param;
631 * Templated message which calls a member function of an object.
632 * This overload passes two value-types to set double-buffered properties.
633 * Template parameters need to match the MemberFunction!
634 * The message will contain copy of the value (in case of & or const&)
636 template< typename T, typename P2, typename P3 >
637 class MessageDoubleBuffered2 : public MessageBase
641 typedef void(T::*MemberFunction)(
643 typename ParameterType< P2 >::PassingType,
644 typename ParameterType< P3 >::PassingType );
648 * @note The object is expected to be const in the thread which sends this message.
649 * However it can be modified when Process() is called in a different thread.
650 * @param[in] obj The object.
651 * @param[in] member The member function of the object.
652 * @param[in] p2 The second parameter to pass to the function.
653 * @param[in] p3 The third parameter to pass to the function.
655 MessageDoubleBuffered2( const T* obj,
656 MemberFunction member,
657 typename ParameterType< P2 >::PassingType p2,
658 typename ParameterType< P3 >::PassingType p3 )
660 object( const_cast< T* >( obj ) ),
661 memberFunction( member ),
665 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
671 virtual ~MessageDoubleBuffered2()
676 * @copydoc MessageBase::Process
678 virtual void Process( BufferIndex bufferIndex )
680 (object->*memberFunction)( bufferIndex, param2, param3 );
686 MemberFunction memberFunction;
687 typename ParameterType< P2 >::HolderType param2;
688 typename ParameterType< P3 >::HolderType param3;
694 * Templated message which calls a member function of an object.
695 * This overload passes three value-types to set double-buffered properties.
696 * Template parameters need to match the MemberFunction!
697 * The message will contain copy of the value (in case of & or const&)
699 template< typename T, typename P2, typename P3, typename P4 >
700 class MessageDoubleBuffered3 : public MessageBase
704 typedef void(T::*MemberFunction)(
706 typename ParameterType< P2 >::PassingType,
707 typename ParameterType< P3 >::PassingType,
708 typename ParameterType< P4 >::PassingType );
712 * @note The object is expected to be const in the thread which sends this message.
713 * However it can be modified when Process() is called in a different thread.
714 * @param[in] obj The object.
715 * @param[in] member The member function of the object.
716 * @param[in] p2 The second parameter to pass.
717 * @param[in] p3 The third parameter to pass.
718 * @param[in] p4 The forth parameter to pass.
720 MessageDoubleBuffered3( const T* obj,
721 MemberFunction member,
722 typename ParameterType< P2 >::PassingType p2,
723 typename ParameterType< P3 >::PassingType p3,
724 typename ParameterType< P4 >::PassingType p4 )
726 object( const_cast< T* >( obj ) ),
727 memberFunction( member ),
732 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
738 virtual ~MessageDoubleBuffered3()
743 * @copydoc MessageBase::Process
745 virtual void Process( BufferIndex bufferIndex )
747 (object->*memberFunction)( bufferIndex, param2, param3, param4 );
753 MemberFunction memberFunction;
754 typename ParameterType< P2 >::HolderType param2;
755 typename ParameterType< P3 >::HolderType param3;
756 typename ParameterType< P4 >::HolderType param4;
761 * Templated message which calls a member function of an object.
762 * This overload passes four value-types to set double-buffered properties.
763 * Template parameters need to match the MemberFunction!
764 * The message will contain copy of the value (in case of & or const&)
766 template< typename T, typename P2, typename P3, typename P4, typename P5 >
767 class MessageDoubleBuffered4 : public MessageBase
771 typedef void(T::*MemberFunction)(
773 typename ParameterType< P2 >::PassingType,
774 typename ParameterType< P3 >::PassingType,
775 typename ParameterType< P4 >::PassingType,
776 typename ParameterType< P5 >::PassingType );
780 * @note The object is expected to be const in the thread which sends this message.
781 * However it can be modified when Process() is called in a different thread.
782 * @param[in] obj The object.
783 * @param[in] member The member function of the object.
784 * @param[in] p2 The second parameter to pass.
785 * @param[in] p3 The third parameter to pass.
786 * @param[in] p4 The forth parameter to pass.
787 * @param[in] p5 The fifth parameter to pass.
789 MessageDoubleBuffered4( const T* obj,
790 MemberFunction member,
791 typename ParameterType< P2 >::PassingType p2,
792 typename ParameterType< P3 >::PassingType p3,
793 typename ParameterType< P4 >::PassingType p4,
794 typename ParameterType< P5 >::PassingType p5 )
796 object( const_cast< T* >( obj ) ),
797 memberFunction( member ),
803 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
809 virtual ~MessageDoubleBuffered4()
814 * @copydoc MessageBase::Process
816 virtual void Process( BufferIndex bufferIndex )
818 (object->*memberFunction)( bufferIndex, param2, param3, param4, param5 );
824 MemberFunction memberFunction;
825 typename ParameterType< P2 >::HolderType param2;
826 typename ParameterType< P3 >::HolderType param3;
827 typename ParameterType< P4 >::HolderType param4;
828 typename ParameterType< P5 >::HolderType param5;
832 } // namespace Internal
836 #endif // DALI_INTERNAL_MESSAGE_H