Idle callback boost removal and tidy up 14/42614/1
authorNick Holland <nick.holland@partner.samsung.com>
Tue, 30 Jun 2015 14:37:04 +0000 (15:37 +0100)
committerNick Holland <nick.holland@partner.samsung.com>
Tue, 30 Jun 2015 14:37:04 +0000 (15:37 +0100)
Change-Id: Ib31b8be4838226030d6dcaba1661898c4cd43e0e

12 files changed:
adaptors/base/interfaces/adaptor-internal-services.h
adaptors/base/update-render-synchronization.cpp
adaptors/common/adaptor-impl.cpp
adaptors/common/adaptor-impl.h
adaptors/common/callback-manager.h
adaptors/common/ecore-callback-manager.cpp
adaptors/common/ecore-callback-manager.h
adaptors/common/trigger-event.h
adaptors/integration-api/adaptor.h
adaptors/integration-api/trigger-event-factory-interface.h
adaptors/integration-api/trigger-event-interface.h
adaptors/public-api/adaptor-framework/application.h

index 109c41a..be085aa 100644 (file)
@@ -74,9 +74,10 @@ public:
   virtual EglFactoryInterface& GetEGLFactoryInterface() const  = 0;
 
   /**
-   * @return trigger event
+   * Used by update-thread to notify core (main-thread) it has messages to process
+   * @return trigger event ProcessCoreEvents
    */
-  virtual TriggerEventInterface& GetTriggerEventInterface()  = 0;
+  virtual TriggerEventInterface& GetProcessCoreEventsTrigger()  = 0;
 
   /**
    * @return trigger event factory interface
index 702b917..dbff252 100644 (file)
@@ -56,7 +56,7 @@ UpdateRenderSynchronization::UpdateRenderSynchronization( AdaptorInternalService
   mSyncSeconds( 0u ),
   mSyncMicroseconds( 0u ),
   mFrameTime( adaptorInterfaces.GetPlatformAbstractionInterface() ),
-  mNotificationTrigger( adaptorInterfaces.GetTriggerEventInterface() ),
+  mNotificationTrigger( adaptorInterfaces.GetProcessCoreEventsTrigger() ),
   mPerformanceInterface( adaptorInterfaces.GetPerformanceInterface() ),
   mReplaceSurfaceRequest(),
   mReplaceSurfaceRequested( false )
index fe957ae..9df9d70 100644 (file)
@@ -35,7 +35,6 @@
 #include <dali/devel-api/text-abstraction/font-client.h>
 
 #include <callback-manager.h>
-#include <trigger-event.h>
 #include <render-surface.h>
 #include <tts-player-impl.h>
 #include <accessibility-adaptor-impl.h>
@@ -147,7 +146,7 @@ void Adaptor::Initialize( Dali::Configuration::ContextLoss configuration )
     mObjectProfiler = new ObjectProfiler( timeInterval );
   }
 
-  mNotificationTrigger = new TriggerEvent( MakeCallback( this, &Adaptor::ProcessCoreEvents ) );
+  mNotificationTrigger = mTriggerEventFactory.CreateTriggerEvent( MakeCallback( this, &Adaptor::ProcessCoreEvents ), TriggerEventInterface::KEEP_ALIVE_AFTER_TRIGGER);
 
   mVSyncMonitor = new VSyncMonitor;
 
@@ -477,24 +476,12 @@ bool Adaptor::AddIdle( CallbackBase* callback )
   // Only add an idle if the Adaptor is actually running
   if( RUNNING == mState )
   {
-    idleAdded = mCallbackManager->AddCallback( callback, CallbackManager::IDLE_PRIORITY );
+    idleAdded = mCallbackManager->AddIdleCallback( callback );
   }
 
   return idleAdded;
 }
 
-bool Adaptor::CallFromMainLoop( CallbackBase* callback )
-{
-  bool callAdded(false);
-
-  // Only allow the callback if the Adaptor is actually running
-  if ( RUNNING == mState )
-  {
-    callAdded = mCallbackManager->AddCallback( callback, CallbackManager::DEFAULT_PRIORITY );
-  }
-
-  return callAdded;
-}
 
 Dali::Adaptor& Adaptor::Get()
 {
@@ -549,7 +536,7 @@ Dali::Integration::GlAbstraction& Adaptor::GetGlesInterface()
   return *mGLES;
 }
 
-TriggerEventInterface& Adaptor::GetTriggerEventInterface()
+TriggerEventInterface& Adaptor::GetProcessCoreEventsTrigger()
 {
   return *mNotificationTrigger;
 }
index 8bf062b..9bebb38 100644 (file)
@@ -205,11 +205,6 @@ public: // AdaptorInternalServices implementation
    */
   virtual bool AddIdle( CallbackBase* callback );
 
