/*
* 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 Tizen.Internals.Errors;
namespace Tizen.Network.Nfc
{
///
/// Enumeration for the NFC Error.
///
/// 3
public enum NfcError
{
///
/// Successful.
///
None = ErrorCode.None,
///
/// I/O Error.
///
IoError = ErrorCode.IoError,
///
/// Invalid Parameter.
///
InvalidParameterError = ErrorCode.InvalidParameter,
///
/// Out of Memory.
///
OutOfMemoryError = ErrorCode.OutOfMemory,
///
/// Timed Out.
///
TimedOutError = ErrorCode.TimedOut,
///
/// Device Busy.
///
DeviceBusyError = ErrorCode.ResourceBusy,
///
/// Not Supported.
///
NotSupportedError = ErrorCode.NotSupported,
///
/// Permission Denied.
///
PermissionDeniedError = ErrorCode.PermissionDenied,
///
/// Operation Failed.
///
OperationFailedError = -0x01C20000 | 0x01,
///
/// Invalied Ndef Message.
///
InvalidNdefMessageError = -0x01C20000 | 0x02,
///
/// Invalid Record Type.
///
InvalidRecordTypeError = -0x01C20000 | 0x03,
///
/// No Device.
///
NoDeviceError = -0x01C20000 | 0x04,
///
/// Not Activated.
///
NotActivatedError = -0x01C20000 | 0x05,
///
/// Already Activated.
///
AlreadyActivatedError = -0x01C20000 | 0x06,
///
/// Already Deactivated.
///
AlreadyDeactivatedError = -0x01C20000 | 0x07,
///
/// Read Only Ndef.
///
ReadOnlyNdefError = -0x01C20000 | 0x08,
///
/// No Space On Ndef.
///
NoSpaceOnNdefError = -0x01C20000 | 0x09,
///
/// No Ndef Message
///
NoNdefMessageError = -0x01C20000 | 0x0a,
///
/// No Ndef Format
///
NotNdefFormatError = -0x01C20000 | 0x0b,
///
/// Security Restricted
///
SecurityRestrictedError = -0x01C20000 | 0x0c,
///
/// Illegal State
///
IllegalStateError = -0x01C20000 | 0x0d,
///
/// Not Initialized
///
NotInitializedError = -0x01C20000 | 0x0e,
///
/// Tag Not Supported
///
TagNotSupportedError = -0x01C20000 | 0x0f,
///
/// Aid Already Registered
///
AidAlreadyRegisteredError = -0x01C20000 | 0x10
}
internal static class NfcErrorFactory
{
static internal void ThrowNfcException(int e)
{
ThrowException(e, false);
}
static internal void ThrowNfcException(int e, int handle)
{
ThrowException(e, (handle < 0));
}
static private void ThrowException(int e, bool isHandleNull)
{
NfcError err = (NfcError)e;
if (isHandleNull)
{
throw new InvalidOperationException("Invalid instance (object may have been disposed or released)");
}
if (err == NfcError.InvalidParameterError)
{
throw new ArgumentException(err.ToString());
}
else if (err == NfcError.NotSupportedError)
{
throw new NotSupportedException();
}
else
{
throw new InvalidOperationException(err.ToString());
}
}
}
}