[Multimedia] Sync with the original project
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia / AudioManager / AudioManagerError.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.Multimedia
21 {
22     internal enum AudioManagerError
23     {
24         SoundManagerError = -0x01960000,
25         /// <summary>
26         /// Successful
27         /// </summary>
28         None = ErrorCode.None,
29         /// <summary>
30         /// Out of memory
31         /// </summary>
32         OutOfMemory = ErrorCode.OutOfMemory,
33         /// <summary>
34         /// Invalid parameter
35         /// </summary>
36         InvalidParameter = ErrorCode.InvalidParameter,
37         /// <summary>
38         /// Invalid operation
39         /// </summary>
40         InvalidOperation = ErrorCode.InvalidOperation,
41         /// <summary>
42         /// Permission denied
43         /// </summary>
44         PermissionDenied = ErrorCode.PermissionDenied,
45         /// <summary>
46         /// Not supported
47         /// </summary>
48         NotSupported = ErrorCode.NotSupported,
49         /// <summary>
50         /// No data
51         /// </summary>
52         NoData = ErrorCode.NoData,
53         /// <summary>
54         /// Internal error inside the sound system
55         /// </summary>
56         Internal = SoundManagerError | 01,
57         /// <summary>
58         /// Noncompliance with the sound system policy
59         /// </summary>
60         Policy = SoundManagerError | 02,
61         /// <summary>
62         /// No playing sound
63         /// </summary>
64         NoPlayingSound = SoundManagerError | 03,
65         /// <summary>
66         /// Invalid state (Since 3.0)
67         /// </summary>
68         InvalidState = SoundManagerError | 04
69     }
70
71     internal static class AudioManagerErrorExtensions
72     {
73         internal static void Validate(this AudioManagerError err, string msg)
74         {
75             if (err == AudioManagerError.None)
76             {
77                 return;
78             }
79
80             msg = msg ?? "";
81             msg += $" : {err}.";
82
83             switch (err)
84             {
85                 case AudioManagerError.OutOfMemory:
86                     throw new OutOfMemoryException(msg);
87
88                 case AudioManagerError.InvalidParameter:
89                     throw new ArgumentException(msg);
90
91                 case AudioManagerError.PermissionDenied:
92                     throw new UnauthorizedAccessException(msg);
93
94                 case AudioManagerError.NotSupported:
95                     throw new NotSupportedException(msg);
96
97                 case AudioManagerError.Policy:
98                     throw new AudioPolicyException(msg);
99
100                 case AudioManagerError.NoData:
101                     // TODO check when it is thrown
102                     throw new InvalidOperationException(msg);
103
104                 case AudioManagerError.Internal:
105                 case AudioManagerError.InvalidOperation:
106                 case AudioManagerError.NoPlayingSound:
107                 case AudioManagerError.InvalidState:
108                     throw new InvalidOperationException(msg);
109
110                 default:
111                     throw new InvalidOperationException("Unknown Error : " + msg);
112             }
113         }
114     }
115 }