2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 using System.Runtime.InteropServices;
21 using Tizen.Uix.VoiceControl;
24 /// Partial interop class.
26 internal static partial class Interop
29 /// VoiceControlCommand interop class.
31 internal static class VoiceControlCommand
33 [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_create")]
34 internal static extern Interop.VoiceControl.ErrorCode VcCmdListCreate(out SafeCommandListHandle cmdList);
36 [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_destroy")]
37 internal static extern Interop.VoiceControl.ErrorCode VcCmdListDestroy(IntPtr cmdList, bool freeCommand);
39 [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_get_count")]
40 internal static extern Interop.VoiceControl.ErrorCode VcCmdListGetCount(SafeCommandListHandle cmdList, out int count);
42 [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_add")]
43 internal static extern Interop.VoiceControl.ErrorCode VcCmdListAdd(SafeCommandListHandle cmdList, SafeCommandHandle vcCommand);
45 [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_remove")]
46 internal static extern Interop.VoiceControl.ErrorCode VcCmdListRemove(SafeCommandListHandle cmdList, SafeCommandHandle vcCommand);
48 [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_foreach_commands")]
49 internal static extern Interop.VoiceControl.ErrorCode VcCmdListForeachCommands(SafeCommandListHandle cmdList, VcCmdListCb callback, IntPtr userData);
51 [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_first")]
52 internal static extern Interop.VoiceControl.ErrorCode VcCmdListFirst(SafeCommandListHandle cmdList);
54 [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_last")]
55 internal static extern Interop.VoiceControl.ErrorCode VcCmdListLast(SafeCommandListHandle cmdList);
57 [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_next")]
58 internal static extern Interop.VoiceControl.ErrorCode VcCmdListNext(SafeCommandListHandle cmdList);
60 [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_prev")]
61 internal static extern Interop.VoiceControl.ErrorCode VcCmdListPrev(SafeCommandListHandle cmdList);
63 [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_list_get_current")]
64 internal static extern Interop.VoiceControl.ErrorCode VcCmdListGetCurrent(SafeCommandListHandle cmdList, out SafeCommandHandle vcCommand);
66 [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_create")]
67 internal static extern Interop.VoiceControl.ErrorCode VcCmdCreate(out SafeCommandHandle vcCommand);
69 [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_destroy")]
70 internal static extern Interop.VoiceControl.ErrorCode VcCmdDestroy(IntPtr vcCommand);
72 [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_set_command")]
73 internal static extern Interop.VoiceControl.ErrorCode VcCmdSetCommand(SafeCommandHandle vcCommand, string command);
75 [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_get_command")]
76 internal static extern Interop.VoiceControl.ErrorCode VcCmdGetCommand(SafeCommandHandle vcCommand, out string command);
78 [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_get_unfixed_command")]
79 internal static extern Interop.VoiceControl.ErrorCode VcCmdGetUnfixedCommand(SafeCommandHandle vcCommand, out string command);
81 [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_set_type")]
82 internal static extern Interop.VoiceControl.ErrorCode VcCmdSetType(SafeCommandHandle vcCommand, CommandType type);
84 [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_get_type")]
85 internal static extern Interop.VoiceControl.ErrorCode VcCmdGetType(SafeCommandHandle vcCommand, out int type);
87 [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_set_format")]
88 internal static extern Interop.VoiceControl.ErrorCode VcCmdSetFormat(SafeCommandHandle vcCommand, CommandFormat format);
90 [DllImport(Libraries.VoiceControl, EntryPoint = "vc_cmd_get_format")]
91 internal static extern Interop.VoiceControl.ErrorCode VcCmdGetFormat(SafeCommandHandle vcCommand, out CommandFormat format);
93 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
94 internal delegate bool VcCmdListCb(IntPtr vcCommand, IntPtr userData);
96 internal sealed class SafeCommandListHandle : SafeHandle
98 internal bool _ownership;
100 public SafeCommandListHandle(IntPtr handle)
106 public SafeCommandListHandle()
107 : base(IntPtr.Zero, true)
112 public override bool IsInvalid
114 get { return this.handle == IntPtr.Zero; }
117 protected override bool ReleaseHandle()
119 if (_ownership && !IsInvalid)
121 Interop.VoiceControl.ErrorCode error = VcCmdListDestroy(this.handle, false);
122 if (error != Interop.VoiceControl.ErrorCode.None)
124 Log.Error(VoiceControl.LogTag, "Destroy Failed with error " + error);
127 this.SetHandle(IntPtr.Zero);
132 internal sealed class SafeCommandHandle : SafeHandle
134 internal bool _ownership;
136 public SafeCommandHandle(IntPtr handle)
142 public SafeCommandHandle()
143 : base(IntPtr.Zero, true)
148 public override bool IsInvalid
150 get { return this.handle == IntPtr.Zero; }
153 protected override bool ReleaseHandle()
155 Interop.VoiceControl.ErrorCode error = VoiceControl.ErrorCode.None;
156 if (_ownership && !IsInvalid)
158 error = VcCmdDestroy(this.handle);
159 if (error != Interop.VoiceControl.ErrorCode.None)
161 Log.Error(VoiceControl.LogTag, "Destroy Failed with error " + error);
164 this.SetHandle(IntPtr.Zero);