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
36 /// <exception cref="InvalidOperationException">
37 /// This Exception can be due to the following reaons
38 /// 1. Invalid parameter
39 /// 2. Permission Denied
43 public VoiceCommandList()
45 SafeCommandListHandle handle = new SafeCommandListHandle();
46 ErrorCode error = VcCmdListCreate(out handle);
47 if (error != ErrorCode.None)
49 Log.Error(LogTag, "Create Failed with error " + error);
50 throw ExceptionFactory.CreateException(error);
55 internal VoiceCommandList(SafeCommandListHandle handle)
61 /// Gets command count of list.
62 /// -1 is returned in case of internal failure.
69 ErrorCode error = VcCmdListGetCount(_handle, out count);
70 if (error != ErrorCode.None)
72 Log.Error(LogTag, "Count Failed with error " + error);
81 /// Get current command from command list by index.
82 /// null will be returned in case of Empty List
84 public VoiceCommand GetCurrent
88 SafeCommandHandle current;
89 ErrorCode error = VcCmdListGetCurrent(_handle, out current);
90 if (error != ErrorCode.None)
92 Log.Error(LogTag, "Current Failed with error " + error);
95 current._ownership = false;
96 return new VoiceCommand(current);
101 /// Adds command to command list.
103 /// <param name="command">The command</param>
104 /// <exception cref="InvalidOperationException">
105 /// This Exception can be due to the following reaons
106 /// 1. Invalid parameter
107 /// 2. Permission Denied
110 /// <exception cref="NullReferenceException">This will occur if the provide parameter is null</exception>
111 public void Add(VoiceCommand command)
113 ErrorCode error = VcCmdListAdd(_handle, command._handle);
114 if (error != ErrorCode.None)
116 Log.Error(LogTag, "Add Failed with error " + error);
117 throw ExceptionFactory.CreateException(error);
122 /// Removes command from command list.
124 /// <param name="command">The command</param>
125 /// <exception cref="InvalidOperationException">
126 /// This Exception can be due to the following reaons
127 /// 1. Invalid parameter
128 /// 2. Permission Denied
131 /// <exception cref="NullReferenceException">This will occur if the provide parameter is null</exception>
132 public void Remove(VoiceCommand command)
134 ErrorCode error = VcCmdListRemove(_handle, command._handle);
135 if (error != ErrorCode.None)
137 Log.Error(LogTag, "Remove Failed with error " + error);
138 throw ExceptionFactory.CreateException(error);
143 /// Retrieves all commands of command list.
145 /// <exception cref="InvalidOperationException">
146 /// This Exception can be due to the following reaons
147 /// 1. Permission Denied
150 public IEnumerable<VoiceCommand> GetAllCommands()
152 _list = new List<VoiceCommand>();
153 _callback = (IntPtr vcCommand, IntPtr userData) =>
155 SafeCommandHandle handle = new SafeCommandHandle(vcCommand);
156 handle._ownership = false;
157 _list.Add(new VoiceCommand(handle));
160 ErrorCode error = VcCmdListForeachCommands(_handle, _callback, IntPtr.Zero);
161 if (error != ErrorCode.None)
163 Log.Error(LogTag, "GetAllCommands Failed with error " + error);
164 throw ExceptionFactory.CreateException(error);
171 /// Moves index to first command.
173 /// <exception cref="InvalidOperationException">
174 /// This Exception can be due to the following reaons
176 /// 2. Permission Denied
181 ErrorCode error = VcCmdListFirst(_handle);
182 if (error != ErrorCode.None)
184 Log.Error(LogTag, "First Failed with error " + error);
185 throw ExceptionFactory.CreateException(error);
190 /// Moves index to last command.
192 /// <exception cref="InvalidOperationException">
193 /// This Exception can be due to the following reaons
195 /// 2. Permission Denied
200 ErrorCode error = VcCmdListLast(_handle);
201 if (error != ErrorCode.None)
203 Log.Error(LogTag, "Last Failed with error " + error);
204 throw ExceptionFactory.CreateException(error);
209 /// Moves index to next command.
211 /// <exception cref="InvalidOperationException">
212 /// This Exception can be due to the following reaons
214 /// 2. List reached end
215 /// 3. Permission Denied
220 ErrorCode error = VcCmdListNext(_handle);
221 if (error != ErrorCode.None)
223 Log.Error(LogTag, "Next Failed with error " + error);
224 throw ExceptionFactory.CreateException(error);
229 /// Moves index to previous command.
231 /// <exception cref="InvalidOperationException">
232 /// This Exception can be due to the following reaons
234 /// 2. List reached end
235 /// 3. Permission Denied
238 public void Previous()
240 ErrorCode error = VcCmdListPrev(_handle);
241 if (error != ErrorCode.None)
243 Log.Error(LogTag, "Previous Failed with error " + error);
244 throw ExceptionFactory.CreateException(error);