Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Convergence / Interop / Interop.Internal.Conv.Channel.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 using System;
10 using System.Runtime.InteropServices;
11 using Tizen;
12 using Tizen.Convergence;
13
14 internal static partial class Interop
15 {
16     internal static partial class Internal
17     {
18         internal static partial class ConvChannel
19         {
20             [DllImport(Libraries.Convergence, EntryPoint = "conv_channel_create")]
21             internal static extern int Create(out ConvChannelHandle /* conv_channel_h */ handle);
22
23             [DllImport(Libraries.Convergence, EntryPoint = "conv_channel_destroy")]
24             internal static extern int Destroy(IntPtr /* conv_channel_h */ handle);
25
26             [DllImport(Libraries.Convergence, EntryPoint = "conv_channel_get_string")]
27             internal static extern int GetString(ConvChannelHandle /* conv_channel_h */ handle, string key, out IntPtr value);
28
29             [DllImport(Libraries.Convergence, EntryPoint = "conv_channel_set_string")]
30             internal static extern int SetString(ConvChannelHandle /* conv_channel_h */ handle, string key, string value);
31         }
32
33         internal class ConvChannelHandle : TizenSafeHandle
34         {
35             private bool _ownsHandle = true;
36
37             public ConvChannelHandle(): base()
38             {
39
40             }
41
42             public ConvChannelHandle(IntPtr handle)
43                 : base(handle)
44             {
45             }
46
47             public ConvChannelHandle(IntPtr handle, bool ownsHandle)
48                 : base(handle)
49             {
50                 _ownsHandle = ownsHandle;
51             }
52
53             public override void Destroy()
54             {
55                 if (_ownsHandle && handle != IntPtr.Zero)
56                 {
57                     var err = ConvChannel.Destroy(this.handle);
58                     if (err != (int)ConvErrorCode.None)
59                     {
60                         Log.Error(ErrorFactory.LogTag, "Failed to destroy conv channel handle");
61                         throw ErrorFactory.GetException(err);
62                     }
63                 }
64             }
65         }
66     }
67 }