-  /**
-   * @copydoc Internal::Framework::CallFromMainLoop()
-   */
-  virtual bool CallFromMainLoop( CallbackBase* callback );
-
 public:
 
   /**
@@ -334,7 +329,7 @@ public:  //AdaptorInternalServices
   /**
    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventInterface()
    */
-  virtual TriggerEventInterface& GetTriggerEventInterface();
+  virtual TriggerEventInterface& GetProcessCoreEventsTrigger();
 
   /**
    * @copydoc Dali::Internal::Adaptor::AdaptorInternalServices::GetTriggerEventFactoryInterface()
@@ -532,7 +527,7 @@ private: // Data
   EventHandler*                         mEventHandler;                ///< event handler
   CallbackManager*                      mCallbackManager;             ///< Used to install callbacks
   bool                                  mNotificationOnIdleInstalled; ///< whether the idle handler is installed to send an notification event
-  TriggerEvent*                         mNotificationTrigger;         ///< Notification event trigger
+  TriggerEventInterface*                mNotificationTrigger;         ///< Notification event trigger
   GestureManager*                       mGestureManager;              ///< Gesture manager
   FeedbackPluginProxy*                  mDaliFeedbackPlugin;          ///< Used to access feedback support
   FeedbackController*                   mFeedbackController;          ///< Plays feedback effects for Dali-Toolkit UI Controls.
index f6f4cec..20f8798 100644 (file)
@@ -40,25 +40,6 @@ class CallbackManager
 public:
 
     /**
-     * Determines the priority of the call back
-     */
-    enum Priority
-    {
-      IDLE_PRIORITY,     ///< idle priority
-      DEFAULT_PRIORITY,  ///< priority of the callback will be the same as input handlers and timer callbacks.
-    };
-
-    /**
-     * Controls whether an event once processed by the handler is passed on to other
-     * handlers, or not.
-     */
-    enum EventControl
-    {
-      CALLBACK_PASS_ON,   ///< Pass the event on to any other handlers registered for this event
-      CALLBACK_DONE,      ///< Don't pass the event to any other handlers
-    };
-
-    /**
      * Create a new call back interface
      */
     static CallbackManager* New();
@@ -69,22 +50,13 @@ public:
     virtual ~CallbackManager() {}
 
     /**
-     * Adds a call back asynchronously.
-     * Can be called from any thread.
+     * Adds a call back to be run on idle.
+     * Must be call from main thread only.
      * @param callback custom call back function
      * @param priority call back priority
      * @return true on success
      */
-    virtual bool AddCallback( CallbackBase* callback, Priority priority ) = 0;
-
-    /**
-     * Adds a call back asynchronously to handle an event.
-     * E.g. to handle a CTRL-C event.
-     * Can be called from any thread.
-     * @param callback custom call back function
-     * @return true on success
-     */
-    virtual bool AddEventCallback( CallbackBase* callback, int type, EventControl control ) = 0;
+    virtual bool AddIdleCallback( CallbackBase* callback ) = 0;
 
     /**
      * Starts the callback manager.
index e5dc5d3..b6e5f3c 100644 (file)
@@ -40,31 +40,16 @@ namespace Adaptor
  */
 struct CallbackData
 {
-  /**
-   * the type of callback
-   */
-  enum CallbackType
-  {
-    STANDARD_CALLBACK,  ///< either an idle call back, or a default call back
-    EVENT_HANDLER       ///< event handler
-  };
 
   /**
    * Constructor
    */
-  CallbackData( CallbackBase* callback, CallbackType type )
+  CallbackData( CallbackBase* callback )
   :  mCallback(callback),
-     mType(type),
-     mIdler(NULL),
-     mPriority(CallbackManager::DEFAULT_PRIORITY),
-     mExecute(true),
-     mEventHandler(NULL),
-     mEvent(0),
-     mEventControl(CallbackManager::CALLBACK_PASS_ON),
-     mRemoveFromContainerFunction(NULL)
+     mRemoveFromContainerFunction(NULL),
+     mIdler(NULL)
   {
   }
-
   /**
    * Destructor
    */
@@ -74,22 +59,10 @@ struct CallbackData
     delete mRemoveFromContainerFunction;
   }
 
-  // Data
   CallbackBase*                   mCallback;      ///< call back
