Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Convergence / Interop / Interop.Internal.Conv.Service.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 enum ServiceType
19         {
20             /// <summary>
21             /// Undefined service
22             /// </summary>
23             None = -1,
24
25             /// <summary>
26             /// App-to-app communication service
27             /// </summary>
28             AppCommunication = 0,
29
30             /// <summary>
31             /// Remote app-control service
32             /// </summary>
33             RemoteAppControl,
34         }
35
36         internal static partial class ConvService
37         {
38             [DllImport(Libraries.Convergence, EntryPoint = "conv_service_create")]
39             internal static extern int Create(out ConvServiceHandle /* conv_service_h */ handle);
40
41             [DllImport(Libraries.Convergence, EntryPoint = "conv_service_clone")]
42             internal static extern int Clone(IntPtr /* conv_service_h */ originalHandle, out ConvServiceHandle /* conv_service_h */ targetHandle);
43
44             [DllImport(Libraries.Convergence, EntryPoint = "conv_service_destroy")]
45             internal static extern int Destroy(IntPtr /* conv_service_h */ handle);
46
47             [DllImport(Libraries.Convergence, EntryPoint = "conv_service_get_property_string")]
48             internal static extern int GetPropertyString(ConvServiceHandle /* conv_service_h */ handle, string key, out IntPtr value);
49
50             [DllImport(Libraries.Convergence, EntryPoint = "conv_service_set_property_string")]
51             internal static extern int SetPropertyString(ConvServiceHandle /* conv_service_h */ handle, string key, string value);
52
53             [DllImport(Libraries.Convergence, EntryPoint = "conv_service_get_type")]
54             internal static extern int GetType(IntPtr /* conv_service_h */ handle, out int /* conv_service_e */ value);
55
56             [DllImport(Libraries.Convergence, EntryPoint = "conv_service_set_type")]
57             internal static extern int SetType(ConvServiceHandle /* conv_service_h */ handle, int /* conv_service_e */ value);
58
59             [DllImport(Libraries.Convergence, EntryPoint = "conv_service_start")]
60             internal static extern int Start(ConvServiceHandle /* conv_service_h */ handle, ConvChannelHandle channel, ConvPayloadHandle payload);
61
62             [DllImport(Libraries.Convergence, EntryPoint = "conv_service_read")]
63             internal static extern int Read(ConvServiceHandle /* conv_service_h */ handle, ConvChannelHandle channel, ConvPayloadHandle payload);
64
65             [DllImport(Libraries.Convergence, EntryPoint = "conv_service_publish")]
66             internal static extern int Publish(ConvServiceHandle /* conv_service_h */ handle, ConvChannelHandle channel, ConvPayloadHandle payload);
67
68             [DllImport(Libraries.Convergence, EntryPoint = "conv_service_stop")]
69             internal static extern int Stop(ConvServiceHandle /* conv_service_h */ handle, ConvChannelHandle channel, ConvPayloadHandle payload);
70
71             [DllImport(Libraries.Convergence, EntryPoint = "conv_service_set_listener_cb")]
72             internal static extern int SetListenerCb(ConvServiceHandle /* conv_service_h */ handle, ConvServiceListenerCallback callback, IntPtr /* void */ userData);
73
74             [DllImport(Libraries.Convergence, EntryPoint = "conv_service_unset_listener_cb")]
75             internal static extern int UnsetListenerCb(ConvServiceHandle /* conv_service_h */ handle);
76
77             [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
78             internal delegate void ConvServiceListenerCallback(IntPtr /* conv_service_h */ serviceHandle, IntPtr channelHandle, int error, IntPtr result, IntPtr /* void */ userData);
79         }
80
81         internal class ConvServiceHandle : TizenSafeHandle
82         {
83             public ConvServiceHandle(): base()
84             {
85
86             }
87
88             public ConvServiceHandle(IntPtr handle)
89                 : base(handle)
90             {
91             }
92
93             public override void Destroy()
94             {
95                 if (handle != IntPtr.Zero)
96                 {
97                     var err = ConvService.Destroy(this.handle);
98                     if (err != (int)ConvErrorCode.None)
99                     {
100                         Log.Error(ErrorFactory.LogTag, "Failed to destroy conv service handle");
101                         throw ErrorFactory.GetException(err);
102                     }
103                 }
104             }
105         }
106     }
107 }