[IoTConnectivity] Added Base implementation
[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 Tizen.Internals.Errors;
11
12 namespace Tizen.Network.IoTConnectivity
13 {
14     internal enum IoTConnectivityError
15     {
16         None = ErrorCode.None,
17         InvalidParameter = ErrorCode.InvalidParameter,
18         OutOfMemory = ErrorCode.OutOfMemory,
19         Io = ErrorCode.IoError,
20         PermissionDenied = ErrorCode.PermissionDenied,
21         NotSupported = ErrorCode.NotSupported,
22         NoData = ErrorCode.NoData,
23         TimedOut = ErrorCode.TimedOut,
24         // TODO: Fix IoTivity error mask
25         Representation = 0x10700000 | 0x01,
26         InvalidType = 0x10700000 | 0x02,
27         Already = 0x10700000 | 0x03,
28         System = 0x10700000 | 0x04,
29     }
30
31     internal static class IoTConnectivityErrorFactory
32     {
33         internal const string LogTag = "Tizen.Network.IoTConnectivity";
34
35         internal static void ThrowException(int err)
36         {
37             IoTConnectivityError error = (IoTConnectivityError)err;
38             if (error == IoTConnectivityError.OutOfMemory)
39             {
40                 throw new InvalidOperationException("Out of memory");
41             }
42             else if (error == IoTConnectivityError.InvalidParameter)
43             {
44                 throw new ArgumentException("Invalid parameter");
45             }
46             else if (error == IoTConnectivityError.Io)
47             {
48                 throw new ArgumentException("I/O Error");
49             }
50             else if (error == IoTConnectivityError.NoData)
51             {
52                 throw new ArgumentException("No data found");
53             }
54             else if (error == IoTConnectivityError.TimedOut)
55             {
56                 throw new ArgumentException("timed out");
57             }
58             else if (error == IoTConnectivityError.PermissionDenied)
59             {
60                 throw new ArgumentException("Permission denied");
61             }
62             else if (error == IoTConnectivityError.NotSupported)
63             {
64                 throw new ArgumentException("Not supported");
65             }
66             else if (error == IoTConnectivityError.Representation)
67             {
68                 throw new ArgumentException("Representation error");
69             }
70             else if (error == IoTConnectivityError.InvalidType)
71             {
72                 throw new ArgumentException("Invalid type");
73             }
74             else if (error == IoTConnectivityError.Already)
75             {
76                 throw new ArgumentException("Duplicate");
77             }
78             else if (error == IoTConnectivityError.System)
79             {
80                 throw new InvalidOperationException("System error");
81             }
82         }
83
84         internal static Exception GetException(int err)
85         {
86             IoTConnectivityError error = (IoTConnectivityError)err;
87             if (error == IoTConnectivityError.OutOfMemory)
88             {
89                 return new InvalidOperationException("Out of memory");
90             }
91             else if (error == IoTConnectivityError.InvalidParameter)
92             {
93                 return new ArgumentException("Invalid parameter");
94             }
95             else if (error == IoTConnectivityError.Io)
96             {
97                 return new ArgumentException("I/O Error");
98             }
99             else if (error == IoTConnectivityError.NoData)
100             {
101                 return new ArgumentException("No data found");
102             }
103             else if (error == IoTConnectivityError.TimedOut)
104             {
105                 return new ArgumentException("timed out");
106             }
107             else if (error == IoTConnectivityError.PermissionDenied)
108             {
109                 return new ArgumentException("Permission denied");
110             }
111             else if (error == IoTConnectivityError.NotSupported)
112             {
113                 return new ArgumentException("Not supported");
114             }
115             else if (error == IoTConnectivityError.Representation)
116             {
117                 return new ArgumentException("Representation error");
118             }
119             else if (error == IoTConnectivityError.InvalidType)
120             {
121                 return new ArgumentException("Invalid type");
122             }
123             else if (error == IoTConnectivityError.Already)
124             {
125                 return new ArgumentException("Duplicate");
126             }
127             else if (error == IoTConnectivityError.System)
128             {
129                 return new InvalidOperationException("System error");
130             }
131             else
132             {
133                 return new InvalidOperationException("Invalid operation");
134             }
135         }
136     }
137 }