-  CallbackType                    mType;          ///< type of call back
-
-    // Data for idle / default call backs
-  Ecore_Idler*                    mIdler;         ///< ecore idler
-  CallbackManager::Priority       mPriority;      ///< Priority (idle or normal)
-  bool                            mExecute;       ///< whether to run the callback
-
-  // Data for event handlers
-  Ecore_Event_Handler*            mEventHandler;  ///< ecore handler
-  int                             mEvent;         ///< ecore event id
-  CallbackManager::EventControl   mEventControl;  ///< event control
-
   CallbackBase*                   mRemoveFromContainerFunction; ///< Called to remove the callbackdata from the callback container
-};
+  Ecore_Idler*                    mIdler;         ///< ecore idler
+ };
 
 namespace
 {
@@ -99,117 +72,21 @@ namespace
  */
 Eina_Bool IdleCallback(void *data)
 {
-  CallbackData *callbackData = static_cast<CallbackData *>(data);
+  CallbackData *callbackData = static_cast< CallbackData * >( data );
 
-  // remove callback data from the container first in case our callback tries to modify the container
+  // remove callback data from the container
   CallbackBase::Execute( *callbackData->mRemoveFromContainerFunction, callbackData );
 
   // run the function
   CallbackBase::Execute( *callbackData->mCallback );
 
-  // remove the idle call back
-  ecore_idler_del(callbackData->mIdler);
-
+  // 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;
 }
 
-/**
- * Ecore callback event handler, called from the main thread
- * @param data  user data
- * @param type event type, e.g. ECORE_EVENT_SIGNAL_EXIT
- * @param event pointer to ecore event
- */
-Eina_Bool EventHandler(void *data, int type, void *event)
-{
-  CallbackData* callbackData = static_cast<CallbackData*>(data);
-
-  // make sure the type is for the right event
-  DALI_ASSERT_ALWAYS( type == callbackData->mEvent && "Callback data does not match event" );
-
-  // remove callback data from the container first in case our callback tries to modify the container
-  CallbackBase::Execute( *callbackData->mRemoveFromContainerFunction, callbackData );
-
-  // run the call back
-  CallbackBase::Execute( *callbackData->mCallback );
-
-  Eina_Bool returnVal;
-
-  if (callbackData->mEventControl == CallbackManager::CALLBACK_PASS_ON)
-  {
-    returnVal = ECORE_CALLBACK_PASS_ON;
-  }
-  else
-  {
-    returnVal = ECORE_CALLBACK_DONE;
-  }
-
-  delete callbackData;
-
-  return returnVal;
-}
-
-/**
- * called from MainLoopCallback to process standard callbacks
- */
-void AddStandardCallback(CallbackData *callbackData)
-{
-  if (callbackData->mPriority == CallbackManager::IDLE_PRIORITY)
-  {
-    // run the call back on idle
-    callbackData->mIdler = ecore_idler_add(IdleCallback, callbackData);
-    DALI_ASSERT_ALWAYS( callbackData->mIdler != NULL && "Idle method not created" );
-  }
-  else
-  {
-    // run the call back now, then delete it from the container
-    if ( callbackData->mExecute )
-    {
-      CallbackBase::Execute( *callbackData->mCallback );
-    }
-    CallbackBase::Execute( *callbackData->mRemoveFromContainerFunction, callbackData );
-    delete callbackData;
-  }
-}
-
-/**
- * called from MainLoopCallback to add event callbacks
- */
-void AddEventCallback(CallbackData *callbackData)
-{
-  callbackData->mEventHandler = ecore_event_handler_add(callbackData->mEvent, &EventHandler, callbackData);
-}
-
-/**
- * main loop call back to process call back data.
- */
-void MainLoopCallback(void *data)
-{
-  CallbackData *callbackData = static_cast< CallbackData* >(data);
-
-  if (callbackData->mType ==  CallbackData::STANDARD_CALLBACK)
-  {
-    AddStandardCallback(callbackData);
-  }
-  else if (callbackData->mType ==  CallbackData::EVENT_HANDLER)
-  {
-    AddEventCallback(callbackData);
-  }
-}
-
-/**
- * Main loop call back to remove all call back data
- */
-void* MainRemoveAllCallback(void* data)
-{
-  EcoreCallbackManager *callbackManager = static_cast<EcoreCallbackManager *>(data);
-
-  callbackManager->RemoveAllCallbacksFromMainThread();
-
-  return NULL;
-}
-
 } // unnamed namespace
 
 EcoreCallbackManager::EcoreCallbackManager()
@@ -217,33 +94,6 @@ EcoreCallbackManager::EcoreCallbackManager()
 {
 }
 
