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 internal enum WiFiError
24 None = ErrorCode.None,
25 InvalidParameterError = ErrorCode.InvalidParameter,
26 OutOfMemoryError = ErrorCode.OutOfMemory,
27 InvalidOperationError = ErrorCode.InvalidOperation,
28 AddressFamilyNotSupportedError = ErrorCode.AddressFamilyNotSupported,
29 OperationFailedError = -0x01C50000 | 0x0301,
30 NoConnectionError = -0x01C50000 | 0x0302,
31 NowInProgressError = ErrorCode.NowInProgress,
32 AlreadyExistsError = -0x01C50000 | 0x0303,
33 OperationAbortedError = -0x01C50000 | 0x0304,
34 DhcpFailedError = -0x01C50000 | 0x0306,
35 InvalidKeyError = -0x01C50000 | 0x0307,
36 NoReplyError = -0x01C50000 | 0x0308,
37 SecurityRestrictedError = -0x01C50000 | 0x0309,
38 PermissionDeniedError = ErrorCode.PermissionDenied,
39 NotSupportedError = ErrorCode.NotSupported
42 internal static class WiFiErrorFactory
44 static internal void ThrowWiFiException(int e, IntPtr handle)
46 ThrowExcption(e, (handle == IntPtr.Zero), false, "");
49 static internal void ThrowWiFiException(int e, IntPtr handle1, IntPtr handle2)
51 ThrowExcption(e, (handle1 == IntPtr.Zero), (handle2 == IntPtr.Zero), "");
54 static internal void ThrowWiFiException(int e, string message)
56 ThrowExcption(e, false, false, message);
59 static internal void ThrowWiFiException(int e, IntPtr handle, string message)
61 ThrowExcption(e, (handle == IntPtr.Zero), false, message);
64 static internal void ThrowWiFiException(int e, IntPtr handle1, IntPtr handle2, string message)
66 ThrowExcption(e, (handle1 == IntPtr.Zero), (handle2 == IntPtr.Zero), message);
69 static private void ThrowExcption(int e, bool isHandle1Null, bool isHandle2Null, string message)
71 WiFiError err = (WiFiError)e;
72 if (err == WiFiError.NotSupportedError)
74 throw new NotSupportedException("Unsupported feature http://tizen.org/feature/network.wifi");
77 if (err == WiFiError.PermissionDeniedError)
79 throw new UnauthorizedAccessException("Permission denied " + message);
82 if (err == WiFiError.OutOfMemoryError)
84 throw new OutOfMemoryException("Out of memory");
87 if (err == WiFiError.InvalidParameterError || err == WiFiError.InvalidKeyError)
89 if (isHandle1Null || isHandle2Null)
91 throw new InvalidOperationException("Invalid instance (object may have been disposed or released)");
94 throw new ArgumentException("Invalid parameter");
97 throw new InvalidOperationException(err.ToString());