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