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="OutOfMemoryException"> This Exception can be due to Out of memory. </exception>
47 /// <exception cref="ArgumentException"> This Exception can be due to Invalid Parameter. </exception>
48 /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
49 /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
50 public VoiceCommandList()
52 SafeCommandListHandle handle;
53 ErrorCode error = VcCmdListCreate(out handle);
54 if (error != ErrorCode.None)
56 Log.Error(LogTag, "Create Failed with error " + error);
57 throw ExceptionFactory.CreateException(error);
62 internal VoiceCommandList(SafeCommandListHandle handle)
68 /// Gets command count of list.
69 /// -1 is returned in case of internal failure.
72 /// Command counts of the list.
75 /// http://tizen.org/privilege/recorder
85 ErrorCode error = VcCmdListGetCount(_handle, out count);
86 if (error != ErrorCode.None)
88 Log.Error(LogTag, "Count Failed with error " + error);
97 /// Get current command from command list by index.
98 /// null will be returned in case of Empty List
101 /// Current command from the command list.
104 /// http://tizen.org/privilege/recorder
109 public VoiceCommand Current
113 SafeCommandHandle current;
114 ErrorCode error = VcCmdListGetCurrent(_handle, out current);
115 if (error != ErrorCode.None)
117 Log.Error(LogTag, "Current Failed with error " + error);
120 current._ownership = false;
121 return new VoiceCommand(current);
126 /// Adds command to command list.
129 /// http://tizen.org/privilege/recorder
135 /// http://tizen.org/feature/speech.control
136 /// http://tizen.org/feature/microphone
138 /// <param name="command">The command</param>
139 /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
140 /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
141 /// <exception cref="NullReferenceException"> This will occur if the provide parameter is null. </exception>
142 public void Add(VoiceCommand command)
144 ErrorCode error = VcCmdListAdd(_handle, command._handle);
145 if (error != ErrorCode.None)
147 Log.Error(LogTag, "Add Failed with error " + error);
148 throw ExceptionFactory.CreateException(error);
153 /// Removes command from command list.
156 /// http://tizen.org/privilege/recorder
162 /// http://tizen.org/feature/speech.control
163 /// http://tizen.org/feature/microphone
165 /// <param name="command">The command</param>
166 /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
167 /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
168 /// <exception cref="NullReferenceException"> This will occur if the provide parameter is null. </exception>
169 public void Remove(VoiceCommand command)
171 ErrorCode error = VcCmdListRemove(_handle, command._handle);
172 if (error != ErrorCode.None)
174 Log.Error(LogTag, "Remove Failed with error " + error);
175 throw ExceptionFactory.CreateException(error);
180 /// Retrieves all commands of command list.
183 /// http://tizen.org/privilege/recorder
189 /// http://tizen.org/feature/speech.control
190 /// http://tizen.org/feature/microphone
192 /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
193 /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
194 public IEnumerable<VoiceCommand> GetAllCommands()
196 _list = new List<VoiceCommand>();
197 _callback = (IntPtr vcCommand, IntPtr userData) =>
199 SafeCommandHandle handle = new SafeCommandHandle(vcCommand);
200 handle._ownership = false;
201 _list.Add(new VoiceCommand(handle));
204 ErrorCode error = VcCmdListForeachCommands(_handle, _callback, IntPtr.Zero);
205 if (error != ErrorCode.None)
207 Log.Error(LogTag, "GetAllCommands Failed with error " + error);
208 throw ExceptionFactory.CreateException(error);
215 /// Moves index to first command.
218 /// http://tizen.org/privilege/recorder
224 /// http://tizen.org/feature/speech.control
225 /// http://tizen.org/feature/microphone
227 /// <exception cref="InvalidOperationException"> This Exception can be due to List Empty. </exception>
228 /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
229 /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
232 ErrorCode error = VcCmdListFirst(_handle);
233 if (error != ErrorCode.None)
235 Log.Error(LogTag, "First Failed with error " + error);
236 throw ExceptionFactory.CreateException(error);
241 /// Moves index to last command.
244 /// http://tizen.org/privilege/recorder
250 /// http://tizen.org/feature/speech.control
251 /// http://tizen.org/feature/microphone
253 /// <exception cref="InvalidOperationException"> This Exception can be due to List Empty. </exception>
254 /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
255 /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
258 ErrorCode error = VcCmdListLast(_handle);
259 if (error != ErrorCode.None)
261 Log.Error(LogTag, "Last Failed with error " + error);
262 throw ExceptionFactory.CreateException(error);
267 /// Moves index to next command.
270 /// http://tizen.org/privilege/recorder
276 /// http://tizen.org/feature/speech.control
277 /// http://tizen.org/feature/microphone
279 /// <exception cref="InvalidOperationException">
280 /// This Exception can be due to the following reaons
282 /// 2. List reached end
284 /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
285 /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
288 ErrorCode error = VcCmdListNext(_handle);
289 if (error != ErrorCode.None)
291 Log.Error(LogTag, "Next Failed with error " + error);
292 throw ExceptionFactory.CreateException(error);
297 /// Moves index to previous command.
300 /// http://tizen.org/privilege/recorder
306 /// http://tizen.org/feature/speech.control
307 /// http://tizen.org/feature/microphone
309 /// <exception cref="InvalidOperationException">
310 /// This Exception can be due to the following reaons
312 /// 2. List reached end
314 /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
315 /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
316 public void Previous()
318 ErrorCode error = VcCmdListPrev(_handle);
319 if (error != ErrorCode.None)
321 Log.Error(LogTag, "Previous Failed with error " + error);
322 throw ExceptionFactory.CreateException(error);