4b8dc0114a51b42eafd7f76a737caf60056123a7
[platform/core/csapi/tizenfx.git] / src / Tizen.Network.IoTConnectivity / Tizen.Network.IoTConnectivity / IoTConnectivityErrorFactory.cs
1 /// Copyright 2016 by Samsung Electronics, Inc.,
2 ///
3 /// This software is the confidential and proprietary information
4 /// of Samsung Electronics, Inc. ("Confidential Information"). You
5 /// shall not disclose such Confidential Information and shall use
6 /// it only in accordance with the terms of the license agreement
7 /// you entered into with Samsung.
8
9 using System;
10 using System.IO;
11 using Tizen.Internals.Errors;
12
13 namespace Tizen.Network.IoTConnectivity
14 {
15     internal enum IoTConnectivityError
16     {
17         None = ErrorCode.None,
18         InvalidParameter = ErrorCode.InvalidParameter,
19         OutOfMemory = ErrorCode.OutOfMemory,
20         Io = ErrorCode.IoError,
21         PermissionDenied = ErrorCode.PermissionDenied,
22         NotSupported = ErrorCode.NotSupported,
23         NoData = ErrorCode.NoData,
24         TimedOut = ErrorCode.TimedOut,
25         Iotivity = -0x01C80000 | 0x01,
26         Representation = -0x01C80000 | 0x02,
27         InvalidType = -0x01C80000 | 0x03,
28         Already = -0x01C80000 | 0x04,
29         System = -0x01C80000 | 0x06,
30     }
31
32     internal static class IoTConnectivityErrorFactory
33     {
34         internal const string LogTag = "Tizen.Network.IoTConnectivity";
35
36         internal static void ThrowException(int err)
37         {
38             throw GetException(err);
39         }
40
41         internal static Exception GetException(int err)
42         {
43             IoTConnectivityError error = (IoTConnectivityError)err;
44             if (error == IoTConnectivityError.OutOfMemory)
45             {
46                 return new OutOfMemoryException("Out of memory");
47             }
48             else if (error == IoTConnectivityError.InvalidParameter)
49             {
50                 return new ArgumentException("Invalid parameter");
51             }
52             else if (error == IoTConnectivityError.Io)
53             {
54                 return new IOException("I/O Error");
55             }
56             else if (error == IoTConnectivityError.NoData)
57             {
58                 return new InvalidOperationException("No data found");
59             }
60             else if (error == IoTConnectivityError.TimedOut)
61             {
62                 return new TimeoutException("timed out");
63             }
64             else if (error == IoTConnectivityError.PermissionDenied)
65             {
66                 return new UnauthorizedAccessException("Permission denied");
67             }
68             else if (error == IoTConnectivityError.NotSupported)
69             {
70                 return new NotSupportedException("Not supported");
71             }
72             else if (error == IoTConnectivityError.Representation)
73             {
74                 return new InvalidOperationException("Representation error");
75             }
76             else if (error == IoTConnectivityError.InvalidType)
77             {
78                 return new ArgumentException("Invalid type");
79             }
80             else if (error == IoTConnectivityError.Already)
81             {
82                 return new InvalidOperationException("Duplicate");
83             }
84             else if (error == IoTConnectivityError.System)
85             {
86                 return new InvalidOperationException("System error");
87             }
88             else
89             {
90                 return new InvalidOperationException("Invalid operation");
91             }
92         }
93     }
94 }