Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia / AudioManager / AudioManagerErrorFactory.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     /// <summary>
23     /// Enumeration for sound manager's error codes.
24     /// </summary>
25     internal enum AudioManagerError{
26
27         SoundManagerError = -0x01960000,
28         /// <summary>
29         /// Successful
30         /// </summary>
31         None = ErrorCode.None,
32         /// <summary>
33         /// Out of memory
34         /// </summary>
35         OutOfMemory = ErrorCode.OutOfMemory,
36         /// <summary>
37         /// Invalid parameter
38         /// </summary>
39         InvalidParameter = ErrorCode.InvalidParameter,
40         /// <summary>
41         /// Invalid operation
42         /// </summary>
43         InvalidOperation = ErrorCode.InvalidOperation,
44         /// <summary>
45         /// Permission denied
46         /// </summary>
47         PermissionDenied = ErrorCode.PermissionDenied,
48         /// <summary>
49         /// Not supported
50         /// </summary>
51         NotSupported = ErrorCode.NotSupported,
52         /// <summary>
53         /// No data
54         /// </summary>
55         NoData = ErrorCode.NoData,
56         /// <summary>
57         /// Internal error inside the sound system
58         /// </summary>
59         Internal = SoundManagerError | 01,
60         /// <summary>
61         /// Noncompliance with the sound system policy
62         /// </summary>
63         Policy = SoundManagerError | 02,
64         /// <summary>
65         /// No playing sound
66         /// </summary>
67         NoPlayingSound = SoundManagerError | 03,
68         /// <summary>
69         /// Invalid state (Since 3.0)
70         /// </summary>
71         InvalidState = SoundManagerError | 04
72     }
73
74     internal static class AudioManagerErrorFactory
75     {
76         static internal void CheckAndThrowException(int error, string msg)
77         {
78             AudioManagerError e = (AudioManagerError) error;
79             switch (e)
80             {
81                 case AudioManagerError.None:
82                     return;
83                 case AudioManagerError.OutOfMemory:
84                     throw new InvalidOperationException("Out of Memory: " + msg);
85                 case AudioManagerError.InvalidParameter:
86                     throw new ArgumentException("Invalid Parameter: " + msg);
87                 case AudioManagerError.InvalidOperation:
88                     throw new InvalidOperationException("Invalid Opertation: " + msg);
89                 case AudioManagerError.PermissionDenied:
90                     throw new InvalidOperationException("Permission Denied: " + msg);
91                 case AudioManagerError.NotSupported:
92                     throw new InvalidOperationException("Not Supported: " + msg);
93                 case AudioManagerError.NoData:
94                     throw new InvalidOperationException("No Data: " + msg);
95                 case AudioManagerError.Internal:
96                     throw new InvalidOperationException("Internal Error: " + msg);
97                 case AudioManagerError.Policy:
98                     throw new InvalidOperationException("Noncomplaince with System Sound Policy error: " + msg);
99                 case AudioManagerError.NoPlayingSound:
100                     throw new InvalidOperationException("No playing sound: " + msg);
101                 case AudioManagerError.InvalidState:
102                     throw new InvalidOperationException("Invalid State: " + msg);
103                 default:
104                     throw new InvalidOperationException("Unknown Error Code: " + msg);
105             }
106         }
107
108         static internal void CheckAndThrowException(int error, IntPtr handle, string msg)
109         {
110             if (handle == IntPtr.Zero)
111             {
112                 throw new InvalidOperationException("Invalid instance (object may have been disposed or released)");
113             }
114             else
115             {
116                 CheckAndThrowException(error, msg);
117             }
118         }
119     }
120 }