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.
18 using System.Runtime.CompilerServices;
21 internal static partial class Interop
23 internal enum ErrorCode
25 None = Tizen.Internals.Errors.ErrorCode.None,
26 PermissionDenied = Tizen.Internals.Errors.ErrorCode.PermissionDenied,
27 OutOfMemory = Tizen.Internals.Errors.ErrorCode.OutOfMemory,
28 InvalidParameter = Tizen.Internals.Errors.ErrorCode.InvalidParameter,
29 NotSupported = Tizen.Internals.Errors.ErrorCode.NotSupported,
30 ConnectionTimeOut = Tizen.Internals.Errors.ErrorCode.ConnectionTimeout,
31 NetworkUnreachable = Tizen.Internals.Errors.ErrorCode.NetworkUnreachable,
32 InvalidOperation = Tizen.Internals.Errors.ErrorCode.InvalidOperation,
33 KeyNotAvailable = Tizen.Internals.Errors.ErrorCode.KeyNotAvailable,
34 ResourceBusy = Tizen.Internals.Errors.ErrorCode.ResourceBusy,
35 Canceled = Tizen.Internals.Errors.ErrorCode.Canceled,
36 Unknown = Tizen.Internals.Errors.ErrorCode.Unknown,
37 UserNotConsented = Tizen.Internals.Errors.ErrorCode.UserNotConsented,
38 ServiceNotAvailable = -0x02C20000 | 0x01, // MAPS_ERROR_SERVICE_NOT_AVAILABLE
39 NotFound = -0x02C20000 | 0x02, // MAPS_ERROR_NOT_FOUND
43 internal static class ErrorCodeExtensions
45 private const string LogTag = "Tizen.Maps";
47 internal static bool IsSuccess(this Interop.ErrorCode err)
49 return err == Interop.ErrorCode.None;
52 internal static bool IsFailed(this Interop.ErrorCode err)
54 return !err.IsSuccess();
58 /// The utility method to check for an error. Returns false on failure and prints warning messages.
60 /// <returns>Returns true in case of no error, otherwise false.</returns>
61 internal static bool WarnIfFailed(this Interop.ErrorCode err, string msg, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
65 Log.Debug(LogTag, $"{msg}, err: {err.ToString()}", file, func, line);
72 /// The utility method to check for an error. Returns false on failure and throws an exception.
74 /// <returns>Returns true in case of no error, otherwise false.</returns>
75 internal static bool ThrowIfFailed(this Interop.ErrorCode err, string msg, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
79 Log.Error(LogTag, $"{msg}, err: {err.ToString()}", file, func, line);
80 throw err.GetException(msg);
85 internal static Exception GetException(this Interop.ErrorCode err, string message)
87 string errMessage = $"{message}, err: {err.ToString()}";
90 //case ErrorCode.None:
91 case Interop.ErrorCode.PermissionDenied: return new System.UnauthorizedAccessException(errMessage);
92 case Interop.ErrorCode.InvalidParameter: return new System.ArgumentException(errMessage);
93 case Interop.ErrorCode.OutOfMemory:
94 case Interop.ErrorCode.NotSupported:
95 case Interop.ErrorCode.ConnectionTimeOut:
96 case Interop.ErrorCode.NetworkUnreachable:
97 case Interop.ErrorCode.InvalidOperation:
98 case Interop.ErrorCode.KeyNotAvailable:
99 case Interop.ErrorCode.ResourceBusy:
100 case Interop.ErrorCode.Canceled:
101 case Interop.ErrorCode.Unknown:
102 case Interop.ErrorCode.ServiceNotAvailable:
103 case Interop.ErrorCode.NotFound:
104 default: return new System.InvalidOperationException(errMessage);