48122d731e78ee5d5dfe3f8bb18b39cfb27db55f
[platform/core/uifw/dali-core.git] / capi / dali / public-api / signals / connection-tracker-interface.h
1 #ifndef __DALI_CONNECTION_TRACKER_INTERFACE_H__
2 #define __DALI_CONNECTION_TRACKER_INTERFACE_H__
3
4 /*
5  * Copyright (c) 2014 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  * @addtogroup CAPI_DALI_SIGNALS_MODULE
23  * @{
24  */
25
26 // INTERNAL INCLUDES
27 #include <dali/public-api/common/dali-common.h>
28 #include <dali/public-api/signals/signal-slot-observers.h>
29
30 namespace Dali DALI_IMPORT_API
31 {
32
33 /**
34  * @brief Interface used to track connections between signals and slots.
35  *
36  * Performs automatic connection and disconnection when either the slot or signal dies.
37  *
38  * @code
39  * class MyApp : public ConnectionTracker
40  * {
41  *   Button.ClickedSignal().Connect( this, &MyApp::OnPress );
42  *
43  *   void OnPress()
44  *   {
45  *     std::cout << "hello world" << std::endl;
46  *   }
47  * }
48  * @endcode
49  *
50  * When MyApp is destroyed, it automatically disconnects from Button.ClickSignal.
51  * It provides a signal observer interface, to observer when signals are destroyed
52  * e.g. if Button object is destroyed while it is still connected.
53  */
54 class ConnectionTrackerInterface : public SignalObserver
55 {
56 public:
57
58   /**
59    * @brief Constructor.
60    */
61   ConnectionTrackerInterface();
62
63   /**
64    * @brief Virtual destructor.
65    */
66   virtual ~ConnectionTrackerInterface();
67
68   /**
69    * @brief Called when a signal is connected.
70    *
71    * @param[in] slotObserver The slot observer i.e. a signal.
72    * @param[in] callback The call back.
73    */
74   virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback ) = 0;
75
76   /**
77    * @brief Query the connection count.
78    *
79    * @return The number of signal/slot connections know by the connection tracker.
80    */
81   virtual std::size_t GetConnectionCount() const = 0;
82
83 private:
84
85   ConnectionTrackerInterface( const ConnectionTrackerInterface& );            ///< undefined copy constructor
86   ConnectionTrackerInterface& operator=( const ConnectionTrackerInterface& ); ///< undefined assignment operator
87 };
88
89 } // namespace Dali
90
91 /**
92  * @}
93  */
94 #endif // __DALI_CONNECTION_TRACKER_INTERFACE_H__