1 #ifndef DALI_SIGNAL_SLOT_CONNECTIONS_H
2 #define DALI_SIGNAL_SLOT_CONNECTIONS_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/signals/callback.h>
23 #include <dali/public-api/signals/signal-slot-observers.h>
28 * @addtogroup dali_core_signals
33 * @brief Slot connection is the connection information held by a connection tracker.
35 * A slot can have zero to many connection objects, depending
36 * on how many signals it is connected to.
38 * A connection contains:
40 * - SlotObserver -interface provided by the signal
42 * It holds a pointer to the callback, but does not own it.
45 class DALI_CORE_API SlotConnection
52 * @param[in] slotObserver The slot observer
53 * @param[in] callback A callback object (not owned)
55 SlotConnection(SlotObserver* slotObserver, CallbackBase* callback);
58 * @brief Retrieves the callback.
61 * @return A pointer to the callback
63 CallbackBase* GetCallback() const
69 * @brief Retrieves the slot observer.
72 * @return A pointer to the slot observer
74 SlotObserver* GetSlotObserver() const
80 SlotObserver* mSlotObserver{nullptr}; ///< a pointer to the slot observer (not owned)
81 CallbackBase* mCallback{nullptr}; ///< The callback. This is not owned, the corresponding SignalConnection has ownership.
85 * @brief SignalConnection is the connection information held by the signal.
87 * A signal can have zero to many connections, depending on how
88 * many slots are connected to this signal.
90 * A connection contains:
92 * - SignalObserver - interface provided by a slot owning object.
94 * It takes ownership of the callback, and will delete it when
95 * the connection is destroyed.
98 class DALI_CORE_API SignalConnection
102 * @brief Constructor.
105 * @param[in] callback The callback which should be a C function
107 SignalConnection(CallbackBase* callback) noexcept
108 : mCallback(callback)
113 * @brief Constructor.
116 * @param[in] signalObserver The signal observer
117 * @param[in] callback Ownership of this callback object is taken
119 SignalConnection(SignalObserver* signalObserver, CallbackBase* callback) noexcept
120 : mSignalObserver(signalObserver),
126 * @brief Non-virtual destructor, not intended as a base class.
129 ~SignalConnection() noexcept
131 // signal connections have ownership of the callback.
136 * @brief Disconnects the signal from the slot.
139 * @param[in] slotObserver The signal disconnecting from the slot
141 void Disconnect(SlotObserver* slotObserver) noexcept;
144 * @brief Retrieves the callback.
147 * @return A pointer to the callback
149 CallbackBase* GetCallback() const noexcept
154 SignalConnection(const SignalConnection&) = delete; ///< Deleted copy constructor. @SINCE_1_0.0
155 SignalConnection& operator=(const SignalConnection&) = delete; ///< Deleted copy assignment operator. @SINCE_1_0.0
158 * @brief Move constructor.
160 * A move constructor enables the resources owned by an rvalue object to be moved into an lvalue without copying.
162 * @param[in] connection The property value to move from
164 SignalConnection(SignalConnection&& connection) noexcept
165 : mSignalObserver(connection.mSignalObserver),
166 mCallback(connection.mCallback)
168 connection.mSignalObserver = nullptr;
169 connection.mCallback = nullptr;
173 * @brief Move assignment operator.
176 * @param[in] connection The connection to move from
177 * @return a reference to this
179 SignalConnection& operator=(SignalConnection&& connection) noexcept
181 if(this != &connection)
183 // release the callback
186 mSignalObserver = connection.mSignalObserver;
187 mCallback = connection.mCallback;
189 connection.mSignalObserver = nullptr;
190 connection.mCallback = nullptr;
195 explicit operator bool() const noexcept
197 return mCallback ? true : false;
201 SignalObserver* mSignalObserver{nullptr}; ///< a pointer to the signal observer (not owned)
202 CallbackBase* mCallback{nullptr}; ///< The callback, has ownership.
210 #endif // DALI_SIGNAL_SLOT_CONNECTIONS_H