Add API for the resource manager
authorJunghoon Park <jh9216.park@samsung.com>
Wed, 8 Mar 2017 10:18:04 +0000 (19:18 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Fri, 10 Mar 2017 08:44:25 +0000 (00:44 -0800)
Change-Id: Ie01ecec531d99f9e5c8a242eb48763f92eccfc05
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
Tizen.Applications/Tizen.Applications.csproj
src/Tizen.Applications.Common/Interop/Interop.AppCommon.cs
src/Tizen.Applications.Common/Tizen.Applications.Common.csproj
src/Tizen.Applications.Common/Tizen.Applications/ResourceManager.cs [new file with mode: 0755]

index 602103a..99239ad 100644 (file)
@@ -64,6 +64,7 @@
     <Compile Include="../Tizen.Applications.Common/Tizen.Applications/ApplicationTerminatedEventArgs.cs" />
     <Compile Include="../Tizen.Applications.Common/Tizen.Applications/ApplicationType.cs" />
     <Compile Include="../Tizen.Applications.Common/Tizen.Applications/Bundle.cs" />
+    <Compile Include="../Tizen.Applications.Common/Tizen.Applications/ResourceManager.cs" />
     <Compile Include="../Tizen.Applications.PackageManager/Tizen.Applications/CertificateType.cs" />
     <Compile Include="../Tizen.Applications.Common/Tizen.Applications/CoreApplication.cs" />
     <Compile Include="../Tizen.Applications.UI/Tizen.Applications/CoreUIApplication.cs" />
index e22019a..a221828 100755 (executable)
@@ -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);
     }
 }
 
index 4abce7f..5b0bd9e 100755 (executable)
@@ -67,6 +67,7 @@
     <Compile Include="Tizen.Applications\ApplicationType.cs" />
     <Compile Include="Tizen.Applications\CoreApplication.cs" />
     <Compile Include="Tizen.Applications\DirectoryInfo.cs" />
+    <Compile Include="Tizen.Applications\ResourceManager.cs" />
     <Compile Include="Tizen.Applications\LocaleChangedEventArgs.cs" />
     <Compile Include="Tizen.Applications\LowBatteryEventArgs.cs" />
     <Compile Include="Tizen.Applications\LowBatteryStatus.cs" />
diff --git a/src/Tizen.Applications.Common/Tizen.Applications/ResourceManager.cs b/src/Tizen.Applications.Common/Tizen.Applications/ResourceManager.cs
new file mode 100755 (executable)
index 0000000..dd36f71
--- /dev/null
@@ -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
+{
+    /// <summary>
+    /// Class for getting resource path.
+    /// </summary>
+    public static class ResourceManager
+    {
+        /// <summary>
+        /// Enumeration for Resource category.
+        /// </summary>
+        public enum Category : int
+        {
+            /// <summary>
+            /// Image format.
+            /// </summary>
+            Image = 0,
+
+            /// <summary>
+            /// Layout format.
+            /// </summary>
+            Layout,
+
+            /// <summary>
+            /// Sound format.
+            /// </summary>
+            Sound,
+
+            /// <summary>
+            /// Binary format.
+            /// </summary>
+            Binary
+        }
+
+        /// <summary>
+        /// Converts resource ID to path name.
+        /// </summary>
+        /// <param name="category">Category to search</param>
+        /// <param name="id">ID to search</param>
+        /// <returns>Found resource path</returns>
+        /// <exception cref="InvalidOperationException">Thrown in case of failed conditions</exception>
+        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;
+        }
+
+        /// <summary>
+        /// Converts resource ID to path name.
+        /// </summary>
+        /// <param name="category">Category to search</param>
+        /// <param name="id">ID to search</param>
+        /// <returns>Found resource path or null when the resource doesn't exist</returns>
+        /// <exception cref="InvalidOperationException">Thrown in case of failed conditions</exception>
+        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;
+        }
+    }
+}