[Connection][WiFi] Use TizenSynchronizationContext.Post for asynchronous methods...
[platform/core/csapi/tizenfx.git] / src / Tizen.Network.Connection / Tizen.Network.Connection / ConnectionProfile.cs
index 87fc8a2..9ba3f3a 100755 (executable)
@@ -19,11 +19,12 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Runtime.InteropServices;
+using Tizen.Applications;
 
 namespace Tizen.Network.Connection
 {
     /// <summary>
-    /// This Class is ConnectionProfile. It provides event and propeties of the connection profile.
+    /// This is the ConnectionProfile class. It provides event and properties of the connection profile.
     /// </summary>
     /// <since_tizen> 3 </since_tizen>
     public class ConnectionProfile : IDisposable
@@ -32,42 +33,51 @@ namespace Tizen.Network.Connection
         private IAddressInformation IPv4;
         private IAddressInformation IPv6;
         private bool disposed = false;
-        private EventHandler _ProfileStateChanged = null;
+        private EventHandler<ProfileStateEventArgs> _ProfileStateChanged = null;
 
         private Interop.ConnectionProfile.ProfileStateChangedCallback _profileChangedCallback;
 
+        private TizenSynchronizationContext context = new TizenSynchronizationContext();
+
         internal IntPtr GetHandle()
         {
             return ProfileHandle;
         }
 
         /// <summary>
-        /// The event that is called when the state of profile is changed.
+        /// The event is called when the state of profile is changed.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
         /// <feature>http://tizen.org/feature/network.ethernet</feature>
         /// <feature>http://tizen.org/feature/network.telephony</feature>
         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
         /// <feature>http://tizen.org/feature/network.wifi</feature>
-        public event EventHandler ProfileStateChanged
+        /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
+        public event EventHandler<ProfileStateEventArgs> ProfileStateChanged
         {
             add
             {
                 Log.Debug(Globals.LogTag, "ProfileStateChanged add");
-                if (_ProfileStateChanged == null)
+                context.Post((x) =>
                 {
-                    ProfileStateChangedStart();
-                }
-                _ProfileStateChanged += value;
+                    if (_ProfileStateChanged == null)
+                    {
+                        ProfileStateChangedStart();
+                    }
+                    _ProfileStateChanged += value;
+                }, null);
             }
             remove
             {
                 Log.Debug(Globals.LogTag, "ProfileStateChanged remove");
-                _ProfileStateChanged -= value;
-                if (_ProfileStateChanged == null)
+                context.Post((x) =>
                 {
-                    ProfileStateChangedStop();
-                }
+                    _ProfileStateChanged -= value;
+                    if (_ProfileStateChanged == null)
+                    {
+                        ProfileStateChangedStop();
+                    }
+                }, null);
             }
         }
 
