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 public SafeCommandListHandle(IntPtr handle)
103 public SafeCommandListHandle()
104 : base(IntPtr.Zero, true)
108 public override bool IsInvalid
110 get { return this.handle == IntPtr.Zero; }
113 protected override bool ReleaseHandle()
117 Interop.VoiceControl.ErrorCode error = VcCmdListDestroy(this.handle, false);
118 if (error != Interop.VoiceControl.ErrorCode.None)
120 Log.Error(VoiceControl.LogTag, "Destroy Failed with error " + error);
123 this.SetHandle(IntPtr.Zero);
128 internal sealed class SafeCommandHandle : SafeHandle
130 internal bool _ownership;
132 public SafeCommandHandle(IntPtr handle)
138 public SafeCommandHandle()
139 : base(IntPtr.Zero, true)
144 public override bool IsInvalid
146 get { return this.handle == IntPtr.Zero; }
149 protected override bool ReleaseHandle()
151 Interop.VoiceControl.ErrorCode error = VoiceControl.ErrorCode.None;
152 if (_ownership && !IsInvalid)
154 error = VcCmdDestroy(this.handle);
155 if (error != Interop.VoiceControl.ErrorCode.None)
157 Log.Error(VoiceControl.LogTag, "Destroy Failed with error " + error);
160 this.SetHandle(IntPtr.Zero);