Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Network.Smartcard / Tizen.Network.Smartcard / SmartcardErrorFactory.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.Smartcard
21 {
22     internal enum SmartcardError
23     {
24         None = ErrorCode.None,
25         IoError = ErrorCode.IoError,
26         InvalidParameterError = ErrorCode.InvalidParameter,
27         PermissionDeniedError = ErrorCode.PermissionDenied,
28         NotSupportedError = ErrorCode.NotSupported,
29         GeneralError = -0x01C70000 | 0x01,
30         NoSuchElementError = -0x01C70000 | 0x02,
31         IllegalStateError = -0x01C70000 | 0x03,
32         IllegalReferenceError = -0x01C70000 | 0x04,
33         OperationNotSupportError = -0x01C70000 | 0x05,
34         ChannelNotAvailableError = -0x01C70000 | 0x06,
35         NotInitializedError = -0x01C70000 | 0x07
36     }
37
38     internal static class SmartcardErrorFactory
39     {
40         static internal void ThrowSmartcardException(int e)
41         {
42             ThrowException(e, false);
43         }
44
45         static internal void ThrowSmartcardException(int e, int handle)
46         {
47             ThrowException(e, (handle < 0));
48         }
49
50         static private void ThrowException(int e, bool isHandleNull)
51         {
52             SmartcardError err = (SmartcardError)e;
53
54             if (isHandleNull)
55             {
56                 throw new InvalidOperationException("Invalid instance (object may have been disposed or released)");
57             }
58
59             if (err == SmartcardError.InvalidParameterError)
60             {
61                 throw new ArgumentException(err.ToString());
62             }
63             else if (err == SmartcardError.NotSupportedError)
64             {
65                 throw new NotSupportedException(err.ToString());
66             }
67             else
68             {
69                 throw new InvalidOperationException(err.ToString());
70             }
71         }
72
73     }
74 }