@@ -75,6 +85,7 @@ namespace Tizen.Network.Connection
         {
             _profileChangedCallback = (ProfileState state, IntPtr userData) =>
             {
+                Log.Info(Globals.LogTag, "***** MOON ProfileStateChanged occur");
                 if (_ProfileStateChanged != null)
                 {
                     _ProfileStateChanged(null, new ProfileStateEventArgs(state));
@@ -106,6 +117,9 @@ namespace Tizen.Network.Connection
             IPv6 = new ConnectionAddressInformation(ProfileHandle, AddressFamily.IPv6);
         }
 
+        /// <summary>
+        /// Destroy the ConnectionProfile object
+        /// </summary>
         ~ConnectionProfile()
         {
             Dispose(false);
@@ -127,12 +141,9 @@ namespace Tizen.Network.Connection
             if (disposed)
                 return;
 
-            if (disposing)
-            {
-                // Free managed objects.
-                UnregisterEvents();
-                Destroy();
-            }
+            // Free unmanaged objects
+            UnregisterEvents();
+            Destroy();
             disposed = true;
         }
 
@@ -223,7 +234,7 @@ namespace Tizen.Network.Connection
         /// The name of the network interface.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
-        /// <value>Network interface name, e.g. eth0 and pdp0.</value>
+        /// <value>Network interface name, for example, eth0 and pdp0.</value>
         public string InterfaceName
         {
             get
@@ -249,11 +260,11 @@ namespace Tizen.Network.Connection
         /// <feature>http://tizen.org/feature/network.telephony</feature>
         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
         /// <feature>http://tizen.org/feature/network.wifi</feature>
-        /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
-        /// <exception cref="System.UnauthorizedAccessException">Thrown when permission is denied.</exception>
-        /// <exception cref="System.ArgumentException">Thrown when value is invalid parameter.</exception>
-        /// <exception cref="System.InvalidOperationException">Thrown when profile instance is invalid or when method failed due to invalid operation</exception>
-        /// <exception cref="System.ObjectDisposedException">Thrown when operation is performed on a disposed object.</exception>
+        /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
+        /// <exception cref="System.UnauthorizedAccessException">Thrown when permission is denied.</exception>
+        /// <exception cref="System.ArgumentException">Thrown when a value is an invalid parameter.</exception>
+        /// <exception cref="System.InvalidOperationException">Thrown when a profile instance is invalid or when a method fails due to an invalid operation.</exception>
+        /// <exception cref="System.ObjectDisposedException">Thrown when an operation is performed on a disposed object.</exception>
         public void Refresh()
         {
             CheckDisposed();
@@ -269,19 +280,19 @@ namespace Tizen.Network.Connection
         }
 
         /// <summary>
-        /// Get the network state.
+        /// Gets the network state.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
-        /// <param name="family">The address family</param>
+        /// <param name="family">The address family.</param>
         /// <returns>The network state.</returns>
         /// <feature>http://tizen.org/feature/network.ethernet</feature>
         /// <feature>http://tizen.org/feature/network.telephony</feature>
         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
         /// <feature>http://tizen.org/feature/network.wifi</feature>
-        /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
-        /// <exception cref="System.ArgumentException">Thrown when value is invalid parameter.</exception>
-        /// <exception cref="System.InvalidOperationException">Thrown when profile instance is invalid or when method failed due to invalid operation</exception>
-        /// <exception cref="System.ObjectDisposedException">Thrown when operation is performed on a disposed object.</exception>
+        /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
+        /// <exception cref="System.ArgumentException">Thrown when a value is an invalid parameter.</exception>
+        /// <exception cref="System.InvalidOperationException">Thrown when a profile instance is invalid or when a method fails due to an invalid operation.</exception>
+        /// <exception cref="System.ObjectDisposedException">Thrown when an operation is performed on a disposed object.</exception>
         public ProfileState GetState(AddressFamily family)
         {
             CheckDisposed();
@@ -313,10 +324,10 @@ namespace Tizen.Network.Connection
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
         /// <value>Proxy type of the connection.</value>
-        /// <exception cref="System.NotSupportedException">Thrown during set when feature is not supported.</exception>
-        /// <exception cref="System.ArgumentException">Thrown during set when value is invalid parameter.</exception>
-        /// <exception cref="System.InvalidOperationException">Thrown during set when profile instance is invalid or when method failed due to invalid operation.</exception>
-        /// <exception cref="System.ObjectDisposedException">Thrown during set when operation is performed on a disposed object.</exception>
+        /// <exception cref="System.NotSupportedException">Thrown during set when feature is not supported.</exception>
+        /// <exception cref="System.ArgumentException">Thrown during set when a value is an invalid parameter.</exception>
+        /// <exception cref="System.InvalidOperationException">Thrown during set when a profile instance is invalid or when a method fails due to an invalid operation.</exception>
+        /// <exception cref="System.ObjectDisposedException">Thrown during set when operation is performed on a disposed object.</exception>
         public ProxyType ProxyType
         {
             get
@@ -350,11 +361,11 @@ namespace Tizen.Network.Connection
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
         /// <value>Proxy address of the connection.</value>
-        /// <exception cref="System.NotSupportedException">Thrown during set when feature is not supported.</exception>
-        /// <exception cref="System.ArgumentException">Thrown during set when value is invalid parameter.</exception>
-        /// <exception cref="System.ArgumentNullException">Thrown during set when value is null.</exception>
-        /// <exception cref="System.InvalidOperationException">Thrown during set when profile instance is invalid or when method failed due to invalid operation.</exception>
-        /// <exception cref="System.ObjectDisposedException">Thrown when operation is performed on a disposed object.</exception>
+        /// <exception cref="System.NotSupportedException">Thrown during set when feature is not supported.</exception>
+        /// <exception cref="System.ArgumentException">Thrown during set when a value is an invalid parameter.</exception>
+        /// <exception cref="System.ArgumentNullException">Thrown during set when value is null.</exception>
+        /// <exception cref="System.InvalidOperationException">Thrown during set when a profile instance is invalid or when a method fails due to an invalid operation.</exception>
+        /// <exception cref="System.ObjectDisposedException">Thrown when an operation is performed on a disposed object.</exception>
         public string ProxyAddress
         {
             get
@@ -394,7 +405,7 @@ namespace Tizen.Network.Connection
         }
 
         /// <summary>
-        /// The address information (IPv4)
+        /// The address information (IPv4).
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
         /// <value>Instance of IAddressInformation with IPV4 address.</value>
@@ -408,7 +419,7 @@ namespace Tizen.Network.Connection
         }
 
         /// <summary>
-        /// The address information (IPv6)
+        /// The address information (IPv6).
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
         /// <value>Instance of IAddressInformation with IPV6 address.</value>
@@ -422,7 +433,7 @@ namespace Tizen.Network.Connection
     }
 
     /// <summary>
-    /// An extended EventArgs class which contains changed profile state.
+    /// An extended EventArgs class, which contains changed profile state.
     /// </summary>
     /// <since_tizen> 3 </since_tizen>
     public class ProfileStateEventArgs : EventArgs