-void EcoreCallbackManager::RemoveStandardCallback(CallbackData *callbackData)
-{
-  if (callbackData->mPriority == CallbackManager::IDLE_PRIORITY)
-  {
-    // delete the idle call back
-    ecore_idler_del(callbackData->mIdler);
-    delete callbackData;
-  }
-  else
-  {
-    // ecore doesn't give us a handle for functions we want executing on the
-    // main thread, E.g. we can't do
-    // handle = ecore_main_loop_thread_safe_call_async( myfunc )
-    // ecore_main_loop_thread_remove_async_call(handle);  // doesn't exist
-    //
-    // We just have to set a flag to say do not execute.
-    // Hence we can't delete the call back at this point.
-    callbackData->mExecute = false;
-  }
-}
-
-void EcoreCallbackManager::RemoveEventCallback(CallbackData *callbackData)
-{
-  ecore_event_handler_del(callbackData->mEventHandler);
-
-  delete callbackData;
-}
 
 void EcoreCallbackManager::Start()
 {
@@ -257,99 +107,52 @@ void EcoreCallbackManager::Stop()
   // make sure we're not called twice
   DALI_ASSERT_DEBUG( mRunning == true );
 
-  // lock out any other call back functions
-  boost::unique_lock< boost::mutex > lock( mMutex );
+  RemoveAllCallbacks();
 
   mRunning = false;
 
-  // the synchronous calls return data from the callback, which we ignore.
-  ecore_main_loop_thread_safe_call_sync(MainRemoveAllCallback, this);
 }
 
-bool EcoreCallbackManager::AddCallback(CallbackBase* callback, Priority priority)
+bool EcoreCallbackManager::AddIdleCallback( CallbackBase* callback )
 {
-  bool added(false);
-
-  if ( mRunning )
+  if( !mRunning )
   {
-    CallbackData *callbackData = new CallbackData(callback, CallbackData::STANDARD_CALLBACK);
-
-    callbackData->mPriority = priority;
-
-    callbackData->mRemoveFromContainerFunction =  MakeCallback( this, &EcoreCallbackManager::RemoveCallbackFromContainer );
-
-    { // acquire lock to access container
-      boost::unique_lock< boost::mutex > lock( mMutex );
-
-      // add the call back to the container
-      mCallbackContainer.push_front(callbackData);
-    }
-
-    // Get callbackData processed on the main loop..
-
-    ecore_main_loop_thread_safe_call_async(MainLoopCallback, callbackData);
-
-    added = true;
+    return false;
   }
 
-  return added;
-}
+  CallbackData *callbackData = new CallbackData( callback );
 
-bool EcoreCallbackManager::AddEventCallback(CallbackBase* callback, int type, EventControl control)
-{
-  bool added(false);
+  callbackData->mRemoveFromContainerFunction =  MakeCallback( this, &EcoreCallbackManager::RemoveCallbackFromContainer );
 
-  if( mRunning )
-  {
-    CallbackData *callbackData = new CallbackData(callback,CallbackData::EVENT_HANDLER);
-    callbackData->mEventControl = control;
-    callbackData->mEvent = type;
-
-    callbackData->mRemoveFromContainerFunction =  MakeCallback( this, &EcoreCallbackManager::RemoveCallbackFromContainer );
-
-    { // acquire lock to access container
-      boost::unique_lock< boost::mutex > lock( mMutex );
+  // add the call back to the container
+  mCallbackContainer.push_front(callbackData);
 
-      // add the call back to the container
-      mCallbackContainer.push_front(callbackData);
-    }
+  // add the idler
+  callbackData->mIdler = ecore_idler_add( IdleCallback, callbackData);
 
-    // Get callbackData processed on the main loop..
-    ecore_main_loop_thread_safe_call_async(MainLoopCallback, callbackData);
+  DALI_ASSERT_ALWAYS( ( callbackData->mIdler != NULL ) && "Idle method not created" );
 
-    added = true;
-  }
-
-  return added;
+  return true;
 }
 
 void EcoreCallbackManager::RemoveCallbackFromContainer(CallbackData *callbackData)
 {
-  // always called from main loop
-  boost::unique_lock< boost::mutex > lock( mMutex );
-
   mCallbackContainer.remove(callbackData);
 }
 
