2 * Copyright (c) 2015 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/callback.h>
27 CallbackBase::CallbackBase()
33 CallbackBase::~CallbackBase()
38 CallbackBase::CallbackBase( Function function )
44 CallbackBase::CallbackBase( void* object, MemberFunction function, Dispatcher dispatcher )
45 : mMemberFunction( function )
47 mImpl = new CallbackBase::Impl;
48 mImpl->mObjectPointer = object;
49 mImpl->mMemberFunctionDispatcher = dispatcher;
50 mImpl->mDestructorDispatcher = NULL; // object is not owned
53 CallbackBase::CallbackBase( void* object, MemberFunction function, Dispatcher dispatcher, Destructor destructor )
54 : mMemberFunction( function )
56 mImpl = new CallbackBase::Impl;
57 mImpl->mObjectPointer = object;
58 mImpl->mMemberFunctionDispatcher = dispatcher;
59 mImpl->mDestructorDispatcher = destructor; // object is owned
62 void CallbackBase::Reset()
66 // if destructor function is set it means we own this object
67 if ( mImpl->mObjectPointer &&
68 mImpl->mDestructorDispatcher )
70 // call the destructor dispatcher
71 (*mImpl->mDestructorDispatcher)( mImpl->mObjectPointer );
83 CallbackBase::Impl::Impl()
84 : mObjectPointer( NULL ),
85 mMemberFunctionDispatcher( NULL ),
86 mDestructorDispatcher( NULL )
90 // Non-member equality operator
92 bool operator==( const CallbackBase& lhs, const CallbackBase& rhs )
96 // check it's the same member function / object
97 return ( lhs.mFunction == rhs.mFunction ) && ( lhs.mImpl->mObjectPointer == rhs.mImpl->mObjectPointer );
101 // check if it the same C function or a static member function
102 return ( lhs.mFunction == rhs.mFunction );