1 /// Copyright 2016 by Samsung Electronics, Inc.,
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.
10 using Tizen.Internals.Errors;
12 namespace Tizen.Network.IoTConnectivity
14 internal enum IoTConnectivityError
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,
31 internal static class IoTConnectivityErrorFactory
33 internal const string LogTag = "Tizen.Network.IoTConnectivity";
35 internal static void ThrowException(int err)
37 IoTConnectivityError error = (IoTConnectivityError)err;
38 if (error == IoTConnectivityError.OutOfMemory)
40 throw new InvalidOperationException("Out of memory");
42 else if (error == IoTConnectivityError.InvalidParameter)
44 throw new ArgumentException("Invalid parameter");
46 else if (error == IoTConnectivityError.Io)
48 throw new ArgumentException("I/O Error");
50 else if (error == IoTConnectivityError.NoData)
52 throw new ArgumentException("No data found");
54 else if (error == IoTConnectivityError.TimedOut)
56 throw new ArgumentException("timed out");
58 else if (error == IoTConnectivityError.PermissionDenied)
60 throw new ArgumentException("Permission denied");
62 else if (error == IoTConnectivityError.NotSupported)
64 throw new ArgumentException("Not supported");
66 else if (error == IoTConnectivityError.Representation)
68 throw new ArgumentException("Representation error");
70 else if (error == IoTConnectivityError.InvalidType)
72 throw new ArgumentException("Invalid type");
74 else if (error == IoTConnectivityError.Already)
76 throw new ArgumentException("Duplicate");
78 else if (error == IoTConnectivityError.System)
80 throw new InvalidOperationException("System error");
84 internal static Exception GetException(int err)
86 IoTConnectivityError error = (IoTConnectivityError)err;
87 if (error == IoTConnectivityError.OutOfMemory)
89 return new InvalidOperationException("Out of memory");
91 else if (error == IoTConnectivityError.InvalidParameter)
93 return new ArgumentException("Invalid parameter");
95 else if (error == IoTConnectivityError.Io)
97 return new ArgumentException("I/O Error");
99 else if (error == IoTConnectivityError.NoData)
101 return new ArgumentException("No data found");
103 else if (error == IoTConnectivityError.TimedOut)
105 return new ArgumentException("timed out");
107 else if (error == IoTConnectivityError.PermissionDenied)
109 return new ArgumentException("Permission denied");
111 else if (error == IoTConnectivityError.NotSupported)
113 return new ArgumentException("Not supported");
115 else if (error == IoTConnectivityError.Representation)
117 return new ArgumentException("Representation error");
119 else if (error == IoTConnectivityError.InvalidType)
121 return new ArgumentException("Invalid type");
123 else if (error == IoTConnectivityError.Already)
125 return new ArgumentException("Duplicate");
127 else if (error == IoTConnectivityError.System)
129 return new InvalidOperationException("System error");
133 return new InvalidOperationException("Invalid operation");