Release 4.0.0-preview1-00051
[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 Nfc Error.
24     /// </summary>
25     /// <since_tizen> 3 </since_tizen>
26     public enum NfcError
27     {
28         None = ErrorCode.None,
29         IoError = ErrorCode.IoError,
30         InvalidParameterError = ErrorCode.InvalidParameter,
31         OutOfMemoryError = ErrorCode.OutOfMemory,
32         TimedOutError = ErrorCode.TimedOut,
33         DeviceBusyError = ErrorCode.ResourceBusy,
34         NotSupportedError = ErrorCode.NotSupported,
35         PermissionDeniedError = ErrorCode.PermissionDenied,
36         OperationFailedError = -0x01C20000 | 0x01,
37         InvalidNdefMessageError = -0x01C20000 | 0x02,
38         InvalidRecordTypeError = -0x01C20000 | 0x03,
39         NoDeviceError = -0x01C20000 | 0x04,
40         NotActivatedError = -0x01C20000 | 0x05,
41         AlreadyActivatedError = -0x01C20000 | 0x06,
42         AlreadyDeactivatedError = -0x01C20000 | 0x07,
43         ReadOnlyNdefError = -0x01C20000 | 0x08,
44         NoSpaceOnNdefError = -0x01C20000 | 0x09,
45         NoNdefMessageError = -0x01C20000 | 0x0a,
46         NotNdefFormatError = -0x01C20000 | 0x0b,
47         SecurityRestrictedError = -0x01C20000 | 0x0c,
48         IllegalStateError = -0x01C20000 | 0x0d,
49         NotInitializedError = -0x01C20000 | 0x0e,
50         TagNotSupportedError = -0x01C20000 | 0x0f,
51         AidAlreadyRegisteredError = -0x01C20000 | 0x10
52     }
53
54     internal static class NfcErrorFactory
55     {
56         static internal void ThrowNfcException(int e)
57         {
58             ThrowException(e, false);
59         }
60
61         static internal void ThrowNfcException(int e, int handle)
62         {
63             ThrowException(e, (handle < 0));
64         }
65
66         static private void ThrowException(int e, bool isHandleNull)
67         {
68             NfcError err = (NfcError)e;
69
70             if (isHandleNull)
71             {
72                 throw new InvalidOperationException("Invalid instance (object may have been disposed or released)");
73             }
74
75             if (err == NfcError.InvalidParameterError)
76             {
77                 throw new ArgumentException(err.ToString());
78             }
79             else if (err == NfcError.NotSupportedError)
80             {
81                 throw new NotSupportedException();
82             }
83             else
84             {
85                 throw new InvalidOperationException(err.ToString());
86             }
87         }
88
89     }
90 }