Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Network.WiFi / Tizen.Network.WiFi / WiFiErrorFactory.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18 using Tizen.Internals.Errors;
19
20 namespace Tizen.Network.WiFi
21 {
22     internal enum WiFiError
23     {
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
40     }
41
42     internal static class WiFiErrorFactory
43     {
44         static internal void ThrowWiFiException(int e, IntPtr handle)
45         {
46             ThrowExcption(e, (handle == IntPtr.Zero), false, "");
47         }
48
49         static internal void ThrowWiFiException(int e, IntPtr handle1, IntPtr handle2)
50         {
51             ThrowExcption(e, (handle1 == IntPtr.Zero), (handle2 == IntPtr.Zero), "");
52         }
53
54         static internal void ThrowWiFiException(int e, string message)
55         {
56             ThrowExcption(e, false, false, message);
57         }
58
59         static internal void ThrowWiFiException(int e, IntPtr handle, string message)
60         {
61             ThrowExcption(e, (handle == IntPtr.Zero), false, message);
62         }
63
64         static internal void ThrowWiFiException(int e, IntPtr handle1, IntPtr handle2, string message)
65         {
66             ThrowExcption(e, (handle1 == IntPtr.Zero), (handle2 == IntPtr.Zero), message);
67         }
68
69         static private void ThrowExcption(int e, bool isHandle1Null, bool isHandle2Null, string message)
70         {
71             WiFiError err = (WiFiError)e;
72             if (err == WiFiError.NotSupportedError)
73             {
74                 throw new NotSupportedException("Unsupported feature http://tizen.org/feature/network.wifi");
75             }
76
77             if (err == WiFiError.PermissionDeniedError)
78             {
79                 throw new UnauthorizedAccessException("Permission denied " + message);
80             }
81
82             if (err == WiFiError.OutOfMemoryError)
83             {
84                 throw new OutOfMemoryException("Out of memory");
85             }
86
87             if (err == WiFiError.InvalidParameterError || err == WiFiError.InvalidKeyError)
88             {
89                 if (isHandle1Null || isHandle2Null)
90                 {
91                     throw new InvalidOperationException("Invalid instance (object may have been disposed or released)");
92                 }
93
94                 throw new ArgumentException("Invalid parameter");
95             }
96
97             throw new InvalidOperationException(err.ToString());
98         }
99     }
100 }