2 * Copyright (c) 2023 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/linux/callback-manager-ecore.h>
22 #include <dali/internal/system/linux/dali-ecore.h>
24 #include <dali/integration-api/debug.h>
35 * Structure contains the callback function and control options
42 CallbackData(CallbackBase* callback, bool hasReturnValue)
43 : mCallback(callback),
44 mRemoveFromContainerFunction(NULL),
47 mHasReturnValue(hasReturnValue)
56 delete mRemoveFromContainerFunction;
59 CallbackBase* mCallback; ///< call back
60 CallbackBase* mRemoveFromContainerFunction; ///< Called to remove the callbackdata from the callback container
61 Ecore_Idler* mIdler; ///< ecore idler
62 Ecore_Idle_Enterer* mIdleEnterer; ///< ecore idle enterer
63 bool mHasReturnValue; ///< true if the callback function has a return value.
69 * Called from the main thread while idle.
71 Eina_Bool IdleCallback(void* data)
73 Eina_Bool ret = ECORE_CALLBACK_CANCEL; // CALLBACK Cancel will delete the idler so we don't need to call ecore_idler_del
74 CallbackData* callbackData = static_cast<CallbackData*>(data);
76 if(callbackData->mHasReturnValue)
79 bool retValue = CallbackBase::ExecuteReturn<bool>(*callbackData->mCallback);
83 ret = ECORE_CALLBACK_RENEW;
87 // remove callback data from the container
88 CallbackBase::Execute(*callbackData->mRemoveFromContainerFunction, callbackData);
96 // remove callback data from the container
97 CallbackBase::Execute(*callbackData->mRemoveFromContainerFunction, callbackData);
100 CallbackBase::Execute(*callbackData->mCallback);
109 } // unnamed namespace
111 EcoreCallbackManager::EcoreCallbackManager()
116 void EcoreCallbackManager::Start()
118 DALI_ASSERT_DEBUG(mRunning == false);
123 void EcoreCallbackManager::Stop()
125 // make sure we're not called twice
126 DALI_ASSERT_DEBUG(mRunning == true);
128 RemoveAllCallbacks();
133 bool EcoreCallbackManager::AddIdleCallback(CallbackBase* callback, bool hasReturnValue)
140 CallbackData* callbackData = new CallbackData(callback, hasReturnValue);
142 callbackData->mRemoveFromContainerFunction = MakeCallback(this, &EcoreCallbackManager::RemoveCallbackFromContainer);
144 // add the call back to the container
145 mCallbackContainer.push_front(callbackData);
148 callbackData->mIdler = ecore_idler_add(IdleCallback, callbackData);
150 DALI_ASSERT_ALWAYS((callbackData->mIdler != NULL) && "Idle method not created");
155 void EcoreCallbackManager::RemoveIdleCallback(CallbackBase* callback)
157 for(CallbackList::iterator it = mCallbackContainer.begin(),
158 endIt = mCallbackContainer.end();
162 CallbackData* data = *it;
164 if(data->mCallback == callback)
166 // remove callback data from the container.
167 CallbackBase::Execute(*data->mRemoveFromContainerFunction, data);
169 ecore_idler_del(data->mIdler);
179 bool EcoreCallbackManager::ProcessIdle()
181 // @todo To be implemented.
185 void EcoreCallbackManager::ClearIdleCallbacks()
187 // @todo To be implemented.
190 bool EcoreCallbackManager::AddIdleEntererCallback(CallbackBase* callback)
197 CallbackData* callbackData = new CallbackData(callback, true);
199 callbackData->mRemoveFromContainerFunction = MakeCallback(this, &EcoreCallbackManager::RemoveCallbackFromContainer);
201 // add the call back to the container
202 mCallbackContainer.push_front(callbackData);
205 callbackData->mIdleEnterer = ecore_idle_enterer_add(IdleCallback, callbackData);
207 DALI_ASSERT_ALWAYS((callbackData->mIdleEnterer != NULL) && "Idle method not created");
212 void EcoreCallbackManager::RemoveIdleEntererCallback(CallbackBase* callback)
214 for(CallbackList::iterator it = mCallbackContainer.begin(),
215 endIt = mCallbackContainer.end();
219 CallbackData* data = *it;
221 if(data->mCallback == callback)
223 // remove callback data from the container.
224 CallbackBase::Execute(*data->mRemoveFromContainerFunction, data);
226 ecore_idle_enterer_del(data->mIdleEnterer);
236 void EcoreCallbackManager::RemoveCallbackFromContainer(CallbackData* callbackData)
238 mCallbackContainer.remove(callbackData);
241 void EcoreCallbackManager::RemoveAllCallbacks()
243 // always called from main thread
244 for(CallbackList::iterator iter = mCallbackContainer.begin(); iter != mCallbackContainer.end(); ++iter)
246 CallbackData* data = (*iter);
250 ecore_idler_del(data->mIdler);
252 else if(data->mIdleEnterer)
254 ecore_idle_enterer_del(data->mIdleEnterer);
259 mCallbackContainer.clear();
262 } // namespace Adaptor
264 } // namespace Internal