Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Convergence / Interop / Interop.Internal.Conv.Payload.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 ConvPayload
19         {
20             [DllImport(Libraries.Convergence, EntryPoint = "conv_payload_create")]
21             internal static extern int Create(out ConvPayloadHandle /* conv_payload_h */ handle);
22
23             [DllImport(Libraries.Convergence, EntryPoint = "conv_payload_destroy")]
24             internal static extern int Destroy(IntPtr /* conv_payload_h */ handle);
25
26             [DllImport(Libraries.Convergence, EntryPoint = "conv_payload_set_string")]
27             internal static extern int SetString(ConvPayloadHandle /* conv_payload_h */ handle, string key, string value);
28
29             [DllImport(Libraries.Convergence, EntryPoint = "conv_payload_get_string")]
30             internal static extern int GetString(ConvPayloadHandle /* conv_payload_h */ handle, string key, out IntPtr value);
31
32             [DllImport(Libraries.Convergence, EntryPoint = "conv_payload_set_byte")]
33             internal static extern int SetByte(ConvPayloadHandle /* conv_payload_h */ handle, string key, int length, byte[] value);
34
35             [DllImport(Libraries.Convergence, EntryPoint = "conv_payload_get_byte")]
36             internal static extern int GetByte(ConvPayloadHandle /* conv_payload_h */ handle, string key, out int length, out IntPtr value);
37
38             [DllImport(Libraries.Convergence, EntryPoint = "conv_payload_set_binary")]
39             internal static extern int SetBinary(ConvPayloadHandle /* conv_payload_h */ handle, int length, byte[] value);
40
41             [DllImport(Libraries.Convergence, EntryPoint = "conv_payload_get_binary")]
42             internal static extern int GetBinary(ConvPayloadHandle /* conv_payload_h */ handle, out int length, out IntPtr value);
43         }
44
45         internal class ConvPayloadHandle : TizenSafeHandle
46         {
47             private bool _ownsHandle = true;
48
49             public ConvPayloadHandle(): base()
50             {
51
52             }
53
54             public ConvPayloadHandle(IntPtr handle)
55                 : base(handle)
56             {
57             }
58
59             public ConvPayloadHandle(IntPtr handle, bool ownsHandle)
60                 : base(handle)
61             {
62                 _ownsHandle = ownsHandle;
63             }
64
65             public override void Destroy()
66             {
67                 if (_ownsHandle && handle != IntPtr.Zero)
68                 {
69                     var err = ConvPayload.Destroy(this.handle);
70                     if (err != (int)ConvErrorCode.None)
71                     {
72                         Log.Error(ErrorFactory.LogTag, "Failed to destroy conv payload handle");
73                         throw ErrorFactory.GetException(err);
74                     }
75                 }
76             }
77         }
78     }
79 }