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 /// <since_tizen> 3 </since_tizen>
28 public class VoiceCommandList
30 internal SafeCommandListHandle _handle;
31 private List<VoiceCommand> _list;
32 private VcCmdListCb _callback;
35 /// Public Constructor
37 /// <since_tizen> 3 </since_tizen>
39 /// http://tizen.org/privilege/recorder
45 /// http://tizen.org/feature/speech.control
46 /// http://tizen.org/feature/microphone
48 /// <exception cref="OutOfMemoryException"> This Exception can be due to Out of memory. </exception>
49 /// <exception cref="ArgumentException"> This Exception can be due to Invalid Parameter. </exception>
50 /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
51 /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
52 public VoiceCommandList()
54 SafeCommandListHandle handle;
55 ErrorCode error = VcCmdListCreate(out handle);
56 if (error != ErrorCode.None)
58 Log.Error(LogTag, "Create Failed with error " + error);
59 throw ExceptionFactory.CreateException(error);
64 internal VoiceCommandList(SafeCommandListHandle handle)
70 /// Gets command count of list.
71 /// -1 is returned in case of internal failure.
73 /// <since_tizen> 3 </since_tizen>
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
103 /// <since_tizen> 3 </since_tizen>
105 /// Current command from the command list.
108 /// http://tizen.org/privilege/recorder
113 public VoiceCommand Current
117 SafeCommandHandle current;
118 ErrorCode error = VcCmdListGetCurrent(_handle, out current);
119 if (error != ErrorCode.None)
121 Log.Error(LogTag, "Current Failed with error " + error);
124 current._ownership = false;
125 return new VoiceCommand(current);
130 /// Adds command to command list.
132 /// <since_tizen> 3 </since_tizen>
134 /// http://tizen.org/privilege/recorder
140 /// http://tizen.org/feature/speech.control
141 /// http://tizen.org/feature/microphone
143 /// <param name="command">The command</param>
144 /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
145 /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
146 /// <exception cref="NullReferenceException"> This will occur if the provide parameter is null. </exception>
147 public void Add(VoiceCommand command)
149 ErrorCode error = VcCmdListAdd(_handle, command._handle);
150 if (error != ErrorCode.None)
152 Log.Error(LogTag, "Add Failed with error " + error);
153 throw ExceptionFactory.CreateException(error);
158 /// Removes command from command list.
160 /// <since_tizen> 3 </since_tizen>
162 /// http://tizen.org/privilege/recorder
168 /// http://tizen.org/feature/speech.control
169 /// http://tizen.org/feature/microphone
171 /// <param name="command">The command</param>
172 /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
173 /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
174 /// <exception cref="NullReferenceException"> This will occur if the provide parameter is null. </exception>
175 public void Remove(VoiceCommand command)
177 ErrorCode error = VcCmdListRemove(_handle, command._handle);
178 if (error != ErrorCode.None)
180 Log.Error(LogTag, "Remove Failed with error " + error);
181 throw ExceptionFactory.CreateException(error);
186 /// Retrieves all commands of command list.
188 /// <since_tizen> 3 </since_tizen>
190 /// http://tizen.org/privilege/recorder
196 /// http://tizen.org/feature/speech.control
197 /// http://tizen.org/feature/microphone
199 /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
200 /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
201 public IEnumerable<VoiceCommand> GetAllCommands()
203 _list = new List<VoiceCommand>();
204 _callback = (IntPtr vcCommand, IntPtr userData) =>
206 SafeCommandHandle handle = new SafeCommandHandle(vcCommand);
207 handle._ownership = false;
208 _list.Add(new VoiceCommand(handle));
211 ErrorCode error = VcCmdListForeachCommands(_handle, _callback, IntPtr.Zero);
212 if (error != ErrorCode.None)
214 Log.Error(LogTag, "GetAllCommands Failed with error " + error);
215 throw ExceptionFactory.CreateException(error);
222 /// Moves index to first command.
224 /// <since_tizen> 3 </since_tizen>
226 /// http://tizen.org/privilege/recorder
232 /// http://tizen.org/feature/speech.control
233 /// http://tizen.org/feature/microphone
235 /// <exception cref="InvalidOperationException"> This Exception can be due to List Empty. </exception>
236 /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
237 /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
240 ErrorCode error = VcCmdListFirst(_handle);
241 if (error != ErrorCode.None)
243 Log.Error(LogTag, "First Failed with error " + error);
244 throw ExceptionFactory.CreateException(error);
249 /// Moves index to last command.
251 /// <since_tizen> 3 </since_tizen>
253 /// http://tizen.org/privilege/recorder
259 /// http://tizen.org/feature/speech.control
260 /// http://tizen.org/feature/microphone
262 /// <exception cref="InvalidOperationException"> This Exception can be due to List Empty. </exception>
263 /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
264 /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
267 ErrorCode error = VcCmdListLast(_handle);
268 if (error != ErrorCode.None)
270 Log.Error(LogTag, "Last Failed with error " + error);
271 throw ExceptionFactory.CreateException(error);
276 /// Moves index to next command.
278 /// <since_tizen> 3 </since_tizen>
280 /// http://tizen.org/privilege/recorder
286 /// http://tizen.org/feature/speech.control
287 /// http://tizen.org/feature/microphone
289 /// <exception cref="InvalidOperationException">
290 /// This Exception can be due to the following reaons
292 /// 2. List reached end
294 /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
295 /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
298 ErrorCode error = VcCmdListNext(_handle);
299 if (error != ErrorCode.None)
301 Log.Error(LogTag, "Next Failed with error " + error);
302 throw ExceptionFactory.CreateException(error);
307 /// Moves index to previous command.
309 /// <since_tizen> 3 </since_tizen>
311 /// http://tizen.org/privilege/recorder
317 /// http://tizen.org/feature/speech.control
318 /// http://tizen.org/feature/microphone
320 /// <exception cref="InvalidOperationException">
321 /// This Exception can be due to the following reaons
323 /// 2. List reached end
325 /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
326 /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
327 public void Previous()
329 ErrorCode error = VcCmdListPrev(_handle);
330 if (error != ErrorCode.None)
332 Log.Error(LogTag, "Previous Failed with error " + error);
333 throw ExceptionFactory.CreateException(error);