ec51d87d07240f01148880bf1907d4c3911e0b7a
[platform/core/uifw/dali-core.git] / dali / public-api / signals / signal-slot-connections.h
1 #ifndef __DALI_SIGNAL_SLOT_CONNECTIONS_H__
2 #define __DALI_SIGNAL_SLOT_CONNECTIONS_H__
3
4 /*
5  * Copyright (c) 2015 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 // INTERNAL INCLUDES
22 #include <dali/public-api/signals/signal-slot-observers.h>
23
24 namespace Dali
25 {
26 /**
27  * @addtogroup dali-core-signals
28  * @{
29  */
30
31 class CallbackBase;
32
33 /**
34  * @brief Slot connection is the connection information held by a connection tracker.
35  *
36  * A slot can have zero to many connection objects, depending
37  * on how many signals it is connected to.
38  *
39  * A connection contains:
40  * - Callback (slot)
41  * - SlotObserver -interface provided by the signal
42  *
43  * It holds a pointer to the callback, but does not own it.
44  */
45 class DALI_IMPORT_API SlotConnection
46 {
47 public:
48
49   /**
50    * @brief Constructor.
51    *
52    * @param[in] slotObserver The slot observer.
53    * @param[in] callback A callback object (not owned).
54    */
55   SlotConnection(SlotObserver* slotObserver, CallbackBase* callback);
56
57   /**
58    * @brief Non-virtual destructor, not intended as a base class.
59    */
60   ~SlotConnection();
61
62   /**
63    * @brief Retrieve the callback.
64    *
65    * @return A pointer to the callback.
66    */
67   CallbackBase* GetCallback();
68
69   /**
70    * @brief Retrieve the slot observer.
71    *
72    * @return A pointer to the slot observer.
73    */
74   SlotObserver* GetSlotObserver();
75
76 private:
77
78   SlotConnection( const SlotConnection& );            ///< undefined copy constructor
79   SlotConnection& operator=( const SlotConnection& ); ///< undefined assignment operator
80
81 private:
82
83   SlotObserver* mSlotObserver; ///< a pointer to the slot observer (not owned)
84   CallbackBase* mCallback;     ///< The callback. This is not owned, the corresponding SignalConnection has ownership.
85 };
86
87 /**
88  * @brief SignalConnection is the connection information held by the signal.
89  *
90  * A signal can have zero to many connections, depending on how
91  * many slots are connected to this signal.
92  *
93  * A connection contains:
94  * - Callback (slot)
95  * - SignalObserver - interface provided by a slot owning object.
96  *
97  * It takes ownership of the callback, and will delete it when
98  * the connection is destroyed.
99  */
100 class DALI_IMPORT_API SignalConnection
101 {
102 public:
103
104   /**
105    * @brief Constructor.
106    *
107    * @param[in] callback The callback which should be a C function.
108    */
109   SignalConnection( CallbackBase* callback );
110
111   /**
112    * @brief Constructor.
113    *
114    * @param[in] signalObserver The signal observer.
115    * @param[in] callback Ownership of this callback object is taken.
116    */
117   SignalConnection( SignalObserver* signalObserver, CallbackBase* callback );
118
119   /**
120    * @brief Non-virtual destructor, not intended as a base class.
121    */
122   ~SignalConnection();
123
124   /**
125    * @brief Disconnect the signal from the slot.
126    *
127    * @param[in] slotObserver The signal disconnecting from the slot.
128    */
129   void Disconnect( SlotObserver* slotObserver );
130
131   /**
132    * @brief Retrieve the callback.
133    *
134    * @return A pointer to the callback.
135    */
136   CallbackBase* GetCallback();
137
138 private:
139
140   SignalConnection( const SignalConnection& );            ///< undefined copy constructor
141   SignalConnection& operator=( const SignalConnection& ); ///< undefined assignment operator
142
143 private:
144
145   SignalObserver* mSignalObserver; ///< a pointer to the signal observer (not owned)
146   CallbackBase* mCallback;         ///< The callback, has ownership.
147 };
148
149 /**
150  * @}
151  */
152 } // namespace Dali
153
154 #endif // __DALI_SIGNAL_SLOT_CONNECTIONS_H__