Add a constructor to SafeAppControlHandle for using pre-existing IntPtr object
authorWonYoung Choi <wy80.choi@samsung.com>
Tue, 12 Jul 2016 13:06:18 +0000 (22:06 +0900)
committerWonYoung Choi <wy80.choi@samsung.com>
Tue, 12 Jul 2016 13:06:18 +0000 (22:06 +0900)
Change-Id: I15dca9677d053eae2ca5ad5b9697c4d9601f8138

Tizen.Applications/Tizen.Applications.CoreBackend/ServiceCoreBackend.cs
Tizen.Applications/Tizen.Applications.CoreBackend/UICoreBackend.cs
Tizen.Applications/Tizen.Applications/AppControl.cs [changed mode: 0755->0644]
Tizen.Applications/Tizen.Applications/AppControlReceivedEventArgs.cs [changed mode: 0755->0644]
Tizen.Applications/Tizen.Applications/ReceivedAppControl.cs [changed mode: 0755->0644]
Tizen.Applications/Tizen.Applications/SafeAppControlHandle.cs [changed mode: 0755->0644]

index e514652..495d2fb 100644 (file)
@@ -62,8 +62,12 @@ namespace Tizen.Applications.CoreBackend
         {
             if (_handlers.ContainsKey(EventType.AppControlReceived))
             {
+                // Create a SafeAppControlHandle but the ownsHandle is false,
+                // because the appControlHandle will be closed by native appfw after this method automatically.
+                SafeAppControlHandle safeHandle = new SafeAppControlHandle(appControlHandle, false);
+
                 var handler = _handlers[EventType.AppControlReceived] as Action<AppControlReceivedEventArgs>;
-                handler.Invoke(new AppControlReceivedEventArgs { ReceivedAppControl = new ReceivedAppControl(appControlHandle) });
+                handler?.Invoke(new AppControlReceivedEventArgs(new ReceivedAppControl(safeHandle)));
             }
         }
 
index f6cf001..3899046 100644 (file)
@@ -70,8 +70,12 @@ namespace Tizen.Applications.CoreBackend
         {
             if (_handlers.ContainsKey(EventType.AppControlReceived))
             {
+                // Create a SafeAppControlHandle but the ownsHandle is false,
+                // because the appControlHandle will be closed by native appfw after this method automatically.
+                SafeAppControlHandle safeHandle = new SafeAppControlHandle(appControlHandle, false);
+
                 var handler = _handlers[EventType.AppControlReceived] as Action<AppControlReceivedEventArgs>;
-                handler.Invoke(new AppControlReceivedEventArgs { ReceivedAppControl = new ReceivedAppControl(appControlHandle) });
+                handler?.Invoke(new AppControlReceivedEventArgs(new ReceivedAppControl(safeHandle)));
             }
         }
 
old mode 100755 (executable)
new mode 100644 (file)
index c1a999c..d86fe64
@@ -67,10 +67,14 @@ namespace Tizen.Applications
         /// <param name="handle"></param>
         public AppControl(SafeAppControlHandle handle)
         {
-            _handle = handle;
+            Interop.AppControl.ErrorCode err = Interop.AppControl.DangerousClone(out _handle, handle.DangerousGetHandle());
+            if (err != Interop.AppControl.ErrorCode.None)
+            {
+                throw new InvalidOperationException("Failed to clone the appcontrol handle. Err = " + err);
+            }
         }
 
-        internal AppControl(IntPtr handle)
+        private AppControl(IntPtr handle)
         {
             Interop.AppControl.ErrorCode err = Interop.AppControl.DangerousClone(out _handle, handle);
             if (err != Interop.AppControl.ErrorCode.None)
old mode 100755 (executable)
new mode 100644 (file)
index 864477e..7bdc610
@@ -16,8 +16,17 @@ namespace Tizen.Applications
     public class AppControlReceivedEventArgs : EventArgs
     {
         /// <summary>
+        /// Initializes AppControlReceivedEventArgs class.
+        /// </summary>
+        /// <param name="appControl"></param>
+        public AppControlReceivedEventArgs(ReceivedAppControl appControl)
+        {
+            ReceivedAppControl = appControl;
+        }
+
+        /// <summary>
         /// The received AppControl.
         /// </summary>
-        public ReceivedAppControl ReceivedAppControl { get; internal set; }
+        public ReceivedAppControl ReceivedAppControl { get; private set; }
     }
 }
old mode 100755 (executable)
new mode 100644 (file)
index a77a053..bb7a80e
@@ -39,7 +39,10 @@ namespace Tizen.Applications
     {
         private const string LogTag = "Tizen.Applications";
 
-        internal ReceivedAppControl(IntPtr handle) : base(handle)
+        /// <summary>
+        /// Initializes a ReceivedAppControl class.
+        /// </summary>
+        public ReceivedAppControl(SafeAppControlHandle handle) : base(handle)
         {
         }
 
old mode 100755 (executable)
new mode 100644 (file)
index 24e163e..1740190
@@ -16,6 +16,16 @@ namespace Tizen.Applications
         }
 
         /// <summary>
+        /// Initializes a new instance of the SafeAppControlHandle class.
+        /// </summary>
+        /// <param name="existingHandle">An IntPtr object that represents the pre-existing handle to use.</param>
+        /// <param name="ownsHandle">true to reliably release the handle during the finalization phase; false to prevent reliable release.</param>
+        public SafeAppControlHandle(IntPtr existingHandle, bool ownsHandle) : base(IntPtr.Zero, ownsHandle)
+        {
+            SetHandle(existingHandle);
+        }
+
+        /// <summary>
         /// Gets a value that indicates whether the handle is invalid.
         /// </summary>
         public override bool IsInvalid