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
73 using MemberFunction = void ( T::* )();
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 )
87 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
98 * @copydoc MessageBase::Process
100 void Process( BufferIndex /*bufferIndex*/ ) override
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
122 using MemberFunction = void ( T::* )( typename ParameterType<P>::PassingType );
126 * @note The object is expected to be const in the thread which sends this message.
127 * However it can be modified when Process() is called in a different thread.
128 * @param[in] obj The object.
129 * @param[in] member The member function of the object.
130 * @param[in] p1 The first value-type parameter to pass to the member function.
132 MessageValue1( const T* obj,
133 MemberFunction member,
134 typename ParameterType< P >::PassingType p1 )
136 object( const_cast< T* >( obj ) ),
137 memberFunction( member ),
140 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
146 ~MessageValue1() override
151 * @copydoc MessageBase::Process
153 void Process( BufferIndex /*bufferIndex*/ ) override
155 (object->*memberFunction)( param1 );
161 MemberFunction memberFunction;
162 typename ParameterType< P >::HolderType param1;
167 * Templated message which calls a member function of an object.
168 * This overload passes two value-type parameters.
169 * Template parameters need to match the MemberFunction!
170 * The message will contain copy of the value (in case of & or const&)
173 template< typename T, typename P1, typename P2 >
174 class MessageValue2 : public MessageBase
177 using MemberFunction = void ( T::* )( typename ParameterType<P1>::PassingType, typename ParameterType<P2>::PassingType );
181 * @note The object is expected to be const in the thread which sends this message.
182 * However it can be modified when Process() is called in a different thread.
183 * @param[in] obj The object.
184 * @param[in] member The member function of the object.
185 * @param[in] p1 The first parameter to pass to the member function.
186 * @param[in] p2 The second parameter to pass to the member function.
188 MessageValue2( const T* obj,
189 MemberFunction member,
190 typename ParameterType< P1 >::PassingType p1,
191 typename ParameterType< P2 >::PassingType p2 )
193 object( const_cast< T* >( obj ) ),
194 memberFunction( member ),
198 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
204 ~MessageValue2() override
209 * @copydoc MessageBase::Process
211 void Process( BufferIndex /*bufferIndex*/ ) override
213 (object->*memberFunction)( param1, param2 );
219 MemberFunction memberFunction;
220 typename ParameterType< P1 >::HolderType param1;
221 typename ParameterType< P2 >::HolderType param2;
226 * Templated message which calls a member function of an object.
227 * This overload passes three value-type parameters.
228 * Template parameters need to match the MemberFunction!
229 * The message will contain copy of the value (in case of & or const&)
231 template< typename T, typename P1, typename P2, typename P3 >
232 class MessageValue3 : public MessageBase
235 using MemberFunction = void ( T::* )( typename ParameterType<P1>::PassingType, typename ParameterType<P2>::PassingType, typename ParameterType<P3>::PassingType );
239 * @note The object is expected to be const in the thread which sends this message.
240 * However it can be modified when Process() is called in a different thread.
241 * @param[in] obj The object.
242 * @param[in] member The member function of the object.
243 * @param[in] p1 The first parameter to pass to the member function.
244 * @param[in] p2 The second parameter to pass to the member function.
245 * @param[in] p3 The third parameter to pass to the member function.
247 MessageValue3( const T* obj,
248 MemberFunction member,
249 typename ParameterType< P1 >::PassingType p1,
250 typename ParameterType< P2 >::PassingType p2,
251 typename ParameterType< P3 >::PassingType p3 )
253 object( const_cast< T* >( obj ) ),
254 memberFunction( member ),
259 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
265 ~MessageValue3() override
270 * @copydoc MessageBase::Process
272 void Process( BufferIndex /*bufferIndex*/ ) override
274 (object->*memberFunction)( param1, param2, param3 );
280 MemberFunction memberFunction;
281 typename ParameterType< P1 >::HolderType param1;
282 typename ParameterType< P2 >::HolderType param2;
283 typename ParameterType< P3 >::HolderType param3;
288 * Templated message which calls a member function of an object.
289 * This overload passes four value-type parameters.
290 * Template parameters need to match the MemberFunction!
291 * The message will contain copy of the value (in case of & or const&)
293 template< typename T, typename P1, typename P2, typename P3, typename P4 >
294 class MessageValue4 : public MessageBase
297 using MemberFunction = void ( T::* )( typename ParameterType<P1>::PassingType, typename ParameterType<P2>::PassingType, typename ParameterType<P3>::PassingType, typename ParameterType<P4>::PassingType );
301 * @note The object is expected to be const in the thread which sends this message.
302 * However it can be modified when Process() is called in a different thread.
303 * @param[in] obj The object.
304 * @param[in] member The member function of the object.
305 * @param[in] p1 The first parameter to pass to the member function.
306 * @param[in] p2 The second parameter to pass to the member function.
307 * @param[in] p3 The third parameter to pass to the member function.
308 * @param[in] p4 The fourth parameter to pass to the member function.
310 MessageValue4( const T* obj,
311 MemberFunction member,
312 typename ParameterType< P1 >::PassingType p1,
313 typename ParameterType< P2 >::PassingType p2,
314 typename ParameterType< P3 >::PassingType p3,
315 typename ParameterType< P4 >::PassingType p4 )
317 object( const_cast< T* >( obj ) ),
318 memberFunction( member ),
324 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
330 ~MessageValue4() override
335 * @copydoc MessageBase::Process
337 void Process( BufferIndex /*bufferIndex*/ ) override
339 (object->*memberFunction)( param1, param2, param3, param4 );
345 MemberFunction memberFunction;
346 typename ParameterType< P1 >::HolderType param1;
347 typename ParameterType< P2 >::HolderType param2;
348 typename ParameterType< P3 >::HolderType param3;
349 typename ParameterType< P4 >::HolderType param4;
354 * Templated message which calls a member function of an object.
355 * This overload passes five value-type parameters.
356 * Template parameters need to match the MemberFunction!
357 * The message will contain copy of the value (in case of & or const&)
359 template< typename T, typename P1, typename P2, typename P3, typename P4, typename P5 >
360 class MessageValue5 : public MessageBase
363 using MemberFunction = void ( T::* )( typename ParameterType<P1>::PassingType, typename ParameterType<P2>::PassingType, typename ParameterType<P3>::PassingType, typename ParameterType<P4>::PassingType, typename ParameterType<P5>::PassingType );
367 * @note The object is expected to be const in the thread which sends this message.
368 * However it can be modified when Process() is called in a different thread.
369 * @param[in] obj The object.
370 * @param[in] member The member function of the object.
371 * @param[in] p1 The first parameter to pass to the member function.
372 * @param[in] p2 The second parameter to pass to the member function.
373 * @param[in] p3 The third parameter to pass to the member function.
374 * @param[in] p4 The fourth parameter to pass to the member function.
375 * @param[in] p5 The fifth parameter to pass to the member function.
377 MessageValue5( const T* obj,
378 MemberFunction member,
379 typename ParameterType< P1 >::PassingType p1,
380 typename ParameterType< P2 >::PassingType p2,
381 typename ParameterType< P3 >::PassingType p3,
382 typename ParameterType< P4 >::PassingType p4,
383 typename ParameterType< P5 >::PassingType p5 )
385 object( const_cast< T* >( obj ) ),
386 memberFunction( member ),
393 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
399 ~MessageValue5() override
404 * @copydoc MessageBase::Process
406 void Process( BufferIndex /*bufferIndex*/ ) override
408 (object->*memberFunction)( param1, param2, param3, param4, param5 );
414 MemberFunction memberFunction;
415 typename ParameterType< P1 >::HolderType param1;
416 typename ParameterType< P2 >::HolderType param2;
417 typename ParameterType< P3 >::HolderType param3;
418 typename ParameterType< P4 >::HolderType param4;
419 typename ParameterType< P5 >::HolderType param5;
424 * Templated message which calls a member function of an object.
425 * This overload passes six value-type parameters.
426 * Template parameters need to match the MemberFunction!
427 * The message will contain copy of the value (in case of & or const&)
429 template< typename T, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6 >
430 class MessageValue6 : public MessageBase
433 using MemberFunction = void ( T::* )( typename ParameterType<P1>::PassingType, typename ParameterType<P2>::PassingType, typename ParameterType<P3>::PassingType, typename ParameterType<P4>::PassingType, typename ParameterType<P5>::PassingType, typename ParameterType<P6>::PassingType );
437 * @note The object is expected to be const in the thread which sends this message.
438 * However it can be modified when Process() is called in a different thread.
439 * @param[in] obj The object.
440 * @param[in] member The member function of the object.
441 * @param[in] p1 The first parameter to pass to the member function.
442 * @param[in] p2 The second parameter to pass to the member function.
443 * @param[in] p3 The third parameter to pass to the member function.
444 * @param[in] p4 The fourth parameter to pass to the member function.
445 * @param[in] p5 The fifth parameter to pass to the member function.
446 * @param[in] p6 The sixth parameter to pass to the member function.
448 MessageValue6( const T* obj,
449 MemberFunction member,
450 typename ParameterType< P1 >::PassingType p1,
451 typename ParameterType< P2 >::PassingType p2,
452 typename ParameterType< P3 >::PassingType p3,
453 typename ParameterType< P4 >::PassingType p4,
454 typename ParameterType< P5 >::PassingType p5,
455 typename ParameterType< P6 >::PassingType p6 )
457 object( const_cast< T* >( obj ) ),
458 memberFunction( member ),
466 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
472 ~MessageValue6() override
477 * @copydoc MessageBase::Process
479 void Process( BufferIndex /*bufferIndex*/ ) override
481 (object->*memberFunction)( param1, param2, param3, param4, param5, param6 );
487 MemberFunction memberFunction;
488 typename ParameterType< P1 >::HolderType param1;
489 typename ParameterType< P2 >::HolderType param2;
490 typename ParameterType< P3 >::HolderType param3;
491 typename ParameterType< P4 >::HolderType param4;
492 typename ParameterType< P5 >::HolderType param5;
493 typename ParameterType< P6 >::HolderType param6;
498 * Templated message which calls a member function of an object.
499 * This overload passes just the buffer index to the method, no parameters.
501 template< typename T >
502 class MessageDoubleBuffered0 : public MessageBase
505 using MemberFunction = void ( T::* )( BufferIndex );
509 * @note The object is expected to be const in the thread which sends this message.
510 * However it can be modified when Process() is called in a different thread.
511 * @param[in] obj The object.
512 * @param[in] member The member function of the object.
514 MessageDoubleBuffered0( const T* obj, MemberFunction member )
516 object( const_cast< T* >( obj ) ),
517 memberFunction( member )
519 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
525 ~MessageDoubleBuffered0() override
530 * @copydoc MessageBase::Process
532 void Process( BufferIndex bufferIndex ) override
534 (object->*memberFunction)( bufferIndex );
540 MemberFunction memberFunction;
546 * Templated message which calls a member function of an object.
547 * This overload passes a value-type to set a double-buffered property.
548 * Template parameters need to match the MemberFunction!
549 * The message will contain copy of the value (in case of & or const&)
551 template< typename T, typename P >
552 class MessageDoubleBuffered1 : public MessageBase
555 using MemberFunction = void ( T::* )( BufferIndex, typename ParameterType<P>::PassingType );
559 * @note The object is expected to be const in the thread which sends this message.
560 * However it can be modified when Process() is called in a different thread.
561 * @param[in] obj The object.
562 * @param[in] member The member function of the object.
563 * @param[in] p The second parameter to pass.
565 MessageDoubleBuffered1( const T* obj,
566 MemberFunction member,
567 typename ParameterType< P >::PassingType p )
569 object( const_cast< T* >( obj ) ),
570 memberFunction( member ),
573 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
579 ~MessageDoubleBuffered1() override
584 * @copydoc MessageBase::Process
586 void Process( BufferIndex bufferIndex ) override
588 (object->*memberFunction)( bufferIndex, param );
594 MemberFunction memberFunction;
595 typename ParameterType< P >::HolderType param;
600 * Templated message which calls a member function of an object.
601 * This overload passes two value-types to set double-buffered properties.
602 * Template parameters need to match the MemberFunction!
603 * The message will contain copy of the value (in case of & or const&)
605 template< typename T, typename P2, typename P3 >
606 class MessageDoubleBuffered2 : public MessageBase
609 using MemberFunction = void ( T::* )( BufferIndex, typename ParameterType<P2>::PassingType, typename ParameterType<P3>::PassingType );
613 * @note The object is expected to be const in the thread which sends this message.
614 * However it can be modified when Process() is called in a different thread.
615 * @param[in] obj The object.
616 * @param[in] member The member function of the object.
617 * @param[in] p2 The second parameter to pass to the function.
618 * @param[in] p3 The third parameter to pass to the function.
620 MessageDoubleBuffered2( const T* obj,
621 MemberFunction member,
622 typename ParameterType< P2 >::PassingType p2,
623 typename ParameterType< P3 >::PassingType p3 )
625 object( const_cast< T* >( obj ) ),
626 memberFunction( member ),
630 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
636 ~MessageDoubleBuffered2() override
641 * @copydoc MessageBase::Process
643 void Process( BufferIndex bufferIndex ) override
645 (object->*memberFunction)( bufferIndex, param2, param3 );
651 MemberFunction memberFunction;
652 typename ParameterType< P2 >::HolderType param2;
653 typename ParameterType< P3 >::HolderType param3;
659 * Templated message which calls a member function of an object.
660 * This overload passes three value-types to set double-buffered properties.
661 * Template parameters need to match the MemberFunction!
662 * The message will contain copy of the value (in case of & or const&)
664 template< typename T, typename P2, typename P3, typename P4 >
665 class MessageDoubleBuffered3 : public MessageBase
668 using MemberFunction = void ( T::* )( BufferIndex, typename ParameterType<P2>::PassingType, typename ParameterType<P3>::PassingType, typename ParameterType<P4>::PassingType );
672 * @note The object is expected to be const in the thread which sends this message.
673 * However it can be modified when Process() is called in a different thread.
674 * @param[in] obj The object.
675 * @param[in] member The member function of the object.
676 * @param[in] p2 The second parameter to pass.
677 * @param[in] p3 The third parameter to pass.
678 * @param[in] p4 The forth parameter to pass.
680 MessageDoubleBuffered3( const T* obj,
681 MemberFunction member,
682 typename ParameterType< P2 >::PassingType p2,
683 typename ParameterType< P3 >::PassingType p3,
684 typename ParameterType< P4 >::PassingType p4 )
686 object( const_cast< T* >( obj ) ),
687 memberFunction( member ),
692 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
698 ~MessageDoubleBuffered3() override
703 * @copydoc MessageBase::Process
705 void Process( BufferIndex bufferIndex ) override
707 (object->*memberFunction)( bufferIndex, param2, param3, param4 );
713 MemberFunction memberFunction;
714 typename ParameterType< P2 >::HolderType param2;
715 typename ParameterType< P3 >::HolderType param3;
716 typename ParameterType< P4 >::HolderType param4;
721 * Templated message which calls a member function of an object.
722 * This overload passes four value-types to set double-buffered properties.
723 * Template parameters need to match the MemberFunction!
724 * The message will contain copy of the value (in case of & or const&)
726 template< typename T, typename P2, typename P3, typename P4, typename P5 >
727 class MessageDoubleBuffered4 : public MessageBase
730 using MemberFunction = void ( T::* )( BufferIndex, typename ParameterType<P2>::PassingType, typename ParameterType<P3>::PassingType, typename ParameterType<P4>::PassingType, typename ParameterType<P5>::PassingType );
734 * @note The object is expected to be const in the thread which sends this message.
735 * However it can be modified when Process() is called in a different thread.
736 * @param[in] obj The object.
737 * @param[in] member The member function of the object.
738 * @param[in] p2 The second parameter to pass.
739 * @param[in] p3 The third parameter to pass.
740 * @param[in] p4 The forth parameter to pass.
741 * @param[in] p5 The fifth parameter to pass.
743 MessageDoubleBuffered4( const T* obj,
744 MemberFunction member,
745 typename ParameterType< P2 >::PassingType p2,
746 typename ParameterType< P3 >::PassingType p3,
747 typename ParameterType< P4 >::PassingType p4,
748 typename ParameterType< P5 >::PassingType p5 )
750 object( const_cast< T* >( obj ) ),
751 memberFunction( member ),
757 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
763 ~MessageDoubleBuffered4() override
768 * @copydoc MessageBase::Process
770 void Process( BufferIndex bufferIndex ) override
772 (object->*memberFunction)( bufferIndex, param2, param3, param4, param5 );
778 MemberFunction memberFunction;
779 typename ParameterType< P2 >::HolderType param2;
780 typename ParameterType< P3 >::HolderType param3;
781 typename ParameterType< P4 >::HolderType param4;
782 typename ParameterType< P5 >::HolderType param5;
786 } // namespace Internal
790 #endif // DALI_INTERNAL_MESSAGE_H