// 32feet.NET - Personal Area Networking for .NET // // InTheHand.Net.Bluetooth.MapServiceClassToAttributeIdList // // Copyright (c) 2003-2020 In The Hand Ltd, All rights reserved. // This source code is licensed under the MIT License using System; using InTheHand.Net.Bluetooth; using InTheHand.Net.Bluetooth.AttributeIds; namespace InTheHand.Net.Bluetooth.Sdp { /// /// Gets a list of enum-like classes containing SDP Service Attribute Id definitions /// for a particular Service Class. /// /// - /// /// See method /// . /// public class MapServiceClassToAttributeIdList { /// /// Initializes a new instance of the class. /// public MapServiceClassToAttributeIdList() { } /// /// Get a list of enum-like classes containing Service Attribute Id definitions /// for the type of the Service Class contained in the given Service Record. /// /// - /// A /// whose /// element will be retrieved, and its Service Class Id will used /// for the lookup. /// /// - /// /// An array of each of which is a enum-like class /// which defines the set of Service Attribute IDs used by a particular /// Service Class e.g. ObjectPushProfile. /// An empty array will be returned if none of the Service Classes /// are known, or the record contains no /// /// attribute, or it is invalid. /// Currently only the first Service Class Id is looked-up. /// /// - /// /// is null. /// public Type[] GetAttributeIdEnumTypes(ServiceRecord record) { if (record == null) { throw new ArgumentNullException("record"); } // ServiceAttribute attr; try { attr = record.GetAttributeById(UniversalAttributeId.ServiceClassIdList); } catch (System.Collections.Generic.KeyNotFoundException ex) { System.Diagnostics.Debug.Assert(ex.Message == ServiceRecord.ErrorMsgNoAttributeWithId); goto InvalidRecord; } ServiceElement element = attr.Value; if (element.ElementType != ElementType.ElementSequence) { goto InvalidRecord; } ServiceElement[] idElements = element.GetValueAsElementArray(); //TODO ((GetServiceClassSpecificAttributeIdEnumDefiningType--foreach (ServiceElement curIdElem in idElements) {)) if (idElements.Length != 0) { ServiceElement curIdElem = idElements[0]; Type enumType = GetAttributeIdEnumType(curIdElem); if (enumType != null) { return new Type[] { enumType }; } }//else fall through... // None-matched, or invalid attribute format etc. InvalidRecord: return new Type[0]; } /// /// Get the enum-like class containing the Service Attribute Id definitions /// for the type of the Service Class contained in the given /// /// (type ) data element. /// /// - /// A /// of 'UUID' type containing the Service Class to search for. /// /// - /// /// A object representing the enum-like class /// holding the Attribute Id definitions, or null if the Service Class is /// unknown or the element is not of /// type. /// /// - /// /// is null. /// protected virtual Type GetAttributeIdEnumType(ServiceElement idElement) { if (idElement == null) { throw new ArgumentNullException("idElement"); } // if (idElement.ElementTypeDescriptor != ElementTypeDescriptor.Uuid) { return null; } Guid uuid = idElement.GetValueAsUuid(); // return GetAttributeIdEnumType(uuid); } /// /// Get the enum-like class containing the Service Attribute Id definitions /// for the type of the Service Class specified. /// /// - /// /// Get the enum-like class containing the Service Attribute Id definitions /// for the type of the Service Class specified by UUID. /// /// - /// The Service Class to search for, as a . /// /// - /// /// A object representing the enum-like class /// holding the Attribute Id definitions, or null if the Service Class is /// unknown. /// protected virtual Type GetAttributeIdEnumType(Guid uuid) { foreach (ServiceClassToIdsMapRow cur in m_serviceClassToIdsMapTable) { if (uuid == cur.ServiceClassId) { return cur.AttributeIdEnumType; } }//for // return null; } private struct ServiceClassToIdsMapRow { public readonly Guid ServiceClassId; public readonly Type AttributeIdEnumType; public ServiceClassToIdsMapRow(Guid ServiceClassId,Type AttributeIdEnumType) { this.ServiceClassId = ServiceClassId; this.AttributeIdEnumType = AttributeIdEnumType; } } private ServiceClassToIdsMapRow[] m_serviceClassToIdsMapTable = { // Note BluetoothService.ServiceDiscoveryServer has a wrong value in 32feet.NET v2.1 and earlier! new ServiceClassToIdsMapRow(BluetoothService.ServiceDiscoveryServer, typeof(ServiceDiscoveryServerAttributeId)), //0x1000 // new ServiceClassToIdsMapRow(BluetoothService.IrMCSync, typeof(ObexAttributeId)), //0x1104 new ServiceClassToIdsMapRow(BluetoothService.ObexObjectPush, typeof(ObexAttributeId)), //0x1105 new ServiceClassToIdsMapRow(BluetoothService.ObexFileTransfer, typeof(ObexAttributeId)), //0x1106 new ServiceClassToIdsMapRow(BluetoothService.IrMCSyncCommand, typeof(ObexAttributeId)), //0x1107 // // The Service Class ID used in the ServiceClassList seems to have changed // between HSP version 1.1 and 1.2. new ServiceClassToIdsMapRow(BluetoothService.Headset, typeof(HeadsetProfileAttributeId)), //0x1108 new ServiceClassToIdsMapRow(BluetoothService.HeadsetHeadset, typeof(HeadsetProfileAttributeId)), //0x1131 //AUX-new Foo(BluetoothService.GenericAudio, typeof(HspAttributeId)), //0x1203 // new ServiceClassToIdsMapRow(BluetoothService.Panu, typeof(PersonalAreaNetworkingProfileAttributeId)), //0x1115 new ServiceClassToIdsMapRow(BluetoothService.Nap, typeof(PersonalAreaNetworkingProfileAttributeId)), //0x1116 new ServiceClassToIdsMapRow(BluetoothService.GN, typeof(PersonalAreaNetworkingProfileAttributeId)), //0x1117 // new ServiceClassToIdsMapRow(BluetoothService.DirectPrinting, typeof(BasicPrintingProfileAttributeId)), //0x1118- new ServiceClassToIdsMapRow(BluetoothService.ReferencePrinting, typeof(BasicPrintingProfileAttributeId)), //0x1119- new ServiceClassToIdsMapRow(BluetoothService.DirectPrintingReferenceObjects, typeof(BasicPrintingProfileAttributeId)), //0x1120- new ServiceClassToIdsMapRow(BluetoothService.ReflectedUI, typeof(BasicPrintingProfileAttributeId)), //0x1121- new ServiceClassToIdsMapRow(BluetoothService.BasicPrinting, typeof(BasicPrintingProfileAttributeId)), //0x1122 new ServiceClassToIdsMapRow(BluetoothService.PrintingStatus, typeof(BasicPrintingProfileAttributeId)), //0x1123- // // The profile specific Attributes are on both ends new ServiceClassToIdsMapRow(BluetoothService.Handsfree, typeof(HandsFreeProfileAttributeId)), //0x111E new ServiceClassToIdsMapRow(BluetoothService.HandsfreeAudioGateway, typeof(HandsFreeProfileAttributeId)), //0x111F //AUX-new Foo(BluetoothService.GenericAudio, typeof(HfpAttributeId)), // new ServiceClassToIdsMapRow(BluetoothService.HumanInterfaceDevice, typeof(HidProfileAttributeId)), //0x1124 new ServiceClassToIdsMapRow(BluetoothService.PnPInformation, typeof(DeviceIdProfileAttributeId)), //0x1200 }; }//class }