71d5f001b2cd24e801066d4cd9e6764d6678b0b3
[platform/core/csapi/tizenfx.git] / src / Tizen.Network.Nfc / Tizen.Network.Nfc / NfcErrorFactory.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 Tizen.Internals.Errors;
19
20 namespace Tizen.Network.Nfc
21 {
22     /// <summary>
23     /// Enumeration for the NFC Error.
24     /// </summary>
25     /// <since_tizen> 3 </since_tizen>
26     public enum NfcError
27     {
28         /// <summary>
29         /// Successful.
30         /// </summary>
31         None = ErrorCode.None,
32         /// <summary>
33         /// I/O Error.
34         /// </summary>
35         IoError = ErrorCode.IoError,
36         /// <summary>
37         /// Invalid Parameter.
38         /// </summary>
39         InvalidParameterError = ErrorCode.InvalidParameter,
40         /// <summary>
41         /// Out of Memory.
42         /// </summary>
43         OutOfMemoryError = ErrorCode.OutOfMemory,
44         /// <summary>
45         /// Timed Out.
46         /// </summary>
47         TimedOutError = ErrorCode.TimedOut,
48         /// <summary>
49         /// Device Busy.
50         /// </summary>
51         DeviceBusyError = ErrorCode.ResourceBusy,
52         /// <summary>
53         /// Not Supported.
54         /// </summary>
55         NotSupportedError = ErrorCode.NotSupported,
56         /// <summary>
57         /// Permission Denied.
58         /// </summary>
59         PermissionDeniedError = ErrorCode.PermissionDenied,
60         /// <summary>
61         /// Operation Failed.
62         /// </summary>
63         OperationFailedError = -0x01C20000 | 0x01,
64         /// <summary>
65         /// Invalied Ndef Message.
66         /// </summary>
67         InvalidNdefMessageError = -0x01C20000 | 0x02,
68         /// <summary>
69         /// Invalid Record Type.
70         /// </summary>
71         InvalidRecordTypeError = -0x01C20000 | 0x03,
72         /// <summary>
73         /// No Device.
74         /// </summary>
75         NoDeviceError = -0x01C20000 | 0x04,
76         /// <summary>
77         /// Not Activated.
78         /// </summary>
79         NotActivatedError = -0x01C20000 | 0x05,
80         /// <summary>
81         /// Already Activated.
82         /// </summary>
83         AlreadyActivatedError = -0x01C20000 | 0x06,
84         /// <summary>
85         /// Already Deactivated.
86         /// </summary>
87         AlreadyDeactivatedError = -0x01C20000 | 0x07,
88         /// <summary>
89         /// Read Only Ndef.
90         /// </summary>
91         ReadOnlyNdefError = -0x01C20000 | 0x08,
92         /// <summary>
93         /// No Space On Ndef.
94         /// </summary>
95         NoSpaceOnNdefError = -0x01C20000 | 0x09,
96         /// <summary>
97         /// No Ndef Message
98         /// </summary>
99         NoNdefMessageError = -0x01C20000 | 0x0a,
100         /// <summary>
101         /// No Ndef Format
102         /// </summary>
103         NotNdefFormatError = -0x01C20000 | 0x0b,
104         /// <summary>
105         /// Security Restricted
106         /// </summary>
107         SecurityRestrictedError = -0x01C20000 | 0x0c,
108         /// <summary>
109         /// Illegal State
110         /// </summary>
111         IllegalStateError = -0x01C20000 | 0x0d,
112         /// <summary>
113         /// Not Initialized
114         /// </summary>
115         NotInitializedError = -0x01C20000 | 0x0e,
116         /// <summary>
117         /// Tag Not Supported
118         /// </summary>
119         TagNotSupportedError = -0x01C20000 | 0x0f,
120         /// <summary>
121         /// Aid Already Registered
122         /// </summary>
123         AidAlreadyRegisteredError = -0x01C20000 | 0x10
124     }
125
126     internal static class NfcErrorFactory
127     {
128         static internal void ThrowNfcException(int e)
129         {
130             ThrowException(e, false);
131         }
132
133         static internal void ThrowNfcException(int e, int handle)
134         {
135             ThrowException(e, (handle < 0));
136         }
137
138         static private void ThrowException(int e, bool isHandleNull)
139         {
140             NfcError err = (NfcError)e;
141
142             if (isHandleNull)
143             {
144                 throw new InvalidOperationException("Invalid instance (object may have been disposed or released)");
145             }
146
147             if (err == NfcError.InvalidParameterError)
148             {
149                 throw new ArgumentException(err.ToString());
150             }
151             else if (err == NfcError.NotSupportedError)
152             {
153                 throw new NotSupportedException();
154             }
155             else
156             {
157                 throw new InvalidOperationException(err.ToString());
158             }
159         }
160
161     }
162 }