Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Network.IoTConnectivity / Tizen.Network.IoTConnectivity / IoTConnectivityErrorFactory.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
18 using System;
19 using System.IO;
20 using Tizen.Internals.Errors;
21
22 namespace Tizen.Network.IoTConnectivity
23 {
24     internal enum IoTConnectivityError
25     {
26         None = ErrorCode.None,
27         InvalidParameter = ErrorCode.InvalidParameter,
28         OutOfMemory = ErrorCode.OutOfMemory,
29         Io = ErrorCode.IoError,
30         PermissionDenied = ErrorCode.PermissionDenied,
31         NotSupported = ErrorCode.NotSupported,
32         NoData = ErrorCode.NoData,
33         TimedOut = ErrorCode.TimedOut,
34         Iotivity = -0x01C80000 | 0x01,
35         Representation = -0x01C80000 | 0x02,
36         InvalidType = -0x01C80000 | 0x03,
37         Already = -0x01C80000 | 0x04,
38         System = -0x01C80000 | 0x06,
39     }
40
41     internal static class IoTConnectivityErrorFactory
42     {
43         internal const string LogTag = "Tizen.Network.IoTConnectivity";
44
45         internal static void ThrowException(int err)
46         {
47             throw GetException(err);
48         }
49
50         internal static Exception GetException(int err)
51         {
52             IoTConnectivityError error = (IoTConnectivityError)err;
53             if (error == IoTConnectivityError.OutOfMemory)
54             {
55                 return new OutOfMemoryException("Out of memory");
56             }
57             else if (error == IoTConnectivityError.InvalidParameter)
58             {
59                 return new ArgumentException("Invalid parameter");
60             }
61             else if (error == IoTConnectivityError.Io)
62             {
63                 return new IOException("I/O Error");
64             }
65             else if (error == IoTConnectivityError.NoData)
66             {
67                 return new InvalidOperationException("No data found");
68             }
69             else if (error == IoTConnectivityError.TimedOut)
70             {
71                 return new TimeoutException("timed out");
72             }
73             else if (error == IoTConnectivityError.PermissionDenied)
74             {
75                 return new UnauthorizedAccessException("Permission denied");
76             }
77             else if (error == IoTConnectivityError.NotSupported)
78             {
79                 return new NotSupportedException("Not supported");
80             }
81             else if (error == IoTConnectivityError.Representation)
82             {
83                 return new InvalidOperationException("Representation error");
84             }
85             else if (error == IoTConnectivityError.InvalidType)
86             {
87                 return new ArgumentException("Invalid type");
88             }
89             else if (error == IoTConnectivityError.Already)
90             {
91                 return new InvalidOperationException("Duplicate");
92             }
93             else if (error == IoTConnectivityError.System)
94             {
95                 return new InvalidOperationException("System error");
96             }
97             else
98             {
99                 return new InvalidOperationException("Invalid operation");
100             }
101         }
102     }
103 }