/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Internal::Adaptor::Application::PreInitialize( argc, argv );
}
+bool AddIdleWithReturnValue( Application application, CallbackBase* callback )
+{
+ return Internal::Adaptor::GetImplementation( application ).AddIdle( callback, true );
+}
+
} // namespace DevelApplication
} // namespace Dali
*/
DALI_ADAPTOR_API void PreInitialize( int* argc, char** argv[] );
+/**
+ * @brief Ensures that the function passed in is called from the main loop when it is idle.
+ * @param[in] application A handle to the Application
+ * @param[in] callback The function to call
+ * @return @c true if added successfully, @c false otherwise
+ *
+ * @note Function must be called from main event thread only
+ *
+ * A callback of the following type should be used:
+ * @code
+ * bool MyFunction();
+ * @endcode
+ * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
+ *
+ * @note Ownership of the callback is passed onto this class.
+ */
+DALI_ADAPTOR_API bool AddIdleWithReturnValue( Application application, CallbackBase* callback );
+
} // namespace DevelApplication
} // namespace Dali
* @brief Ensures that the function passed in is called from the main loop when it is idle.
* @note Function must be called from the main event thread only.
*
- * A callback of the following type may be used:
+ * Callbacks of the following types may be used:
* @code
* void MyFunction();
* @endcode
+ * This callback will be deleted once it is called.
+ *
+ * @code
+ * bool MyFunction();
+ * @endcode
+ * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
*
* @param[in] callback The function to call.
+ * @param[in] hasReturnValue Sould be set to true if the callback function has a return value.
* @return true if added successfully, false otherwise
*
* @note Ownership of the callback is passed onto this class.
*/
- bool AddIdle( CallbackBase* callback );
+ bool AddIdle( CallbackBase* callback, bool hasReturnValue );
/**
* @brief Removes a previously added @p callback.
return mTtsPlayers[mode];
}
-bool Adaptor::AddIdle( CallbackBase* callback, bool forceAdd )
+bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue, bool forceAdd )
{
bool idleAdded(false);
// Only add an idle if the Adaptor is actually running
if( RUNNING == mState || READY == mState || forceAdd )
{
- idleAdded = mCallbackManager->AddIdleCallback( callback );
+ idleAdded = mCallbackManager->AddIdleCallback( callback, hasReturnValue );
}
return idleAdded;
// and we haven't installed the idle notification
if( ( ! mNotificationOnIdleInstalled ) && ( RUNNING == mState || READY == mState || forceProcess ) )
{
- mNotificationOnIdleInstalled = AddIdle( MakeCallback( this, &Adaptor::ProcessCoreEventsFromIdle ), forceProcess );
+ mNotificationOnIdleInstalled = AddIdleEnterer( MakeCallback( this, &Adaptor::ProcessCoreEventsFromIdle ), forceProcess );
}
}
static_cast< LayoutDirection::Type >( Internal::Adaptor::Locale::GetDirection( std::string( locale ) ) ) );
}
+bool Adaptor::AddIdleEnterer( CallbackBase* callback, bool forceAdd )
+{
+ bool idleAdded( false );
+
+ // Only add an idle if the Adaptor is actually running
+ if( RUNNING == mState || READY == mState || forceAdd )
+ {
+ idleAdded = mCallbackManager->AddIdleEntererCallback( callback );
+ }
+
+ return idleAdded;
+}
+
+void Adaptor::RemoveIdleEnterer( CallbackBase* callback )
+{
+ mCallbackManager->RemoveIdleEntererCallback( callback );
+}
+
} // namespace Adaptor
} // namespace Internal
/**
* @copydoc Dali::Adaptor::AddIdle()
*/
- virtual bool AddIdle( CallbackBase* callback, bool forceAdd );
+ virtual bool AddIdle( CallbackBase* callback, bool hasReturnValue, bool forceAdd );
/**
* @copydoc Dali::Adaptor::RemoveIdle()
*/
void SetupSystemInformation();
+ /**
+ * Adds a callback to be run when entering an idle state.
+ *
+ * A callback of the following type should be used:
+ * @code
+ * bool MyFunction();
+ * @endcode
+ * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
+ */
+ bool AddIdleEnterer( CallbackBase* callback, bool forceAdd );
+
+ /**
+ * Removes a previously added the idle enterer callback.
+ */
+ void RemoveIdleEnterer( CallbackBase* callback );
+
private:
/**
mImpl->Stop();
}
-bool Adaptor::AddIdle( CallbackBase* callback )
+bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
{
- return mImpl->AddIdle( callback, false );
+ return mImpl->AddIdle( callback, hasReturnValue, false );
}
void Adaptor::RemoveIdle( CallbackBase* callback )
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
{
// Actually quit the application.
// Force a call to Quit even if adaptor is not running.
- Internal::Adaptor::Adaptor::GetImplementation(*mAdaptor).AddIdle( MakeCallback( this, &Application::QuitFromMainLoop ), true );
+ Internal::Adaptor::Adaptor::GetImplementation(*mAdaptor).AddIdle( MakeCallback( this, &Application::QuitFromMainLoop ), false, true );
}
void Application::QuitFromMainLoop()
mResizeSignal.Emit( application );
}
-bool Application::AddIdle( CallbackBase* callback )
+bool Application::AddIdle( CallbackBase* callback, bool hasReturnValue )
{
- return mAdaptor->AddIdle( callback );
+ return mAdaptor->AddIdle( callback, hasReturnValue );
}
std::string Application::GetRegion() const
#define __DALI_INTERNAL_APPLICATION_H__
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
/**
* @copydoc Dali::Application::AddIdle()
*/
- bool AddIdle( CallbackBase* callback );
+ bool AddIdle( CallbackBase* callback, bool hasReturnValue );
/**
* @copydoc Dali::Application::GetAdaptor();
/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
/**
* Constructor
*/
- CallbackData( CallbackBase* callback )
- : mCallback(callback),
- mRemoveFromContainerFunction(NULL),
- mIdler(NULL)
+ CallbackData( CallbackBase* callback, bool hasReturnValue )
+ : mCallback( callback ),
+ mRemoveFromContainerFunction( NULL ),
+ mIdler( NULL ),
+ mIdleEnterer( NULL ),
+ mHasReturnValue( hasReturnValue )
{
}
/**
delete mRemoveFromContainerFunction;
}
- CallbackBase* mCallback; ///< call back
+ CallbackBase* mCallback; ///< call back
CallbackBase* mRemoveFromContainerFunction; ///< Called to remove the callbackdata from the callback container
- Ecore_Idler* mIdler; ///< ecore idler
- };
+ Ecore_Idler* mIdler; ///< ecore idler
+ Ecore_Idle_Enterer* mIdleEnterer; ///< ecore idle enterer
+ bool mHasReturnValue; ///< true if the callback function has a return value.
+};
namespace
{
*/
Eina_Bool IdleCallback(void *data)
{
+ Eina_Bool ret = ECORE_CALLBACK_CANCEL; // CALLBACK Cancel will delete the idler so we don't need to call ecore_idler_del
CallbackData *callbackData = static_cast< CallbackData * >( data );
- // remove callback data from the container
- CallbackBase::Execute( *callbackData->mRemoveFromContainerFunction, callbackData );
+ if( callbackData->mHasReturnValue )
+ {
+ // run the function
+ bool retValue = CallbackBase::ExecuteReturn< bool >( *callbackData->mCallback );
+ if( retValue )
+ {
+ // keep the callback
+ ret = ECORE_CALLBACK_RENEW;
+ }
+ else
+ {
+ // remove callback data from the container
+ CallbackBase::Execute( *callbackData->mRemoveFromContainerFunction, callbackData );
+
+ // delete our data
+ delete callbackData;
+ }
+ }
+ else
+ {
+ // remove callback data from the container
+ CallbackBase::Execute( *callbackData->mRemoveFromContainerFunction, callbackData );
- // run the function
- CallbackBase::Execute( *callbackData->mCallback );
+ // run the function
+ CallbackBase::Execute( *callbackData->mCallback );
- // delete our data
- delete callbackData;
+ // delete our data
+ delete callbackData;
+ }
- // CALLBACK Cancel will delete the idler so we don't need to call ecore_idler_del
- return ECORE_CALLBACK_CANCEL;
+ return ret;
}
} // unnamed namespace
}
-bool EcoreCallbackManager::AddIdleCallback( CallbackBase* callback )
+bool EcoreCallbackManager::AddIdleCallback( CallbackBase* callback, bool hasReturnValue )
{
if( !mRunning )
{
return false;
}
- CallbackData* callbackData = new CallbackData( callback );
+ CallbackData* callbackData = new CallbackData( callback, hasReturnValue );
callbackData->mRemoveFromContainerFunction = MakeCallback( this, &EcoreCallbackManager::RemoveCallbackFromContainer );
}
}
+bool EcoreCallbackManager::AddIdleEntererCallback( CallbackBase* callback )
+{
+ if( !mRunning )
+ {
+ return false;
+ }
+
+ CallbackData* callbackData = new CallbackData( callback, true );
+
+ callbackData->mRemoveFromContainerFunction = MakeCallback( this, &EcoreCallbackManager::RemoveCallbackFromContainer );
+
+ // add the call back to the container
+ mCallbackContainer.push_front( callbackData );
+
+ // add the idler
+ callbackData->mIdleEnterer = ecore_idle_enterer_add( IdleCallback, callbackData );
+
+ DALI_ASSERT_ALWAYS( ( callbackData->mIdleEnterer != NULL ) && "Idle method not created" );
+
+ return true;
+}
+
+void EcoreCallbackManager::RemoveIdleEntererCallback( CallbackBase* callback )
+{
+ for( CallbackList::iterator it = mCallbackContainer.begin(),
+ endIt = mCallbackContainer.end();
+ it != endIt;
+ ++it )
+ {
+ CallbackData* data = *it;
+
+ if( data->mCallback == callback )
+ {
+ // remove callback data from the container.
+ CallbackBase::Execute( *data->mRemoveFromContainerFunction, data );
+
+ ecore_idle_enterer_del( data->mIdleEnterer );
+ }
+ }
+}
+
void EcoreCallbackManager::RemoveCallbackFromContainer(CallbackData *callbackData)
{
mCallbackContainer.remove(callbackData);
{
CallbackData* data = (*iter);
- ecore_idler_del( data->mIdler );
+ if( data->mIdler )
+ {
+ ecore_idler_del( data->mIdler );
+ }
+ else if( data->mIdleEnterer )
+ {
+ ecore_idle_enterer_del( data->mIdleEnterer );
+ }
delete data;
-
}
mCallbackContainer.clear();
}
#define __DALI_ECORE_CALLBACK_MANAGER_H__
/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
/**
* @copydoc CallbackManager::AddIdleCallback()
*/
- virtual bool AddIdleCallback( CallbackBase* callback );
+ virtual bool AddIdleCallback( CallbackBase* callback, bool hasReturnValue );
/**
* @copydoc CallbackManager::RemoveIdleCallback()
virtual void RemoveIdleCallback( CallbackBase* callback );
/**
+ * @copydoc CallbackManager::AddIdleEntererCallback()
+ */
+ virtual bool AddIdleEntererCallback( CallbackBase* callback );
+
+ /**
+ * @copydoc CallbackManager::RemoveIdleEntererCallback()
+ */
+ virtual void RemoveIdleEntererCallback( CallbackBase* callback );
+
+ /**
* @copydoc CallbackManager::Start()
*/
virtual void Start();
* @brief Adds a @p callback to be run on idle.
* @note Must be called from the main thread only.
*
+ * Callbacks of the following types may be used:
+ * @code
+ * void MyFunction();
+ * @endcode
+ * This callback will be deleted once it is called.
+ *
+ * @code
+ * bool MyFunction();
+ * @endcode
+ * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
+ *
* @param[in] callback custom callback function.
+ * @param[in] hasReturnValue Sould be set to true if the callback function has a return value.
*
* @return true on success
*/
- virtual bool AddIdleCallback( CallbackBase* callback ) = 0;
+ virtual bool AddIdleCallback( CallbackBase* callback, bool hasReturnValue ) = 0;
/**
* @brief Removes a previously added @p callback.
virtual void RemoveIdleCallback( CallbackBase* callback ) = 0;
/**
+ * @brief Adds a @p callback to be run when entering an idle state.
+ * @note Must be called from the main thread only.
+ *
+ * A callback of the following type should be used:
+ * @code
+ * bool MyFunction();
+ * @endcode
+ * This callback will be called repeatedly as long as it returns true. A return of 0 deletes this callback.
+ *
+ * @param[in] callback custom callback function.
+ *
+ * @return true on success
+ */
+ virtual bool AddIdleEntererCallback( CallbackBase* callback ) = 0;
+
+ /**
+ * @brief Removes a previously added the idle enterer callback.
+ * @note Must be called from main thread only.
+ *
+ * Does nothing if the @p callback doesn't exist.
+ *
+ * @param[in] callback The callback to be removed.
+ */
+ virtual void RemoveIdleEntererCallback( CallbackBase* callback ) = 0;
+
+ /**
* Starts the callback manager.
*/
virtual void Start() = 0;
bool Application::AddIdle( CallbackBase* callback )
{
- return Internal::Adaptor::GetImplementation(*this).AddIdle( callback );
+ return Internal::Adaptor::GetImplementation(*this).AddIdle( callback, false );
}
Window Application::GetWindow()
* @code
* void MyFunction();
* @endcode
+ * This callback will be deleted once it is called.
*
* @note Ownership of the callback is passed onto this class.
*/