Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Network.Connection / Tizen.Network.Connection / ConnectionError.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 System.Collections.Generic;
19 using System.Linq;
20 using System.Text;
21 using System.Threading.Tasks;
22
23 namespace Tizen.Network.Connection
24 {
25     internal static class ConnectionErrorFactory
26     {
27         internal static void CheckFeatureUnsupportedException(int err, string message)
28         {
29             if ((ConnectionError)err == ConnectionError.NotSupported)
30             {
31                 ThrowConnectionException(err, message);
32             }
33         }
34
35         internal static void CheckPermissionDeniedException(int err, string message)
36         {
37             if ((ConnectionError)err == ConnectionError.PermissionDenied)
38             {
39                 ThrowConnectionException(err, message);
40             }
41         }
42
43         internal static void CheckHandleNullException(int err, bool isHandleInvalid, string message)
44         {
45             if ((ConnectionError)err == ConnectionError.InvalidParameter)
46             {
47                 if (isHandleInvalid)
48                 {
49                     ThrowConnectionException((int)ConnectionError.InvalidOperation, message);
50                 }
51             }
52         }
53
54         internal static void ThrowConnectionException(int errno , string message = "")
55         {
56             ConnectionError _error = (ConnectionError)errno;
57             Log.Debug(Globals.LogTag, "ThrowConnectionException " + _error);
58             switch (_error)
59             {
60                 case ConnectionError.AddressFamilyNotSupported:
61                     throw new InvalidOperationException("Address Family Not Supported");
62                 case ConnectionError.AlreadyExists:
63                     throw new InvalidOperationException("Already Exists");
64                 case ConnectionError.DhcpFailed:
65                     throw new InvalidOperationException("DHCP Failed");
66                 case ConnectionError.EndOfIteration:
67                     throw new InvalidOperationException("End Of Iteration");
68                 case ConnectionError.InvalidKey:
69                     throw new InvalidOperationException("Invalid Key");
70                 case ConnectionError.InvalidOperation:
71                     throw new InvalidOperationException("Invalid Operation " + message);
72                 case ConnectionError.InvalidParameter:
73                     throw new ArgumentException("Invalid Parameter");
74                 case ConnectionError.NoConnection:
75                     throw new InvalidOperationException("No Connection");
76                 case ConnectionError.NoReply:
77                     throw new InvalidOperationException("No Reply");
78                 case ConnectionError.NotSupported:
79                     throw new NotSupportedException("Unsupported feature " + message);
80                 case ConnectionError.NowInProgress:
81                     throw new InvalidOperationException("Now In Progress");
82                 case ConnectionError.OperationAborted:
83                     throw new InvalidOperationException("Operation Aborted");
84                 case ConnectionError.OperationFailed:
85                     throw new InvalidOperationException("Operation Failed");
86                 case ConnectionError.OutOfMemoryError:
87                     throw new OutOfMemoryException("Out Of Memory Error");
88                 case ConnectionError.PermissionDenied:
89                     throw new UnauthorizedAccessException("Permission Denied " + message);
90             }
91         }
92     }
93 }