/// <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> /// - /// <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. /// </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 ( #if V1 ArgumentException #else System.Collections.Generic.KeyNotFoundException #endif 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]; }
private static void SetRecordService(ServiceRecord m_record, Guid uuid128) { ServiceAttribute attr = m_record.GetAttributeById(UniversalAttributeId.ServiceClassIdList); ServiceElement element = (ServiceElement)attr.Value.GetValueAsElementList()[0]; element.SetValue(uuid128); }
private Guid GetRecordService(ServiceRecord m_record) { ServiceAttribute attr = m_record.GetAttributeById(UniversalAttributeId.ServiceClassIdList); ServiceElement element = (ServiceElement)attr.Value.GetValueAsElementList()[0]; Guid uuid128 = (Guid)element.Value; return(uuid128); }
static ServiceElement GetChannelElement(ServiceRecord record, BluetoothProtocolDescriptorType proto) { if (!record.Contains(UniversalAttributeId.ProtocolDescriptorList)) { goto NotFound; } ServiceAttribute attr = record.GetAttributeById(UniversalAttributeId.ProtocolDescriptorList); #if !V1 bool?isSimpleRfcomm; #else object isSimpleRfcomm; #endif 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 ( #if V1 ArgumentException #else System.Collections.Generic.KeyNotFoundException #endif 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]); }
//-------------------------------------------------------------- /// <summary> /// Reads the RFCOMM Channel Number element from the service record. /// </summary> /// <returns>The <see cref="T:InTheHand.Net.Bluetooth.ServiceElement"/> /// holding the Channel Number. /// or <see langword="null"/> if at the <see cref="F:InTheHand.Net.Bluetooth.AttributeIds.UniversalAttributeId.ProtocolDescriptorList"/> /// attribute is missing or contains invalid elements. /// </returns> public static ServiceElement GetRfcommChannelElement(ServiceRecord record) { if (!record.Contains(UniversalAttributeId.ProtocolDescriptorList)) { goto NotFound; } ServiceAttribute attr = record.GetAttributeById(UniversalAttributeId.ProtocolDescriptorList); ServiceElement e0 = attr.Value; if (e0.ElementType == ElementType.ElementAlternative) { #if ! WinCE Trace.WriteLine("Don't support ElementAlternative ProtocolDescriptorList values."); #endif goto NotFound; } else if (e0.ElementType != ElementType.ElementSequence) { #if ! WinCE Trace.WriteLine("Bad ProtocolDescriptorList base element."); #endif goto NotFound; } IList_ServiceElement protoStack = e0.GetValueAsElementList(); IEnumerator_ServiceElement etor = protoStack.GetEnumerator(); ServiceElement layer; IList_ServiceElement layerContent; if (!etor.MoveNext()) { #if ! WinCE Trace.WriteLine("Protocol stack truncated before {0}.", "L2CAP"); #endif goto NotFound; } layer = (ServiceElement)etor.Current; //cast here are for non-Generic version. layerContent = layer.GetValueAsElementList(); if (((ServiceElement)layerContent[0]).GetValueAsUuid() != BluetoothService.L2CapProtocol) { #if ! WinCE Trace.WriteLine(String.Format(System.Globalization.CultureInfo.InvariantCulture, "Bad protocol stack, layer {0} is not {1}.", 1, "L2CAP")); #endif goto NotFound; } // if (!etor.MoveNext()) { #if ! WinCE Trace.WriteLine("Protocol stack truncated before {0}.", "RFCOMM"); #endif goto NotFound; } layer = (ServiceElement)etor.Current; layerContent = layer.GetValueAsElementList(); if (((ServiceElement)layerContent[0]).GetValueAsUuid() != BluetoothService.RFCommProtocol) { #if ! WinCE Trace.WriteLine(String.Format(System.Globalization.CultureInfo.InvariantCulture, "Bad protocol stack, layer {0} is not {1}.", 2, "RFCOMM")); #endif goto NotFound; } // if (layerContent.Count < 2) { #if ! WinCE Trace.WriteLine(String.Format(System.Globalization.CultureInfo.InvariantCulture, "Bad protocol stack, layer {0} hasn't a second element.", 2)); #endif goto NotFound; } ServiceElement channelElement = (ServiceElement)layerContent[1]; if (channelElement.ElementType != ElementType.UInt8) { #if ! WinCE Trace.WriteLine(String.Format(System.Globalization.CultureInfo.InvariantCulture, "Bad protocol stack, layer {0} is not UInt8.", 2)); #endif goto NotFound; } // Success return channelElement; NotFound: return null; }
private Guid GetRecordService(ServiceRecord m_record) { ServiceAttribute attr = m_record.GetAttributeById(UniversalAttributeId.ServiceClassIdList); ServiceElement element = (ServiceElement)attr.Value.GetValueAsElementList()[0]; Guid uuid128 = (Guid)element.Value; return uuid128; }