-void EcoreCallbackManager::RemoveAllCallbacksFromMainThread()
+void EcoreCallbackManager::RemoveAllCallbacks()
 {
-   // always called from main thread
-   // the mutex will already be locked at this point
-
-   for( CallbackList::iterator  iter =  mCallbackContainer.begin(); iter != mCallbackContainer.end(); ++iter)
-   {
-     CallbackData* data = (*iter);
-
-     if (data->mType ==  CallbackData::STANDARD_CALLBACK)
-     {
-       RemoveStandardCallback(data);
-     }
-     else if (data->mType ==  CallbackData::EVENT_HANDLER)
-     {
-       RemoveEventCallback(data);
-     }
-   }
-   mCallbackContainer.clear();
+  // always called from main thread
+  for( CallbackList::iterator  iter =  mCallbackContainer.begin(); iter != mCallbackContainer.end(); ++iter)
+  {
+    CallbackData* data = (*iter);
+
+    ecore_idler_del( data->mIdler );
+
+    delete data;
+
+  }
+  mCallbackContainer.clear();
 }
 
 // Creates a concrete interface for CallbackManager
index 7e94941..9b961aa 100644 (file)
@@ -19,7 +19,6 @@
  */
 
 // EXTERNAL INCLUDES
-#include <boost/thread.hpp>
 #include <list>
 
 // INTERNAL INCLUDES
@@ -60,12 +59,7 @@ public:
     /**
      * @copydoc CallbackManager::AddCallback()
      */
-    virtual bool AddCallback(CallbackBase* callback, Priority priority);
-
-    /**
-     * @copydoc CallbackManager::AddEventCallback()
-     */
-    virtual bool AddEventCallback(CallbackBase* callback, int type, EventControl control);
+    virtual bool AddIdleCallback( CallbackBase* callback );
 
     /**
      * @copydoc CallbackManager::Start()
@@ -77,18 +71,14 @@ public:
      */
     virtual void Stop();
 
-    /**
-     * Remove all call backs
-     * Always called from the main thread
-     */
-    void RemoveAllCallbacksFromMainThread();
-
 private:
 
     /**
-     * Deletes any expired callbacks in the callback container
+     * Remove all idle call backs that are pending
+     * Called by Stop()
+     * Always called from the main thread
      */
-    void RefreshContainer();
+    void RemoveAllCallbacks();
 
     /**
      * Removes a single call back from the container
@@ -104,20 +94,11 @@ private:
      */
     void RemoveStandardCallback(CallbackData *callbackData);
 
-    /**
-     * Remove an event handler from ecore
-     * Always called from main thread
-     * @param callbackData callback data
-     */
-    void RemoveEventCallback(CallbackData *callbackData);
-
-
 
     typedef std::list<CallbackData *>  CallbackList;
 
     bool                           mRunning;            ///< flag is set to true if when running
-    CallbackList                   mCallbackContainer;  ///< container of live callbacks
-    boost::mutex                   mMutex;              ///< protect access to shared data
+    CallbackList                   mCallbackContainer;  ///< container of live idle callbacks
 };
 
 } // namespace Adaptor
index bd057ac..8de3d73 100644 (file)
@@ -59,7 +59,7 @@ public:
    * @param[in] options Trigger event options.
    * @note The ownership of callback is taken by this class.
    */
-  TriggerEvent( CallbackBase* callback, TriggerEventInterface::Options options = TriggerEventInterface::NONE );
+  TriggerEvent( CallbackBase* callback, TriggerEventInterface::Options options );
 
   /**
    * Destructor
index d5a1826..6558e40 100644 (file)
@@ -173,6 +173,7 @@ public:
 
   /**
    * @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:
    * @code
index be3cb3e..947f812 100644 (file)
@@ -44,7 +44,7 @@ public:
    * @note Ownership of callback should be taken over by deriving classes
    */
   virtual TriggerEventInterface* CreateTriggerEvent( CallbackBase* callback,
-                                                     TriggerEventInterface::Options options = TriggerEventInterface::NONE) = 0;
+                                                     TriggerEventInterface::Options options ) = 0;
   /**
    * @brief destroy a trigger event
    * @param triggerEventInterface event to destroy
index 7dd3287..c6c1eaa 100644 (file)
@@ -38,7 +38,7 @@ public:
    */
   enum Options
   {
-    NONE,
+    KEEP_ALIVE_AFTER_TRIGGER,
     DELETE_AFTER_TRIGGER,  // automatically delete the trigger event object, after Trigger() is called.
   };
 
index 22156f7..6258f23 100644 (file)
@@ -187,6 +187,7 @@ public:
 
   /**
    * Ensures that the function passed in is called from the main loop when it is idle.
+   * @note Function must be called from main event thread only
    *
    * A callback of the following type may be used:
    * @code