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