Add descriptions for privilege and features
[platform/core/csapi/tizenfx.git] / src / Tizen.Uix.VoiceControl / Tizen.Uix.VoiceControl / VoiceCommandList.cs
1 /*
2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 using System;
18 using System.Collections.Generic;
19 using static Interop.VoiceControl;
20 using static Interop.VoiceControlCommand;
21
22 namespace Tizen.Uix.VoiceControl
23 {
24     /// <summary>
25     /// this class represents list of Voice Commands
26     /// </summary>
27     public class VoiceCommandList
28     {
29         internal SafeCommandListHandle _handle;
30         private List<VoiceCommand> _list;
31         private VcCmdListCb _callback;
32
33         /// <summary>
34         /// Public Constructor
35         /// </summary>
36         /// <privilege>
37         /// http://tizen.org/privilege/recorder
38         /// </privilege>
39         /// <privlevel>
40         /// public
41         /// </privlevel>
42         /// <feature>
43         /// http://tizen.org/feature/speech.control
44         /// http://tizen.org/feature/microphone
45         /// </feature>
46         /// <exception cref="InvalidOperationException">
47         /// This Exception can be due to the following reaons
48         /// 1. Invalid parameter
49         /// 2. Permission Denied
50         /// 3. Not supported
51         /// 4. Out of memory
52         /// </exception>
53         public VoiceCommandList()
54         {
55             SafeCommandListHandle handle = new SafeCommandListHandle();
56             ErrorCode error = VcCmdListCreate(out handle);
57             if (error != ErrorCode.None)
58             {
59                 Log.Error(LogTag, "Create Failed with error " + error);
60                 throw ExceptionFactory.CreateException(error);
61             }
62             _handle = handle;
63         }
64
65         internal VoiceCommandList(SafeCommandListHandle handle)
66         {
67             _handle = handle;
68         }
69
70         /// <summary>
71         /// Gets command count of list.
72         /// -1 is returned in case of internal failure.
73         /// </summary>
74         /// <value>
75         /// Command counts of the list.
76         /// </value>
77         /// <privilege>
78         /// http://tizen.org/privilege/recorder
79         /// </privilege>
80         /// <privlevel>
81         /// public
82         /// </privlevel>
83         public int GetCount
84         {
85             get
86             {
87                 int count;
88                 ErrorCode error = VcCmdListGetCount(_handle, out count);
89                 if (error != ErrorCode.None)
90                 {
91                     Log.Error(LogTag, "Count Failed with error " + error);
92                     return -1;
93                 }
94
95                 return count;
96             }
97         }
98
99         /// <summary>
100         /// Get current command from command list by index.
101         /// null will be returned in case of Empty List
102         /// </summary>
103         /// <value>
104         /// Current command from the command list.
105         /// </value>
106         /// <privilege>
107         /// http://tizen.org/privilege/recorder
108         /// </privilege>
109         /// <privlevel>
110         /// public
111         /// </privlevel>
112         public VoiceCommand GetCurrent
113         {
114             get
115             {
116                 SafeCommandHandle current;
117                 ErrorCode error = VcCmdListGetCurrent(_handle, out current);
118                 if (error != ErrorCode.None)
119                 {
120                     Log.Error(LogTag, "Current Failed with error " + error);
121                     return null;
122                 }
123                 current._ownership = false;
124                 return new VoiceCommand(current);
125             }
126         }
127
128         /// <summary>
129         /// Adds command to command list.
130         /// </summary>
131         /// <privilege>
132         /// http://tizen.org/privilege/recorder
133         /// </privilege>
134         /// <privlevel>
135         /// public
136         /// </privlevel>
137         /// <feature>
138         /// http://tizen.org/feature/speech.control
139         /// http://tizen.org/feature/microphone
140         /// </feature>
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
146         /// 3. Not supported
147         /// </exception>
148         /// <exception cref="NullReferenceException">This will occur if the provide parameter is null</exception>
149         public void Add(VoiceCommand command)
150         {
151             ErrorCode error = VcCmdListAdd(_handle, command._handle);
152             if (error != ErrorCode.None)
153             {
154                 Log.Error(LogTag, "Add Failed with error " + error);
155                 throw ExceptionFactory.CreateException(error);
156             }
157         }
158
159         /// <summary>
160         /// Removes command from command list.
161         /// </summary>
162         /// <privilege>
163         /// http://tizen.org/privilege/recorder
164         /// </privilege>
165         /// <privlevel>
166         /// public
167         /// </privlevel>
168         /// <feature>
169         /// http://tizen.org/feature/speech.control
170         /// http://tizen.org/feature/microphone
171         /// </feature>
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
177         /// 3. Not supported
178         /// </exception>
179         /// <exception cref="NullReferenceException">This will occur if the provide parameter is null</exception>
180         public void Remove(VoiceCommand command)
181         {
182             ErrorCode error = VcCmdListRemove(_handle, command._handle);
183             if (error != ErrorCode.None)
184             {
185                 Log.Error(LogTag, "Remove Failed with error " + error);
186                 throw ExceptionFactory.CreateException(error);
187             }
188         }
189
190         /// <summary>
191         /// Retrieves all commands of command list.
192         /// </summary>
193         /// <privilege>
194         /// http://tizen.org/privilege/recorder
195         /// </privilege>
196         /// <privlevel>
197         /// public
198         /// </privlevel>
199         /// <feature>
200         /// http://tizen.org/feature/speech.control
201         /// http://tizen.org/feature/microphone
202         /// </feature>
203         /// <exception cref="InvalidOperationException">
204         /// This Exception can be due to the following reaons
205         /// 1. Permission Denied
206         /// 2. Not supported
207         /// </exception>
208         public IEnumerable<VoiceCommand> GetAllCommands()
209         {
210             _list = new List<VoiceCommand>();
211             _callback = (IntPtr vcCommand, IntPtr userData) =>
212             {
213                 SafeCommandHandle handle = new SafeCommandHandle(vcCommand);
214                 handle._ownership = false;
215                 _list.Add(new VoiceCommand(handle));
216                 return true;
217             };
218             ErrorCode error = VcCmdListForeachCommands(_handle, _callback, IntPtr.Zero);
219             if (error != ErrorCode.None)
220             {
221                 Log.Error(LogTag, "GetAllCommands Failed with error " + error);
222                 throw ExceptionFactory.CreateException(error);
223             }
224
225             return _list;
226         }
227
228         /// <summary>
229         /// Moves index to first command.
230         /// </summary>
231         /// <privilege>
232         /// http://tizen.org/privilege/recorder
233         /// </privilege>
234         /// <privlevel>
235         /// public
236         /// </privlevel>
237         /// <feature>
238         /// http://tizen.org/feature/speech.control
239         /// http://tizen.org/feature/microphone
240         /// </feature>
241         /// <exception cref="InvalidOperationException">
242         /// This Exception can be due to the following reaons
243         /// 1. List Empty
244         /// 2. Permission Denied
245         /// 3. Not supported
246         /// </exception>
247         public void First()
248         {
249             ErrorCode error = VcCmdListFirst(_handle);
250             if (error != ErrorCode.None)
251             {
252                 Log.Error(LogTag, "First Failed with error " + error);
253                 throw ExceptionFactory.CreateException(error);
254             }
255         }
256
257         /// <summary>
258         /// Moves index to last command.
259         /// </summary>
260         /// <privilege>
261         /// http://tizen.org/privilege/recorder
262         /// </privilege>
263         /// <privlevel>
264         /// public
265         /// </privlevel>
266         /// <feature>
267         /// http://tizen.org/feature/speech.control
268         /// http://tizen.org/feature/microphone
269         /// </feature>
270         /// <exception cref="InvalidOperationException">
271         /// This Exception can be due to the following reaons
272         /// 1. List Empty
273         /// 2. Permission Denied
274         /// 3. Not supported
275         /// </exception>
276         public void Last()
277         {
278             ErrorCode error = VcCmdListLast(_handle);
279             if (error != ErrorCode.None)
280             {
281                 Log.Error(LogTag, "Last Failed with error " + error);
282                 throw ExceptionFactory.CreateException(error);
283             }
284         }
285
286         /// <summary>
287         /// Moves index to next command.
288         /// </summary>
289         /// <privilege>
290         /// http://tizen.org/privilege/recorder
291         /// </privilege>
292         /// <privlevel>
293         /// public
294         /// </privlevel>
295         /// <feature>
296         /// http://tizen.org/feature/speech.control
297         /// http://tizen.org/feature/microphone
298         /// </feature>
299         /// <exception cref="InvalidOperationException">
300         /// This Exception can be due to the following reaons
301         /// 1. List Empty
302         /// 2. List reached end
303         /// 3. Permission Denied
304         /// 4. Not supported
305         /// </exception>
306         public void Next()
307         {
308             ErrorCode error = VcCmdListNext(_handle);
309             if (error != ErrorCode.None)
310             {
311                 Log.Error(LogTag, "Next Failed with error " + error);
312                 throw ExceptionFactory.CreateException(error);
313             }
314         }
315
316         /// <summary>
317         /// Moves index to previous command.
318         /// </summary>
319         /// <privilege>
320         /// http://tizen.org/privilege/recorder
321         /// </privilege>
322         /// <privlevel>
323         /// public
324         /// </privlevel>
325         /// <feature>
326         /// http://tizen.org/feature/speech.control
327         /// http://tizen.org/feature/microphone
328         /// </feature>
329         /// <exception cref="InvalidOperationException">
330         /// This Exception can be due to the following reaons
331         /// 1. List Empty
332         /// 2. List reached end
333         /// 3. Permission Denied
334         /// 4. Not supported
335         /// </exception>
336         public void Previous()
337         {
338             ErrorCode error = VcCmdListPrev(_handle);
339             if (error != ErrorCode.None)
340             {
341                 Log.Error(LogTag, "Previous Failed with error " + error);
342                 throw ExceptionFactory.CreateException(error);
343             }
344         }
345     }
346 }