Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Convergence / Tizen.Convergence / InternalErrorFactory.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 using System.Threading.Tasks;
20 using System.Threading;
21
22 namespace Tizen.Convergence
23 {
24     internal enum ConvErrorCode
25     {
26         None = ErrorCode.None,
27         OutOfMemory = ErrorCode.OutOfMemory,
28         InvalidParameter = ErrorCode.InvalidParameter,
29         InvalidOperation = ErrorCode.InvalidOperation,
30         NoData = ErrorCode.NoData,
31         NotSupported = ErrorCode.NotSupported,
32         PermissionDenied = ErrorCode.PermissionDenied,
33     }
34
35     internal class ErrorFactory
36     {
37         internal static string LogTag = "Tizen.Convergence";
38
39         internal static Exception GetException(int error)
40         {
41             if ((ConvErrorCode)error == ConvErrorCode.OutOfMemory)
42             {
43                 return new OutOfMemoryException("Out of memory");
44             }
45             else if ((ConvErrorCode)error == ConvErrorCode.InvalidParameter)
46             {
47                 return new ArgumentException("Invalid parameter");
48             }
49             else if ((ConvErrorCode)error == ConvErrorCode.InvalidOperation)
50             {
51                 return new InvalidOperationException("Invalid operation");
52             }
53             else if ((ConvErrorCode)error == ConvErrorCode.NotSupported)
54             {
55                 return new NotSupportedException("Unsupported feature http://tizen.org/feature/convergence.d2d");
56             }
57             else if ((ConvErrorCode)error == ConvErrorCode.PermissionDenied)
58             {
59                 return new UnauthorizedAccessException("Permission denied. (http://tizen.org/privilege/internet, http://tizen.org/privilege/bluetooth, http://tizen.org/privilege/d2d.datasharing)");
60             }
61             else if ((ConvErrorCode)error == ConvErrorCode.NoData)
62             {
63                 return new InvalidOperationException("The payload is empty");
64             }
65             else
66             {
67                 return new Exception("Unknown error");
68             }
69         }
70     }
71 }