Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-core.git] / dali / public-api / signals / dali-signal.h
1 #ifndef DALI_SIGNAL_H
2 #define DALI_SIGNAL_H
3
4 /*
5  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 /**
22  * @brief The class should implement Dali::ConnectionTrackerInterface, or inherit from Dali::ConnectionTracker.
23  *
24  * This enforces automatic disconnection when an object is destroyed, so you don't have
25  * to manually disconnect from signals.
26  *
27  * Alternatively, you can use a Dali::SlotDelegate if you don't want to inherit.
28  *
29  * E.g:
30  * @code
31  * class MyClass : public ConnectionTracker
32  * {
33  *
34  *   void Callback( Actor actor, const TouchEvent& event )
35  *   {
36  *     ...
37  *   }
38  *
39  *   void Init()
40  *   {
41  *     Actor actor = Actor::New();
42  *
43  *     actor.TouchedSignal().Connect( this, &MyClass::Callback );
44  *   }
45  *
46  *   ~MyClass()
47  *   {
48  *     // ConnectionTracker base class automatically disconnects
49  *   }
50  * }
51  * @endcode
52  * @SINCE_1_0.0
53  */
54
55 // EXTERNAL_INCLUDES
56 #include <memory>
57
58 // INTERNAL INCLUDES
59 #include <dali/public-api/common/dali-common.h>
60 #include <dali/public-api/common/vector-wrapper.h>
61 #include <dali/public-api/signals/base-signal.h>
62 #include <dali/public-api/signals/callback.h>
63 #include <dali/public-api/signals/signal-slot-connections.h>
64 #include <dali/public-api/signals/slot-delegate.h>
65
66 namespace Dali
67 {
68 /**
69  * @addtogroup dali_core_signals
70  * @{
71  */
72
73 /**
74  * @brief Base Template class to provide signals.
75  *
76  * To create a signal for this class, you first have to define a typedef within your handle's scope:
77  * @code
78  * class MyHandle : public Handle
79  * {
80  * public:
81  *
82  *   // Typedefs
83  *
84  *   typedef Signal< void ()> VoidSignalType;         ///< For signals that require no parameters and no return value
85  *   typedef Signal< bool ()> BoolSignalType;         ///< For signals that do not need parameters but require a boolean return
86  *   typedef Signal< void ( float )> ParamSignalType; ///< For signals that need a float as a parameter but no return value
87  *
88  *   ...
89  *
90  * public:
91  *
92  *   // Signals
93  *
94  *   VoidSignalType&  VoidSignal();
95  *   BoolSignalType&  BoolSignal();
96  *   ParamSignalType& ParamSignal();
97  *
98  *   ...
99  * };
100  * @endcode
101  * The methods are required in the handle class so that the application writer can retrieve the Signal in order to connect/disconnect.
102  *
103  * In the implementation class, the members should be defined and the methods should be provided to retrieve the signal itself.
104  * These will be called by the equivalent methods in the MyHandle class.
105  * @code
106  * class MyObject : public Object
107  * {
108  *   ...
109  *
110  * public:
111  *
112  *   MyHandle::VoidSignalType&  VoidSignal()
113  *   {
114  *     return mVoidSignal;
115  *   }
116  *
117  *   MyHandle::BoolSignalType&  BoolSignal()
118  *   {
119  *     return mBoolSignal;
120  *   }
121  *
122  *   MyHandle::ParamSignalType& ParamSignal()
123  *   {
124  *     return mParamSignal;
125  *   }
126  *
127  * private:
128  *
129  *   // Signals
130  *   MyHandle::VoidSignalType   mVoidSignal;
131  *   MyHandle::BoolSignalType   mBoolSignal;
132  *   MyHandle::ParamSignalType  mParamSignal;
133  *
134  *   ...
135  * };
136  * @endcode
137  * @SINCE_1_0.0
138  */
139 template<typename _Signature>
140 class Signal
141 {
142 };
143
144 class SignalMixin
145 {
146 public:
147   /**
148    * @brief Queries whether there are any connected slots.
149    *
150    * @SINCE_1_0.0
151    * @return True if there are any slots connected to the signal
152    */
153   bool Empty() const
154   {
155     return mImpl ? mImpl->Empty() : true;
156   }
157
158   /**
159    * @brief Queries the number of slots.
160    *
161    * @SINCE_1_0.0
162    * @return The number of slots connected to this signal
163    */
164   std::size_t GetConnectionCount() const
165   {
166     return mImpl ? mImpl->GetConnectionCount() : 0;
167   }
168
169 protected:
170   BaseSignal& Impl()
171   {
172     if(!mImpl)
173     {
174       mImpl = std::make_unique<BaseSignal>();
175     }
176     return *mImpl;
177   }
178
179 private:
180   std::unique_ptr<BaseSignal> mImpl;
181 };
182
183 /**
184  * @brief A template for Signals with no parameters or return value.
185  * @SINCE_1_0.0
186  */
187 template<>
188 class Signal<void()> : public SignalMixin
189 {
190 public:
191   /**
192    * @brief Connects a function.
193    *
194    * @SINCE_1_0.0
195    * @param[in] func The function to connect
196    */
197   void Connect(void (*func)())
198   {
199     Impl().OnConnect(MakeCallback(func));
200   }
201
202   /**
203    * @brief Disconnects a function.
204    *
205    * @SINCE_1_0.0
206    * @param[in] func The function to disconnect
207    */
208   void Disconnect(void (*func)())
209   {
210     Impl().OnDisconnect(MakeCallback(func));
211   }
212
213   /**
214    * @brief Connects a member function.
215    *
216    * @SINCE_1_0.0
217    * @param[in] obj An object which must implement the ConnectionTrackerInterface
218    * @param[in] func The member function to connect
219    */
220   template<class X>
221   void Connect(X* obj, void (X::*func)())
222   {
223     Impl().OnConnect(obj, MakeCallback(obj, func));
224   }
225
226   /**
227    * @brief Disconnects a member function.
228    *
229    * @SINCE_1_0.0
230    * @param[in] obj An object which must implement the ConnectionTrackerInterface
231    * @param[in] func The member function to disconnect
232    */
233   template<class X>
234   void Disconnect(X* obj, void (X::*func)())
235   {
236     Impl().OnDisconnect(obj, MakeCallback(obj, func));
237   }
238
239   /**
240    * @brief Connects a member function.
241    *
242    * @SINCE_1_0.0
243    * @param[in] delegate A slot delegate
244    * @param[in] func The member function to connect
245    */
246   template<class X>
247   void Connect(SlotDelegate<X>& delegate, void (X::*func)())
248   {
249     Impl().OnConnect(delegate.GetConnectionTracker(), MakeCallback(delegate.GetSlot(), func));
250   }
251
252   /**
253    * @brief Disconnects a member function.
254    *
255    * @SINCE_1_0.0
256    * @param[in] delegate A slot delegate
257    * @param[in] func The member function to disconnect
258    */
259   template<class X>
260   void Disconnect(SlotDelegate<X>& delegate, void (X::*func)())
261   {
262     Impl().OnDisconnect(delegate.GetConnectionTracker(), MakeCallback(delegate.GetSlot(), func));
263   }
264
265   /**
266    * @brief Connects a function object.
267    *
268    * @SINCE_1_0.0
269    * @param[in] connectionTracker A connection tracker which can be used to disconnect
270    * @param[in] func The function object to copy
271    */
272   template<class X>
273   void Connect(ConnectionTrackerInterface* connectionTracker, const X& func)
274   {
275     Impl().OnConnect(connectionTracker, new CallbackFunctor0<X>(func));
276   }
277
278   /**
279    * @brief Connects a function object using FunctorDelegate.
280    *
281    * @SINCE_1_0.0
282    * @param[in] connectionTracker A connection tracker which can be used to disconnect
283    * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken)
284    */
285   void Connect(ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate)
286   {
287     Impl().OnConnect(connectionTracker, new CallbackFunctorDelegate0(delegate));
288   }
289
290   /**
291    * @brief Emits the signal.
292    * @SINCE_1_0.0
293    */
294   void Emit()
295   {
296     Impl().Emit();
297   }
298 };
299
300 /**
301  * @brief A template for Signals with no parameters and a return value.
302  * @SINCE_1_0.0
303  */
304 template<typename Ret>
305 class Signal<Ret()> : public SignalMixin
306 {
307 public:
308   /**
309    * @brief Connects a function.
310    *
311    * @SINCE_1_0.0
312    * @param[in] func The function to connect
313    */
314   void Connect(Ret (*func)())
315   {
316     Impl().OnConnect(MakeCallback(func));
317   }
318
319   /**
320    * @brief Disconnects a function.
321    *
322    * @SINCE_1_0.0
323    * @param[in] func The function to disconnect
324    */
325   void Disconnect(Ret (*func)())
326   {
327     Impl().OnDisconnect(MakeCallback(func));
328   }
329
330   /**
331    * @brief Connects a member function.
332    *
333    * @SINCE_1_0.0
334    * @param[in] obj An object which must implement the ConnectionTrackerInterface
335    * @param[in] func The member function to connect
336    */
337   template<class X>
338   void Connect(X* obj, Ret (X::*func)())
339   {
340     Impl().OnConnect(obj, MakeCallback(obj, func));
341   }
342
343   /**
344    * @brief Disconnects a member function.
345    *
346    * @SINCE_1_0.0
347    * @param[in] obj An object which must implement the ConnectionTrackerInterface
348    * @param[in] func The member function to disconnect
349    */
350   template<class X>
351   void Disconnect(X* obj, Ret (X::*func)())
352   {
353     Impl().OnDisconnect(obj, MakeCallback(obj, func));
354   }
355
356   /**
357    * @brief Connects a member function.
358    *
359    * @SINCE_1_0.0
360    * @param[in] delegate A slot delegate
361    * @param[in] func The member function to connect
362    */
363   template<class X>
364   void Connect(SlotDelegate<X>& delegate, Ret (X::*func)())
365   {
366     Impl().OnConnect(delegate.GetConnectionTracker(), MakeCallback(delegate.GetSlot(), func));
367   }
368
369   /**
370    * @brief Disconnects a member function.
371    *
372    * @SINCE_1_0.0
373    * @param[in] delegate A slot delegate
374    * @param[in] func The member function to disconnect
375    */
376   template<class X>
377   void Disconnect(SlotDelegate<X>& delegate, Ret (X::*func)())
378   {
379     Impl().OnDisconnect(delegate.GetConnectionTracker(), MakeCallback(delegate.GetSlot(), func));
380   }
381
382   /**
383    * @brief Connects a function object.
384    *
385    * @SINCE_1_0.0
386    * @param[in] connectionTracker A connection tracker which can be used to disconnect
387    * @param[in] func The function object to copy
388    */
389   template<class X>
390   void Connect(ConnectionTrackerInterface* connectionTracker, const X& func)
391   {
392     Impl().OnConnect(connectionTracker, new CallbackFunctorReturn0<X, Ret>(func));
393   }
394
395   /**
396    * @brief Connects a function object using FunctorDelegate.
397    *
398    * @SINCE_1_0.0
399    * @param[in] connectionTracker A connection tracker which can be used to disconnect
400    * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken)
401    */
402   void Connect(ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate)
403   {
404     Impl().OnConnect(connectionTracker, new CallbackFunctorDelegateReturn0<Ret>(delegate));
405   }
406
407   /**
408    * @brief Emits the signal.
409    *
410    * @SINCE_1_0.0
411    * @return The value returned by the last callback, or a default constructed value if no callbacks are connected
412    */
413   Ret Emit()
414   {
415     return Impl().template EmitReturn<Ret>();
416   }
417 };
418
419 /**
420  * @brief A template for Signals with 1 parameter.
421  * @SINCE_1_0.0
422  */
423 template<typename Arg0>
424 class Signal<void(Arg0)> : public SignalMixin
425 {
426 public:
427   /**
428    * @brief Connects a function.
429    *
430    * @SINCE_1_0.0
431    * @param[in] func The function to connect
432    */
433   void Connect(void (*func)(Arg0 arg0))
434   {
435     Impl().OnConnect(MakeCallback(func));
436   }
437
438   /**
439    * @brief Disconnects a function.
440    *
441    * @SINCE_1_0.0
442    * @param[in] func The function to disconnect
443    */
444   void Disconnect(void (*func)(Arg0 arg0))
445   {
446     Impl().OnDisconnect(MakeCallback(func));
447   }
448
449   /**
450    * @brief Connects a member function.
451    *
452    * @SINCE_1_0.0
453    * @param[in] obj An object which must implement the ConnectionTrackerInterface
454    * @param[in] func The member function to connect
455    */
456   template<class X>
457   void Connect(X* obj, void (X::*func)(Arg0 arg0))
458   {
459     Impl().OnConnect(obj, MakeCallback(obj, func));
460   }
461
462   /**
463    * @brief Disconnects a member function.
464    *
465    * @SINCE_1_0.0
466    * @param[in] obj An object which must implement the ConnectionTrackerInterface
467    * @param[in] func The member function to disconnect
468    */
469   template<class X>
470   void Disconnect(X* obj, void (X::*func)(Arg0 arg0))
471   {
472     Impl().OnDisconnect(obj, MakeCallback(obj, func));
473   }
474
475   /**
476    * @brief Connects a member function.
477    *
478    * @SINCE_1_0.0
479    * @param[in] delegate A slot delegate
480    * @param[in] func The member function to connect
481    */
482   template<class X>
483   void Connect(SlotDelegate<X>& delegate, void (X::*func)(Arg0 arg0))
484   {
485     Impl().OnConnect(delegate.GetConnectionTracker(), MakeCallback(delegate.GetSlot(), func));
486   }
487
488   /**
489    * @brief Disconnects a member function.
490    *
491    * @SINCE_1_0.0
492    * @param[in] delegate A slot delegate
493    * @param[in] func The member function to disconnect
494    */
495   template<class X>
496   void Disconnect(SlotDelegate<X>& delegate, void (X::*func)(Arg0 arg0))
497   {
498     Impl().OnDisconnect(delegate.GetConnectionTracker(), MakeCallback(delegate.GetSlot(), func));
499   }
500
501   /**
502    * @brief Connects a function object.
503    *
504    * @SINCE_1_0.0
505    * @param[in] connectionTracker A connection tracker which can be used to disconnect
506    * @param[in] func The function object to copy
507    */
508   template<class X>
509   void Connect(ConnectionTrackerInterface* connectionTracker, const X& func)
510   {
511     Impl().OnConnect(connectionTracker, new CallbackFunctor1<X, Arg0>(func));
512   }
513
514   /**
515    * @brief Connects a function object using FunctorDelegate.
516    *
517    * @SINCE_1_0.0
518    * @param[in] connectionTracker A connection tracker which can be used to disconnect
519    * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken)
520    */
521   void Connect(ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate)
522   {
523     Impl().OnConnect(connectionTracker, new CallbackFunctorDelegate1<Arg0>(delegate));
524   }
525
526   /**
527    * @brief Emits the signal.
528    *
529    * @SINCE_1_0.0
530    * @param[in] arg0 The first value to pass to callbacks
531    */
532   void Emit(Arg0 arg0)
533   {
534     Impl().template Emit<Arg0>(arg0);
535   }
536 };
537
538 /**
539  * @brief A template for Signals with 1 parameter and a return value.
540  * @SINCE_1_0.0
541  */
542 template<typename Ret, typename Arg0>
543 class Signal<Ret(Arg0)> : public SignalMixin
544 {
545 public:
546   /**
547    * @brief Connects a function.
548    *
549    * @SINCE_1_0.0
550    * @param[in] func The function to connect
551    */
552   void Connect(Ret (*func)(Arg0 arg0))
553   {
554     Impl().OnConnect(MakeCallback(func));
555   }
556
557   /**
558    * @brief Disconnects a function.
559    *
560    * @SINCE_1_0.0
561    * @param[in] func The function to disconnect
562    */
563   void Disconnect(Ret (*func)(Arg0 arg0))
564   {
565     Impl().OnDisconnect(MakeCallback(func));
566   }
567
568   /**
569    * @brief Connects a member function.
570    *
571    * @SINCE_1_0.0
572    * @param[in] obj An object which must implement the ConnectionTrackerInterface
573    * @param[in] func The member function to connect
574    */
575   template<class X>
576   void Connect(X* obj, Ret (X::*func)(Arg0 arg0))
577   {
578     Impl().OnConnect(obj, MakeCallback(obj, func));
579   }
580
581   /**
582    * @brief Disconnects a member function.
583    *
584    * @SINCE_1_0.0
585    * @param[in] obj An object which must implement the ConnectionTrackerInterface
586    * @param[in] func The member function to disconnect
587    */
588   template<class X>
589   void Disconnect(X* obj, Ret (X::*func)(Arg0 arg0))
590   {
591     Impl().OnDisconnect(obj, MakeCallback(obj, func));
592   }
593
594   /**
595    * @brief Connects a member function.
596    *
597    * @SINCE_1_0.0
598    * @param[in] delegate A slot delegate
599    * @param[in] func The member function to connect
600    */
601   template<class X>
602   void Connect(SlotDelegate<X>& delegate, Ret (X::*func)(Arg0 arg0))
603   {
604     Impl().OnConnect(delegate.GetConnectionTracker(), MakeCallback(delegate.GetSlot(), func));
605   }
606
607   /**
608    * @brief Disconnects a member function.
609    *
610    * @SINCE_1_0.0
611    * @param[in] delegate A slot delegate
612    * @param[in] func The member function to disconnect
613    */
614   template<class X>
615   void Disconnect(SlotDelegate<X>& delegate, Ret (X::*func)(Arg0 arg0))
616   {
617     Impl().OnDisconnect(delegate.GetConnectionTracker(), MakeCallback(delegate.GetSlot(), func));
618   }
619
620   /**
621    * @brief Connects a function object.
622    *
623    * @SINCE_1_0.0
624    * @param[in] connectionTracker A connection tracker which can be used to disconnect
625    * @param[in] func The function object to copy
626    */
627   template<class X>
628   void Connect(ConnectionTrackerInterface* connectionTracker, const X& func)
629   {
630     Impl().OnConnect(connectionTracker, new CallbackFunctorReturn1<X, Arg0, Ret>(func));
631   }
632
633   /**
634    * @brief Connects a function object using FunctorDelegate.
635    *
636    * @SINCE_1_0.0
637    * @param[in] connectionTracker A connection tracker which can be used to disconnect
638    * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken)
639    */
640   void Connect(ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate)
641   {
642     Impl().OnConnect(connectionTracker, new CallbackFunctorDelegateReturn1<Arg0, Ret>(delegate));
643   }
644
645   /**
646    * @brief Emits the signal.
647    *
648    * @SINCE_1_0.0
649    * @param[in] arg0 The first value to pass to callbacks
650    * @return The value returned by the last callback, or a default constructed value if no callbacks are connected
651    */
652   Ret Emit(Arg0 arg0)
653   {
654     return Impl().template EmitReturn<Ret, Arg0>(arg0);
655   }
656 };
657
658 /**
659  * @brief A template for Signals with 2 parameters.
660  *
661  * @SINCE_1_0.0
662  */
663 template<typename Arg0, typename Arg1>
664 class Signal<void(Arg0, Arg1)> : public SignalMixin
665 {
666 public:
667   /**
668    * @brief Connects a function.
669    *
670    * @SINCE_1_0.0
671    * @param[in] func The function to connect
672    */
673   void Connect(void (*func)(Arg0 arg0, Arg1 arg1))
674   {
675     Impl().OnConnect(MakeCallback(func));
676   }
677
678   /**
679    * @brief Disconnects a function.
680    *
681    * @SINCE_1_0.0
682    * @param[in] func The function to disconnect
683    */
684   void Disconnect(void (*func)(Arg0 arg0, Arg1 arg1))
685   {
686     Impl().OnDisconnect(MakeCallback(func));
687   }
688
689   /**
690    * @brief Connects a member function.
691    *
692    * @SINCE_1_0.0
693    * @param[in] obj An object which must implement the ConnectionTrackerInterface
694    * @param[in] func The member function to connect
695    */
696   template<class X>
697   void Connect(X* obj, void (X::*func)(Arg0 arg0, Arg1 arg1))
698   {
699     Impl().OnConnect(obj, MakeCallback(obj, func));
700   }
701
702   /**
703    * @brief Disconnects a member function.
704    *
705    * @SINCE_1_0.0
706    * @param[in] obj An object which must implement the ConnectionTrackerInterface
707    * @param[in] func The member function to disconnect
708    */
709   template<class X>
710   void Disconnect(X* obj, void (X::*func)(Arg0 arg0, Arg1 arg1))
711   {
712     Impl().OnDisconnect(obj, MakeCallback(obj, func));
713   }
714
715   /**
716    * @brief Connects a member function.
717    *
718    * @SINCE_1_0.0
719    * @param[in] delegate A slot delegate
720    * @param[in] func The member function to connect
721    */
722   template<class X>
723   void Connect(SlotDelegate<X>& delegate, void (X::*func)(Arg0 arg0, Arg1 arg1))
724   {
725     Impl().OnConnect(delegate.GetConnectionTracker(), MakeCallback(delegate.GetSlot(), func));
726   }
727
728   /**
729    * @brief Disconnects a member function.
730    *
731    * @SINCE_1_0.0
732    * @param[in] delegate A slot delegate
733    * @param[in] func The member function to disconnect
734    */
735   template<class X>
736   void Disconnect(SlotDelegate<X>& delegate, void (X::*func)(Arg0 arg0, Arg1 arg1))
737   {
738     Impl().OnDisconnect(delegate.GetConnectionTracker(), MakeCallback(delegate.GetSlot(), func));
739   }
740
741   /**
742    * @brief Connects a function object.
743    *
744    * @SINCE_1_0.0
745    * @param[in] connectionTracker A connection tracker which can be used to disconnect
746    * @param[in] func The function object to copy
747    */
748   template<class X>
749   void Connect(ConnectionTrackerInterface* connectionTracker, const X& func)
750   {
751     Impl().OnConnect(connectionTracker, new CallbackFunctor2<X, Arg0, Arg1>(func));
752   }
753
754   /**
755    * @brief Connects a function object using FunctorDelegate.
756    *
757    * @SINCE_1_0.0
758    * @param[in] connectionTracker A connection tracker which can be used to disconnect
759    * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken)
760    */
761   void Connect(ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate)
762   {
763     Impl().OnConnect(connectionTracker, new CallbackFunctorDelegate2<Arg0, Arg1>(delegate));
764   }
765
766   /**
767    * @brief Emits the signal.
768    *
769    * @SINCE_1_0.0
770    * @param[in] arg0 The first value to pass to callbacks
771    * @param[in] arg1 The second value to pass to callbacks
772    */
773   void Emit(Arg0 arg0, Arg1 arg1)
774   {
775     Impl().template Emit<Arg0, Arg1>(arg0, arg1);
776   }
777 };
778
779 /**
780  * @brief A template for Signals with 2 parameters and a return value.
781  * @SINCE_1_0.0
782  */
783 template<typename Ret, typename Arg0, typename Arg1>
784 class Signal<Ret(Arg0, Arg1)> : public SignalMixin
785 {
786 public:
787   /**
788    * @brief Connects a function.
789    * @SINCE_1_0.0
790    * @param[in] func The function to connect
791    */
792   void Connect(Ret (*func)(Arg0 arg0, Arg1 arg1))
793   {
794     Impl().OnConnect(MakeCallback(func));
795   }
796
797   /**
798    * @brief Disconnects a function.
799    *
800    * @SINCE_1_0.0
801    * @param[in] func The function to disconnect
802    */
803   void Disconnect(Ret (*func)(Arg0 arg0, Arg1 arg1))
804   {
805     Impl().OnDisconnect(MakeCallback(func));
806   }
807
808   /**
809    * @brief Connects a member function.
810    *
811    * @SINCE_1_0.0
812    * @param[in] obj An object which must implement the ConnectionTrackerInterface
813    * @param[in] func The member function to connect
814    */
815   template<class X>
816   void Connect(X* obj, Ret (X::*func)(Arg0 arg0, Arg1 arg1))
817   {
818     Impl().OnConnect(obj, MakeCallback(obj, func));
819   }
820
821   /**
822    * @brief Disconnects a member function.
823    *
824    * @SINCE_1_0.0
825    * @param[in] obj An object which must implement the ConnectionTrackerInterface
826    * @param[in] func The member function to disconnect
827    */
828   template<class X>
829   void Disconnect(X* obj, Ret (X::*func)(Arg0 arg0, Arg1 arg1))
830   {
831     Impl().OnDisconnect(obj, MakeCallback(obj, func));
832   }
833
834   /**
835    * @brief Connects a member function.
836    *
837    * @SINCE_1_0.0
838    * @param[in] delegate A slot delegate
839    * @param[in] func The member function to connect
840    */
841   template<class X>
842   void Connect(SlotDelegate<X>& delegate, Ret (X::*func)(Arg0 arg0, Arg1 arg1))
843   {
844     Impl().OnConnect(delegate.GetConnectionTracker(), MakeCallback(delegate.GetSlot(), func));
845   }
846
847   /**
848    * @brief Disconnects a member function.
849    *
850    * @SINCE_1_0.0
851    * @param[in] delegate A slot delegate
852    * @param[in] func The member function to disconnect
853    */
854   template<class X>
855   void Disconnect(SlotDelegate<X>& delegate, Ret (X::*func)(Arg0 arg0, Arg1 arg1))
856   {
857     Impl().OnDisconnect(delegate.GetConnectionTracker(), MakeCallback(delegate.GetSlot(), func));
858   }
859
860   /**
861    * @brief Connects a function object.
862    *
863    * @SINCE_1_0.0
864    * @param[in] connectionTracker A connection tracker which can be used to disconnect
865    * @param[in] func The function object to copy
866    */
867   template<class X>
868   void Connect(ConnectionTrackerInterface* connectionTracker, const X& func)
869   {
870     Impl().OnConnect(connectionTracker, new CallbackFunctorReturn2<X, Arg0, Arg1, Ret>(func));
871   }
872
873   /**
874    * @brief Connects a function object using FunctorDelegate.
875    *
876    * @SINCE_1_0.0
877    * @param[in] connectionTracker A connection tracker which can be used to disconnect
878    * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken)
879    */
880   void Connect(ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate)
881   {
882     Impl().OnConnect(connectionTracker, new CallbackFunctorDelegateReturn2<Arg0, Arg1, Ret>(delegate));
883   }
884
885   /**
886    * @brief Emits the signal.
887    *
888    * @SINCE_1_0.0
889    * @param[in] arg0 The first value to pass to callbacks
890    * @param[in] arg1 The second value to pass to callbacks
891    * @return The value returned by the last callback, or a default constructed value if no callbacks are connected
892    */
893   Ret Emit(Arg0 arg0, Arg1 arg1)
894   {
895     return Impl().template EmitReturn<Ret, Arg0, Arg1>(arg0, arg1);
896   }
897 };
898
899 /**
900  * @brief A template for Signals with 3 parameters.
901  * @SINCE_1_0.0
902  */
903 template<typename Arg0, typename Arg1, typename Arg2>
904 class Signal<void(Arg0, Arg1, Arg2)> : public SignalMixin
905 {
906 public:
907   /**
908    * @brief Connects a function.
909    *
910    * @SINCE_1_0.0
911    * @param[in] func The function to connect
912    */
913   void Connect(void (*func)(Arg0 arg0, Arg1 arg1, Arg2 arg2))
914   {
915     Impl().OnConnect(MakeCallback(func));
916   }
917
918   /**
919    * @brief Disconnects a function.
920    *
921    * @SINCE_1_0.0
922    * @param[in] func The function to disconnect
923    */
924   void Disconnect(void (*func)(Arg0 arg0, Arg1 arg1, Arg2 arg2))
925   {
926     Impl().OnDisconnect(MakeCallback(func));
927   }
928
929   /**
930    * @brief Connects a member function.
931    *
932    * @SINCE_1_0.0
933    * @param[in] obj An object which must implement the ConnectionTrackerInterface
934    * @param[in] func The member function to connect
935    */
936   template<class X>
937   void Connect(X* obj, void (X::*func)(Arg0 arg0, Arg1 arg1, Arg2 arg2))
938   {
939     Impl().OnConnect(obj, MakeCallback(obj, func));
940   }
941
942   /**
943    * @brief Disconnects a member function.
944    *
945    * @SINCE_1_0.0
946    * @param[in] obj An object which must implement the ConnectionTrackerInterface
947    * @param[in] func The member function to disconnect
948    */
949   template<class X>
950   void Disconnect(X* obj, void (X::*func)(Arg0 arg0, Arg1 arg1, Arg2 arg2))
951   {
952     Impl().OnDisconnect(obj, MakeCallback(obj, func));
953   }
954
955   /**
956    * @brief Connects a member function.
957    *
958    * @SINCE_1_0.0
959    * @param[in] delegate A slot delegate
960    * @param[in] func The member function to connect
961    */
962   template<class X>
963   void Connect(SlotDelegate<X>& delegate, void (X::*func)(Arg0 arg0, Arg1 arg1, Arg2 arg2))
964   {
965     Impl().OnConnect(delegate.GetConnectionTracker(), MakeCallback(delegate.GetSlot(), func));
966   }
967
968   /**
969    * @brief Disconnects a member function.
970    *
971    * @SINCE_1_0.0
972    * @param[in] delegate A slot delegate
973    * @param[in] func The member function to disconnect
974    */
975   template<class X>
976   void Disconnect(SlotDelegate<X>& delegate, void (X::*func)(Arg0 arg0, Arg1 arg1, Arg2 arg2))
977   {
978     Impl().OnDisconnect(delegate.GetConnectionTracker(), MakeCallback(delegate.GetSlot(), func));
979   }
980
981   /**
982    * @brief Connects a function object.
983    *
984    * @SINCE_1_0.0
985    * @param[in] connectionTracker A connection tracker which can be used to disconnect
986    * @param[in] func The function object to copy
987    */
988   template<class X>
989   void Connect(ConnectionTrackerInterface* connectionTracker, const X& func)
990   {
991     Impl().OnConnect(connectionTracker, new CallbackFunctor3<X, Arg0, Arg1, Arg2>(func));
992   }
993
994   /**
995    * @brief Connects a function object using FunctorDelegate.
996    *
997    * @SINCE_1_0.0
998    * @param[in] connectionTracker A connection tracker which can be used to disconnect
999    * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken)
1000    */
1001   void Connect(ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate)
1002   {
1003     Impl().OnConnect(connectionTracker, new CallbackFunctorDelegate3<Arg0, Arg1, Arg2>(delegate));
1004   }
1005
1006   /**
1007    * @brief Emits the signal.
1008    *
1009    * @SINCE_1_0.0
1010    * @param[in] arg0 The first value to pass to callbacks
1011    * @param[in] arg1 The second value to pass to callbacks
1012    * @param[in] arg2 The third value to pass to callbacks
1013    */
1014   void Emit(Arg0 arg0, Arg1 arg1, Arg2 arg2)
1015   {
1016     Impl().template Emit<Arg0, Arg1, Arg2>(arg0, arg1, arg2);
1017   }
1018 };
1019
1020 /**
1021  * @brief A template for Signals with 2 parameters and a return value.
1022  * @SINCE_1_0.0
1023  */
1024 template<typename Ret, typename Arg0, typename Arg1, typename Arg2>
1025 class Signal<Ret(Arg0, Arg1, Arg2)> : public SignalMixin
1026 {
1027 public:
1028   /**
1029    * @brief Connects a function.
1030    *
1031    * @SINCE_1_0.0
1032    * @param[in] func The function to connect
1033    */
1034   void Connect(Ret (*func)(Arg0 arg0, Arg1 arg1, Arg2 arg2))
1035   {
1036     Impl().OnConnect(MakeCallback(func));
1037   }
1038
1039   /**
1040    * @brief Disconnects a function.
1041    *
1042    * @SINCE_1_0.0
1043    * @param[in] func The function to disconnect
1044    */
1045   void Disconnect(Ret (*func)(Arg0 arg0, Arg1 arg1, Arg2 arg2))
1046   {
1047     Impl().OnDisconnect(MakeCallback(func));
1048   }
1049
1050   /**
1051    * @brief Connects a member function.
1052    *
1053    * @SINCE_1_0.0
1054    * @param[in] obj An object which must implement the ConnectionTrackerInterface
1055    * @param[in] func The member function to connect
1056    */
1057   template<class X>
1058   void Connect(X* obj, Ret (X::*func)(Arg0 arg0, Arg1 arg1, Arg2 arg2))
1059   {
1060     Impl().OnConnect(obj, MakeCallback(obj, func));
1061   }
1062
1063   /**
1064    * @brief Disconnects a member function.
1065    *
1066    * @SINCE_1_0.0
1067    * @param[in] obj An object which must implement the ConnectionTrackerInterface
1068    * @param[in] func The member function to disconnect
1069    */
1070   template<class X>
1071   void Disconnect(X* obj, Ret (X::*func)(Arg0 arg0, Arg1 arg1, Arg2 arg2))
1072   {
1073     Impl().OnDisconnect(obj, MakeCallback(obj, func));
1074   }
1075
1076   /**
1077    * @brief Connects a member function.
1078    *
1079    * @SINCE_1_0.0
1080    * @param[in] delegate A slot delegate
1081    * @param[in] func The member function to connect
1082    */
1083   template<class X>
1084   void Connect(SlotDelegate<X>& delegate, Ret (X::*func)(Arg0 arg0, Arg1 arg1, Arg2 arg2))
1085   {
1086     Impl().OnConnect(delegate.GetConnectionTracker(), MakeCallback(delegate.GetSlot(), func));
1087   }
1088
1089   /**
1090    * @brief Disconnects a member function.
1091    *
1092    * @SINCE_1_0.0
1093    * @param[in] delegate A slot delegate
1094    * @param[in] func The member function to disconnect
1095    */
1096   template<class X>
1097   void Disconnect(SlotDelegate<X>& delegate, Ret (X::*func)(Arg0 arg0, Arg1 arg1, Arg2 arg2))
1098   {
1099     Impl().OnDisconnect(delegate.GetConnectionTracker(), MakeCallback(delegate.GetSlot(), func));
1100   }
1101
1102   /**
1103    * @brief Connects a function object.
1104    *
1105    * @SINCE_1_0.0
1106    * @param[in] connectionTracker A connection tracker which can be used to disconnect
1107    * @param[in] func The function object to copy
1108    */
1109   template<class X>
1110   void Connect(ConnectionTrackerInterface* connectionTracker, const X& func)
1111   {
1112     Impl().OnConnect(connectionTracker, new CallbackFunctorReturn3<X, Arg0, Arg1, Arg2, Ret>(func));
1113   }
1114
1115   /**
1116    * @brief Connects a function object using FunctorDelegate.
1117    *
1118    * @SINCE_1_0.0
1119    * @param[in] connectionTracker A connection tracker which can be used to disconnect
1120    * @param[in] delegate A newly allocated FunctorDelegate (ownership is taken)
1121    */
1122   void Connect(ConnectionTrackerInterface* connectionTracker, FunctorDelegate* delegate)
1123   {
1124     Impl().OnConnect(connectionTracker, new CallbackFunctorDelegateReturn3<Arg0, Arg1, Arg2, Ret>(delegate));
1125   }
1126
1127   /**
1128    * @brief Emits the signal.
1129    *
1130    * @SINCE_1_0.0
1131    * @param[in] arg0 The first value to pass to callbacks
1132    * @param[in] arg1 The second value to pass to callbacks
1133    * @param[in] arg2 The third value to pass to callbacks
1134    * @return The value returned by the last callback, or a default constructed value if no callbacks are connected
1135    */
1136   Ret Emit(Arg0 arg0, Arg1 arg1, Arg2 arg2)
1137   {
1138     return Impl().template EmitReturn<Ret, Arg0, Arg1, Arg2>(arg0, arg1, arg2);
1139   }
1140 };
1141
1142 /**
1143  * @}
1144  */
1145 } // namespace Dali
1146
1147 #endif // DALI_SIGNAL_H