Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.Vision / MediaVision / MediaVisionError.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 System.IO;
19 using Tizen.Internals.Errors;
20
21 namespace Tizen.Multimedia
22 {
23     internal static class MediaVisionLog
24     {
25         internal const string Tag = "Tizen.Multimedia.MediaVision";
26     }
27
28     /// <summary>
29     /// Enumeration for media vision's error codes.
30     /// </summary>
31     internal enum MediaVisionError
32     {
33         MediaVisionErrorCode = -0x019D0000,
34         /// <summary>
35         /// Successful
36         /// </summary>
37         None = ErrorCode.None,
38         /// <summary>
39         /// Not supported
40         /// </summary>
41         NotSupported = ErrorCode.NotSupported,
42         /// <summary>
43         /// Message too long
44         /// </summary>
45         MsgTooLong = ErrorCode.MsgTooLong,
46         /// <summary>
47         /// No data
48         /// </summary>
49         NoData = ErrorCode.NoData,
50         /// <summary>
51         /// Key not available
52         /// </summary>
53         KeyNotAvailable = ErrorCode.KeyNotAvailable,
54         /// <summary>
55         /// Out of memory
56         /// </summary>
57         OutOfMemory = ErrorCode.OutOfMemory,
58         /// <summary>
59         /// Invalid parameter
60         /// </summary>
61         InvalidParameter = ErrorCode.InvalidParameter,
62         /// <summary>
63         /// Invalid operation
64         /// </summary>
65         InvalidOperation = ErrorCode.InvalidOperation,
66         /// <summary>
67         /// Permission denied
68         /// </summary>
69         PermissionDenied = ErrorCode.NotPermitted,
70         /// <summary>
71         /// Not supported format
72         /// </summary>
73         NotSupportedFormat = MediaVisionErrorCode | 0x01,
74         /// <summary>
75         /// Internal error
76         /// </summary>
77         Internal = MediaVisionErrorCode | 0x02,
78         /// <summary>
79         /// Invalid data
80         /// </summary>
81         InvalidData = MediaVisionErrorCode | 0x03,
82         /// <summary>
83         /// Invalid path (Since 3.0)
84         /// </summary>
85         InvalidPath = MediaVisionErrorCode | 0x04
86     }
87
88     internal static class MediaVisionErrorExtensions
89     {
90         public static void Validate(this MediaVisionError error, string msg)
91         {
92             if (error == MediaVisionError.None)
93             {
94                 return;
95             }
96
97             switch (error)
98             {
99                 case MediaVisionError.NotSupported:
100                     throw new NotSupportedException(msg);
101                 case MediaVisionError.MsgTooLong:
102                     throw new ArgumentException($"{msg} : Message too long.");
103                 case MediaVisionError.NoData:
104                     throw new InvalidOperationException($"{msg} : No Data.");
105                 case MediaVisionError.KeyNotAvailable:
106                     throw new ArgumentException($"{msg} : Key Not Available.");
107                 case MediaVisionError.OutOfMemory:
108                     throw new OutOfMemoryException($"{msg} : Out of Memory.");
109                 case MediaVisionError.InvalidParameter:
110                     throw new ArgumentException($"{msg} : Invalid argument.");
111                 case MediaVisionError.InvalidOperation:
112                     throw new InvalidOperationException($"{msg} : Invalid Operation.");
113                 case MediaVisionError.PermissionDenied:
114                     throw new UnauthorizedAccessException($"{msg} : Permission Denied.");
115                 case MediaVisionError.NotSupportedFormat:
116                     throw new NotSupportedException($"{msg} : Not Supported Format.");
117                 case MediaVisionError.Internal:
118                     throw new InvalidOperationException($"{msg} : Internal Error.");
119                 case MediaVisionError.InvalidData:
120                     throw new ArgumentException($"{msg} : Invalid Data.");
121                 case MediaVisionError.InvalidPath:
122                     throw new FileNotFoundException($"{msg} : Invalid Path.");
123                 default:
124                     throw new InvalidOperationException($"{msg} : Unknown Error.");
125             }
126         }
127     }
128 }