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