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.
24 #include <dali/internal/common/buffer-index.h>
25 #include <dali/internal/common/type-abstraction.h>
26 #include <dali/internal/update/common/scene-graph-buffers.h>
27 #include <dali/integration-api/debug.h>
36 * An abstract base class for messages queued across threads.
37 * Messages are only allowed to contain value objects, either copies of the parameters or pointers
38 * If message parameter type is & or const& the message will try to take a copy of the actual type
45 * Construct the message base.
54 virtual ~MessageBase()
59 * Called to process the message.
60 * @param [in] bufferIndex The current update/render buffer index (depending on which thread processes the message).
62 virtual void Process( BufferIndex bufferIndex ) = 0;
68 * Templated message which calls a member function of an object.
69 * This allows nodes etc. to be modified in a thread-safe manner, when the update occurs in a separate thread.
70 * The object lifetime must controlled i.e. not destroyed before the message is processed.
72 template< typename T >
73 class Message : public MessageBase
77 typedef void(T::*MemberFunction)();
81 * @note The object is expected to be const in the thread which sends this message.
82 * However it can be modified when Process() is called in a different thread.
83 * @param[in] obj The object to be updated in a separate thread.
84 * @param[in] member The member function of the object.
86 Message( const T* obj, MemberFunction member )
88 object( const_cast< T* >( obj ) ),
89 memberFunction( member )
101 * @copydoc MessageBase::Process
103 virtual void Process( BufferIndex /*bufferIndex*/ )
105 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
107 DALI_LOG_ERROR("Message::Process: object: %s, function pointer: %p\n", typeid(object).name(), memberFunction);
109 (object->*memberFunction)();
115 MemberFunction memberFunction;
120 * Templated message which calls a member function of an object.
121 * This overload passes one value-type parameter.
122 * Template parameters need to match the MemberFunction!
123 * The message will contain copy of the value (in case of & or const&)
125 template< typename T, typename P >
126 class MessageValue1 : public MessageBase
130 typedef void(T::*MemberFunction)( typename ParameterType< P >::PassingType );
134 * @note The object is expected to be const in the thread which sends this message.
135 * However it can be modified when Process() is called in a different thread.
136 * @param[in] obj The object.
137 * @param[in] member The member function of the object.
138 * @param[in] p1 The first value-type parameter to pass to the member function.
140 MessageValue1( const T* obj,
141 MemberFunction member,
142 typename ParameterType< P >::PassingType p1 )
144 object( const_cast< T* >( obj ) ),
145 memberFunction( member ),
153 virtual ~MessageValue1()
158 * @copydoc MessageBase::Process
160 virtual void Process( BufferIndex /*bufferIndex*/ )
162 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
164 DALI_LOG_ERROR("Message::Process: object: %s, function pointer: %p\n", typeid(object).name(), memberFunction);
166 (object->*memberFunction)( param1 );
172 MemberFunction memberFunction;
173 typename ParameterType< P >::HolderType param1;
178 * Templated message which calls a member function of an object.
179 * This overload passes two value-type parameters.
180 * Template parameters need to match the MemberFunction!
181 * The message will contain copy of the value (in case of & or const&)
184 template< typename T, typename P1, typename P2 >
185 class MessageValue2 : public MessageBase
189 typedef void(T::*MemberFunction)(
190 typename ParameterType< P1 >::PassingType,
191 typename ParameterType< P2 >::PassingType );
195 * @note The object is expected to be const in the thread which sends this message.
196 * However it can be modified when Process() is called in a different thread.
197 * @param[in] obj The object.
198 * @param[in] member The member function of the object.
199 * @param[in] p1 The first parameter to pass to the member function.
200 * @param[in] p2 The second parameter to pass to the member function.
202 MessageValue2( const T* obj,
203 MemberFunction member,
204 typename ParameterType< P1 >::PassingType p1,
205 typename ParameterType< P2 >::PassingType p2 )
207 object( const_cast< T* >( obj ) ),
208 memberFunction( member ),
217 virtual ~MessageValue2()
222 * @copydoc MessageBase::Process
224 virtual void Process( BufferIndex /*bufferIndex*/ )
226 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
228 DALI_LOG_ERROR("Message::Process: object: %s, function pointer: %p\n", typeid(object).name(), memberFunction);
230 (object->*memberFunction)( param1, param2 );
236 MemberFunction memberFunction;
237 typename ParameterType< P1 >::HolderType param1;
238 typename ParameterType< P2 >::HolderType param2;
243 * Templated message which calls a member function of an object.
244 * This overload passes three value-type parameters.
245 * Template parameters need to match the MemberFunction!
246 * The message will contain copy of the value (in case of & or const&)
248 template< typename T, typename P1, typename P2, typename P3 >
249 class MessageValue3 : public MessageBase
253 typedef void(T::*MemberFunction)(
254 typename ParameterType< P1 >::PassingType,
255 typename ParameterType< P2 >::PassingType,
256 typename ParameterType< P3 >::PassingType );
260 * @note The object is expected to be const in the thread which sends this message.
261 * However it can be modified when Process() is called in a different thread.
262 * @param[in] obj The object.
263 * @param[in] member The member function of the object.
264 * @param[in] p1 The first parameter to pass to the member function.
265 * @param[in] p2 The second parameter to pass to the member function.
266 * @param[in] p3 The third parameter to pass to the member function.
268 MessageValue3( const T* obj,
269 MemberFunction member,
270 typename ParameterType< P1 >::PassingType p1,
271 typename ParameterType< P2 >::PassingType p2,
272 typename ParameterType< P3 >::PassingType p3 )
274 object( const_cast< T* >( obj ) ),
275 memberFunction( member ),
285 virtual ~MessageValue3()
290 * @copydoc MessageBase::Process
292 virtual void Process( BufferIndex /*bufferIndex*/ )
294 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
296 DALI_LOG_ERROR("Message::Process: object: %s, function pointer: %p\n", typeid(object).name(), memberFunction);
298 (object->*memberFunction)( param1, param2, param3 );
304 MemberFunction memberFunction;
305 typename ParameterType< P1 >::HolderType param1;
306 typename ParameterType< P2 >::HolderType param2;
307 typename ParameterType< P3 >::HolderType param3;
312 * Templated message which calls a member function of an object.
313 * This overload passes four value-type parameters.
314 * Template parameters need to match the MemberFunction!
315 * The message will contain copy of the value (in case of & or const&)
317 template< typename T, typename P1, typename P2, typename P3, typename P4 >
318 class MessageValue4 : public MessageBase
322 typedef void(T::*MemberFunction)(
323 typename ParameterType< P1 >::PassingType,
324 typename ParameterType< P2 >::PassingType,
325 typename ParameterType< P3 >::PassingType,
326 typename ParameterType< P4 >::PassingType );
330 * @note The object is expected to be const in the thread which sends this message.
331 * However it can be modified when Process() is called in a different thread.
332 * @param[in] obj The object.
333 * @param[in] member The member function of the object.
334 * @param[in] p1 The first parameter to pass to the member function.
335 * @param[in] p2 The second parameter to pass to the member function.
336 * @param[in] p3 The third parameter to pass to the member function.
337 * @param[in] p4 The fourth parameter to pass to the member function.
339 MessageValue4( const T* obj,
340 MemberFunction member,
341 typename ParameterType< P1 >::PassingType p1,
342 typename ParameterType< P2 >::PassingType p2,
343 typename ParameterType< P3 >::PassingType p3,
344 typename ParameterType< P4 >::PassingType p4 )
346 object( const_cast< T* >( obj ) ),
347 memberFunction( member ),
358 virtual ~MessageValue4()
363 * @copydoc MessageBase::Process
365 virtual void Process( BufferIndex /*bufferIndex*/ )
367 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
369 DALI_LOG_ERROR("Message::Process: object: %s, function pointer: %p\n", typeid(object).name(), memberFunction);
371 (object->*memberFunction)( param1, param2, param3, param4 );
377 MemberFunction memberFunction;
378 typename ParameterType< P1 >::HolderType param1;
379 typename ParameterType< P2 >::HolderType param2;
380 typename ParameterType< P3 >::HolderType param3;
381 typename ParameterType< P4 >::HolderType param4;
386 * Templated message which calls a member function of an object.
387 * This overload passes five value-type parameters.
388 * Template parameters need to match the MemberFunction!
389 * The message will contain copy of the value (in case of & or const&)
391 template< typename T, typename P1, typename P2, typename P3, typename P4, typename P5 >
392 class MessageValue5 : public MessageBase
396 typedef void(T::*MemberFunction)(
397 typename ParameterType< P1 >::PassingType,
398 typename ParameterType< P2 >::PassingType,
399 typename ParameterType< P3 >::PassingType,
400 typename ParameterType< P4 >::PassingType,
401 typename ParameterType< P5 >::PassingType );
405 * @note The object is expected to be const in the thread which sends this message.
406 * However it can be modified when Process() is called in a different thread.
407 * @param[in] obj The object.
408 * @param[in] member The member function of the object.
409 * @param[in] p1 The first parameter to pass to the member function.
410 * @param[in] p2 The second parameter to pass to the member function.
411 * @param[in] p3 The third parameter to pass to the member function.
412 * @param[in] p4 The fourth parameter to pass to the member function.
413 * @param[in] p5 The fifth parameter to pass to the member function.
415 MessageValue5( const T* obj,
416 MemberFunction member,
417 typename ParameterType< P1 >::PassingType p1,
418 typename ParameterType< P2 >::PassingType p2,
419 typename ParameterType< P3 >::PassingType p3,
420 typename ParameterType< P4 >::PassingType p4,
421 typename ParameterType< P5 >::PassingType p5 )
423 object( const_cast< T* >( obj ) ),
424 memberFunction( member ),
436 virtual ~MessageValue5()
441 * @copydoc MessageBase::Process
443 virtual void Process( BufferIndex /*bufferIndex*/ )
445 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
447 DALI_LOG_ERROR("Message::Process: object: %s, function pointer: %p\n", typeid(object).name(), memberFunction);
449 (object->*memberFunction)( param1, param2, param3, param4, param5 );
456 MemberFunction memberFunction;
457 typename ParameterType< P1 >::HolderType param1;
458 typename ParameterType< P2 >::HolderType param2;
459 typename ParameterType< P3 >::HolderType param3;
460 typename ParameterType< P4 >::HolderType param4;
461 typename ParameterType< P5 >::HolderType param5;
466 * Templated message which calls a member function of an object.
467 * This overload passes six value-type parameters.
468 * Template parameters need to match the MemberFunction!
469 * The message will contain copy of the value (in case of & or const&)
471 template< typename T, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6 >
472 class MessageValue6 : public MessageBase
476 typedef void(T::*MemberFunction)(
477 typename ParameterType< P1 >::PassingType,
478 typename ParameterType< P2 >::PassingType,
479 typename ParameterType< P3 >::PassingType,
480 typename ParameterType< P4 >::PassingType,
481 typename ParameterType< P5 >::PassingType,
482 typename ParameterType< P6 >::PassingType );
486 * @note The object is expected to be const in the thread which sends this message.
487 * However it can be modified when Process() is called in a different thread.
488 * @param[in] obj The object.
489 * @param[in] member The member function of the object.
490 * @param[in] p1 The first parameter to pass to the member function.
491 * @param[in] p2 The second parameter to pass to the member function.
492 * @param[in] p3 The third parameter to pass to the member function.
493 * @param[in] p4 The fourth parameter to pass to the member function.
494 * @param[in] p5 The fifth parameter to pass to the member function.
495 * @param[in] p6 The sixth parameter to pass to the member function.
497 MessageValue6( const T* obj,
498 MemberFunction member,
499 typename ParameterType< P1 >::PassingType p1,
500 typename ParameterType< P2 >::PassingType p2,
501 typename ParameterType< P3 >::PassingType p3,
502 typename ParameterType< P4 >::PassingType p4,
503 typename ParameterType< P5 >::PassingType p5,
504 typename ParameterType< P6 >::PassingType p6 )
506 object( const_cast< T* >( obj ) ),
507 memberFunction( member ),
520 virtual ~MessageValue6()
525 * @copydoc MessageBase::Process
527 virtual void Process( BufferIndex /*bufferIndex*/ )
529 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
531 DALI_LOG_ERROR("Message::Process: object: %s, function pointer: %p\n", typeid(object).name(), memberFunction);
533 (object->*memberFunction)( param1, param2, param3, param4, param5, param6 );
540 MemberFunction memberFunction;
541 typename ParameterType< P1 >::HolderType param1;
542 typename ParameterType< P2 >::HolderType param2;
543 typename ParameterType< P3 >::HolderType param3;
544 typename ParameterType< P4 >::HolderType param4;
545 typename ParameterType< P5 >::HolderType param5;
546 typename ParameterType< P6 >::HolderType param6;
551 * Templated message which calls a member function of an object.
552 * This overload passes just the buffer index to the method, no parameters.
554 template< typename T >
555 class MessageDoubleBuffered0 : public MessageBase
559 typedef void(T::*MemberFunction)( BufferIndex );
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.
568 MessageDoubleBuffered0( const T* obj, MemberFunction member )
570 object( const_cast< T* >( obj ) ),
571 memberFunction( member )
578 virtual ~MessageDoubleBuffered0()
583 * @copydoc MessageBase::Process
585 virtual void Process( BufferIndex bufferIndex )
587 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
589 DALI_LOG_ERROR("Message::Process: object: %s, function pointer: %p\n", typeid(object).name(), memberFunction);
591 (object->*memberFunction)( bufferIndex );
597 MemberFunction memberFunction;
603 * Templated message which calls a member function of an object.
604 * This overload passes a value-type to set a double-buffered property.
605 * Template parameters need to match the MemberFunction!
606 * The message will contain copy of the value (in case of & or const&)
608 template< typename T, typename P >
609 class MessageDoubleBuffered1 : public MessageBase
613 typedef void(T::*MemberFunction)(
615 typename ParameterType< P >::PassingType );
619 * @note The object is expected to be const in the thread which sends this message.
620 * However it can be modified when Process() is called in a different thread.
621 * @param[in] obj The object.
622 * @param[in] member The member function of the object.
623 * @param[in] p The second parameter to pass.
625 MessageDoubleBuffered1( const T* obj,
626 MemberFunction member,
627 typename ParameterType< P >::PassingType p )
629 object( const_cast< T* >( obj ) ),
630 memberFunction( member ),
638 virtual ~MessageDoubleBuffered1()
643 * @copydoc MessageBase::Process
645 virtual void Process( BufferIndex bufferIndex )
647 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
649 DALI_LOG_ERROR("Message::Process: object: %s, function pointer: %p\n", typeid(object).name(), memberFunction);
651 (object->*memberFunction)( bufferIndex, param );
657 MemberFunction memberFunction;
658 typename ParameterType< P >::HolderType param;
663 * Templated message which calls a member function of an object.
664 * This overload passes two value-types to set double-buffered properties.
665 * Template parameters need to match the MemberFunction!
666 * The message will contain copy of the value (in case of & or const&)
668 template< typename T, typename P2, typename P3 >
669 class MessageDoubleBuffered2 : public MessageBase
673 typedef void(T::*MemberFunction)(
675 typename ParameterType< P2 >::PassingType,
676 typename ParameterType< P3 >::PassingType );
680 * @note The object is expected to be const in the thread which sends this message.
681 * However it can be modified when Process() is called in a different thread.
682 * @param[in] obj The object.
683 * @param[in] member The member function of the object.
684 * @param[in] p2 The second parameter to pass to the function.
685 * @param[in] p3 The third parameter to pass to the function.
687 MessageDoubleBuffered2( const T* obj,
688 MemberFunction member,
689 typename ParameterType< P2 >::PassingType p2,
690 typename ParameterType< P3 >::PassingType p3 )
692 object( const_cast< T* >( obj ) ),
693 memberFunction( member ),
702 virtual ~MessageDoubleBuffered2()
707 * @copydoc MessageBase::Process
709 virtual void Process( BufferIndex bufferIndex )
711 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
713 DALI_LOG_ERROR("Message::Process: object: %s, function pointer: %p\n", typeid(object).name(), memberFunction);
715 (object->*memberFunction)(
716 bufferIndex, param2, param3 );
722 MemberFunction memberFunction;
723 typename ParameterType< P2 >::HolderType param2;
724 typename ParameterType< P3 >::HolderType param3;
730 * Templated message which calls a member function of an object.
731 * This overload passes three value-types to set double-buffered properties.
732 * Template parameters need to match the MemberFunction!
733 * The message will contain copy of the value (in case of & or const&)
735 template< typename T, typename P2, typename P3, typename P4 >
736 class MessageDoubleBuffered3 : public MessageBase
740 typedef void(T::*MemberFunction)(
742 typename ParameterType< P2 >::PassingType,
743 typename ParameterType< P3 >::PassingType,
744 typename ParameterType< P4 >::PassingType );
748 * @note The object is expected to be const in the thread which sends this message.
749 * However it can be modified when Process() is called in a different thread.
750 * @param[in] obj The object.
751 * @param[in] member The member function of the object.
752 * @param[in] p2 The second parameter to pass.
753 * @param[in] p3 The third parameter to pass.
754 * @param[in] p4 The forth parameter to pass.
756 MessageDoubleBuffered3( const T* obj,
757 MemberFunction member,
758 typename ParameterType< P2 >::PassingType p2,
759 typename ParameterType< P3 >::PassingType p3,
760 typename ParameterType< P4 >::PassingType p4 )
762 object( const_cast< T* >( obj ) ),
763 memberFunction( member ),
773 virtual ~MessageDoubleBuffered3()
778 * @copydoc MessageBase::Process
780 virtual void Process( BufferIndex bufferIndex )
782 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
784 DALI_LOG_ERROR("Message::Process: object: %s, function pointer: %p\n", typeid(object).name(), memberFunction);
786 (object->*memberFunction)( bufferIndex, param2, param3, param4 );
792 MemberFunction memberFunction;
793 typename ParameterType< P2 >::HolderType param2;
794 typename ParameterType< P3 >::HolderType param3;
795 typename ParameterType< P4 >::HolderType param4;
800 * Templated message which calls a member function of an object.
801 * This overload passes four value-types to set double-buffered properties.
802 * Template parameters need to match the MemberFunction!
803 * The message will contain copy of the value (in case of & or const&)
805 template< typename T, typename P2, typename P3, typename P4, typename P5 >
806 class MessageDoubleBuffered4 : public MessageBase
810 typedef void(T::*MemberFunction)(
812 typename ParameterType< P2 >::PassingType,
813 typename ParameterType< P3 >::PassingType,
814 typename ParameterType< P4 >::PassingType,
815 typename ParameterType< P5 >::PassingType );
819 * @note The object is expected to be const in the thread which sends this message.
820 * However it can be modified when Process() is called in a different thread.
821 * @param[in] obj The object.
822 * @param[in] member The member function of the object.
823 * @param[in] p2 The second parameter to pass.
824 * @param[in] p3 The third parameter to pass.
825 * @param[in] p4 The forth parameter to pass.
826 * @param[in] p5 The fifth parameter to pass.
828 MessageDoubleBuffered4( const T* obj,
829 MemberFunction member,
830 typename ParameterType< P2 >::PassingType p2,
831 typename ParameterType< P3 >::PassingType p3,
832 typename ParameterType< P4 >::PassingType p4,
833 typename ParameterType< P5 >::PassingType p5 )
835 object( const_cast< T* >( obj ) ),
836 memberFunction( member ),
847 virtual ~MessageDoubleBuffered4()
852 * @copydoc MessageBase::Process
854 virtual void Process( BufferIndex bufferIndex )
856 DALI_ASSERT_DEBUG( object && "Message does not have an object" );
858 DALI_LOG_ERROR("Message::Process: object: %s, function pointer: %p\n", typeid(object).name(), memberFunction);
860 (object->*memberFunction)( bufferIndex, param2, param3, param4, param5 );
866 MemberFunction memberFunction;
867 typename ParameterType< P2 >::HolderType param2;
868 typename ParameterType< P3 >::HolderType param3;
869 typename ParameterType< P4 >::HolderType param4;
870 typename ParameterType< P5 >::HolderType param5;
874 } // namespace Internal
878 #endif // __DALI_INTERNAL_MESSAGE_H__