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>
Initialize();
}
+ /// <summary>
+ /// Destroy the WiFiAP object
+ /// </summary>
~WiFiAP()
{
Dispose(false);
/// <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))
- {
- ret = Interop.WiFi.ConnectByWpsPbc(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, _callback_map[id], id);
- }
-
- else if (info.GetType() == typeof(WpsPinInfo))
+ context.Post((x) =>
{
- 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;
}
/// <summary>
- /// Deletes the information of a stored access point and disconnects it when the AP is connected.<br>
+ /// Deletes the information of a stored access point and disconnects it when the AP is connected.
/// If an AP is connected, then the connection information will be stored. This information is used when a connection to that AP is established automatically.
/// </summary>
/// <since_tizen> 3 </since_tizen>
WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle);
}
}
- }
+
+ /// <summary>
+ /// Update the information of a stored access point.
+ /// When a AP information is changed, the change will not be applied until this method is called.
+ /// </summary>
+ /// <since_tizen> 5 </since_tizen>
+ /// <feature>http://tizen.org/feature/network.wifi</feature>
+ /// <privilege>http://tizen.org/privilege/network.profile</privilege>
+ /// <privilege>http://tizen.org/privilege/network.get</privilege>
+ /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
+ /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
+ /// <exception cref="ObjectDisposedException">Thrown when the object instance is disposed or released.</exception>
+ /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
+ public void Update()
+ {
+ Log.Debug(Globals.LogTag, "Update");
+ if (_disposed)
+ {
+ throw new ObjectDisposedException("Invalid AP instance (Object may have been disposed or released)");
+ }
+ int ret = Interop.WiFi.UpdateAP(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle);
+ if (ret != (int)WiFiError.None)
+ {
+ Log.Error(Globals.LogTag, "Failed to update AP, Error - " + (WiFiError)ret);
+ WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle);
+ }
+ }
+ }
/// <summary>
/// An abstract class which is used to represent the WPS information of the access point.
/// <summary>
/// A class which is used to represent WPS PBC information of the access point.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
public class WpsPbcInfo : WpsInfo
{
}
/// <summary>
/// A class which is used to represent WPS PIN information of the access point.
/// </summary>
+ /// <since_tizen> 3 </since_tizen>
public class WpsPinInfo : WpsInfo
{
private string _pin;