/*
* 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 System.Collections.Generic;
using static Interop.VoiceControl;
using static Interop.VoiceControlCommand;
namespace Tizen.Uix.VoiceControl
{
///
/// this class represents list of Voice Commands
///
/// 3
public class VoiceCommandList
{
internal SafeCommandListHandle _handle;
private List _list;
private VcCmdListCb _callback;
///
/// Public Constructor
///
/// 3
///
/// http://tizen.org/privilege/recorder
///
///
/// public
///
///
/// http://tizen.org/feature/speech.control
/// http://tizen.org/feature/microphone
///
/// This Exception can be due to Out of memory.
/// This Exception can be due to Invalid Parameter.
/// This Exception can be due to Permission Denied.
/// This Exception can be due to Not Supported.
public VoiceCommandList()
{
SafeCommandListHandle handle;
ErrorCode error = VcCmdListCreate(out handle);
if (error != ErrorCode.None)
{
Log.Error(LogTag, "Create Failed with error " + error);
throw ExceptionFactory.CreateException(error);
}
_handle = handle;
}
internal VoiceCommandList(SafeCommandListHandle handle)
{
_handle = handle;
}
///
/// Gets command count of list.
/// -1 is returned in case of internal failure.
///
/// 3
///
/// Command counts of the list.
///
///
/// http://tizen.org/privilege/recorder
///
///
/// public
///
public int Count
{
get
{
int count;
ErrorCode error = VcCmdListGetCount(_handle, out count);
if (error != ErrorCode.None)
{
Log.Error(LogTag, "Count Failed with error " + error);
return -1;
}
return count;
}
}
///
/// Get current command from command list by index.
/// null will be returned in case of Empty List
///
/// 3
///
/// Current command from the command list.
///
///
/// http://tizen.org/privilege/recorder
///
///
/// public
///
public VoiceCommand Current
{
get
{
SafeCommandHandle current;
ErrorCode error = VcCmdListGetCurrent(_handle, out current);
if (error != ErrorCode.None)
{
Log.Error(LogTag, "Current Failed with error " + error);
return null;
}
current._ownership = false;
return new VoiceCommand(current);
}
}
///
/// Adds command to command list.
///
/// 3
///
/// http://tizen.org/privilege/recorder
///
///
/// public
///
///
/// http://tizen.org/feature/speech.control
/// http://tizen.org/feature/microphone
///
/// The command
/// This Exception can be due to Permission Denied.
/// This Exception can be due to Not Supported.
/// This will occur if the provide parameter is null.
public void Add(VoiceCommand command)
{
ErrorCode error = VcCmdListAdd(_handle, command._handle);
if (error != ErrorCode.None)
{
Log.Error(LogTag, "Add Failed with error " + error);
throw ExceptionFactory.CreateException(error);
}
}
///
/// Removes command from command list.
///
/// 3
///
/// http://tizen.org/privilege/recorder
///
///
/// public
///
///
/// http://tizen.org/feature/speech.control
/// http://tizen.org/feature/microphone
///
/// The command
/// This Exception can be due to Permission Denied.
/// This Exception can be due to Not Supported.
/// This will occur if the provide parameter is null.
public void Remove(VoiceCommand command)
{
ErrorCode error = VcCmdListRemove(_handle, command._handle);
if (error != ErrorCode.None)
{
Log.Error(LogTag, "Remove Failed with error " + error);
throw ExceptionFactory.CreateException(error);
}
}
///
/// Retrieves all commands of command list.
///
/// 3
///
/// http://tizen.org/privilege/recorder
///
///
/// public
///
///
/// http://tizen.org/feature/speech.control
/// http://tizen.org/feature/microphone
///
/// This Exception can be due to Permission Denied.
/// This Exception can be due to Not Supported.
public IEnumerable GetAllCommands()
{
_list = new List();
_callback = (IntPtr vcCommand, IntPtr userData) =>
{
SafeCommandHandle handle = new SafeCommandHandle(vcCommand);
handle._ownership = false;
_list.Add(new VoiceCommand(handle));
return true;
};
ErrorCode error = VcCmdListForeachCommands(_handle, _callback, IntPtr.Zero);
if (error != ErrorCode.None)
{
Log.Error(LogTag, "GetAllCommands Failed with error " + error);
throw ExceptionFactory.CreateException(error);
}
return _list;
}
///
/// Moves index to first command.
///
/// 3
///
/// http://tizen.org/privilege/recorder
///
///
/// public
///
///
/// http://tizen.org/feature/speech.control
/// http://tizen.org/feature/microphone
///
/// This Exception can be due to List Empty.
/// This Exception can be due to Permission Denied.
/// This Exception can be due to Not Supported.
public void First()
{
ErrorCode error = VcCmdListFirst(_handle);
if (error != ErrorCode.None)
{
Log.Error(LogTag, "First Failed with error " + error);
throw ExceptionFactory.CreateException(error);
}
}
///
/// Moves index to last command.
///
/// 3
///
/// http://tizen.org/privilege/recorder
///
///
/// public
///
///
/// http://tizen.org/feature/speech.control
/// http://tizen.org/feature/microphone
///
/// This Exception can be due to List Empty.
/// This Exception can be due to Permission Denied.
/// This Exception can be due to Not Supported.
public void Last()
{
ErrorCode error = VcCmdListLast(_handle);
if (error != ErrorCode.None)
{
Log.Error(LogTag, "Last Failed with error " + error);
throw ExceptionFactory.CreateException(error);
}
}
///
/// Moves index to next command.
///
/// 3
///
/// http://tizen.org/privilege/recorder
///
///
/// public
///
///
/// http://tizen.org/feature/speech.control
/// http://tizen.org/feature/microphone
///
///
/// This Exception can be due to the following reaons
/// 1. List Empty
/// 2. List reached end
///
/// This Exception can be due to Permission Denied.
/// This Exception can be due to Not Supported.
public void Next()
{
ErrorCode error = VcCmdListNext(_handle);
if (error != ErrorCode.None)
{
Log.Error(LogTag, "Next Failed with error " + error);
throw ExceptionFactory.CreateException(error);
}
}
///
/// Moves index to previous command.
///
/// 3
///
/// http://tizen.org/privilege/recorder
///
///
/// public
///
///
/// http://tizen.org/feature/speech.control
/// http://tizen.org/feature/microphone
///
///
/// This Exception can be due to the following reaons
/// 1. List Empty
/// 2. List reached end
///
/// This Exception can be due to Permission Denied.
/// This Exception can be due to Not Supported.
public void Previous()
{
ErrorCode error = VcCmdListPrev(_handle);
if (error != ErrorCode.None)
{
Log.Error(LogTag, "Previous Failed with error " + error);
throw ExceptionFactory.CreateException(error);
}
}
}
}