From: Junghoon Park Date: Wed, 8 Mar 2017 10:18:04 +0000 (+0900) Subject: Add API for the resource manager X-Git-Tag: submit/trunk/20170823.075128~121^2~88 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e2fc2c3fb976a1e04b95c6a4b4abfb0fb7fb76d5;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git Add API for the resource manager Change-Id: Ie01ecec531d99f9e5c8a242eb48763f92eccfc05 Signed-off-by: Junghoon Park --- diff --git a/Tizen.Applications/Tizen.Applications.csproj b/Tizen.Applications/Tizen.Applications.csproj index 602103a..99239ad 100644 --- a/Tizen.Applications/Tizen.Applications.csproj +++ b/Tizen.Applications/Tizen.Applications.csproj @@ -64,6 +64,7 @@ + diff --git a/src/Tizen.Applications.Common/Interop/Interop.AppCommon.cs b/src/Tizen.Applications.Common/Interop/Interop.AppCommon.cs index e22019a..a221828 100755 --- a/src/Tizen.Applications.Common/Interop/Interop.AppCommon.cs +++ b/src/Tizen.Applications.Common/Interop/Interop.AppCommon.cs @@ -24,6 +24,14 @@ internal static partial class Interop { internal static partial class AppCommon { + internal enum ResourceCategory : int + { + Image = 0, + Layout, + Sound, + Binary + } + [DllImport(Libraries.AppCommon, EntryPoint = "app_get_id")] internal static extern ErrorCode AppGetId(out string appId); @@ -75,6 +83,8 @@ internal static partial class Interop [DllImport(Libraries.AppCommon, EntryPoint = "app_event_get_region_format")] internal static extern ErrorCode AppEventGetRegionFormat(IntPtr handle, out string region); + [DllImport(Libraries.AppCommon, EntryPoint = "app_resource_manager_get")] + internal static extern ErrorCode AppResourceManagerGet(ResourceCategory category, string id, out string path); } } diff --git a/src/Tizen.Applications.Common/Tizen.Applications.Common.csproj b/src/Tizen.Applications.Common/Tizen.Applications.Common.csproj index 4abce7f..5b0bd9e 100755 --- a/src/Tizen.Applications.Common/Tizen.Applications.Common.csproj +++ b/src/Tizen.Applications.Common/Tizen.Applications.Common.csproj @@ -67,6 +67,7 @@ + diff --git a/src/Tizen.Applications.Common/Tizen.Applications/ResourceManager.cs b/src/Tizen.Applications.Common/Tizen.Applications/ResourceManager.cs new file mode 100755 index 0000000..dd36f71 --- /dev/null +++ b/src/Tizen.Applications.Common/Tizen.Applications/ResourceManager.cs @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using Tizen.Internals.Errors; + +namespace Tizen.Applications +{ + /// + /// Class for getting resource path. + /// + public static class ResourceManager + { + /// + /// Enumeration for Resource category. + /// + public enum Category : int + { + /// + /// Image format. + /// + Image = 0, + + /// + /// Layout format. + /// + Layout, + + /// + /// Sound format. + /// + Sound, + + /// + /// Binary format. + /// + Binary + } + + /// + /// Converts resource ID to path name. + /// + /// Category to search + /// ID to search + /// Found resource path + /// Thrown in case of failed conditions + public static string GetPath(Category category, string id) + { + string path; + ErrorCode err = Interop.AppCommon.AppResourceManagerGet( + (Interop.AppCommon.ResourceCategory)category, id, out path); + + switch (err) + { + case ErrorCode.InvalidParameter: + throw new InvalidOperationException("Invalid parameter"); + + case ErrorCode.OutOfMemory: + throw new InvalidOperationException("Out-of-memory at unmanaged code"); + + case ErrorCode.IoError: + throw new InvalidOperationException("IO error at unmanaged code"); + } + + return path; + } + + /// + /// Converts resource ID to path name. + /// + /// Category to search + /// ID to search + /// Found resource path or null when the resource doesn't exist + /// Thrown in case of failed conditions + public static string TryGetPath(Category category, string id) + { + string path; + ErrorCode err = Interop.AppCommon.AppResourceManagerGet( + (Interop.AppCommon.ResourceCategory)category, id, out path); + + switch (err) + { + case ErrorCode.InvalidParameter: + throw new InvalidOperationException("Invalid parameter"); + + case ErrorCode.OutOfMemory: + throw new InvalidOperationException("Out-of-memory at unmanaged code"); + + case ErrorCode.IoError: + return null; + } + + return path; + } + } +}