[NUI] Change all CallingConvention to `Cdecl`
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Utility / Timer.cs
index df48769..0bb293d 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright(c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright(c) 2021 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.
@@ -36,10 +36,10 @@ namespace Tizen.NUI
     public class Timer : BaseHandle
     {
         private bool played = false;
-        private EventHandlerWithReturnType<object, TickEventArgs, bool> _timerTickEventHandler;
-        private TickCallbackDelegate _timerTickCallbackDelegate;
+        private EventHandlerWithReturnType<object, TickEventArgs, bool> timerTickEventHandler;
+        private TickCallbackDelegate timerTickCallbackDelegate;
 
-        private System.IntPtr _timerTickCallbackOfNative;
+        private System.IntPtr timerTickCallbackOfNative;
 
         /// <summary>
         /// Creates a tick timer that emits periodic signal.
@@ -58,13 +58,12 @@ namespace Tizen.NUI
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
-        internal Timer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.Timer.Upcast(cPtr), cMemoryOwn)
+        internal Timer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
         {
+            timerTickCallbackDelegate = OnTick;
+            timerTickCallbackOfNative = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(timerTickCallbackDelegate);
 
-            _timerTickCallbackDelegate = OnTick;
-            _timerTickCallbackOfNative = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(_timerTickCallbackDelegate);
-
-            NUILog.Debug($"(0x{SwigCPtr.Handle:X})Timer() contructor!");
+            NUILog.Debug($"(0x{SwigCPtr.Handle:X})Timer() constructor!");
         }
 
         /// <summary>
@@ -72,10 +71,10 @@ namespace Tizen.NUI
         /// </summary>
         ~Timer()
         {
-            Tizen.Log.Debug("NUI",$"(0x{SwigCPtr.Handle:X})Timer() distructor!, disposed={disposed}");
+            Tizen.Log.Debug("NUI", $"(0x{SwigCPtr.Handle:X})Timer() destructor!, disposed={disposed}");
         }
 
-        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
         private delegate bool TickCallbackDelegate();
 
         /// <summary>
@@ -87,18 +86,18 @@ namespace Tizen.NUI
         {
             add
             {
-                if (_timerTickEventHandler == null && disposed == false)
+                if (timerTickEventHandler == null && disposed == false)
                 {
-                    TickSignal().Connect(_timerTickCallbackOfNative);
+                    TickSignal().Connect(timerTickCallbackOfNative);
                 }
-                _timerTickEventHandler += value;
+                timerTickEventHandler += value;
             }
             remove
             {
-                _timerTickEventHandler -= value;
-                if (_timerTickEventHandler == null && TickSignal().Empty() == false)
+                timerTickEventHandler -= value;
+                if (timerTickEventHandler == null && TickSignal().Empty() == false)
                 {
-                    TickSignal().Disconnect(_timerTickCallbackOfNative);
+                    TickSignal().Disconnect(timerTickCallbackOfNative);
                 }
             }
         }
@@ -163,7 +162,6 @@ namespace Tizen.NUI
             {
                 Tizen.Log.Error("NUI", "current threadID : " + Thread.CurrentThread.ManagedThreadId);
 
-
                 StackTrace st = new StackTrace(true);
                 for (int i = 0; i < st.FrameCount; i++)
                 {
@@ -214,11 +212,6 @@ namespace Tizen.NUI
             return ret;
         }
 
-        internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Timer obj)
-        {
-            return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
-        }
-
         /// <summary>
         /// Sets a new interval on the timer and starts the timer.<br />
         /// Cancels the previous timer.<br />
@@ -268,9 +261,9 @@ namespace Tizen.NUI
         {
             NUILog.Debug($"(0x{SwigCPtr.Handle:X}) Timer.Dispose(type={type}, disposed={disposed})");
 
-            if (this != null && _timerTickCallbackDelegate != null)
+            if (this != null && timerTickCallbackDelegate != null)
             {
-                TickSignal().Disconnect(_timerTickCallbackOfNative);
+                TickSignal().Disconnect(timerTickCallbackOfNative);
             }
 
             if (disposed)
@@ -296,13 +289,13 @@ namespace Tizen.NUI
             if (played == false)
             {
                 Tizen.Log.Fatal("NUI", $"(0x{SwigCPtr.Handle:X}) OnTick() is called even played is false!");
-                //throw new System.InvalidOperationException($"OnTick() excpetion!");
+                //throw new System.InvalidOperationException($"OnTick() exception!");
             }
 
-            if (_timerTickEventHandler != null && played == true)
+            if (timerTickEventHandler != null && played == true)
             {
                 //here we send all data to user event handlers
-                return _timerTickEventHandler(this, e);
+                return timerTickEventHandler(this, e);
             }
             return false;
         }
@@ -315,6 +308,4 @@ namespace Tizen.NUI
         {
         }
     }
-
 }
-