Ejemplo n.º 1
0
        internal Task CloseProfileAsync(ConnectionProfile profile)
        {
            Log.Info(Globals.LogTag, "CloseProfileAsync");
            if (profile != null)
            {
                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);
                        task.SetException(new InvalidOperationException("Error occurs during disconnecting profile, " + Result));
                    }
                    else
                    {
                        task.SetResult(true);
                    }
                };

                context.Post((x) =>
                {
                    Log.Info(Globals.LogTag, "Interop.Connection.CloseProfile " + profile.Name);
                    try
                    {
                        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);
                        }
                    }
                    catch (Exception e)
                    {
                        Log.Error(Globals.LogTag, "Exception on CloseProfile\n" + e.ToString());
                        task.SetException(e);
                    }
                }, null);

                return(task.Task);
            }

            else
            {
                throw new ArgumentNullException("Profile is null");
            }
        }
Ejemplo n.º 2
0
        internal Task SetDefaultCellularProfile(CellularServiceType type, ConnectionProfile profile)
        {
            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);
                        task.SetException(new InvalidOperationException("Error occurs during set default cellular profile, " + Result));
                    }
                    else
                    {
                        task.SetResult(true);
                    }
                };

                context.Post((x) =>
                {
                    Log.Info(Globals.LogTag, "Interop.Connection.SetDefaultCellularServiceProfileAsync " + profile.Name);
                    try
                    {
                        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);
                        }
                    } catch (Exception e)
                    {
                        Log.Error(Globals.LogTag, "Exception on SetDefaultCellularServiceProfileAsync\n" + e.ToString());
                        task.SetException(e);
                    }
                }, null);

                return(task.Task);
            }
            else
            {
                throw new ArgumentNullException("Profile is null");
            }
        }
Ejemplo n.º 3
0
        internal Task OpenProfileAsync(ConnectionProfile profile)
        {
            Log.Debug(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);
                    if (Result != ConnectionError.None)
                    {
                        Log.Error(Globals.LogTag, "Error occurs during connecting profile, " + Result);
                        task.SetException(new InvalidOperationException("Error occurs during connecting profile, " + Result));
                    }
                    else
                    {
                        task.SetResult(true);
                    }
                };

                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);
                }

                return(task.Task);
            }

            else
            {
                throw new ArgumentNullException("Profile is null");
            }
        }