/*
* 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 System;
using static Interop.VoiceControl;
using static Interop.VoiceControlCommand;
namespace Tizen.Uix.VoiceControl
{
///
/// Enumeration for Command Format
///
/// 3
public enum CommandFormat
{
///
/// fixed command format.
///
Fixed = 0,
///
/// fixed and variable fixed command format.
///
FixedAndVFixed = 1,
///
/// variable fixed and fixed command format.
///
VFixedAndFixed = 2,
///
/// fixed and non-fixed command format.
///
FixedAndNonFixed = 3,
///
/// non-fixed and fixed command format.
///
NonFixedAndFixed = 4,
///
/// Undefined
///
Undefined = 5
};
///
/// This class represents a Voice Command
///
/// 3
public class VoiceCommand
{
internal SafeCommandHandle _handle;
///
/// Public Constructor
///
/// 3
/// This Exception can be due to 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.
/// 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/Sets command type.
///
/// 3
/// If you do not set the command type, the default value is Undefined. You should set type if 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/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/Sets command
/// in case of 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);
}
}
}
}
}