Refactor Lifecycles
[platform/core/csapi/tizenfx.git] / Tizen.Applications / Interop / Interop.AppControl.cs
1 /// Copyright 2016 by Samsung Electronics, Inc.,
2 ///
3 /// This software is the confidential and proprietary information
4 /// of Samsung Electronics, Inc. ("Confidential Information"). You
5 /// shall not disclose such Confidential Information and shall use
6 /// it only in accordance with the terms of the license agreement
7 /// you entered into with Samsung.
8
9
10 using System;
11 using System.Runtime.InteropServices;
12
13 internal static partial class Interop
14 {
15     internal static partial class AppControl
16     {
17         [DllImport(Libraries.Application, EntryPoint = "app_control_create")]
18         internal static extern int Create(out SafeAppControlHandle handle);
19
20         [DllImport(Libraries.Application, EntryPoint = "app_control_get_app_id", CallingConvention = CallingConvention.Cdecl)]
21         internal static extern int GetAppId(IntPtr app_control, out IntPtr app_id);
22
23         [DllImport(Libraries.Application, EntryPoint = "app_control_get_operation", CallingConvention = CallingConvention.Cdecl)]
24         internal static extern int GetOperation(SafeAppControlHandle handle, out string operation);
25
26         [DllImport(Libraries.Application, EntryPoint = "app_control_get_uri", CallingConvention = CallingConvention.Cdecl)]
27         internal static extern int GetUri(SafeAppControlHandle handle, out string uri);
28
29         [DllImport(Libraries.Application, EntryPoint = "app_control_get_mime", CallingConvention = CallingConvention.Cdecl)]
30         internal static extern int GetMime(SafeAppControlHandle handle, out string mime);
31
32         [DllImport(Libraries.Application, EntryPoint = "app_control_destroy", CallingConvention = CallingConvention.Cdecl)]
33         private static extern int DangerousDestroy(IntPtr handle);
34
35         internal sealed class SafeAppControlHandle : SafeHandle
36         {
37             public SafeAppControlHandle() : base(IntPtr.Zero, true)
38             {
39             }
40
41             public SafeAppControlHandle(IntPtr handle) : base(handle, false)
42             {
43             }
44
45             public override bool IsInvalid
46             {
47                 get { return this.handle == IntPtr.Zero; }
48             }
49
50             protected override bool ReleaseHandle()
51             {
52                 AppControl.DangerousDestroy(this.handle);
53                 this.SetHandle(IntPtr.Zero);
54                 return true;
55             }
56         }
57     }
58 }