Use existing callback ID for recurring callbacks 22/247522/2
authorCheng-Shiun Tsai <cheng.tsai@samsung.com>
Wed, 11 Nov 2020 12:59:23 +0000 (12:59 +0000)
committerTsai <cheng.tsai@samsung.com>
Wed, 11 Nov 2020 13:10:19 +0000 (13:10 +0000)
Owner of callback object keep track of callback id,
this id is used in RemoveIdle();

The current Impl::OnIdle() will fire callbacks, if it's recurring callback object,
assigned a new id without telling the owner
Therefore when the owner needs to RemoveIdle() the owner gives out-of-dated id.

Changing the code to reuse callback id in recurring callback case to be consistent with the owner.

Change-Id: I9e891f271825dde1228be3298a85110059e4bceb

dali/internal/adaptor/android/framework-android.cpp

index f91f596..3212f4d 100644 (file)
@@ -180,7 +180,7 @@ struct Framework::Impl
         {
           if ( callback() ) // keep the callback
           {
-            AddIdle( callback.timeout, callback.data, callback.callback );
+            AddIdle( callback.timeout, callback.data, callback.callback, callback.id );
           }
         }
 
@@ -199,21 +199,30 @@ struct Framework::Impl
     }
   }
 
-  unsigned int AddIdle( int timeout, void* data, bool ( *callback )( void *data ) )
+  unsigned int AddIdle( int timeout, void* data, bool ( *callback )( void *data ) , unsigned int existingId = 0 )
   {
-    ++mIdleId;
-    if( mIdleId == 0 )
+    unsigned int chosenId;
+    if (existingId)
+    {
+      chosenId = existingId;
+    }
+    else
     {
       ++mIdleId;
+      if( mIdleId == 0 )
+      {
+        ++mIdleId;
+      }
+      chosenId = mIdleId;
     }
 
-    mIdleCallbacks.push( IdleCallback( timeout, mIdleId, data, callback ) );
+    mIdleCallbacks.push( IdleCallback( timeout, chosenId, data, callback ) );
 
     // To wake up the idle pipe and to trigger OnIdle
     int8_t msg = 1;
     write( mIdleWritePipe, &msg, sizeof( msg ) );
 
-    return mIdleId;
+    return chosenId;
   }
 
   void RemoveIdle( unsigned int id )