public HandleHolder()
{
_tid = Thread.CurrentThread.ManagedThreadId;
- Log.Info(Globals.LogTag, "PInvoke connection_destroy for Thread " + _tid);
+ Log.Info(Globals.LogTag, "PInvoke connection_create for Thread " + _tid);
int ret = Interop.Connection.Create(_tid, out Handle);
Log.Info(Globals.LogTag, "Handle: " + Handle);
if(ret != (int)ConnectionError.None)
add
{
context.Post((x) =>
- {
- if (_ConnectionTypeChanged == null)
- {
- ConnectionTypeChangedStart();
- }
- _ConnectionTypeChanged += value;
- }, null);
+ {
+ if (_ConnectionTypeChanged == null)
+ {
+ ConnectionTypeChangedStart();
+ }
+ _ConnectionTypeChanged += value;
+ }, null);
}
remove
{
context.Post((x) =>
- {
- _ConnectionTypeChanged -= value;
- if (_ConnectionTypeChanged == null)
- {
- ConnectionTypeChangedStop();
- }
- }, null);
+ {
+ _ConnectionTypeChanged -= value;
+ if (_ConnectionTypeChanged == null)
+ {
+ ConnectionTypeChangedStop();
+ }
+ }, null);
}
}
private void ConnectionTypeChangedStart()
{
+ Log.Info(Globals.LogTag, "Register ConnectionTypeChanged");
_connectionTypeChangedCallback = (ConnectionType type, IntPtr user_data) =>
{
if (_ConnectionTypeChanged != null)
private void ConnectionTypeChangedStop()
{
+ Log.Info(Globals.LogTag, "Unregister ConnectionTypeChanged");
int ret = Interop.Connection.UnsetTypeChangedCallback(GetHandle());
if ((ConnectionError)ret != ConnectionError.None)
{
add
{
context.Post((x) =>
- {
- if (_EthernetCableStateChanged == null)
- {
- EthernetCableStateChangedStart();
- }
- _EthernetCableStateChanged += value;
- }, null);
+ {
+ if (_EthernetCableStateChanged == null)
+ {
+ EthernetCableStateChangedStart();
+ }
+ _EthernetCableStateChanged += value;
+ }, null);
}
remove
{
context.Post((x) =>
- {
- _EthernetCableStateChanged -= value;
- if (_EthernetCableStateChanged == null)
- {
- EthernetCableStateChangedStop();
- }
- }, null);
+ {
+ _EthernetCableStateChanged -= value;
+ if (_EthernetCableStateChanged == null)
+ {
+ EthernetCableStateChangedStop();
+ }
+ }, null);
}
}
private void EthernetCableStateChangedStart()
{
+ Log.Info(Globals.LogTag, "Register EthernetCableStateChanged");
_ethernetCableStateChangedCallback = (EthernetCableState state, IntPtr user_data) =>
{
if (_EthernetCableStateChanged != null)
private void EthernetCableStateChangedStop()
{
+ Log.Info(Globals.LogTag, "Unregister EthernetCableStateChanged");
int ret = Interop.Connection.UnsetEthernetCableStateChagedCallback(GetHandle());
if ((ConnectionError)ret != ConnectionError.None)
{
add
{
context.Post((x) =>
- {
- if (_IPAddressChanged == null)
- {
- IPAddressChangedStart();
- }
- _IPAddressChanged += value;
- }, null);
+ {
+ if (_IPAddressChanged == null)
+ {
+ IPAddressChangedStart();
+ }
+ _IPAddressChanged += value;
+ }, null);
}
remove
{
context.Post((x) =>
- {
- _IPAddressChanged -= value;
- if (_IPAddressChanged == null)
- {
- IPAddressChangedStop();
- }
- }, null);
+ {
+ _IPAddressChanged -= value;
+ if (_IPAddressChanged == null)
+ {
+ IPAddressChangedStop();
+ }
+ }, null);
}
}
private void IPAddressChangedStart()
{
+ Log.Info(Globals.LogTag, "Register IPAddressChanged");
_connectionAddressChangedCallback = (IntPtr IPv4, IntPtr IPv6, IntPtr UserData) =>
{
if (_IPAddressChanged != null)
private void IPAddressChangedStop()
{
+ Log.Info(Globals.LogTag, "Unregister IPAddressChanged");
int ret = Interop.Connection.UnsetIPAddressChangedCallback(GetHandle());
if ((ConnectionError)ret != ConnectionError.None)
{
add
{
context.Post((x) =>
- {
- if (_ProxyAddressChanged == null)
- {
- ProxyAddressChangedStart();
- }
- _ProxyAddressChanged += value;
- }, null);
+ {
+ if (_ProxyAddressChanged == null)
+ {
+ ProxyAddressChangedStart();
+ }
+ _ProxyAddressChanged += value;
+ }, null);
}
remove
{
context.Post((x) =>
- {
- _ProxyAddressChanged -= value;
- if (_ProxyAddressChanged == null)
- {
- ProxyAddressChangedStop();
- }
- }, null);
+ {
+ _ProxyAddressChanged -= value;
+ if (_ProxyAddressChanged == null)
+ {
+ ProxyAddressChangedStop();
+ }
+ }, null);
}
}
private void ProxyAddressChangedStart()
{
+ Log.Info(Globals.LogTag, "Register ProxyAddressChanged");
_proxyAddressChangedCallback = (IntPtr IPv4, IntPtr IPv6, IntPtr UserData) =>
{
if (_ProxyAddressChanged != null)
private void ProxyAddressChangedStop()
{
+ Log.Info(Globals.LogTag, "Unregister ProxyAddressChanged");
int ret = Interop.Connection.UnsetProxyAddressChangedCallback(GetHandle());
if ((ConnectionError)ret != ConnectionError.None)
{
internal Task SetDefaultCellularProfile(CellularServiceType type, ConnectionProfile profile)
{
- Log.Debug(Globals.LogTag, "SetDefaultCellularProfile");
+ Log.Info(Globals.LogTag, "SetDefaultCellularProfile");
if (profile != null)
{
TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
Interop.Connection.ConnectionCallback Callback = (ConnectionError Result, IntPtr Data) =>
{
+ Log.Info(Globals.LogTag, "SetDefaultCellularProfile done " + profile.Name);
if (Result != ConnectionError.None)
{
Log.Error(Globals.LogTag, "Error occurs during set default cellular profile, " + Result);
}
};
- int ret = Interop.Connection.SetDefaultCellularServiceProfileAsync(GetHandle(), (int)type, profile.ProfileHandle, Callback, (IntPtr)0);
- if ((ConnectionError)ret != ConnectionError.None)
+ context.Post((x) =>
{
- Log.Error(Globals.LogTag, "It failed to set default cellular profile, " + (ConnectionError)ret);
- ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony");
- ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released");
- ConnectionErrorFactory.ThrowConnectionException(ret);
- }
+ Log.Info(Globals.LogTag, "Interop.Connection.SetDefaultCellularServiceProfileAsync " + profile.Name);
+ int ret = Interop.Connection.SetDefaultCellularServiceProfileAsync(GetHandle(), (int)type, profile.ProfileHandle, Callback, (IntPtr)0);
+ if ((ConnectionError)ret != ConnectionError.None)
+ {
+ Log.Error(Globals.LogTag, "It failed to set default cellular profile, " + (ConnectionError)ret);
+ ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony");
+ ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released");
+ ConnectionErrorFactory.ThrowConnectionException(ret);
+ }
+ }, null);
return task.Task;
}
-
else
{
throw new ArgumentNullException("Profile is null");
internal Task OpenProfileAsync(ConnectionProfile profile)
{
- Log.Debug(Globals.LogTag, "OpenProfileAsync");
+ Log.Info(Globals.LogTag, "OpenProfileAsync");
if (profile != null)
{
Log.Debug(Globals.LogTag, "OpenProfileAsync " + profile.Name);
TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
Interop.Connection.ConnectionCallback Callback = (ConnectionError Result, IntPtr Data) =>
{
- Log.Debug(Globals.LogTag, "Connected " + profile.Name);
+ Log.Info(Globals.LogTag, "OpenProfileAsync done " + profile.Name);
if (Result != ConnectionError.None)
{
Log.Error(Globals.LogTag, "Error occurs during connecting profile, " + Result);
}
};
- int ret = Interop.Connection.OpenProfile(GetHandle(), profile.ProfileHandle, Callback, IntPtr.Zero);
- if ((ConnectionError)ret != ConnectionError.None)
+ context.Post((x) =>
{
- Log.Error(Globals.LogTag, "It failed to connect profile, " + (ConnectionError)ret);
- ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth");
- ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released");
- ConnectionErrorFactory.ThrowConnectionException(ret);
- }
+ Log.Info(Globals.LogTag, "Interop.Connection.OpenProfile " + profile.Name);
+ int ret = Interop.Connection.OpenProfile(GetHandle(), profile.ProfileHandle, Callback, IntPtr.Zero);
+ if ((ConnectionError)ret != ConnectionError.None)
+ {
+ Log.Error(Globals.LogTag, "It failed to connect profile, " + (ConnectionError)ret);
+ ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth");
+ ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released");
+ ConnectionErrorFactory.ThrowConnectionException(ret);
+ }
+ }, null);
return task.Task;
}
internal Task CloseProfileAsync(ConnectionProfile profile)
{
- Log.Debug(Globals.LogTag, "CloseProfileAsync");
+ Log.Info(Globals.LogTag, "CloseProfileAsync");
if (profile != null)
{
- Log.Debug(Globals.LogTag, "CloseProfileAsync " + profile.Name);
+ Log.Info(Globals.LogTag, "CloseProfileAsync " + profile.Name);
TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
Interop.Connection.ConnectionCallback Callback = (ConnectionError Result, IntPtr Data) =>
{
+ Log.Info(Globals.LogTag, "CloseProfileAsync done " + profile.Name);
if (Result != ConnectionError.None)
{
Log.Error(Globals.LogTag, "Error occurs during disconnecting profile, " + Result);
}
};
- int ret = Interop.Connection.CloseProfile(GetHandle(), profile.ProfileHandle, Callback, IntPtr.Zero);
- if ((ConnectionError)ret != ConnectionError.None)
+ context.Post((x) =>
{
- Log.Error(Globals.LogTag, "It failed to disconnect profile, " + (ConnectionError)ret);
- ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth");
- ConnectionErrorFactory.CheckPermissionDeniedException(ret, "(http://tizen.org/privilege/network.set)");
- ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released");
- ConnectionErrorFactory.ThrowConnectionException(ret);
- }
+ Log.Info(Globals.LogTag, "Interop.Connection.CloseProfile " + profile.Name);
+ int ret = Interop.Connection.CloseProfile(GetHandle(), profile.ProfileHandle, Callback, IntPtr.Zero);
+ if ((ConnectionError)ret != ConnectionError.None)
+ {
+ Log.Error(Globals.LogTag, "It failed to disconnect profile, " + (ConnectionError)ret);
+ ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth");
+ ConnectionErrorFactory.CheckPermissionDeniedException(ret, "(http://tizen.org/privilege/network.set)");
+ ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released");
+ ConnectionErrorFactory.ThrowConnectionException(ret);
+ }
+ }, null);
return task.Task;
}
{
Log.Debug(Globals.LogTag, "ProfileStateChanged add");
context.Post((x) =>
- {
- if (_ProfileStateChanged == null)
- {
- ProfileStateChangedStart();
- }
- _ProfileStateChanged += value;
- }, null);
+ {
+ if (_ProfileStateChanged == null)
+ {
+ ProfileStateChangedStart();
+ }
+ _ProfileStateChanged += value;
+ }, null);
}
remove
{
Log.Debug(Globals.LogTag, "ProfileStateChanged remove");
context.Post((x) =>
- {
- _ProfileStateChanged -= value;
- if (_ProfileStateChanged == null)
- {
- ProfileStateChangedStop();
- }
- }, null);
+ {
+ _ProfileStateChanged -= value;
+ if (_ProfileStateChanged == null)
+ {
+ ProfileStateChangedStop();
+ }
+ }, null);
}
}
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
+using Tizen.Applications;
namespace Tizen.Network.WiFi
{
private WiFiSecurity _security;
private bool _disposed = false;
+ private TizenSynchronizationContext context = new TizenSynchronizationContext();
+ private static TizenSynchronizationContext s_context = new TizenSynchronizationContext();
+
/// <summary>
/// The network information of the access point (AP).
/// </summary>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
public Task ConnectAsync()
{
- Log.Debug(Globals.LogTag, "ConnectAsync");
+ Log.Info(Globals.LogTag, "ConnectAsync");
if (_disposed)
{
throw new ObjectDisposedException("Invalid AP instance (Object may have been disposed or released)");
id = (IntPtr)_requestId++;
_callback_map[id] = (error, key) =>
{
- Log.Debug(Globals.LogTag, "Connecting finished : " + (WiFiError)error);
+ Log.Info(Globals.LogTag, "ConnectAsync done " + (WiFiError)error);
if (error != (int)WiFiError.None)
{
Log.Error(Globals.LogTag, "Error occurs during WiFi connecting, " + (WiFiError)error);
};
}
- int ret = Interop.WiFi.Connect(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, _callback_map[id], id);
- if (ret != (int)WiFiError.None)
+ context.Post((x) =>
{
- Log.Error(Globals.LogTag, "Failed to connect wifi, Error - " + (WiFiError)ret);
- WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle);
- }
+ Log.Info(Globals.LogTag, "Interop.WiFi.Connect");
+ int ret = Interop.WiFi.Connect(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, _callback_map[id], id);
+ if (ret != (int)WiFiError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to connect wifi, Error - " + (WiFiError)ret);
+ WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle);
+ }
+ }, null);
return task.Task;
}
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
public Task ConnectWpsAsync(WpsInfo info)
{
- Log.Debug(Globals.LogTag, "ConnectWpsAsync");
+ Log.Info(Globals.LogTag, "ConnectWpsAsync");
if (_disposed)
{
throw new ObjectDisposedException("Invalid AP instance (Object may have been disposed or released)");
id = (IntPtr)_requestId++;
_callback_map[id] = (error, key) =>
{
- Log.Debug(Globals.LogTag, "Connecting by WPS finished");
+ Log.Info(Globals.LogTag, "ConnectWpsAsync done");
if (error != (int)WiFiError.None)
{
Log.Error(Globals.LogTag, "Error occurs during WiFi connecting, " + (WiFiError)error);
};
}
- int ret = -1;
- if (info.GetType() == typeof(WpsPbcInfo))
+ context.Post((x) =>
{
- ret = Interop.WiFi.ConnectByWpsPbc(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, _callback_map[id], id);
- }
-
- else if (info.GetType() == typeof(WpsPinInfo))
- {
- WpsPinInfo pinInfo = (WpsPinInfo)info;
- if (pinInfo.GetWpsPin() == null)
+ int ret = -1;
+ if (info.GetType() == typeof(WpsPbcInfo))
{
- throw new ArgumentNullException("Wps pin should not be null");
+ Log.Info(Globals.LogTag, "Interop.WiFi.ConnectByWpsPb");
+ ret = Interop.WiFi.ConnectByWpsPbc(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, _callback_map[id], id);
}
-
- if (pinInfo.GetWpsPin().Length == 0 || pinInfo.GetWpsPin().Length > 8)
+ else if (info.GetType() == typeof(WpsPinInfo))
{
- throw new ArgumentOutOfRangeException("Wps pin should not be empty or more than 7 characters");
- }
+ WpsPinInfo pinInfo = (WpsPinInfo)info;
+ if (pinInfo.GetWpsPin() == null)
+ {
+ throw new ArgumentNullException("Wps pin should not be null");
+ }
- ret = Interop.WiFi.ConnectByWpsPin(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, pinInfo.GetWpsPin(), _callback_map[id], id);
- }
+ if (pinInfo.GetWpsPin().Length == 0 || pinInfo.GetWpsPin().Length > 8)
+ {
+ throw new ArgumentOutOfRangeException("Wps pin should not be empty or more than 7 characters");
+ }
- if (ret != (int)WiFiError.None)
- {
- Log.Error(Globals.LogTag, "Failed to connect wifi, Error - " + (WiFiError)ret);
- WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle);
- }
+ Log.Info(Globals.LogTag, "Interop.WiFi.ConnectByWpsPin");
+ ret = Interop.WiFi.ConnectByWpsPin(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, pinInfo.GetWpsPin(), _callback_map[id], id);
+ }
+
+ if (ret != (int)WiFiError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to connect wifi, Error - " + (WiFiError)ret);
+ WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle);
+ }
+ }, null);
return task.Task;
}
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
public static Task<WiFiAP> ConnectWpsWithoutSsidAsync(WpsInfo info)
{
+ Log.Info(Globals.LogTag, "ConnectWpsWithoutSsidAsync");
TaskCompletionSource<WiFiAP> task = new TaskCompletionSource<WiFiAP>();
IntPtr id;
lock (s_callbackMap)
id = (IntPtr)s_requestId++;
s_callbackMap[id] = (error, key) =>
{
- Log.Debug(Globals.LogTag, "Connecting by WPS finished");
+ Log.Info(Globals.LogTag, "ConnectWpsWithoutSsidAsync done");
if (error != (int)WiFiError.None)
{
Log.Error(Globals.LogTag, "Error occurs during WiFi connecting, " + (WiFiError)error);
};
}
- int ret = -1;
- if (info.GetType() == typeof(WpsPbcInfo))
+ s_context.Post((x) =>
{
- ret = Interop.WiFi.ConnectByWpsPbcWithoutSsid(WiFiManagerImpl.Instance.GetSafeHandle(), s_callbackMap[id], id);
- }
-
- else if (info.GetType() == typeof(WpsPinInfo))
- {
- WpsPinInfo pinInfo = (WpsPinInfo)info;
- if (pinInfo.GetWpsPin() == null)
+ int ret = -1;
+ if (info.GetType() == typeof(WpsPbcInfo))
{
- throw new ArgumentNullException("Wps pin should not be null");
+ Log.Info(Globals.LogTag, "Interop.WiFi.ConnectByWpsPbcWithoutSsid");
+ ret = Interop.WiFi.ConnectByWpsPbcWithoutSsid(WiFiManagerImpl.Instance.GetSafeHandle(), s_callbackMap[id], id);
}
-
- if (pinInfo.GetWpsPin().Length != 4 && pinInfo.GetWpsPin().Length != 8)
+ else if (info.GetType() == typeof(WpsPinInfo))
{
- throw new ArgumentOutOfRangeException("Wps pin should be of 4 or 8 characters long");
- }
+ WpsPinInfo pinInfo = (WpsPinInfo)info;
+ if (pinInfo.GetWpsPin() == null)
+ {
+ throw new ArgumentNullException("Wps pin should not be null");
+ }
- ret = Interop.WiFi.ConnectByWpsPinWithoutSsid(WiFiManagerImpl.Instance.GetSafeHandle(), pinInfo.GetWpsPin(), s_callbackMap[id], id);
- }
+ if (pinInfo.GetWpsPin().Length != 4 && pinInfo.GetWpsPin().Length != 8)
+ {
+ throw new ArgumentOutOfRangeException("Wps pin should be of 4 or 8 characters long");
+ }
- if (ret != (int)WiFiError.None)
- {
- Log.Error(Globals.LogTag, "Failed to connect wifi, Error - " + (WiFiError)ret);
- WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle());
- }
+ Log.Info(Globals.LogTag, "Interop.WiFi.ConnectByWpsPinWithoutSsid");
+ ret = Interop.WiFi.ConnectByWpsPinWithoutSsid(WiFiManagerImpl.Instance.GetSafeHandle(), pinInfo.GetWpsPin(), s_callbackMap[id], id);
+ }
+
+ if (ret != (int)WiFiError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to connect wifi, Error - " + (WiFiError)ret);
+ WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle());
+ }
+ }, null);
return task.Task;
}
id = (IntPtr)_requestId++;
_callback_map[id] = (error, key) =>
{
- Log.Debug(Globals.LogTag, "Disconnecting finished");
+ Log.Info(Globals.LogTag, "DisconnectAsync done");
if (error != (int)WiFiError.None)
{
Log.Error(Globals.LogTag, "Error occurs during WiFi disconnecting, " + (WiFiError)error);
}
};
}
- int ret = Interop.WiFi.Disconnect(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, _callback_map[id], id);
- if (ret != (int)WiFiError.None)
+
+ context.Post((x) =>
{
- Log.Error(Globals.LogTag, "Failed to disconnect wifi, Error - " + (WiFiError)ret);
- WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle);
- }
+ Log.Info(Globals.LogTag, "Interop.WiFi.Disconnect");
+ int ret = Interop.WiFi.Disconnect(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, _callback_map[id], id);
+ if (ret != (int)WiFiError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to disconnect wifi, Error - " + (WiFiError)ret);
+ WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle);
+ }
+ }, null);
+
return task.Task;
}
using System.Threading;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
+using Tizen.Applications;
namespace Tizen.Network.WiFi
{
{
private static readonly Lazy<WiFiManagerImpl> _instance =
new Lazy<WiFiManagerImpl>(() => new WiFiManagerImpl());
- private Dictionary<IntPtr, Interop.WiFi.VoidCallback> _callback_map = new Dictionary<IntPtr, Interop.WiFi.VoidCallback>();
+
+ private TizenSynchronizationContext context = new TizenSynchronizationContext();
+
+ private Dictionary<IntPtr, Interop.WiFi.VoidCallback> _callback_map =
+ new Dictionary<IntPtr, Interop.WiFi.VoidCallback>();
+
private int _requestId = 0;
private string _macAddress;
id = (IntPtr)_requestId++;
_callback_map[id] = (error, key) =>
{
- Log.Info(Globals.LogTag, "wifi activated");
+ Log.Info(Globals.LogTag, "ActivateAsync done");
if (error != (int)WiFiError.None)
{
Log.Error(Globals.LogTag, "Error occurs during WiFi activating, " + (WiFiError)error);
}
};
}
- int ret = Interop.WiFi.Activate(GetSafeHandle(), _callback_map[id], id);
- if (ret != (int)WiFiError.None)
+
+ context.Post((x) =>
{
+ Log.Info(Globals.LogTag, "Interop.WiFi.ActivateAsync");
+ int ret = Interop.WiFi.Activate(GetSafeHandle(), _callback_map[id], id);
+ if (ret != (int)WiFiError.None)
+ {
Log.Error(Globals.LogTag, "Failed to activate wifi, Error - " + (WiFiError)ret);
WiFiErrorFactory.ThrowWiFiException(ret, GetSafeHandle().DangerousGetHandle());
- }
+ }
+ }, null);
+
return task.Task;
}
internal Task ActivateWithWiFiPickerTestedAsync()
{
- Log.Debug(Globals.LogTag, "ActivateWithWiFiPickerTestedAsync");
+ Log.Info(Globals.LogTag, "ActivateWithWiFiPickerTestedAsync");
TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
IntPtr id;
lock (_callback_map)
id = (IntPtr)_requestId++;
_callback_map[id] = (error, key) =>
{
- Log.Debug(Globals.LogTag, "Activation finished");
+ Log.Info(Globals.LogTag, "ActivateWithWiFiPickerTestedAsync done");
if (error != (int)WiFiError.None)
{
Log.Error(Globals.LogTag, "Error occurs during WiFi activating, " + (WiFiError)error);
}
};
}
- int ret = Interop.WiFi.ActivateWithWiFiPickerTested(GetSafeHandle(), _callback_map[id], id);
- if (ret != (int)WiFiError.None)
+
+ context.Post((x) =>
{
- Log.Error(Globals.LogTag, "Failed to activate wifi, Error - " + (WiFiError)ret);
- WiFiErrorFactory.ThrowWiFiException(ret, GetSafeHandle().DangerousGetHandle());
- }
+ Log.Info(Globals.LogTag, "Interop.WiFi.ActivateWithWiFiPickerTestedAsync");
+ int ret = Interop.WiFi.ActivateWithWiFiPickerTested(GetSafeHandle(), _callback_map[id], id);
+ if (ret != (int)WiFiError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to activate wifi, Error - " + (WiFiError)ret);
+ WiFiErrorFactory.ThrowWiFiException(ret, GetSafeHandle().DangerousGetHandle());
+ }
+ }, null);
+
return task.Task;
}
id = (IntPtr)_requestId++;
_callback_map[id] = (error, key) =>
{
- Log.Info(Globals.LogTag, "Deactivation finished");
+ Log.Info(Globals.LogTag, "DeactivateAsync done");
if (error != (int)WiFiError.None)
{
Log.Error(Globals.LogTag, "Error occurs during WiFi deactivating, " + (WiFiError)error);
}
};
}
- int ret = Interop.WiFi.Deactivate(GetSafeHandle(), _callback_map[id], id);
- if (ret != (int)WiFiError.None)
+
+ context.Post((x) =>
{
- Log.Error(Globals.LogTag, "Failed to deactivate wifi, Error - " + (WiFiError)ret);
- WiFiErrorFactory.ThrowWiFiException(ret, GetSafeHandle().DangerousGetHandle());
- }
- return task.Task;
+ Log.Info(Globals.LogTag, "Interop.WiFi.Deactivate");
+ int ret = Interop.WiFi.Deactivate(GetSafeHandle(), _callback_map[id], id);
+ if (ret != (int)WiFiError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to deactivate wifi, Error - " + (WiFiError)ret);
+ WiFiErrorFactory.ThrowWiFiException(ret, GetSafeHandle().DangerousGetHandle());
+ }
+ }, null);
+
+ return task.Task;
}
internal Task ScanAsync()
id = (IntPtr)_requestId++;
_callback_map[id] = (error, key) =>
{
- Log.Info(Globals.LogTag, "Scanning finished");
+ Log.Info(Globals.LogTag, "ScanAsync done");
if (error != (int)WiFiError.None)
{
Log.Error(Globals.LogTag, "Error occurs during WiFi scanning, " + (WiFiError)error);
}
};
}
- int ret = Interop.WiFi.Scan(GetSafeHandle(), _callback_map[id], id);
- if (ret != (int)WiFiError.None)
+
+ context.Post((x) =>
{
- Log.Error(Globals.LogTag, "Failed to scan all AP, Error - " + (WiFiError)ret);
- WiFiErrorFactory.ThrowWiFiException(ret, GetSafeHandle().DangerousGetHandle());
- }
+ Log.Info(Globals.LogTag, "Interop.WiFi.Scan");
+ int ret = Interop.WiFi.Scan(GetSafeHandle(), _callback_map[id], id);
+ if (ret != (int)WiFiError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to scan all AP, Error - " + (WiFiError)ret);
+ WiFiErrorFactory.ThrowWiFiException(ret, GetSafeHandle().DangerousGetHandle());
+ }
+ }, null);
+
return task.Task;
}
id = (IntPtr)_requestId++;
_callback_map[id] = (error, key) =>
{
- Log.Info(Globals.LogTag, "Scanning with specific AP finished");
+ Log.Info(Globals.LogTag, "ScanSpecificAPAsync Done " + essid);
if (error != (int)WiFiError.None)
{
Log.Error(Globals.LogTag, "Error occurs during WiFi scanning, " + (WiFiError)error);
}
};
}
- int ret = Interop.WiFi.ScanSpecificAP(GetSafeHandle(), essid, _callback_map[id], id);
- if (ret != (int)WiFiError.None)
+
+ context.Post((x) =>
{
- Log.Error(Globals.LogTag, "Failed to scan with specific AP, Error - " + (WiFiError)ret);
- WiFiErrorFactory.ThrowWiFiException(ret, GetSafeHandle().DangerousGetHandle());
- }
+ Log.Info(Globals.LogTag, "Interop.WiFi.ScanSpecificAPAsync");
+ int ret = Interop.WiFi.ScanSpecificAP(GetSafeHandle(), essid, _callback_map[id], id);
+ if (ret != (int)WiFiError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to scan with specific AP, Error - " + (WiFiError)ret);
+ WiFiErrorFactory.ThrowWiFiException(ret, GetSafeHandle().DangerousGetHandle());
+ }
+ }, null);
+
return task.Task;
}
}
using System;
using System.Threading.Tasks;
using System.Threading;
-using Tizen.Applications;
namespace Tizen.Network.WiFi
{
private Interop.WiFi.RssiLevelChangedCallback _rssiChangedCallback;
private Interop.WiFi.VoidCallback _backgroundScanFinishedCallback;
- private TizenSynchronizationContext context = new TizenSynchronizationContext();
internal event EventHandler<DeviceStateChangedEventArgs> DeviceStateChanged
{
add
{
context.Post((x) =>
- {
- if (_deviceStateChanged == null)
- {
- RegisterDeviceStateChangedEvent();
- }
- _deviceStateChanged += value;
- }, null);
+ {
+ if (_deviceStateChanged == null)
+ {
+ RegisterDeviceStateChangedEvent();
+ }
+ _deviceStateChanged += value;
+ }, null);
}
remove
{
context.Post((x) =>
- {
- _deviceStateChanged -= value;
- if (_deviceStateChanged == null)
- {
- UnregisterDeviceStateChangedEvent();
- }
- }, null);
+ {
+ _deviceStateChanged -= value;
+ if (_deviceStateChanged == null)
+ {
+ UnregisterDeviceStateChangedEvent();
+ }
+ }, null);
}
}
add
{
context.Post((x) =>
- {
- if (_connectionStateChanged == null)
- {
- RegisterConnectionStateChangedEvent();
- }
- _connectionStateChanged += value;
- }, null);
+ {
+ if (_connectionStateChanged == null)
+ {
+ RegisterConnectionStateChangedEvent();
+ }
+ _connectionStateChanged += value;
+ }, null);
}
remove
{
context.Post((x) =>
- {
- _connectionStateChanged -= value;
- if (_connectionStateChanged == null)
- {
- UnregisterConnectionStateChangedEvent();
- }
- }, null);
+ {
+ _connectionStateChanged -= value;
+ if (_connectionStateChanged == null)
+ {
+ UnregisterConnectionStateChangedEvent();
+ }
+ }, null);
}
}
add
{
context.Post((x) =>
- {
- if (_rssiLevelChanged == null)
- {
- RegisterRssiLevelChangedEvent();
- }
- _rssiLevelChanged += value;
- }, null);
+ {
+ if (_rssiLevelChanged == null)
+ {
+ RegisterRssiLevelChangedEvent();
+ }
+ _rssiLevelChanged += value;
+ }, null);
}
remove
{
context.Post((x) =>
- {
- _rssiLevelChanged -= value;
- if (_rssiLevelChanged == null)
- {
- UnregisterRssiLevelChangedEvent();
- }
- }, null);
+ {
+ _rssiLevelChanged -= value;
+ if (_rssiLevelChanged == null)
+ {
+ UnregisterRssiLevelChangedEvent();
+ }
+ }, null);
}
}
add
{
context.Post((x) =>
- {
- if (_backgroundScanFinished == null)
- {
- RegisterBackgroundScanFinishedEvent();
- }
- _backgroundScanFinished += value;
- }, null);
+ {
+ if (_backgroundScanFinished == null)
+ {
+ RegisterBackgroundScanFinishedEvent();
+ }
+ _backgroundScanFinished += value;
+ }, null);
}
remove
{
context.Post((x) =>
- {
- _backgroundScanFinished -= value;
- if (_backgroundScanFinished == null)
- {
- UnregisterBackgroundScanFinishedEvent();
- }
- }, null);
+ {
+ _backgroundScanFinished -= value;
+ if (_backgroundScanFinished == null)
+ {
+ UnregisterBackgroundScanFinishedEvent();
+ }
+ }, null);
}
}