Revert "[Tizen] Add codes for Dali Windows Backend"
[platform/core/uifw/dali-core.git] / dali / public-api / signals / connection-tracker.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/public-api/signals/connection-tracker.h>
20
21 #include <dali/public-api/signals/callback.h>
22 #include <dali/public-api/signals/signal-slot-observers.h>
23 #include <dali/public-api/signals/signal-slot-connections.h>
24
25 namespace Dali
26 {
27
28 ConnectionTracker::ConnectionTracker()
29 {
30 }
31
32 ConnectionTracker::~ConnectionTracker()
33 {
34   DisconnectAll();
35 }
36
37 void ConnectionTracker::DisconnectAll()
38 {
39   std::size_t size = mConnections.Size();
40
41   for( std::size_t i = 0; i< size; ++i )
42   {
43     SlotConnection* connection = mConnections[i];
44
45     // Tell the signal that the slot is disconnected
46     connection->GetSlotObserver()->SlotDisconnected( connection->GetCallback() );
47
48     delete connection;
49   }
50
51   mConnections.Clear();
52 }
53
54 void ConnectionTracker::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
55 {
56   SlotConnection* connection = new SlotConnection( slotObserver, callback );
57   mConnections.PushBack( connection );
58 }
59
60 void ConnectionTracker::SignalDisconnected( SlotObserver* signal, CallbackBase* callback )
61 {
62   std::size_t size = mConnections.Size();
63
64   for( std::size_t i = 0; i< size; ++i )
65   {
66     SlotConnection* connection = mConnections[i];
67
68     // Pointer comparison i.e. SignalConnection contains pointer to same callback instance
69     if( connection->GetCallback() == callback )
70     {
71       // Remove from connection list
72       mConnections.Erase( mConnections.Begin() + i );
73
74       // Delete connection
75       delete connection;
76
77       // Disconnection complete
78       return;
79     }
80   }
81
82   DALI_ABORT( "Callback lost in SignalDisconnected()" );
83 }
84
85 std::size_t ConnectionTracker::GetConnectionCount() const
86 {
87   return mConnections.Size();
88 }
89
90 } // namespace Dali