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.
44 MessageBase() = default;
49 virtual ~MessageBase() = default;
52 * Called to process the message.
53 * @param [in] bufferIndex The current update/render buffer index (depending on which thread processes the message).
55 virtual void Process( BufferIndex bufferIndex ) = 0;
61 * Templated message which calls a member function of an object.
62 * This allows nodes etc. to be modified in a thread-safe manner, when the update occurs in a separate thread.
63 * The object lifetime must controlled i.e. not destroyed before the message is processed.
65 template< typename T >
66 class Message : public MessageBase
69 using MemberFunction = void ( T::* )();
73 * @note The object is expected to be const in the thread which sends this message.
74 * However it can be modified when Process() is called in a different thread.
75 * @param[in] obj The object to be updated in a separate thread.
76 * @param[in] member The member function of the object.
78 Message( const T* obj, MemberFunction member )
80 object( const_cast< T* >( obj ) ),
81 memberFunction( member )
83 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
89 ~Message() override = default;
92 * @copydoc MessageBase::Process
94 void Process( BufferIndex /*bufferIndex*/ ) override
96 (object->*memberFunction)();
102 MemberFunction memberFunction;
107 * Templated message which calls a member function of an object.
108 * This overload passes one value-type parameter.
109 * Template parameters need to match the MemberFunction!
110 * The message will contain copy of the value (in case of & or const&)
112 template< typename T, typename P >
113 class MessageValue1 : public MessageBase
116 using MemberFunction = void ( T::* )( typename ParameterType<P>::PassingType );
120 * @note The object is expected to be const in the thread which sends this message.
121 * However it can be modified when Process() is called in a different thread.
122 * @param[in] obj The object.
123 * @param[in] member The member function of the object.
124 * @param[in] p1 The first value-type parameter to pass to the member function.
126 MessageValue1( const T* obj,
127 MemberFunction member,
128 typename ParameterType< P >::PassingType p1 )
130 object( const_cast< T* >( obj ) ),
131 memberFunction( member ),
134 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
140 ~MessageValue1() override = default;
143 * @copydoc MessageBase::Process
145 void Process( BufferIndex /*bufferIndex*/ ) override
147 (object->*memberFunction)( param1 );
153 MemberFunction memberFunction;
154 typename ParameterType< P >::HolderType param1;
159 * Templated message which calls a member function of an object.
160 * This overload passes two value-type parameters.
161 * Template parameters need to match the MemberFunction!
162 * The message will contain copy of the value (in case of & or const&)
165 template< typename T, typename P1, typename P2 >
166 class MessageValue2 : public MessageBase
169 using MemberFunction = void ( T::* )( typename ParameterType<P1>::PassingType, typename ParameterType<P2>::PassingType );
173 * @note The object is expected to be const in the thread which sends this message.
174 * However it can be modified when Process() is called in a different thread.
175 * @param[in] obj The object.
176 * @param[in] member The member function of the object.
177 * @param[in] p1 The first parameter to pass to the member function.
178 * @param[in] p2 The second parameter to pass to the member function.
180 MessageValue2( const T* obj,
181 MemberFunction member,
182 typename ParameterType< P1 >::PassingType p1,
183 typename ParameterType< P2 >::PassingType p2 )
185 object( const_cast< T* >( obj ) ),
186 memberFunction( member ),
190 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
196 ~MessageValue2() override = default;
199 * @copydoc MessageBase::Process
201 void Process( BufferIndex /*bufferIndex*/ ) override
203 (object->*memberFunction)( param1, param2 );
209 MemberFunction memberFunction;
210 typename ParameterType< P1 >::HolderType param1;
211 typename ParameterType< P2 >::HolderType param2;
216 * Templated message which calls a member function of an object.
217 * This overload passes three value-type parameters.
218 * Template parameters need to match the MemberFunction!
219 * The message will contain copy of the value (in case of & or const&)
221 template< typename T, typename P1, typename P2, typename P3 >
222 class MessageValue3 : public MessageBase
225 using MemberFunction = void ( T::* )( typename ParameterType<P1>::PassingType, typename ParameterType<P2>::PassingType, typename ParameterType<P3>::PassingType );
229 * @note The object is expected to be const in the thread which sends this message.
230 * However it can be modified when Process() is called in a different thread.
231 * @param[in] obj The object.
232 * @param[in] member The member function of the object.
233 * @param[in] p1 The first parameter to pass to the member function.
234 * @param[in] p2 The second parameter to pass to the member function.
235 * @param[in] p3 The third parameter to pass to the member function.
237 MessageValue3( const T* obj,
238 MemberFunction member,
239 typename ParameterType< P1 >::PassingType p1,
240 typename ParameterType< P2 >::PassingType p2,
241 typename ParameterType< P3 >::PassingType p3 )
243 object( const_cast< T* >( obj ) ),
244 memberFunction( member ),
249 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
255 ~MessageValue3() override = default;
258 * @copydoc MessageBase::Process
260 void Process( BufferIndex /*bufferIndex*/ ) override
262 (object->*memberFunction)( param1, param2, param3 );
268 MemberFunction memberFunction;
269 typename ParameterType< P1 >::HolderType param1;
270 typename ParameterType< P2 >::HolderType param2;
271 typename ParameterType< P3 >::HolderType param3;
276 * Templated message which calls a member function of an object.
277 * This overload passes four value-type parameters.
278 * Template parameters need to match the MemberFunction!
279 * The message will contain copy of the value (in case of & or const&)
281 template< typename T, typename P1, typename P2, typename P3, typename P4 >
282 class MessageValue4 : public MessageBase
285 using MemberFunction = void ( T::* )( typename ParameterType<P1>::PassingType, typename ParameterType<P2>::PassingType, typename ParameterType<P3>::PassingType, typename ParameterType<P4>::PassingType );
289 * @note The object is expected to be const in the thread which sends this message.
290 * However it can be modified when Process() is called in a different thread.
291 * @param[in] obj The object.
292 * @param[in] member The member function of the object.
293 * @param[in] p1 The first parameter to pass to the member function.
294 * @param[in] p2 The second parameter to pass to the member function.
295 * @param[in] p3 The third parameter to pass to the member function.
296 * @param[in] p4 The fourth parameter to pass to the member function.
298 MessageValue4( const T* obj,
299 MemberFunction member,
300 typename ParameterType< P1 >::PassingType p1,
301 typename ParameterType< P2 >::PassingType p2,
302 typename ParameterType< P3 >::PassingType p3,
303 typename ParameterType< P4 >::PassingType p4 )
305 object( const_cast< T* >( obj ) ),
306 memberFunction( member ),
312 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
318 ~MessageValue4() override = default;
321 * @copydoc MessageBase::Process
323 void Process( BufferIndex /*bufferIndex*/ ) override
325 (object->*memberFunction)( param1, param2, param3, param4 );
331 MemberFunction memberFunction;
332 typename ParameterType< P1 >::HolderType param1;
333 typename ParameterType< P2 >::HolderType param2;
334 typename ParameterType< P3 >::HolderType param3;
335 typename ParameterType< P4 >::HolderType param4;
340 * Templated message which calls a member function of an object.
341 * This overload passes five value-type parameters.
342 * Template parameters need to match the MemberFunction!
343 * The message will contain copy of the value (in case of & or const&)
345 template< typename T, typename P1, typename P2, typename P3, typename P4, typename P5 >
346 class MessageValue5 : public MessageBase
349 using MemberFunction = void ( T::* )( typename ParameterType<P1>::PassingType, typename ParameterType<P2>::PassingType, typename ParameterType<P3>::PassingType, typename ParameterType<P4>::PassingType, typename ParameterType<P5>::PassingType );
353 * @note The object is expected to be const in the thread which sends this message.
354 * However it can be modified when Process() is called in a different thread.
355 * @param[in] obj The object.
356 * @param[in] member The member function of the object.
357 * @param[in] p1 The first parameter to pass to the member function.
358 * @param[in] p2 The second parameter to pass to the member function.
359 * @param[in] p3 The third parameter to pass to the member function.
360 * @param[in] p4 The fourth parameter to pass to the member function.
361 * @param[in] p5 The fifth parameter to pass to the member function.
363 MessageValue5( const T* obj,
364 MemberFunction member,
365 typename ParameterType< P1 >::PassingType p1,
366 typename ParameterType< P2 >::PassingType p2,
367 typename ParameterType< P3 >::PassingType p3,
368 typename ParameterType< P4 >::PassingType p4,
369 typename ParameterType< P5 >::PassingType p5 )
371 object( const_cast< T* >( obj ) ),
372 memberFunction( member ),
379 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
385 ~MessageValue5() override = default;
388 * @copydoc MessageBase::Process
390 void Process( BufferIndex /*bufferIndex*/ ) override
392 (object->*memberFunction)( param1, param2, param3, param4, param5 );
398 MemberFunction memberFunction;
399 typename ParameterType< P1 >::HolderType param1;
400 typename ParameterType< P2 >::HolderType param2;
401 typename ParameterType< P3 >::HolderType param3;
402 typename ParameterType< P4 >::HolderType param4;
403 typename ParameterType< P5 >::HolderType param5;
408 * Templated message which calls a member function of an object.
409 * This overload passes six value-type parameters.
410 * Template parameters need to match the MemberFunction!
411 * The message will contain copy of the value (in case of & or const&)
413 template< typename T, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6 >
414 class MessageValue6 : public MessageBase
417 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 );
421 * @note The object is expected to be const in the thread which sends this message.
422 * However it can be modified when Process() is called in a different thread.
423 * @param[in] obj The object.
424 * @param[in] member The member function of the object.
425 * @param[in] p1 The first parameter to pass to the member function.
426 * @param[in] p2 The second parameter to pass to the member function.
427 * @param[in] p3 The third parameter to pass to the member function.
428 * @param[in] p4 The fourth parameter to pass to the member function.
429 * @param[in] p5 The fifth parameter to pass to the member function.
430 * @param[in] p6 The sixth parameter to pass to the member function.
432 MessageValue6( const T* obj,
433 MemberFunction member,
434 typename ParameterType< P1 >::PassingType p1,
435 typename ParameterType< P2 >::PassingType p2,
436 typename ParameterType< P3 >::PassingType p3,
437 typename ParameterType< P4 >::PassingType p4,
438 typename ParameterType< P5 >::PassingType p5,
439 typename ParameterType< P6 >::PassingType p6 )
441 object( const_cast< T* >( obj ) ),
442 memberFunction( member ),
450 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
456 ~MessageValue6() override = default;
459 * @copydoc MessageBase::Process
461 void Process( BufferIndex /*bufferIndex*/ ) override
463 (object->*memberFunction)( param1, param2, param3, param4, param5, param6 );
469 MemberFunction memberFunction;
470 typename ParameterType< P1 >::HolderType param1;
471 typename ParameterType< P2 >::HolderType param2;
472 typename ParameterType< P3 >::HolderType param3;
473 typename ParameterType< P4 >::HolderType param4;
474 typename ParameterType< P5 >::HolderType param5;
475 typename ParameterType< P6 >::HolderType param6;
480 * Templated message which calls a member function of an object.
481 * This overload passes just the buffer index to the method, no parameters.
483 template< typename T >
484 class MessageDoubleBuffered0 : public MessageBase
487 using MemberFunction = void ( T::* )( BufferIndex );
491 * @note The object is expected to be const in the thread which sends this message.
492 * However it can be modified when Process() is called in a different thread.
493 * @param[in] obj The object.
494 * @param[in] member The member function of the object.
496 MessageDoubleBuffered0( const T* obj, MemberFunction member )
498 object( const_cast< T* >( obj ) ),
499 memberFunction( member )
501 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
507 ~MessageDoubleBuffered0() override = default;
510 * @copydoc MessageBase::Process
512 void Process( BufferIndex bufferIndex ) override
514 (object->*memberFunction)( bufferIndex );
520 MemberFunction memberFunction;
526 * Templated message which calls a member function of an object.
527 * This overload passes a value-type to set a double-buffered property.
528 * Template parameters need to match the MemberFunction!
529 * The message will contain copy of the value (in case of & or const&)
531 template< typename T, typename P >
532 class MessageDoubleBuffered1 : public MessageBase
535 using MemberFunction = void ( T::* )( BufferIndex, typename ParameterType<P>::PassingType );
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.
543 * @param[in] p The second parameter to pass.
545 MessageDoubleBuffered1( const T* obj,
546 MemberFunction member,
547 typename ParameterType< P >::PassingType p )
549 object( const_cast< T* >( obj ) ),
550 memberFunction( member ),
553 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
559 ~MessageDoubleBuffered1() override = default;
562 * @copydoc MessageBase::Process
564 void Process( BufferIndex bufferIndex ) override
566 (object->*memberFunction)( bufferIndex, param );
572 MemberFunction memberFunction;
573 typename ParameterType< P >::HolderType param;
578 * Templated message which calls a member function of an object.
579 * This overload passes two value-types to set double-buffered properties.
580 * Template parameters need to match the MemberFunction!
581 * The message will contain copy of the value (in case of & or const&)
583 template< typename T, typename P2, typename P3 >
584 class MessageDoubleBuffered2 : public MessageBase
587 using MemberFunction = void ( T::* )( BufferIndex, typename ParameterType<P2>::PassingType, typename ParameterType<P3>::PassingType );
591 * @note The object is expected to be const in the thread which sends this message.
592 * However it can be modified when Process() is called in a different thread.
593 * @param[in] obj The object.
594 * @param[in] member The member function of the object.
595 * @param[in] p2 The second parameter to pass to the function.
596 * @param[in] p3 The third parameter to pass to the function.
598 MessageDoubleBuffered2( const T* obj,
599 MemberFunction member,
600 typename ParameterType< P2 >::PassingType p2,
601 typename ParameterType< P3 >::PassingType p3 )
603 object( const_cast< T* >( obj ) ),
604 memberFunction( member ),
608 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
614 ~MessageDoubleBuffered2() override = default;
617 * @copydoc MessageBase::Process
619 void Process( BufferIndex bufferIndex ) override
621 (object->*memberFunction)( bufferIndex, param2, param3 );
627 MemberFunction memberFunction;
628 typename ParameterType< P2 >::HolderType param2;
629 typename ParameterType< P3 >::HolderType param3;
635 * Templated message which calls a member function of an object.
636 * This overload passes three value-types to set double-buffered properties.
637 * Template parameters need to match the MemberFunction!
638 * The message will contain copy of the value (in case of & or const&)
640 template< typename T, typename P2, typename P3, typename P4 >
641 class MessageDoubleBuffered3 : public MessageBase
644 using MemberFunction = void ( T::* )( BufferIndex, typename ParameterType<P2>::PassingType, typename ParameterType<P3>::PassingType, typename ParameterType<P4>::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.
653 * @param[in] p3 The third parameter to pass.
654 * @param[in] p4 The forth parameter to pass.
656 MessageDoubleBuffered3( const T* obj,
657 MemberFunction member,
658 typename ParameterType< P2 >::PassingType p2,
659 typename ParameterType< P3 >::PassingType p3,
660 typename ParameterType< P4 >::PassingType p4 )
662 object( const_cast< T* >( obj ) ),
663 memberFunction( member ),
668 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
674 ~MessageDoubleBuffered3() override = default;
677 * @copydoc MessageBase::Process
679 void Process( BufferIndex bufferIndex ) override
681 (object->*memberFunction)( bufferIndex, param2, param3, param4 );
687 MemberFunction memberFunction;
688 typename ParameterType< P2 >::HolderType param2;
689 typename ParameterType< P3 >::HolderType param3;
690 typename ParameterType< P4 >::HolderType param4;
695 * Templated message which calls a member function of an object.
696 * This overload passes four value-types to set double-buffered properties.
697 * Template parameters need to match the MemberFunction!
698 * The message will contain copy of the value (in case of & or const&)
700 template< typename T, typename P2, typename P3, typename P4, typename P5 >
701 class MessageDoubleBuffered4 : public MessageBase
704 using MemberFunction = void ( T::* )( BufferIndex, typename ParameterType<P2>::PassingType, typename ParameterType<P3>::PassingType, typename ParameterType<P4>::PassingType, typename ParameterType<P5>::PassingType );
708 * @note The object is expected to be const in the thread which sends this message.
709 * However it can be modified when Process() is called in a different thread.
710 * @param[in] obj The object.
711 * @param[in] member The member function of the object.
712 * @param[in] p2 The second parameter to pass.
713 * @param[in] p3 The third parameter to pass.
714 * @param[in] p4 The forth parameter to pass.
715 * @param[in] p5 The fifth parameter to pass.
717 MessageDoubleBuffered4( const T* obj,
718 MemberFunction member,
719 typename ParameterType< P2 >::PassingType p2,
720 typename ParameterType< P3 >::PassingType p3,
721 typename ParameterType< P4 >::PassingType p4,
722 typename ParameterType< P5 >::PassingType p5 )
724 object( const_cast< T* >( obj ) ),
725 memberFunction( member ),
731 DALI_ASSERT_DEBUG( object && "nullptr passed into message as object" );
737 ~MessageDoubleBuffered4() override = default;
740 * @copydoc MessageBase::Process
742 void Process( BufferIndex bufferIndex ) override
744 (object->*memberFunction)( bufferIndex, param2, param3, param4, param5 );
750 MemberFunction memberFunction;
751 typename ParameterType< P2 >::HolderType param2;
752 typename ParameterType< P3 >::HolderType param3;
753 typename ParameterType< P4 >::HolderType param4;
754 typename ParameterType< P5 >::HolderType param5;
758 } // namespace Internal
762 #endif // DALI_INTERNAL_MESSAGE_H