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.
18 using System.Collections.Generic;
19 using static Interop.VoiceControl;
20 using static Interop.VoiceControlCommand;
22 namespace Tizen.Uix.VoiceControl
25 /// this class represents list of Voice Commands
27 public class VoiceCommandList
29 internal SafeCommandListHandle _handle;
30 private List<VoiceCommand> _list;
31 private VcCmdListCb _callback;
34 /// Public Constructor
37 /// http://tizen.org/privilege/recorder
43 /// http://tizen.org/feature/speech.control
44 /// http://tizen.org/feature/microphone
46 /// <exception cref="InvalidOperationException">
47 /// This Exception can be due to the following reaons
48 /// 1. Invalid parameter
49 /// 2. Permission Denied
53 public VoiceCommandList()
55 SafeCommandListHandle handle = new SafeCommandListHandle();
56 ErrorCode error = VcCmdListCreate(out handle);
57 if (error != ErrorCode.None)
59 Log.Error(LogTag, "Create Failed with error " + error);
60 throw ExceptionFactory.CreateException(error);
65 internal VoiceCommandList(SafeCommandListHandle handle)
71 /// Gets command count of list.
72 /// -1 is returned in case of internal failure.
75 /// Command counts of the list.
78 /// http://tizen.org/privilege/recorder
88 ErrorCode error = VcCmdListGetCount(_handle, out count);
89 if (error != ErrorCode.None)
91 Log.Error(LogTag, "Count Failed with error " + error);
100 /// Get current command from command list by index.
101 /// null will be returned in case of Empty List
104 /// Current command from the command list.
107 /// http://tizen.org/privilege/recorder
112 public VoiceCommand GetCurrent
116 SafeCommandHandle current;
117 ErrorCode error = VcCmdListGetCurrent(_handle, out current);
118 if (error != ErrorCode.None)
120 Log.Error(LogTag, "Current Failed with error " + error);
123 current._ownership = false;
124 return new VoiceCommand(current);
129 /// Adds command to command list.
132 /// http://tizen.org/privilege/recorder
138 /// http://tizen.org/feature/speech.control
139 /// http://tizen.org/feature/microphone
141 /// <param name="command">The command</param>
142 /// <exception cref="InvalidOperationException">
143 /// This Exception can be due to the following reaons
144 /// 1. Invalid parameter
145 /// 2. Permission Denied
148 /// <exception cref="NullReferenceException">This will occur if the provide parameter is null</exception>
149 public void Add(VoiceCommand command)
151 ErrorCode error = VcCmdListAdd(_handle, command._handle);
152 if (error != ErrorCode.None)
154 Log.Error(LogTag, "Add Failed with error " + error);
155 throw ExceptionFactory.CreateException(error);
160 /// Removes command from command list.
163 /// http://tizen.org/privilege/recorder
169 /// http://tizen.org/feature/speech.control
170 /// http://tizen.org/feature/microphone
172 /// <param name="command">The command</param>
173 /// <exception cref="InvalidOperationException">
174 /// This Exception can be due to the following reaons
175 /// 1. Invalid parameter
176 /// 2. Permission Denied
179 /// <exception cref="NullReferenceException">This will occur if the provide parameter is null</exception>
180 public void Remove(VoiceCommand command)
182 ErrorCode error = VcCmdListRemove(_handle, command._handle);
183 if (error != ErrorCode.None)
185 Log.Error(LogTag, "Remove Failed with error " + error);
186 throw ExceptionFactory.CreateException(error);
191 /// Retrieves all commands of command list.
194 /// http://tizen.org/privilege/recorder
200 /// http://tizen.org/feature/speech.control
201 /// http://tizen.org/feature/microphone
203 /// <exception cref="InvalidOperationException">
204 /// This Exception can be due to the following reaons
205 /// 1. Permission Denied
208 public IEnumerable<VoiceCommand> GetAllCommands()
210 _list = new List<VoiceCommand>();
211 _callback = (IntPtr vcCommand, IntPtr userData) =>
213 SafeCommandHandle handle = new SafeCommandHandle(vcCommand);
214 handle._ownership = false;
215 _list.Add(new VoiceCommand(handle));
218 ErrorCode error = VcCmdListForeachCommands(_handle, _callback, IntPtr.Zero);
219 if (error != ErrorCode.None)
221 Log.Error(LogTag, "GetAllCommands Failed with error " + error);
222 throw ExceptionFactory.CreateException(error);
229 /// Moves index to first command.
232 /// http://tizen.org/privilege/recorder
238 /// http://tizen.org/feature/speech.control
239 /// http://tizen.org/feature/microphone
241 /// <exception cref="InvalidOperationException">
242 /// This Exception can be due to the following reaons
244 /// 2. Permission Denied
249 ErrorCode error = VcCmdListFirst(_handle);
250 if (error != ErrorCode.None)
252 Log.Error(LogTag, "First Failed with error " + error);
253 throw ExceptionFactory.CreateException(error);
258 /// Moves index to last command.
261 /// http://tizen.org/privilege/recorder
267 /// http://tizen.org/feature/speech.control
268 /// http://tizen.org/feature/microphone
270 /// <exception cref="InvalidOperationException">
271 /// This Exception can be due to the following reaons
273 /// 2. Permission Denied
278 ErrorCode error = VcCmdListLast(_handle);
279 if (error != ErrorCode.None)
281 Log.Error(LogTag, "Last Failed with error " + error);
282 throw ExceptionFactory.CreateException(error);
287 /// Moves index to next command.
290 /// http://tizen.org/privilege/recorder
296 /// http://tizen.org/feature/speech.control
297 /// http://tizen.org/feature/microphone
299 /// <exception cref="InvalidOperationException">
300 /// This Exception can be due to the following reaons
302 /// 2. List reached end
303 /// 3. Permission Denied
308 ErrorCode error = VcCmdListNext(_handle);
309 if (error != ErrorCode.None)
311 Log.Error(LogTag, "Next Failed with error " + error);
312 throw ExceptionFactory.CreateException(error);
317 /// Moves index to previous command.
320 /// http://tizen.org/privilege/recorder
326 /// http://tizen.org/feature/speech.control
327 /// http://tizen.org/feature/microphone
329 /// <exception cref="InvalidOperationException">
330 /// This Exception can be due to the following reaons
332 /// 2. List reached end
333 /// 3. Permission Denied
336 public void Previous()
338 ErrorCode error = VcCmdListPrev(_handle);
339 if (error != ErrorCode.None)
341 Log.Error(LogTag, "Previous Failed with error " + error);
342 throw ExceptionFactory.CreateException(error);