// 32feet.NET - Personal Area Networking for .NET
//
// InTheHand.Net.Widcomm.WidcommSocketExceptions
//
// Copyright (c) 2008-2009 In The Hand Ltd, All rights reserved.
// Copyright (c) 2008-2009 Alan J. McFarlane, All rights reserved.
// This source code is licensed under the In The Hand Community License - see License.txt
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
namespace InTheHand.Net.Bluetooth.Widcomm{
sealed class WidcommRfcommInterface : IDisposable
{
IRfCommIf m_RfCommIf;
internal WidcommRfcommInterface(IRfCommIf rfCommIf)
{
m_RfCommIf = rfCommIf;
}
//--------------------------------------------------------------
internal void SetScnForPeerServer(Guid serviceGuid, byte scn)
{
bool success = m_RfCommIf.ClientAssignScnValue(serviceGuid, scn);
if (!success)
throw new IOException(WidcommRfcommStream.WrappingIOExceptionMessage, WidcommSocketExceptions.Create_NoResultCode(
WidcommSocketExceptions.SocketError_SetSecurityLevel_Client_Fail, "SetScnForPeerServer"));
}
internal void SetSecurityLevelClient(BTM_SEC securityLevel)
{
const bool isServerFalse = false;
bool success = m_RfCommIf.SetSecurityLevel(WidcommUtils.SetSecurityLevel_Client_ServiceName, securityLevel, isServerFalse);
if (!success)
throw new IOException(WidcommRfcommStream.WrappingIOExceptionMessage, WidcommSocketExceptions.Create_NoResultCode(
WidcommSocketExceptions.SocketError_SetSecurityLevel_Client_Fail, "SetSecurityLevel"));
}
//--------------------------------------------------------------
internal byte SetScnForLocalServer(Guid serviceGuid, byte scn)
{
bool success = m_RfCommIf.ClientAssignScnValue(serviceGuid, scn);
if (!success)
throw new IOException(WidcommRfcommStream.WrappingIOExceptionMessage, WidcommSocketExceptions.Create_NoResultCode(
WidcommSocketExceptions.SocketError_SetSecurityLevel_Client_Fail, "SetScnForPeerServer"));
int scnAssigned = m_RfCommIf.GetScn();
WidcommUtils.Trace_WriteLine("Server GetScn returned port: {0}", scnAssigned);
Debug.Assert(scnAssigned != 0);
return checked((byte)scnAssigned);
}
internal void SetSecurityLevelServer(BTM_SEC securityLevel, byte[] serviceName)
{
const bool isServerTrue = true;
bool success = m_RfCommIf.SetSecurityLevel(serviceName, securityLevel, isServerTrue);
if (!success)
throw new IOException(WidcommRfcommStream.WrappingIOExceptionMessage, WidcommSocketExceptions.Create_NoResultCode(
WidcommSocketExceptions.SocketError_SetSecurityLevel_Client_Fail, "SetSecurityLevel"));
}
//--------------------------------------------------------------
public void Dispose()
{
Dispose(true);
}
[SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "disposing")]
void Dispose(bool disposing)
{
m_RfCommIf.Destroy();
}
}
}
|