diff options
author | Hyunho Kang <hhstark.kang@samsung.com> | 2017-03-20 13:32:27 +0900 |
---|---|---|
committer | Hyunho Kang <hhstark.kang@samsung.com> | 2017-03-20 14:54:47 +0900 |
commit | 5f5fc92a5dc545d155821b5b8bab267a93d4ec7b (patch) | |
tree | 0d64908e12b329e094f91ce7ef08e073505c67f5 | |
parent | 1824590de7863fe2c32334fd7579f4080d7dfd03 (diff) | |
download | application-5f5fc92a5dc545d155821b5b8bab267a93d4ec7b.tar.gz application-5f5fc92a5dc545d155821b5b8bab267a93d4ec7b.tar.bz2 application-5f5fc92a5dc545d155821b5b8bab267a93d4ec7b.zip |
Add bundle encode/decode APIs
- Encode
- Decode
Change-Id: If27b9fcb3c8cdc95878568e575842a47be71797b
Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com>
-rwxr-xr-x | Tizen.Applications.Common/Interop/Interop.Bundle.cs | 6 | ||||
-rwxr-xr-x | Tizen.Applications.Common/Tizen.Applications/Bundle.cs | 47 |
2 files changed, 53 insertions, 0 deletions
diff --git a/Tizen.Applications.Common/Interop/Interop.Bundle.cs b/Tizen.Applications.Common/Interop/Interop.Bundle.cs index ab996f0..65c314a 100755 --- a/Tizen.Applications.Common/Interop/Interop.Bundle.cs +++ b/Tizen.Applications.Common/Interop/Interop.Bundle.cs @@ -59,6 +59,12 @@ internal static partial class Interop [DllImport(Libraries.Bundle, EntryPoint = "bundle_foreach")] internal static extern void Foreach(SafeBundleHandle handle, Iterator iterator, IntPtr userData); + [DllImport(Libraries.Bundle, EntryPoint = "bundle_encode")] + internal static extern void BundleEncode(SafeBundleHandle handle, out string str, out int len); + + [DllImport(Libraries.Bundle, EntryPoint = "bundle_decode")] + internal static extern SafeBundleHandle BundleDecode(string bundleRaw, int len); + [DllImport(Libraries.Bundle, EntryPoint = "bundle_dup")] internal static extern SafeBundleHandle DangerousClone(IntPtr handle); diff --git a/Tizen.Applications.Common/Tizen.Applications/Bundle.cs b/Tizen.Applications.Common/Tizen.Applications/Bundle.cs index eafb307..1b56e8e 100755 --- a/Tizen.Applications.Common/Tizen.Applications/Bundle.cs +++ b/Tizen.Applications.Common/Tizen.Applications/Bundle.cs @@ -586,6 +586,53 @@ namespace Tizen.Applications } /// <summary> + /// Decodes an encoded bundle data. + /// </summary> + /// <param name="bundleRaw">The encoded bundle data. bundleRaw should be return value of Tizen.Applications.Bundle.Encode, otherwise this method will not succeed</param> + /// <returns>Decoded Bundle object.</returns> + /// <exception cref="System.ArgumentException">Thrown when there is an invalid parameter.</exception> + /// <code> + /// Tizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); + /// string bundleRaw = bundle.Encode(); + /// Bundle data = bundle.Decode(bundleRaw); + /// </code> + public static Bundle Decode(string bundleRaw) + { + SafeBundleHandle handle; + + handle = Interop.Bundle.BundleDecode(bundleRaw, bundleRaw.Length); + if (ErrorFacts.GetLastResult() == (int)BundleErrorFactory.BundleError.InvalidParameter) + { + throw new ArgumentException("Invalid bundle raw"); + } + + return new Bundle(handle); + } + + /// <summary> + /// Encodes bundle to string. + /// </summary> + /// <returns>Encoded Bundle data in string.</returns> + /// <exception cref="System.InvalidOperationException">Thrown when out of memory or when the Bundle instance has been disposed.</exception> + /// <code> + /// Tizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); + /// string bundleRaw = bundle.Encode(); + /// </code> + public string Encode() + { + string bundleRaw; + int len; + + Interop.Bundle.BundleEncode(_handle, out bundleRaw, out len); + if (ErrorFacts.GetLastResult() == (int)BundleErrorFactory.BundleError.InvalidParameter) + { + throw new InvalidOperationException("Invalid bundle"); + } + + return bundleRaw; + } + + /// <summary> /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects. /// </summary> /// <param name="disposing">If true, disposes any disposable objects. If false, does not dispose disposable objects.</param> |