<ItemGroup>
<ProjectReference Include="..\Tizen\Tizen.csproj" />
<ProjectReference Include="..\Tizen.Log\Tizen.Log.csproj" />
+ <ProjectReference Include="..\Tizen.Applications.Common\Tizen.Applications.Common.csproj" />
</ItemGroup>
</Project>
using System.Runtime.InteropServices;
using System.Collections;
using System.Threading;
+using Tizen.Applications;
namespace Tizen.Network.Connection
{
class HandleHolder
{
private IntPtr Handle;
- private int tid;
+ private int _tid;
public HandleHolder()
{
- tid = Thread.CurrentThread.ManagedThreadId;
- Log.Info(Globals.LogTag, "PInvoke connection_destroy for Thread " + tid);
- int ret = Interop.Connection.Create(tid, out Handle);
+ _tid = Thread.CurrentThread.ManagedThreadId;
+ Log.Info(Globals.LogTag, "PInvoke connection_destroy for Thread " + _tid);
+ int ret = Interop.Connection.Create(_tid, out Handle);
Log.Info(Globals.LogTag, "Handle: " + Handle);
if(ret != (int)ConnectionError.None)
{
private void Destroy()
{
- Log.Info(Globals.LogTag, "PInvoke connection_destroy for Thread " + tid);
- Interop.Connection.Destroy(tid, Handle);
+
+ Log.Info(Globals.LogTag, "PInvoke connection_destroy for Thread " + _tid);
+ Interop.Connection.Destroy(_tid, Handle);
if (Handle != IntPtr.Zero)
{
Handle = IntPtr.Zero;
private Interop.Connection.ConnectionAddressChangedCallback _proxyAddressChangedCallback;
private Interop.Connection.EthernetCableStateChangedCallback _ethernetCableStateChangedCallback;
+ private TizenSynchronizationContext context = new TizenSynchronizationContext();
+
internal static ConnectionInternalManager Instance
{
get
~ConnectionInternalManager()
{
+ UnregisterEvents();
}
internal IntPtr GetHandle()
{
add
{
- if (_ConnectionTypeChanged == null)
- {
- ConnectionTypeChangedStart();
- }
-
- _ConnectionTypeChanged += value;
+ context.Post((x) =>
+ {
+ if (_ConnectionTypeChanged == null)
+ {
+ ConnectionTypeChangedStart();
+ }
+ _ConnectionTypeChanged += value;
+ }, null);
}
remove
{
- _ConnectionTypeChanged -= value;
- if (_ConnectionTypeChanged == null)
- {
- ConnectionTypeChangedStop();
- }
+ context.Post((x) =>
+ {
+ _ConnectionTypeChanged -= value;
+ if (_ConnectionTypeChanged == null)
+ {
+ ConnectionTypeChangedStop();
+ }
+ }, null);
}
}
{
add
{
- if (_EthernetCableStateChanged == null)
- {
- EthernetCableStateChangedStart();
- }
- _EthernetCableStateChanged += value;
+ context.Post((x) =>
+ {
+ if (_EthernetCableStateChanged == null)
+ {
+ EthernetCableStateChangedStart();
+ }
+ _EthernetCableStateChanged += value;
+ }, null);
}
remove
{
- _EthernetCableStateChanged -= value;
- if (_EthernetCableStateChanged == null)
- {
- EthernetCableStateChangedStop();
- }
+ context.Post((x) =>
+ {
+ _EthernetCableStateChanged -= value;
+ if (_EthernetCableStateChanged == null)
+ {
+ EthernetCableStateChangedStop();
+ }
+ }, null);
}
}
{
add
{
- if (_IPAddressChanged == null)
- {
- IPAddressChangedStart();
- }
- _IPAddressChanged += value;
+ context.Post((x) =>
+ {
+ if (_IPAddressChanged == null)
+ {
+ IPAddressChangedStart();
+ }
+ _IPAddressChanged += value;
+ }, null);
}
remove
{
- _IPAddressChanged -= value;
- if (_IPAddressChanged == null)
- {
- IPAddressChangedStop();
- }
+ context.Post((x) =>
+ {
+ _IPAddressChanged -= value;
+ if (_IPAddressChanged == null)
+ {
+ IPAddressChangedStop();
+ }
+ }, null);
}
}
{
add
{
- //Console.WriteLine("ProxyAddressChanged Add **");
- if (_ProxyAddressChanged == null)
- {
- ProxyAddressChangedStart();
- }
-
- _ProxyAddressChanged += value;
+ context.Post((x) =>
+ {
+ if (_ProxyAddressChanged == null)
+ {
+ ProxyAddressChangedStart();
+ }
+ _ProxyAddressChanged += value;
+ }, null);
}
remove
{
- //Console.WriteLine("ProxyAddressChanged Remove");
- _ProxyAddressChanged -= value;
- if (_ProxyAddressChanged == null)
- {
- ProxyAddressChangedStop();
- }
+ context.Post((x) =>
+ {
+ _ProxyAddressChanged -= value;
+ if (_ProxyAddressChanged == null)
+ {
+ ProxyAddressChangedStop();
+ }
+ }, null);
}
}
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
+using Tizen.Applications;
namespace Tizen.Network.Connection
{
private Interop.ConnectionProfile.ProfileStateChangedCallback _profileChangedCallback;
+ private TizenSynchronizationContext context = new TizenSynchronizationContext();
+
internal IntPtr GetHandle()
{
return ProfileHandle;
add
{
Log.Debug(Globals.LogTag, "ProfileStateChanged add");
- if (_ProfileStateChanged == null)
- {
- ProfileStateChangedStart();
- }
- _ProfileStateChanged += value;
+ context.Post((x) =>
+ {
+ if (_ProfileStateChanged == null)
+ {
+ ProfileStateChangedStart();
+ }
+ _ProfileStateChanged += value;
+ }, null);
}
remove
{
Log.Debug(Globals.LogTag, "ProfileStateChanged remove");
- _ProfileStateChanged -= value;
- if (_ProfileStateChanged == null)
- {
- ProfileStateChangedStop();
- }
+ context.Post((x) =>
+ {
+ _ProfileStateChanged -= value;
+ if (_ProfileStateChanged == null)
+ {
+ ProfileStateChangedStop();
+ }
+ }, null);
}
}
if (disposed)
return;
- if (disposing)
- {
- // Free managed objects.
- UnregisterEvents();
- Destroy();
- }
+ // Free unmanaged objects
+ UnregisterEvents();
+ Destroy();
disposed = true;
}
<ItemGroup>
<ProjectReference Include="..\Tizen.Network.Connection\Tizen.Network.Connection.csproj" />
+ <ProjectReference Include="..\Tizen.Applications.Common\Tizen.Applications.Common.csproj" />
</ItemGroup>
</Project>
[EditorBrowsable(EditorBrowsableState.Never)]
public sealed class SafeWiFiManagerHandle : SafeHandle
{
- private int tid;
+ private int _tid;
internal SafeWiFiManagerHandle() : base(IntPtr.Zero, true)
{
/// </summary>
protected override bool ReleaseHandle()
{
- Interop.WiFi.Deinitialize(tid, this.handle);
+ Interop.WiFi.Deinitialize(_tid, this.handle);
this.SetHandle(IntPtr.Zero);
return true;
}
- internal int TID
+ internal void SetTID(int id)
{
- set
- {
- tid = value;
- Log.Info(Globals.LogTag, "New Handle for Thread " + tid);
- }
+ _tid = id;
+ Log.Info(Globals.LogTag, "New Handle for Thread " + _tid);
}
}
{
get
{
- return _instance.Value;
+ return _instance.Value;
}
}
Log.Error(Globals.LogTag, "Failed to initialize wifi, Error - " + (WiFiError)ret);
WiFiErrorFactory.ThrowWiFiException(ret, "http://tizen.org/privilege/network.get");
}
- handle.TID = tid;
+ handle.SetTID(tid);
return handle;
}
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
{
- if (_deviceStateChanged == null)
- {
- RegisterDeviceStateChangedEvent();
- }
- _deviceStateChanged += value;
+ context.Post((x) =>
+ {
+ if (_deviceStateChanged == null)
+ {
+ RegisterDeviceStateChangedEvent();
+ }
+ _deviceStateChanged += value;
+ }, null);
}
remove
{
- _deviceStateChanged -= value;
- if (_deviceStateChanged == null)
- {
- UnregisterDeviceStateChangedEvent();
- }
+ context.Post((x) =>
+ {
+ _deviceStateChanged -= value;
+ if (_deviceStateChanged == null)
+ {
+ UnregisterDeviceStateChangedEvent();
+ }
+ }, null);
}
}
{
add
{
- if (_connectionStateChanged == null)
- {
- RegisterConnectionStateChangedEvent();
- }
- _connectionStateChanged += value;
+ context.Post((x) =>
+ {
+ if (_connectionStateChanged == null)
+ {
+ RegisterConnectionStateChangedEvent();
+ }
+ _connectionStateChanged += value;
+ }, null);
}
remove
{
- _connectionStateChanged -= value;
- if (_connectionStateChanged == null)
- {
- UnregisterConnectionStateChangedEvent();
- }
+ context.Post((x) =>
+ {
+ _connectionStateChanged -= value;
+ if (_connectionStateChanged == null)
+ {
+ UnregisterConnectionStateChangedEvent();
+ }
+ }, null);
}
}
{
add
{
- if (_rssiLevelChanged == null)
- {
- RegisterRssiLevelChangedEvent();
- }
- _rssiLevelChanged += value;
+ context.Post((x) =>
+ {
+ if (_rssiLevelChanged == null)
+ {
+ RegisterRssiLevelChangedEvent();
+ }
+ _rssiLevelChanged += value;
+ }, null);
}
remove
{
- _rssiLevelChanged -= value;
- if (_rssiLevelChanged == null)
- {
- UnregisterRssiLevelChangedEvent();
- }
+ context.Post((x) =>
+ {
+ _rssiLevelChanged -= value;
+ if (_rssiLevelChanged == null)
+ {
+ UnregisterRssiLevelChangedEvent();
+ }
+ }, null);
}
}
{
add
{
- if (_backgroundScanFinished == null)
- {
- RegisterBackgroundScanFinishedEvent();
- }
- _backgroundScanFinished += value;
+ context.Post((x) =>
+ {
+ if (_backgroundScanFinished == null)
+ {
+ RegisterBackgroundScanFinishedEvent();
+ }
+ _backgroundScanFinished += value;
+ }, null);
}
remove
{
- _backgroundScanFinished -= value;
- if (_backgroundScanFinished == null)
- {
- UnregisterBackgroundScanFinishedEvent();
- }
+ context.Post((x) =>
+ {
+ _backgroundScanFinished -= value;
+ if (_backgroundScanFinished == null)
+ {
+ UnregisterBackgroundScanFinishedEvent();
+ }
+ }, null);
}
}
private void RegisterDeviceStateChangedEvent()
{
+ Log.Info(Globals.LogTag, "RegisterDeviceStateChangedEvent in Thread " + Thread.CurrentThread.ManagedThreadId);
_deviceChangedCallback = (int deviceState, IntPtr userDate) =>
{
WiFiDeviceState state = (WiFiDeviceState)deviceState;
private void UnregisterDeviceStateChangedEvent()
{
+ Log.Info(Globals.LogTag, "UnregisterDeviceStateChangedEvent in Thread " + Thread.CurrentThread.ManagedThreadId);
int ret = Interop.WiFi.UnsetDeviceStateChangedCallback(GetSafeHandle());
if (ret != (int)WiFiError.None)
{