2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using Tizen.Internals.Errors;
20 namespace Tizen.Network.WiFi
22 static internal class WiFiErrorValue
24 internal const int Base = -0x01CE0000;
27 internal enum WiFiError
29 None = ErrorCode.None,
30 InvalidParameterError = ErrorCode.InvalidParameter,
31 OutOfMemoryError = ErrorCode.OutOfMemory,
32 InvalidOperationError = ErrorCode.InvalidOperation,
33 AddressFamilyNotSupportedError = ErrorCode.AddressFamilyNotSupported,
34 OperationFailedError = WiFiErrorValue.Base | 0x01,
35 NoConnectionError = WiFiErrorValue.Base | 0x02,
36 NowInProgressError = ErrorCode.NowInProgress,
37 AlreadyExistsError = WiFiErrorValue.Base | 0x03,
38 OperationAbortedError = WiFiErrorValue.Base | 0x04,
39 DhcpFailedError = WiFiErrorValue.Base | 0x05,
40 InvalidKeyError = WiFiErrorValue.Base | 0x06,
41 NoReplyError = WiFiErrorValue.Base | 0x07,
42 SecurityRestrictedError = WiFiErrorValue.Base | 0x08,
43 WpsTimeoutError = WiFiErrorValue.Base | 0x10,
44 PermissionDeniedError = ErrorCode.PermissionDenied,
45 NotSupportedError = ErrorCode.NotSupported
48 internal static class WiFiErrorFactory
50 static internal void ThrowWiFiException(int e, IntPtr handle)
52 ThrowException(e, (handle == IntPtr.Zero), false, "");
55 static internal void ThrowWiFiException(int e, IntPtr handle1, IntPtr handle2)
57 ThrowException(e, (handle1 == IntPtr.Zero), (handle2 == IntPtr.Zero), "");
60 static internal void ThrowWiFiException(int e, string message)
62 ThrowException(e, false, false, message);
65 static internal void ThrowWiFiException(int e, IntPtr handle, string message)
67 ThrowException(e, (handle == IntPtr.Zero), false, message);
70 static internal void ThrowWiFiException(int e, IntPtr handle1, IntPtr handle2, string message)
72 ThrowException(e, (handle1 == IntPtr.Zero), (handle2 == IntPtr.Zero), message);
75 // Used for return value of native API
76 static private void ThrowException(int e, bool isHandle1Null, bool isHandle2Null, string message)
78 WiFiError err = (WiFiError)e;
81 case WiFiError.NotSupportedError:
82 throw new NotSupportedException("Unsupported feature http://tizen.org/feature/network.wifi");
83 case WiFiError.PermissionDeniedError:
84 throw new UnauthorizedAccessException("Permission denied " + message);
85 case WiFiError.SecurityRestrictedError:
86 throw new UnauthorizedAccessException("Disabled by the device policy");
87 case WiFiError.OutOfMemoryError:
88 throw new OutOfMemoryException("Out of memory");
89 case WiFiError.InvalidParameterError:
90 if (isHandle1Null || isHandle2Null)
91 throw new InvalidOperationException("Invalid instance (object may have been disposed or released)");
92 throw new ArgumentException("Invalid parameter");
93 case WiFiError.InvalidKeyError:
94 if (isHandle1Null || isHandle2Null)
95 throw new InvalidOperationException("Invalid instance (object may have been disposed or released)");
96 throw new InvalidKeyException(message);
97 case WiFiError.NowInProgressError:
98 throw new NowInProgressException(message);
100 throw new InvalidOperationException(err.ToString());
105 static internal Exception GetException(int e, string message)
107 WiFiError err = (WiFiError)e;
110 case WiFiError.NowInProgressError:
111 return new NowInProgressException(message);
112 case WiFiError.InvalidKeyError:
113 return new InvalidKeyException(message);
114 case WiFiError.SecurityRestrictedError:
115 return new UnauthorizedAccessException("Disabled by the device policy");
116 case WiFiError.WpsTimeoutError:
117 return new TimeoutException("WPS connection is timed out");
119 return new InvalidOperationException(message + " " + err.ToString());