3f245d98132360c0d9a0f4ff51d83d72259ecf2b
[platform/core/csapi/tizenfx.git] / src / Tizen.Network.Bluetooth / Tizen.Network.Bluetooth / BluetoothError.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
19 namespace Tizen.Network.Bluetooth
20 {
21     /// <summary>
22     /// A class which is used to Throw the Bluetooth Error exceptions.
23     /// </summary>
24     static internal class BluetoothErrorFactory
25     {
26         /// <summary>
27         /// Exceptions for Bluetooth Errors.
28         /// </summary>
29         /// <exception cref="InvalidOperationException">Thrown when the Bluetooth Error happens.</exception>
30         internal static void ThrowBluetoothException(int exception)
31         {
32             throw CreateBluetoothException(exception);
33         }
34
35         /// <summary>
36         /// Creates Bluetooth Exception.
37         /// </summary>
38         internal static Exception CreateBluetoothException(int exception)
39         {
40             BluetoothError error = (BluetoothError)exception;
41             switch (error)
42             {
43                 case BluetoothError.InvalidParameter:
44                     return new InvalidOperationException("Invalid parameter");
45
46                 case BluetoothError.Cancelled:
47                     return new InvalidOperationException("Operation cancelled");
48
49                 case BluetoothError.AlreadyDone:
50                     return new InvalidOperationException("Operation already done");
51
52                 case BluetoothError.TimedOut:
53                     return new InvalidOperationException("Timeout error");
54
55                 case BluetoothError.AuthFailed:
56                     return new InvalidOperationException("Authentication failed");
57
58                 case BluetoothError.AuthRejected:
59                     return new InvalidOperationException("Authentication rejected");
60
61                 case BluetoothError.NoData:
62                     return new InvalidOperationException("No data available");
63
64                 case BluetoothError.NotEnabled:
65                     return new InvalidOperationException("Local adapter not enabled");
66
67                 case BluetoothError.NotInitialized:
68                     return new InvalidOperationException("Local adapter not initialized");
69
70                 case BluetoothError.NowInProgress:
71                     return new InvalidOperationException("Operation now in progress");
72
73                 case BluetoothError.NotInProgress:
74                     return new InvalidOperationException("Operation not in progress");
75
76                 case BluetoothError.NotSupported:
77                     return new NotSupportedException("Bluetooth is not supported");
78
79                 case BluetoothError.OperationFailed:
80                     return new InvalidOperationException("Operation failed");
81
82                 case BluetoothError.OutOfMemory:
83                     return new InvalidOperationException("Out of memory");
84
85                 case BluetoothError.PermissionDenied:
86                     return new InvalidOperationException("Permission denied");
87
88                 case BluetoothError.QuotaExceeded:
89                     return new InvalidOperationException("Quota exceeded");
90
91                 case BluetoothError.RemoteDeviceNotBonded:
92                     return new InvalidOperationException("Remote device not bonded");
93
94                 case BluetoothError.RemoteDeviceNotConnected:
95                     return new InvalidOperationException("Remote device not connected");
96
97                 case BluetoothError.RemoteDeviceNotFound:
98                     return new InvalidOperationException("Remote device not found");
99
100                 case BluetoothError.ResourceBusy:
101                     return new InvalidOperationException("Device or resource busy");
102
103                 case BluetoothError.ResourceUnavailable:
104                     return new InvalidOperationException("Resource temporarily unavailable");
105
106                 case BluetoothError.ServiceNotFound:
107                     return new InvalidOperationException("Service Not Found");
108
109                 case BluetoothError.ServiceSearchFailed:
110                     return new InvalidOperationException("Service search failed");
111
112                 default:
113                     return new InvalidOperationException("Unknown exception");
114             }
115         }
116     }
117 }
118