Merge "ApplicationManager : Remove redundant code using inheritance" into devel
authorSeungkeun Lee <sngn.lee@samsung.com>
Mon, 11 Apr 2016 01:13:01 +0000 (10:13 +0900)
committerGerrit Code Review <gerrit@s001>
Mon, 11 Apr 2016 01:13:01 +0000 (10:13 +0900)
Tizen.Applications/Interop/Interop.AppControl.cs
Tizen.Applications/Tizen.Applications.csproj
Tizen.Applications/Tizen.Applications/AppControl.cs
Tizen.Applications/Tizen.Applications/AppControlReplyCallback.cs
Tizen.Applications/Tizen.Applications/AppControlReplyResult.cs [moved from Tizen.Applications/Tizen.Applications/AppControlLaunchResult.cs with 78% similarity]
Tizen.Applications/Tizen.Applications/Bundle.cs
Tizen.Applications/Tizen.Applications/ReceivedAppControl.cs

index de97b74..fb032a5 100755 (executable)
@@ -13,6 +13,8 @@ internal static partial class Interop
 {
     internal static partial class AppControl
     {
+        internal const int AppStartedStatus = 1;
+
         internal delegate bool ExtraDataCallback(SafeAppControlHandle handle, string key, IntPtr userData);
         internal delegate bool AppMatchedCallback(SafeAppControlHandle handle, string applicationId, IntPtr userData);
         internal delegate void ReplyCallback(IntPtr request, IntPtr reply, int result, IntPtr userData);
index ac5167c..b8e4c39 100755 (executable)
@@ -84,7 +84,7 @@
     <Compile Include="Tizen.Applications.Managers\RunningApplication.cs" />
     <Compile Include="Tizen.Applications\AppControl.cs" />
     <Compile Include="Tizen.Applications\AppControlLaunchMode.cs" />
-    <Compile Include="Tizen.Applications\AppControlLaunchResult.cs" />
+    <Compile Include="Tizen.Applications\AppControlReplyResult.cs" />
     <Compile Include="Tizen.Applications\AppControlOperations.cs" />
     <Compile Include="Tizen.Applications\Application.cs" />
     <Compile Include="Tizen.Applications\Bundle.cs" />
   <Target Name="AfterBuild">
   </Target>
   -->
-</Project>
\ No newline at end of file
+</Project>
index 19da7b7..12e9c6a 100755 (executable)
@@ -31,6 +31,9 @@ namespace Tizen.Applications
 
         private ExtraDataCollection _extraData = null;
 
+        static private Dictionary<int, Interop.AppControl.ReplyCallback>  _replyNativeCallbackMaps = new Dictionary<int, Interop.AppControl.ReplyCallback>();
+        static private int _replyNativeCallbackId = 0;
+
         /// <summary>
         ///
         /// </summary>
@@ -281,10 +284,10 @@ namespace Tizen.Applications
         }
 
         /// <summary>
-        ///
+        /// 
         /// </summary>
-        /// <param name="receiver"></param>
-        /// <param name="replyCallback"></param>
+        /// <param name="launchRequest"></param>
+        /// <param name="replyAfterLaunching"></param>
         public static void SendLaunchRequest(AppControl launchRequest, AppControlReplyCallback replyAfterLaunching = null)
         {
             Interop.AppControl.ErrorCode err;
@@ -295,13 +298,30 @@ namespace Tizen.Applications
 
             if (replyAfterLaunching != null)
             {
-                Interop.AppControl.ReplyCallback replyNativeCallback = (launchRequestHandle, replyRequestHandle, result, userData) =>
+                int id = 0;
+                lock (_replyNativeCallbackMaps)
                 {
-                    AppControlReplyCallback replyCallbackAfterLaunching = Marshal.GetObjectForIUnknown(userData) as AppControlReplyCallback;
-                    if (replyCallbackAfterLaunching != null)
-                        replyCallbackAfterLaunching(new AppControl(launchRequestHandle), new AppControl(replyRequestHandle), (AppControlLaunchResult)result);
-                };
-                err = Interop.AppControl.SendLaunchRequest(launchRequest._handle, replyNativeCallback, Marshal.GetIUnknownForObject(replyAfterLaunching));
+                    id = _replyNativeCallbackId++;
+                    _replyNativeCallbackMaps[id] = (launchRequestHandle, replyRequestHandle, result, userData) =>
+                    {
+                        if (result == Interop.AppControl.AppStartedStatus)
+                        {
+                            Log.Debug(LogTag, "Callee App is started");
+                            return;
+                        }
+
+                        if (replyAfterLaunching != null)
+                        {
+                            Log.Debug(LogTag, "Reply Callback is launched");
+                            replyAfterLaunching(new AppControl(launchRequestHandle), new AppControl(replyRequestHandle), (AppControlReplyResult)result);
+                            lock (_replyNativeCallbackMaps)
+                            {
+                                _replyNativeCallbackMaps.Remove(id);
+                            }
+                        }
+                    };
+                }
+                err = Interop.AppControl.SendLaunchRequest(launchRequest._handle, _replyNativeCallbackMaps[id], IntPtr.Zero);
             }
             else
             {
index 5ab2139..7eb88e3 100755 (executable)
@@ -15,5 +15,5 @@ using System.Threading.Tasks;
 
 namespace Tizen.Applications
 {
-    public delegate void AppControlReplyCallback(AppControl launchRequest, AppControl replyRequest, AppControlLaunchResult result);
+    public delegate void AppControlReplyCallback(AppControl launchRequest, AppControl replyRequest, AppControlReplyResult result);
 }
@@ -9,14 +9,9 @@ namespace Tizen.Applications
     /// <summary>
     /// Enumeration for App Control Result.
     /// </summary>
-    public enum AppControlLaunchResult
+    public enum AppControlReplyResult
     {
         /// <summary>
-        /// Callee application is launched actually.
-        /// </summary>
-        AppStarted = 1,
-
-        /// <summary>
         /// Operation is succeeded
         /// </summary>
         Succeeded = 0,
index 4a3a614..b6a5adc 100755 (executable)
@@ -10,6 +10,7 @@ using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Runtime.InteropServices;
+using Tizen.Internals.Errors;
 
 namespace Tizen.Applications
 {
@@ -18,6 +19,7 @@ namespace Tizen.Applications
     /// A bundle holds items (key-value pairs) and can be used with other Tizen APIs.
     /// Keys can be used to access values.
     /// This class is accessed by using a constructor to create a new instance of this object.
+    /// A bundle instance is not guaranteed to be thread safe if the instance is modified by multiple threads.
     /// </summary>
     public class Bundle : IDisposable
     {
@@ -31,7 +33,7 @@ namespace Tizen.Applications
         public Bundle()
         {
             _handle = Interop.Bundle.Create();
-            BundleErrorFactory.CheckAndThrowException(Internals.Errors.ErrorFacts.GetLastResult(), _handle);
+            BundleErrorFactory.CheckAndThrowException(ErrorFacts.GetLastResult(), _handle);
             _keys = new HashSet<string>();
         }
 
@@ -55,7 +57,7 @@ namespace Tizen.Applications
                 };
 
                 Interop.Bundle.Foreach(_handle, iterator, IntPtr.Zero);
-                if ((BundleErrorFactory.BundleError)Internals.Errors.ErrorFacts.GetLastResult() == BundleErrorFactory.BundleError.InvalidParameter)
+                if ((BundleErrorFactory.BundleError)ErrorFacts.GetLastResult() == BundleErrorFactory.BundleError.InvalidParameter)
                 {
                     throw new ArgumentException("Invalid parameter - cannot create bundle instance");
                 }
@@ -229,7 +231,7 @@ namespace Tizen.Applications
             if (_keys.Contains(key))
             {
                 int type = Interop.Bundle.GetType(_handle, key);
-                BundleErrorFactory.CheckAndThrowException(Internals.Errors.ErrorFacts.GetLastResult(), _handle);
+                BundleErrorFactory.CheckAndThrowException(ErrorFacts.GetLastResult(), _handle);
                 switch (type)
                 {
                     case (int)BundleType.String:
@@ -243,7 +245,7 @@ namespace Tizen.Applications
                         // get string array
                         int stringArraySize;
                         IntPtr stringArrayPtr = Interop.Bundle.GetStringArray(_handle, key, out stringArraySize);
-                        BundleErrorFactory.CheckAndThrowException(Internals.Errors.ErrorFacts.GetLastResult(), _handle);
+                        BundleErrorFactory.CheckAndThrowException(ErrorFacts.GetLastResult(), _handle);
                         string[] stringArray;
                         IntPtrToStringArray(stringArrayPtr, stringArraySize, out stringArray);
                         return stringArray;
@@ -295,7 +297,7 @@ namespace Tizen.Applications
             }
             else
             {
-                if (_keys.Contains(key) && Internals.Errors.ErrorFacts.GetLastResult() == (int)BundleErrorFactory.BundleError.InvalidParameter)
+                if (_keys.Contains(key) && ErrorFacts.GetLastResult() == (int)BundleErrorFactory.BundleError.InvalidParameter)
                 {
                     throw new InvalidOperationException("Invalid bundle instance (object may have been disposed or released)");
                 }
@@ -319,7 +321,7 @@ namespace Tizen.Applications
             }
             else
             {
-                if (_keys.Contains(key) && Internals.Errors.ErrorFacts.GetLastResult() == (int)BundleErrorFactory.BundleError.InvalidParameter)
+                if (_keys.Contains(key) && ErrorFacts.GetLastResult() == (int)BundleErrorFactory.BundleError.InvalidParameter)
                 {
                     throw new InvalidOperationException("Invalid bundle instance (object may have been disposed or released)");
                 }
@@ -343,7 +345,7 @@ namespace Tizen.Applications
             }
             else
             {
-                if (_keys.Contains(key) && Internals.Errors.ErrorFacts.GetLastResult() == (int)BundleErrorFactory.BundleError.InvalidParameter)
+                if (_keys.Contains(key) && ErrorFacts.GetLastResult() == (int)BundleErrorFactory.BundleError.InvalidParameter)
                 {
                     throw new InvalidOperationException("Invalid bundle instance (object may have been disposed or released)");
                 }
@@ -453,10 +455,10 @@ namespace Tizen.Applications
     {
         internal enum BundleError
         {
-            None = Internals.Errors.ErrorCode.None,
-            OutOfMemory = Internals.Errors.ErrorCode.OutOfMemory,
-            InvalidParameter = Internals.Errors.ErrorCode.InvalidParameter,
-            KeyNotAvailable = Internals.Errors.ErrorCode.KeyNotAvailable,
+            None = ErrorCode.None,
+            OutOfMemory = ErrorCode.OutOfMemory,
+            InvalidParameter = ErrorCode.InvalidParameter,
+            KeyNotAvailable = ErrorCode.KeyNotAvailable,
             KeyExists = -0x01180000 | 0x01
         }
 
index 4250cc9..a394fa2 100755 (executable)
@@ -58,7 +58,7 @@ namespace Tizen.Applications
         /// <param name="replyRequest"></param>
         /// <param name="launchRequest"></param>
         /// <param name="result"></param>
-        public void ReplyToLaunchRequest(AppControl replyRequest, AppControlLaunchResult result)
+        public void ReplyToLaunchRequest(AppControl replyRequest, AppControlReplyResult result)
         {
             Interop.AppControl.ErrorCode err = Interop.AppControl.ReplyToLaunchRequest(replyRequest._handle, this._handle, (int)result);
             if (err == Interop.AppControl.ErrorCode.InvalidParameter)