Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Uix.VoiceControl / Tizen.Uix.VoiceControl / VoiceCommand.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 static Interop.VoiceControl;
19 using static Interop.VoiceControlCommand;
20
21 namespace Tizen.Uix.VoiceControl
22 {
23     /// <summary>
24     /// Enumeration for Command Format
25     /// </summary>
26     /// <since_tizen> 3 </since_tizen>
27     public enum CommandFormat
28     {
29         /// <summary>
30         /// fixed command format.
31         /// </summary>
32         Fixed = 0,
33         /// <summary>
34         /// fixed and variable fixed command format.
35         /// </summary>
36         FixedAndVFixed = 1,
37         /// <summary>
38         /// variable fixed and fixed command format.
39         /// </summary>
40         VFixedAndFixed = 2,
41         /// <summary>
42         /// fixed and non-fixed command format.
43         /// </summary>
44         FixedAndNonFixed = 3,
45         /// <summary>
46         /// non-fixed and fixed command format.
47         /// </summary>
48         NonFixedAndFixed = 4,
49         /// <summary>
50         /// Undefined
51         /// </summary>
52         Undefined = 5
53     };
54
55     /// <summary>
56     /// This class represents a Voice Command
57     /// </summary>
58     /// <since_tizen> 3 </since_tizen>
59     public class VoiceCommand
60     {
61         internal SafeCommandHandle _handle;
62
63         /// <summary>
64         /// Public Constructor
65         /// </summary>
66         /// <since_tizen> 3 </since_tizen>
67         /// <exception cref="InvalidOperationException"> This Exception can be due to Invalid State. </exception>
68         /// <exception cref="OutOfMemoryException"> This Exception can be due to Out Of Memory. </exception>
69         /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
70         /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
71         public VoiceCommand()
72         {
73             SafeCommandHandle handle;
74             ErrorCode error = VcCmdCreate(out handle);
75             if (error != ErrorCode.None)
76             {
77                 Log.Error(LogTag, "Create Failed with error " + error);
78                 throw ExceptionFactory.CreateException(error);
79             }
80             _handle = handle;
81         }
82
83         internal VoiceCommand(SafeCommandHandle handle)
84         {
85             _handle = handle;
86         }
87
88         /// <summary>
89         /// Gets the unfixed command.
90         /// This property should be used for commands which have non-fixed format.
91         /// empty string will be returned in case of some internal error
92         /// </summary>
93         /// <since_tizen> 3 </since_tizen>
94         public string UnfixedCommand
95         {
96             get
97             {
98                 string unfixedCommand;
99                 ErrorCode error = VcCmdGetUnfixedCommand(_handle, out unfixedCommand);
100                 if (error != ErrorCode.None)
101                 {
102                     Log.Error(LogTag, "UnfixedCommand Failed with error " + error);
103                     return "";
104                 }
105
106                 return unfixedCommand;
107             }
108         }
109
110         /// <summary>
111         /// Gets/Sets command type.
112         /// </summary>
113         /// <since_tizen> 3 </since_tizen>
114         /// <remarks>If you do not set the command type, the default value is Undefined. You should set type if command is valid</remarks>
115         /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
116         /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
117         public CommandType Type
118         {
119             get
120             {
121                 CommandType cmdType = CommandType.Undefined;
122                 int type;
123                 ErrorCode error = VcCmdGetType(_handle, out type);
124                 if (error != ErrorCode.None)
125                 {
126                     Log.Error(LogTag, "GetType Failed with error " + error);
127                     return CommandType.Undefined;
128                 }
129
130                 if (type != -1)
131                 {
132                     cmdType = (CommandType)type;
133                 }
134
135                 return cmdType;
136             }
137             set
138             {
139                 ErrorCode error = VcCmdSetType(_handle, value);
140                 if (error != ErrorCode.None)
141                 {
142                     Log.Error(LogTag, "SetType Failed with error " + error);
143                 }
144             }
145         }
146
147         /// <summary>
148         /// Gets/Sets the command format.
149         /// </summary>
150         /// <since_tizen> 3 </since_tizen>
151         /// <remarks>The default format is Fixed</remarks>
152         /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
153         /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
154         public CommandFormat Format
155         {
156             get
157             {
158                 CommandFormat format;
159                 ErrorCode error = VcCmdGetFormat(_handle, out format);
160                 if (error != ErrorCode.None)
161                 {
162                     Log.Error(LogTag, "GetFormat Failed with error " + error);
163                     return CommandFormat.Undefined;
164                 }
165
166                 return format;
167             }
168             set
169             {
170                 ErrorCode error = VcCmdSetFormat(_handle, value);
171                 if (error != ErrorCode.None)
172                 {
173                     Log.Error(LogTag, "SetFormat Failed with error " + error);
174                 }
175             }
176         }
177
178         /// <summary>
179         /// Gets/Sets command
180         /// in case of get empty string will be returned in case of some internal error
181         /// </summary>
182         /// <since_tizen> 3 </since_tizen>
183         /// <exception cref="UnauthorizedAccessException"> This Exception can be due to Permission Denied. </exception>
184         /// <exception cref="NotSupportedException"> This Exception can be due to Not Supported. </exception>
185         public string Command
186         {
187             get
188             {
189                 string command;
190                 ErrorCode error = VcCmdGetCommand(_handle, out command);
191                 if (error != ErrorCode.None)
192                 {
193                     Log.Error(LogTag, "GetCommand Failed with error " + error);
194                     return "";
195                 }
196
197                 return command;
198             }
199             set
200             {
201                 ErrorCode error = VcCmdSetCommand(_handle, value);
202                 if (error != ErrorCode.None)
203                 {
204                     Log.Error(LogTag, "SetCommand Failed with error " + error);
205                 }
206             }
207         }
208     }
209 }