2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 using System.Runtime.CompilerServices;
22 namespace Tizen.Multimedia
24 internal static partial class Interop
26 internal enum ErrorCode
28 None = Tizen.Internals.Errors.ErrorCode.None,
29 OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory,
30 InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter,
31 InvalidOperation = Tizen.Internals.Errors.ErrorCode.InvalidOperation,
32 PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied,
33 NotSupported = Tizen.Internals.Errors.ErrorCode.NotSupported,
34 ResourceBusy = Tizen.Internals.Errors.ErrorCode.ResourceBusy,
35 NoSuchFile = Tizen.Internals.Errors.ErrorCode.NoSuchFile,
38 InvalidState = -0x019A0000 | 0x01, // RADIO_ERROR_INVALID_STATE
39 SoundPolicy = -0x019A0000 | 0x02, // RADIO_ERROR_SOUND_POLICY
40 NoAntenna = -0x019A0000 | 0x03, // RADIO_ERROR_NO_ANTENNA
42 // Image/ Video Utility
43 NotSupportedFormat = -0x01980000 | 0x01, // VIDEO_UTIL_ERROR_NOT_SUPPORTED_FORMAT
47 internal static class ErrorCodeExtensions
49 private const string LogTag = "Tizen.Multimedia";
51 internal static bool IsSuccess(this Interop.ErrorCode err)
53 return err == Interop.ErrorCode.None;
56 internal static bool IsFailed(this Interop.ErrorCode err)
58 return !err.IsSuccess();
62 /// Utility method to check for error, returns false if failed and print warning messages
64 /// <returns>true in case of no error, false otherwise</returns>
65 internal static bool WarnIfFailed(this Interop.ErrorCode err, string msg, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
69 Log.Debug(LogTag, $"{msg}, err: {err.ToString()}", file, func, line);
76 /// Utility method to check for error, returns false if failed and throw exception
78 /// <returns>true in case of no error</returns>
79 internal static bool ThrowIfFailed(this Interop.ErrorCode err, string msg, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
83 Log.Error(LogTag, $"{msg}, err: {err.ToString()}", file, func, line);
84 throw err.GetException(msg);
89 internal static Exception GetException(this Interop.ErrorCode err, string message)
91 string errMessage = $"{message}, err: {err.ToString()}";
94 //case ErrorCode.None:
95 case Interop.ErrorCode.PermissionDenied: return new UnauthorizedAccessException(errMessage);
96 case Interop.ErrorCode.InvalidParameter: return new ArgumentException(errMessage);
97 case Interop.ErrorCode.NoSuchFile: return new FileNotFoundException(errMessage);
98 case Interop.ErrorCode.OutOfMemory: return new OutOfMemoryException(errMessage);
99 case Interop.ErrorCode.NoAntenna:
100 case Interop.ErrorCode.NotSupported: return new NotSupportedException(errMessage);
101 case Interop.ErrorCode.InvalidOperation:
102 case Interop.ErrorCode.InvalidState:
103 case Interop.ErrorCode.SoundPolicy:
104 case Interop.ErrorCode.ResourceBusy:
105 default: return new InvalidOperationException(errMessage);