2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "AddonClass.h"
16 * <p>This is the parent class for the class templates that hold
17 * a callback. A callback is essentially a templatized
18 * functor (functoid?) for a call to a member function.</p>
20 * <p>This class combined with the attending CallbackHandlers should make
21 * sure that the AddonClass isn't in the midst of deallocating when
22 * the callback executes. In this way the Callback class acts as
23 * a weak reference.</p>
25 class Callback
: public AddonClass
28 AddonClass
* addonClassObject
;
29 explicit Callback(AddonClass
* _object
) : addonClassObject(_object
) { XBMC_TRACE
; }
32 virtual void executeCallback() = 0;
35 AddonClass
* getObject() { XBMC_TRACE
; return addonClassObject
; }
38 struct cb_null_type
{};
40 // stub type template to be partial specialized
41 template<typename M
= cb_null_type
, typename T1
= cb_null_type
,
42 typename T2
= cb_null_type
, typename T3
= cb_null_type
,
43 typename T4
= cb_null_type
, typename Extraneous
= cb_null_type
>
44 class CallbackFunction
{};
47 * This is the template to carry a callback to a member function
48 * that returns 'void' (has no return) and takes no parameters.
50 template<class M
> class CallbackFunction
<M
, cb_null_type
, cb_null_type
, cb_null_type
, cb_null_type
, cb_null_type
> : public Callback
53 typedef void (M::*MemberFunction
)();
60 CallbackFunction(M
* object
, MemberFunction method
) :
61 Callback(object
), meth(method
), obj(object
) { XBMC_TRACE
; }
63 ~CallbackFunction() override
{ XBMC_TRACE
; deallocating(); }
65 void executeCallback() override
{ XBMC_TRACE
; ((*obj
).*(meth
))(); }
69 * This is the template to carry a callback to a member function
70 * that returns 'void' (has no return) and takes one parameter.
72 template<class M
, typename P1
> class CallbackFunction
<M
,P1
, cb_null_type
, cb_null_type
, cb_null_type
, cb_null_type
> : public Callback
75 typedef void (M::*MemberFunction
)(P1
);
83 CallbackFunction(M
* object
, MemberFunction method
, P1 parameter
) :
84 Callback(object
), meth(method
), obj(object
),
85 param(parameter
) { XBMC_TRACE
; }
87 ~CallbackFunction() override
{ XBMC_TRACE
; deallocating(); }
89 void executeCallback() override
{ XBMC_TRACE
; ((*obj
).*(meth
))(param
); }
93 * This is the template to carry a callback to a member function
94 * that returns 'void' (has no return) and takes one parameter
95 * that can be held in an AddonClass::Ref
97 template<class M
, typename P1
> class CallbackFunction
<M
,AddonClass::Ref
<P1
>, cb_null_type
, cb_null_type
, cb_null_type
, cb_null_type
> : public Callback
100 typedef void (M::*MemberFunction
)(P1
*);
105 AddonClass::Ref
<P1
> param
;
108 CallbackFunction(M
* object
, MemberFunction method
, P1
* parameter
) :
109 Callback(object
), meth(method
), obj(object
),
110 param(parameter
) { XBMC_TRACE
; }
112 ~CallbackFunction() override
{ XBMC_TRACE
; deallocating(); }
114 void executeCallback() override
{ XBMC_TRACE
; ((*obj
).*(meth
))(param
); }
119 * This is the template to carry a callback to a member function
120 * that returns 'void' (has no return) and takes two parameters.
122 template<class M
, typename P1
, typename P2
> class CallbackFunction
<M
,P1
,P2
, cb_null_type
, cb_null_type
, cb_null_type
> : public Callback
125 typedef void (M::*MemberFunction
)(P1
,P2
);
134 CallbackFunction(M
* object
, MemberFunction method
, P1 parameter
, P2 parameter2
) :
135 Callback(object
), meth(method
), obj(object
),
136 param1(parameter
), param2(parameter2
) { XBMC_TRACE
; }
138 ~CallbackFunction() override
{ XBMC_TRACE
; deallocating(); }
140 void executeCallback() override
{ XBMC_TRACE
; ((*obj
).*(meth
))(param1
,param2
); }
145 * This is the template to carry a callback to a member function
146 * that returns 'void' (has no return) and takes three parameters.
148 template<class M
, typename P1
, typename P2
, typename P3
> class CallbackFunction
<M
,P1
,P2
,P3
, cb_null_type
, cb_null_type
> : public Callback
151 typedef void (M::*MemberFunction
)(P1
,P2
,P3
);
161 CallbackFunction(M
* object
, MemberFunction method
, P1 parameter
, P2 parameter2
, P3 parameter3
) :
162 Callback(object
), meth(method
), obj(object
),
163 param1(parameter
), param2(parameter2
), param3(parameter3
) { XBMC_TRACE
; }
165 ~CallbackFunction() override
{ XBMC_TRACE
; deallocating(); }
167 void executeCallback() override
{ XBMC_TRACE
; ((*obj
).*(meth
))(param1
,param2
,param3
); }