[ACR-564] deprecate unused API
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / EcoreMainloop.cs
old mode 100755 (executable)
new mode 100644 (file)
index 505e2c0..6f1be47
  */
 
 using System;
-using System.Collections.Generic;
+using System.Collections.Concurrent;
 
 namespace ElmSharp
 {
     /// <summary>
-    /// EcoreMainloop is a helper class, it provide functions relative Ecore's main loop.
+    /// EcoreMainloop is a helper class, which provides the functions relative to Ecore's main loop.
     /// </summary>
+    /// <since_tizen> preview </since_tizen>
+    [Obsolete("This has been deprecated in API12")]
     public static class EcoreMainloop
     {
-        static readonly Dictionary<int, Func<bool>> _taskMap = new Dictionary<int, Func<bool>>();
+
+        static readonly ConcurrentDictionary<int, Func<bool>> _taskMap = new ConcurrentDictionary<int, Func<bool>>();
         static readonly Object _taskLock = new Object();
         static int _newTaskId = 0;
 
@@ -40,20 +43,26 @@ namespace ElmSharp
         /// <summary>
         /// Checks if you are calling this function from the main thread.
         /// </summary>
-        /// <remarks>True is the calling function is the same thread, false otherwise.</remarks>
+        /// <remarks>True if the calling function is the same thread, false otherwise.</remarks>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public static bool IsMainThread => Interop.Eina.eina_main_loop_is();
 
         /// <summary>
         /// Runs the application main loop.
         /// </summary>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public static void Begin()
         {
             Interop.Ecore.ecore_main_loop_begin();
         }
 
         /// <summary>
-        /// Quits the main loop once all the events currently on the queue have been processed.
+        /// Quits the main loop, once all the events currently on the queue have been processed.
         /// </summary>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public static void Quit()
         {
             Interop.Ecore.ecore_main_loop_quit();
@@ -62,7 +71,9 @@ namespace ElmSharp
         /// <summary>
         /// Adds an idler handler.
         /// </summary>
-        /// <param name="task">The action to call when idling</param>
+        /// <param name="task">The action to call when idle.</param>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public static void Post(Action task)
         {
             int id = RegistHandler(() => { task(); return false; });
@@ -70,19 +81,30 @@ namespace ElmSharp
         }
 
         /// <summary>
-        /// Calls callback asynchronously in the main loop.
+        /// Calls the callback asynchronously in the main loop.
         /// </summary>
-        /// <param name="task">The action wanted to be called</param>
+        /// <param name="task">The action wanted to be called.</param>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public static void PostAndWakeUp(Action task)
         {
-            int id = RegistHandler(() => { task(); return false; });
-            Interop.Ecore.ecore_main_loop_thread_safe_call_async(_nativeHandler, (IntPtr)id);
+            if (IsMainThread)
+            {
+                Post(task);
+            }
+            else
+            {
+                int id = RegistHandler(() => { task(); return false; });
+                Interop.Ecore.ecore_main_loop_thread_safe_call_async(_nativeHandler, (IntPtr)id);
+            }
         }
 
         /// <summary>
-        /// Calls callback synchronously in the main loop.
+        /// Calls the callback synchronously in the main loop.
         /// </summary>
-        /// <param name="task">The action wanted to be called</param>
+        /// <param name="task">The action wanted to be called.</param>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public static void Send(Action task)
         {
             int id = RegistHandler(() => { task(); return false; });
@@ -94,7 +116,9 @@ namespace ElmSharp
         /// </summary>
         /// <param name="interval">The interval in seconds.</param>
         /// <param name="handler">The given function.</param>
-        /// <returns>A timer object handler on success, NULL on failure.</returns>
+        /// <returns>A timer object handler on success, or null on failure.</returns>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public static IntPtr AddTimer(double interval, Func<bool> handler)
         {
             int id = RegistHandler(handler);
@@ -105,10 +129,13 @@ namespace ElmSharp
         /// Removes the specified timer from the timer list.
         /// </summary>
         /// <param name="id">The specified timer handler</param>
+        /// <since_tizen> preview </since_tizen>
+        [Obsolete("This has been deprecated in API12")]
         public static void RemoveTimer(IntPtr id)
         {
             int taskId = (int)Interop.Ecore.ecore_timer_del(id);
-            _taskMap.Remove(taskId);
+            Func<bool> unused;
+            _taskMap.TryRemove(taskId, out unused);
         }
 
         static int RegistHandler(Func<bool> task)
@@ -131,11 +158,14 @@ namespace ElmSharp
                 bool result = false;
 
                 if (userAction != null)
+                {
                     result = userAction();
+                }
 
-                if (result == false)
-                    _taskMap.Remove(task_id);
-
+                if (!result)
+                {
+                    _taskMap.TryRemove(task_id, out userAction);
+                }
                 return result;
             }
             return false;