static Guid _GetPrimaryServiceClassId(ServiceRecord sr) { var a = sr.GetAttributeById(UniversalAttributeId.ServiceClassIdList); var eL = a.Value; var eClassList = eL.GetValueAsElementList(); var e0 = eClassList[0]; var classId = e0.GetValueAsUuid(); return(classId); }
static ServiceElement GetChannelElement(ServiceRecord record, BluetoothProtocolDescriptorType proto) { if (!record.Contains(UniversalAttributeId.ProtocolDescriptorList)) { goto NotFound; } ServiceAttribute attr = record.GetAttributeById(UniversalAttributeId.ProtocolDescriptorList); bool?isSimpleRfcomm; return(GetChannelElement(attr, proto, out isSimpleRfcomm)); NotFound: return(null); }
/// <summary> /// 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. /// </summary> /// - /// <param name="record">A <see cref="T:InTheHand.Net.Bluetooth.ServiceRecord"/> /// whose <see cref="F:InTheHand.Net.Bluetooth.AttributeIds.UniversalAttributeId.ServiceClassIdList"/> /// element will be retrieved, and its Service Class Id will used /// for the lookup. /// </param> /// - /// <returns> /// An array of <see cref="T:System.Type"/> 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 /// <see cref="F:InTheHand.Net.Bluetooth.AttributeIds.UniversalAttributeId.ServiceClassIdList"/> /// attribute, or it is invalid. /// <note>Currently only the first Service Class Id is looked-up.</note> /// </returns> /// - /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="record"/> is null. /// </exception> 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]); }