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 ServiceNotAvailable = -0x02C20000 | 0x01, // MAPS_ERROR_SERVICE_NOT_AVAILABLE
38 NotFound = -0x02C20000 | 0x02, // MAPS_ERROR_NOT_FOUND
42 internal static class ErrorCodeExtensions
44 private const string LogTag = "Tizen.Maps";
46 internal static bool IsSuccess(this Interop.ErrorCode err)
48 return err == Interop.ErrorCode.None;
51 internal static bool IsFailed(this Interop.ErrorCode err)
53 return !err.IsSuccess();
57 /// Utility method to check for error, returns false if failed and print warning messages
59 /// <returns>true in case of no error, false otherwise</returns>
60 internal static bool WarnIfFailed(this Interop.ErrorCode err, string msg, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
64 Log.Debug(LogTag, string.Format("{0}, err: {1}", msg, err.ToString()), file, func, line);
71 /// Utility method to check for error, returns false if failed and throw exception
73 /// <returns>true in case of no error</returns>
74 internal static bool ThrowIfFailed(this Interop.ErrorCode err, string msg, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
78 Log.Error(LogTag, string.Format("{0}, err: {1}", msg, err.ToString()), file, func, line);
79 throw err.GetException(msg);
84 internal static Exception GetException(this Interop.ErrorCode err, string message)
86 string errMessage = string.Format("{0}, err: {1}", message, err.ToString());
89 //case ErrorCode.None:
90 case Interop.ErrorCode.PermissionDenied: return new UnauthorizedAccessException(errMessage);
91 case Interop.ErrorCode.InvalidParameter: return new ArgumentException(errMessage);
92 case Interop.ErrorCode.OutOfMemory:
93 case Interop.ErrorCode.NotSupported:
94 case Interop.ErrorCode.ConnectionTimeOut:
95 case Interop.ErrorCode.NetworkUnreachable:
96 case Interop.ErrorCode.InvalidOperation:
97 case Interop.ErrorCode.KeyNotAvailable:
98 case Interop.ErrorCode.ResourceBusy:
99 case Interop.ErrorCode.Canceled:
100 case Interop.ErrorCode.Unknown:
101 case Interop.ErrorCode.ServiceNotAvailable:
102 case Interop.ErrorCode.NotFound:
103 default: return new InvalidOperationException(errMessage);