/*
* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using static Interop.VoiceControlCommand;
using static Interop.VoiceControlWidget;
namespace Tizen.Uix.VoiceControlWidget
{
///
/// Enumeration for the command format.
///
/// 3
public enum CommandFormat
{
///
/// The fixed command format.
///
Fixed = 0,
///
/// The fixed and variable fixed command format.
///
FixedAndVFixed = 1,
///
/// The variable fixed and fixed command format.
///
VFixedAndFixed = 2,
///
/// The fixed and non-fixed command format.
///
FixedAndNonFixed = 3,
///
/// The non-fixed and fixed command format.
///
NonFixedAndFixed = 4,
///
/// The action command
///
Action = 5,
///
/// The partial matched command
///
Partial = 6,
///
/// Undefined
///
Undefined = -1
};
///
/// This class represents a voice command.
///
/// 3
public class VoiceCommand
{
internal SafeCommandHandle _handle;
///
/// The public constructor.
///
/// 3
/// This exception can be due to an invalid state.
/// This exception can be due to out Of memory.
/// This exception can be due to permission denied.
/// This exception can be due to not supported.
public VoiceCommand()
{
SafeCommandHandle handle;
ErrorCode error = VcCmdCreate(out handle);
if (error != ErrorCode.None)
{
Log.Error(LogTag, "Create Failed with error " + error);
throw ExceptionFactory.CreateException(error);
}
_handle = handle;
}
internal VoiceCommand(SafeCommandHandle handle)
{
_handle = handle;
}
///
/// Gets the unfixed command.
/// This property should be used for commands which have non-fixed format.
/// An empty string will be returned in case of some internal error.
///
/// 3
public string UnfixedCommand
{
get
{
string unfixedCommand;
ErrorCode error = VcCmdGetUnfixedCommand(_handle, out unfixedCommand);
if (error != ErrorCode.None)
{
Log.Error(LogTag, "UnfixedCommand Failed with error " + error);
return "";
}
return unfixedCommand;
}
}
///
/// Gets or sets the command type.
///
/// 3
/// If you do not set the command type, the default value is undefined. You should set the type if the command is valid.
/// This exception can be due to permission denied.
/// This exception can be due to not supported.
public CommandType Type
{
get
{
CommandType cmdType = CommandType.Undefined;
int type;
ErrorCode error = VcCmdGetType(_handle, out type);
if (error != ErrorCode.None)
{
Log.Error(LogTag, "GetType Failed with error " + error);
return CommandType.Undefined;
}
if (type != -1)
{
cmdType = (CommandType)type;
}
return cmdType;
}
set
{
ErrorCode error = VcCmdSetType(_handle, value);
if (error != ErrorCode.None)
{
Log.Error(LogTag, "SetType Failed with error " + error);
}
}
}
///
/// Gets or sets the command format.
///
/// 3
/// The default format is Fixed.
/// This exception can be due to permission denied.
/// This exception can be due to not supported.
public CommandFormat Format
{
get
{
CommandFormat format;
ErrorCode error = VcCmdGetFormat(_handle, out format);
if (error != ErrorCode.None)
{
Log.Error(LogTag, "GetFormat Failed with error " + error);
return CommandFormat.Undefined;
}
return format;
}
set
{
ErrorCode error = VcCmdSetFormat(_handle, value);
if (error != ErrorCode.None)
{
Log.Error(LogTag, "SetFormat Failed with error " + error);
}
}
}
///
/// Gets or sets the command.
/// A get empty string will be returned in case of some internal error.
///
/// 3
/// This exception can be due to permission denied.
/// This exception can be due to not supported.
public string Command
{
get
{
string command;
ErrorCode error = VcCmdGetCommand(_handle, out command);
if (error != ErrorCode.None)
{
Log.Error(LogTag, "GetCommand Failed with error " + error);
return "";
}
return command;
}
set
{
ErrorCode error = VcCmdSetCommand(_handle, value);
if (error != ErrorCode.None)
{
Log.Error(LogTag, "SetCommand Failed with error " + error);
}
}
}
}
}