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 PermissionDeniedError = ErrorCode.PermissionDenied,
44 NotSupportedError = ErrorCode.NotSupported
47 internal static class WiFiErrorFactory
49 static internal void ThrowWiFiException(int e, IntPtr handle)
51 ThrowException(e, (handle == IntPtr.Zero), false, "");
54 static internal void ThrowWiFiException(int e, IntPtr handle1, IntPtr handle2)
56 ThrowException(e, (handle1 == IntPtr.Zero), (handle2 == IntPtr.Zero), "");
59 static internal void ThrowWiFiException(int e, string message)
61 ThrowException(e, false, false, message);
64 static internal void ThrowWiFiException(int e, IntPtr handle, string message)
66 ThrowException(e, (handle == IntPtr.Zero), false, message);
69 static internal void ThrowWiFiException(int e, IntPtr handle1, IntPtr handle2, string message)
71 ThrowException(e, (handle1 == IntPtr.Zero), (handle2 == IntPtr.Zero), message);
74 static private void ThrowException(int e, bool isHandle1Null, bool isHandle2Null, string message)
76 WiFiError err = (WiFiError)e;
77 if (err == WiFiError.NotSupportedError)
79 throw new NotSupportedException("Unsupported feature http://tizen.org/feature/network.wifi");
82 if (err == WiFiError.PermissionDeniedError)
84 throw new UnauthorizedAccessException("Permission denied " + message);
87 if (err == WiFiError.OutOfMemoryError)
89 throw new OutOfMemoryException("Out of memory");
92 if (err == WiFiError.InvalidParameterError || err == WiFiError.InvalidKeyError)
94 if (isHandle1Null || isHandle2Null)
96 throw new InvalidOperationException("Invalid instance (object may have been disposed or released)");
99 throw new ArgumentException("Invalid parameter");
102 throw new InvalidOperationException(err.ToString());