Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Applications.Common / Interop / Interop.Bundle.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18 using System.Runtime.InteropServices;
19
20 using Tizen.Applications;
21
22 internal static partial class Interop
23 {
24     internal static partial class Bundle
25     {
26         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
27         internal delegate void Iterator(string key, int type, IntPtr keyval, IntPtr userData);
28
29         [DllImport(Libraries.Bundle, EntryPoint = "bundle_create")]
30         internal static extern SafeBundleHandle Create();
31
32         [DllImport(Libraries.Bundle, EntryPoint = "bundle_free")]
33         internal static extern int DangerousFree(IntPtr handle);
34
35         [DllImport(Libraries.Bundle, EntryPoint = "bundle_del")]
36         internal static extern int RemoveItem(SafeBundleHandle handle, string key);
37
38         [DllImport(Libraries.Bundle, EntryPoint = "bundle_add_str")]
39         internal static extern int AddString(SafeBundleHandle handle, string key, string value);
40
41         [DllImport(Libraries.Bundle, EntryPoint = "bundle_get_type")]
42         internal static extern int GetType(SafeBundleHandle handle, string key);
43
44         [DllImport(Libraries.Bundle, EntryPoint = "bundle_get_str")]
45         internal static extern int GetString(SafeBundleHandle handle, string key, out IntPtr value);
46
47         [DllImport(Libraries.Bundle, EntryPoint = "bundle_add_byte")]
48         internal static extern unsafe int AddByte(SafeBundleHandle handle, string key, byte* value, int size);
49
50         [DllImport(Libraries.Bundle, EntryPoint = "bundle_get_byte")]
51         internal static extern int GetByte(SafeBundleHandle handle, string key, out IntPtr value, out int size);
52
53         [DllImport(Libraries.Bundle, EntryPoint = "bundle_add_str_array")]
54         internal static extern int AddStringArray(SafeBundleHandle handle, string key, string[] value, int size);
55
56         [DllImport(Libraries.Bundle, EntryPoint = "bundle_get_str_array")]
57         internal static extern IntPtr GetStringArray(SafeBundleHandle handle, string key, out int size);
58
59         [DllImport(Libraries.Bundle, EntryPoint = "bundle_foreach")]
60         internal static extern void Foreach(SafeBundleHandle handle, Iterator iterator, IntPtr userData);
61
62         [DllImport(Libraries.Bundle, EntryPoint = "bundle_encode")]
63         internal static extern void BundleEncode(SafeBundleHandle handle, out string str, out int len);
64
65         [DllImport(Libraries.Bundle, EntryPoint = "bundle_decode")]
66         internal static extern SafeBundleHandle BundleDecode(string bundleRaw, int len);
67
68         [DllImport(Libraries.Bundle, EntryPoint = "bundle_dup")]
69         internal static extern SafeBundleHandle DangerousClone(IntPtr handle);
70
71         internal static class UnsafeCode
72         {
73             internal static unsafe int AddItem(SafeBundleHandle handle, string key, byte[] value, int offset, int count)
74             {
75                 fixed (byte* pointer = value)
76                 {
77                     return AddByte(handle, key, pointer + offset, count);
78                 }
79             }
80         }
81     }
82 }