2 * Copyright (c) 2017 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/internal/system/common/callback-manager-ecore.h>
22 // Ecore is littered with C style cast
23 #pragma GCC diagnostic push
24 #pragma GCC diagnostic ignored "-Wold-style-cast"
27 #include <dali/integration-api/debug.h>
42 * Structure contains the callback function and control options
50 CallbackData( CallbackBase* callback )
51 : mCallback(callback),
52 mRemoveFromContainerFunction(NULL),
62 delete mRemoveFromContainerFunction;
65 CallbackBase* mCallback; ///< call back
66 CallbackBase* mRemoveFromContainerFunction; ///< Called to remove the callbackdata from the callback container
67 Ecore_Idler* mIdler; ///< ecore idler
74 * Called from the main thread while idle.
76 Eina_Bool IdleCallback(void *data)
78 CallbackData *callbackData = static_cast< CallbackData * >( data );
80 // remove callback data from the container
81 CallbackBase::Execute( *callbackData->mRemoveFromContainerFunction, callbackData );
84 CallbackBase::Execute( *callbackData->mCallback );
89 // CALLBACK Cancel will delete the idler so we don't need to call ecore_idler_del
90 return ECORE_CALLBACK_CANCEL;
93 } // unnamed namespace
95 EcoreCallbackManager::EcoreCallbackManager()
101 void EcoreCallbackManager::Start()
103 DALI_ASSERT_DEBUG( mRunning == false );
108 void EcoreCallbackManager::Stop()
110 // make sure we're not called twice
111 DALI_ASSERT_DEBUG( mRunning == true );
113 RemoveAllCallbacks();
119 bool EcoreCallbackManager::AddIdleCallback( CallbackBase* callback )
126 CallbackData* callbackData = new CallbackData( callback );
128 callbackData->mRemoveFromContainerFunction = MakeCallback( this, &EcoreCallbackManager::RemoveCallbackFromContainer );
130 // add the call back to the container
131 mCallbackContainer.push_front(callbackData);
134 callbackData->mIdler = ecore_idler_add( IdleCallback, callbackData);
136 DALI_ASSERT_ALWAYS( ( callbackData->mIdler != NULL ) && "Idle method not created" );
141 void EcoreCallbackManager::RemoveIdleCallback( CallbackBase* callback )
143 for( CallbackList::iterator it = mCallbackContainer.begin(),
144 endIt = mCallbackContainer.end();
148 CallbackData* data = *it;
150 if( data->mCallback == callback )
152 // remove callback data from the container.
153 CallbackBase::Execute( *data->mRemoveFromContainerFunction, data );
155 ecore_idler_del( data->mIdler );
160 void EcoreCallbackManager::RemoveCallbackFromContainer(CallbackData *callbackData)
162 mCallbackContainer.remove(callbackData);
165 void EcoreCallbackManager::RemoveAllCallbacks()
167 // always called from main thread
168 for( CallbackList::iterator iter = mCallbackContainer.begin(); iter != mCallbackContainer.end(); ++iter)
170 CallbackData* data = (*iter);
172 ecore_idler_del( data->mIdler );
177 mCallbackContainer.clear();
180 // Creates a concrete interface for CallbackManager
181 CallbackManager* CallbackManager::New()
183 return new EcoreCallbackManager;
186 } // namespace Adaptor
188 } // namespace Internal
192 #pragma GCC diagnostic pop