6dee6db220c9d73b97b5ae73baf7347d2a654176
[platform/core/csapi/tizenfx.git] / internals / src / Tizen.Network.Mtp / Tizen.Network.Mtp / MtpErrorFactory.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.Mtp
21 {
22     static internal class MtpErrorValue
23     {
24         internal const int Base = -0x01CC0000;
25     }
26
27     /// <summary>
28     /// Enumeration for Mtp Error.
29     /// </summary>
30     /// <since_tizen> 4 </since_tizen>
31     public enum MtpError
32     {
33         /// <summary>
34         /// Successful.
35         /// </summary>
36         None = ErrorCode.None,
37         /// <summary>
38         /// I/O Error.
39         /// </summary>
40         IoError = ErrorCode.IoError,
41         /// <summary>
42         /// Invalid Parameter.
43         /// </summary>
44         InvalidParameterError = ErrorCode.InvalidParameter,
45         /// <summary>
46         /// Out of memory.
47         /// </summary>
48         OutOfMemoryError = ErrorCode.OutOfMemory,
49         /// <summary>
50         /// Permission Denied.
51         /// </summary>
52         PermissionDeniedError = ErrorCode.PermissionDenied,
53         /// <summary>
54         /// Not Supported.
55         /// </summary>
56         NotSupportedError = ErrorCode.NotSupported,
57         /// <summary>
58         /// Not available communication with Mtp framework.
59         /// </summary>
60         CommunicationError = MtpErrorValue.Base | 0x01,
61         /// <summary>
62         /// Controller Error.
63         /// </summary>
64         ControllerError = MtpErrorValue.Base | 0x02,
65         /// <summary>
66         /// No device.
67         /// </summary>
68         NoDeviceError = MtpErrorValue.Base | 0x03,
69         /// <summary>
70         /// Not Initialized.
71         /// </summary>
72         NotInitializedError = MtpErrorValue.Base | 0x04,
73         /// <summary>
74         /// Not Activated.
75         /// </summary>
76         NotActivatedError = MtpErrorValue.Base | 0x05,
77         /// <summary>
78         /// Not Activated Communication.
79         /// </summary>
80         NotActivatedCommunicationError = MtpErrorValue.Base | 0x06,
81         /// <summary>
82         /// Plugin Fail.
83         /// </summary>
84         PluginFailError = MtpErrorValue.Base | 0x07
85     }
86
87     internal static class MtpErrorFactory
88     {
89         static internal void ThrowMtpException(int e)
90         {
91             ThrowException(e, false);
92         }
93
94         static internal void ThrowMtpException(int e, int handle)
95         {
96             ThrowException(e, (handle < 0));
97         }
98
99         static private void ThrowException(int e, bool isHandleNull)
100         {
101             MtpError err = (MtpError)e;
102
103             if (isHandleNull)
104             {
105                 throw new InvalidOperationException("Invalid instance (object may have been disposed or released)");
106             }
107
108             if (err == MtpError.InvalidParameterError)
109             {
110                 throw new ArgumentException(err.ToString());
111             }
112             else if (err == MtpError.NotSupportedError)
113             {
114                 throw new NotSupportedException();
115             }
116             else
117             {
118                 throw new InvalidOperationException(err.ToString());
119             }
120         }
121
122     }
123 }