2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/public-api/signals/connection-tracker.h>
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>
31 const int INVALID_CALLBACK_INDEX = -1;
33 } // unnamed namespace
36 ConnectionTracker::ConnectionTracker()
40 ConnectionTracker::~ConnectionTracker()
45 void ConnectionTracker::DisconnectAll()
47 std::size_t size = mConnections.size();
49 for( std::size_t i = 0; i< size; ++i )
51 SlotConnection* connection = mConnections[i];
53 // Tell the signal that the slot is disconnected
54 connection->GetSlotObserver()->SlotDisconnected( connection->GetCallback() );
62 void ConnectionTracker::SignalConnected( SlotObserver* slotObserver, CallbackBase* callback )
64 SlotConnection* connection = new SlotConnection( slotObserver, callback );
65 mConnections.push_back( connection );
68 void ConnectionTracker::SignalDisconnected( SlotObserver* signal, CallbackBase* callback )
70 std::size_t size = mConnections.size();
72 for( std::size_t i = 0; i< size; ++i )
74 SlotConnection* connection = mConnections[i];
76 // Pointer comparison i.e. SignalConnection contains pointer to same callback instance
77 if( connection->GetCallback() == callback )
79 // Remove from connection list
80 mConnections.erase( mConnections.begin() + i );
85 // Disconnection complete
90 DALI_ASSERT_ALWAYS( false && "Callback lost in SignalDisconnected()" );
93 std::size_t ConnectionTracker::GetConnectionCount() const
95 return mConnections.size();