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