{
_tid = Thread.CurrentThread.ManagedThreadId;
Log.Info(Globals.LogTag, "PInvoke connection_create for Thread " + _tid);
- int ret = Interop.Connection.Create(_tid, out Handle);
+ int ret = Interop.Connection.Create(out Handle);
Log.Info(Globals.LogTag, "Handle: " + Handle);
if(ret != (int)ConnectionError.None)
{
{
Log.Info(Globals.LogTag, "PInvoke connection_destroy for Thread " + _tid);
- Interop.Connection.Destroy(_tid, Handle);
+ Interop.Connection.Destroy(Handle);
if (Handle != IntPtr.Zero)
{
Handle = IntPtr.Zero;
private Interop.Connection.ConnectionAddressChangedCallback _proxyAddressChangedCallback;
private Interop.Connection.EthernetCableStateChangedCallback _ethernetCableStateChangedCallback;
- private TizenSynchronizationContext context = new TizenSynchronizationContext();
-
private Dictionary<IntPtr, Interop.Connection.ConnectionCallback> _callback_map =
new Dictionary<IntPtr, Interop.Connection.ConnectionCallback>();
private int _requestId = 0;
}
}
- private static ThreadLocal<HandleHolder> s_threadName = new ThreadLocal<HandleHolder>(() =>
- {
- Log.Info(Globals.LogTag, "In threadlocal delegate");
- return new HandleHolder();
- });
+ private HandleHolder _handleHolder;
private ConnectionInternalManager()
{
+ _handleHolder = new HandleHolder();
Log.Info(Globals.LogTag, "ConnectionInternalManager constructor");
}
internal IntPtr GetHandle()
{
- return s_threadName.Value.GetHandle();
+ return _handleHolder.GetHandle();
}
internal event EventHandler<ConnectionTypeEventArgs> ConnectionTypeChanged
{
add
{
- context.Post((x) =>
+ if (_ConnectionTypeChanged == null)
{
- if (_ConnectionTypeChanged == null)
+ try
{
- try
- {
- ConnectionTypeChangedStart();
- }
- catch (Exception e)
- {
- Log.Error(Globals.LogTag, "Exception on adding ConnectionTypeChanged\n" + e.ToString());
- return;
- }
+ ConnectionTypeChangedStart();
}
- _ConnectionTypeChanged += value;
- }, null);
+ catch (Exception e)
+ {
+ Log.Error(Globals.LogTag, "Exception on adding ConnectionTypeChanged\n" + e.ToString());
+ return;
+ }
+ }
+ _ConnectionTypeChanged += value;
}
remove
{
- context.Post((x) =>
+ _ConnectionTypeChanged -= value;
+ if (_ConnectionTypeChanged == null)
{
- _ConnectionTypeChanged -= value;
- if (_ConnectionTypeChanged == null)
+ try
{
- try
- {
- ConnectionTypeChangedStop();
- }
- catch (Exception e)
- {
- Log.Error(Globals.LogTag, "Exception on removing ConnectionTypeChanged\n" + e.ToString());
- }
+ ConnectionTypeChangedStop();
}
- }, null);
+ catch (Exception e)
+ {
+ Log.Error(Globals.LogTag, "Exception on removing ConnectionTypeChanged\n" + e.ToString());
+ }
+ }
}
}
{
add
{
- context.Post((x) =>
+ if (_EthernetCableStateChanged == null)
{
- if (_EthernetCableStateChanged == null)
+ try
{
- try
- {
- EthernetCableStateChangedStart();
- }
- catch (Exception e)
- {
- Log.Error(Globals.LogTag, "Exception on adding EthernetCableStateChanged\n" + e.ToString());
- return;
- }
+ EthernetCableStateChangedStart();
+ }
+ catch (Exception e)
+ {
+ Log.Error(Globals.LogTag, "Exception on adding EthernetCableStateChanged\n" + e.ToString());
+ return;
}
- _EthernetCableStateChanged += value;
- }, null);
+ }
+ _EthernetCableStateChanged += value;
}
remove
{
- context.Post((x) =>
+ _EthernetCableStateChanged -= value;
+ if (_EthernetCableStateChanged == null)
{
- _EthernetCableStateChanged -= value;
- if (_EthernetCableStateChanged == null)
+ try
{
- try
- {
- EthernetCableStateChangedStop();
- }
- catch (Exception e)
- {
- Log.Error(Globals.LogTag, "Exception on removing EthernetCableStateChanged\n" + e.ToString());
- }
+ EthernetCableStateChangedStop();
}
- }, null);
+ catch (Exception e)
+ {
+ Log.Error(Globals.LogTag, "Exception on removing EthernetCableStateChanged\n" + e.ToString());
+ }
+ }
}
}
{
add
{
- context.Post((x) =>
+ if (_IPAddressChanged == null)
{
- if (_IPAddressChanged == null)
+ try
{
- try
- {
- IPAddressChangedStart();
- }
- catch (Exception e)
- {
- Log.Error(Globals.LogTag, "Exception on adding IPAddressChanged\n" + e.ToString());
- return;
- }
+ IPAddressChangedStart();
}
- _IPAddressChanged += value;
- }, null);
+ catch (Exception e)
+ {
+ Log.Error(Globals.LogTag, "Exception on adding IPAddressChanged\n" + e.ToString());
+ return;
+ }
+ }
+ _IPAddressChanged += value;
}
remove
{
- context.Post((x) =>
+ _IPAddressChanged -= value;
+ if (_IPAddressChanged == null)
{
- _IPAddressChanged -= value;
- if (_IPAddressChanged == null)
+ try
{
- try
- {
- IPAddressChangedStop();
- }
- catch (Exception e)
- {
- Log.Error(Globals.LogTag, "Exception on removing IPAddressChanged\n" + e.ToString());
- }
+ IPAddressChangedStop();
+ }
+ catch (Exception e)
+ {
+ Log.Error(Globals.LogTag, "Exception on removing IPAddressChanged\n" + e.ToString());
}
- }, null);
+ }
}
}
{
add
{
- context.Post((x) =>
+ if (_ProxyAddressChanged == null)
{
- if (_ProxyAddressChanged == null)
+ try
{
- try
- {
- ProxyAddressChangedStart();
- }
- catch (Exception e)
- {
- Log.Error(Globals.LogTag, "Exception on adding ProxyAddressChanged\n" + e.ToString());
- return;
- }
+ ProxyAddressChangedStart();
}
- _ProxyAddressChanged += value;
- }, null);
+ catch (Exception e)
+ {
+ Log.Error(Globals.LogTag, "Exception on adding ProxyAddressChanged\n" + e.ToString());
+ return;
+ }
+ }
+ _ProxyAddressChanged += value;
}
remove
{
- context.Post((x) =>
+ _ProxyAddressChanged -= value;
+ if (_ProxyAddressChanged == null)
{
- _ProxyAddressChanged -= value;
- if (_ProxyAddressChanged == null)
+ try
{
- try
- {
- ProxyAddressChangedStop();
- }
- catch (Exception e)
- {
- Log.Error(Globals.LogTag, "Exception on removing ProxyAddressChanged\n" + e.ToString());
- }
+ ProxyAddressChangedStop();
}
- }, null);
+ catch (Exception e)
+ {
+ Log.Error(Globals.LogTag, "Exception on removing ProxyAddressChanged\n" + e.ToString());
+ }
+ }
}
}
};
}
- context.Post((x) =>
+ Log.Info(Globals.LogTag, "Interop.Connection.SetDefaultCellularServiceProfileAsync " + profile.Name);
+ try
{
- Log.Info(Globals.LogTag, "Interop.Connection.SetDefaultCellularServiceProfileAsync " + profile.Name);
- try
- {
- int ret = Interop.Connection.SetDefaultCellularServiceProfileAsync(GetHandle(), (int)type, profile.ProfileHandle, _callback_map[id], id);
+ int ret = Interop.Connection.SetDefaultCellularServiceProfileAsync(GetHandle(), (int)type, profile.ProfileHandle, _callback_map[id], id);
- 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);
- }
- } catch (Exception e)
+ if ((ConnectionError)ret != ConnectionError.None)
{
- Log.Error(Globals.LogTag, "Exception on SetDefaultCellularServiceProfileAsync\n" + e.ToString());
- task.SetException(e);
+ 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);
+ } catch (Exception e)
+ {
+ Log.Error(Globals.LogTag, "Exception on SetDefaultCellularServiceProfileAsync\n" + e.ToString());
+ task.SetException(e);
+ }
return task.Task;
}
};
}
- context.Post((x) =>
+ Log.Info(Globals.LogTag, "Interop.Connection.OpenProfile " + profile.Name);
+ try
{
- Log.Info(Globals.LogTag, "Interop.Connection.OpenProfile " + profile.Name);
- try
- {
- int ret = Interop.Connection.OpenProfile(GetHandle(), profile.ProfileHandle, _callback_map[id], id);
- 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);
- }
- }
- catch (Exception e)
+ int ret = Interop.Connection.OpenProfile(GetHandle(), profile.ProfileHandle, _callback_map[id], id);
+ if ((ConnectionError)ret != ConnectionError.None)
{
- Log.Error(Globals.LogTag, "Exception on OpenProfile\n" + e.ToString());
- task.SetException(e);
+ 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);
+ }
+ catch (Exception e)
+ {
+ Log.Error(Globals.LogTag, "Exception on OpenProfile\n" + e.ToString());
+ task.SetException(e);
+ }
return task.Task;
}
};
}
- context.Post((x) =>
+ Log.Info(Globals.LogTag, "Interop.Connection.CloseProfile " + profile.Name);
+ try
{
- Log.Info(Globals.LogTag, "Interop.Connection.CloseProfile " + profile.Name);
- try
- {
- int ret = Interop.Connection.CloseProfile(GetHandle(), profile.ProfileHandle, _callback_map[id], id);
- 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);
- }
- }
- catch (Exception e)
+ int ret = Interop.Connection.CloseProfile(GetHandle(), profile.ProfileHandle, _callback_map[id], id);
+ if ((ConnectionError)ret != ConnectionError.None)
{
- Log.Error(Globals.LogTag, "Exception on CloseProfile\n" + e.ToString());
- task.SetException(e);
+ 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);
+ }
+ catch (Exception e)
+ {
+ Log.Error(Globals.LogTag, "Exception on CloseProfile\n" + e.ToString());
+ task.SetException(e);
+ }
return task.Task;
}