SdpRecordTemp.cs :  » Business-Application » 32feet.NET » InTheHand » Net » Bluetooth » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Business Application » 32feet.NET 
32feet.NET » InTheHand » Net » Bluetooth » SdpRecordTemp.cs
// 32feet.NET
//
// InTheHand.Net.Bluetooth.SdpRecordTemp
// 
// Copyright (c) 2003-2006 In The Hand Ltd, All rights reserved.
// This source code is licensed under the In The Hand Community License - see License.txt

using System;
#if ! V1
using List_ServiceAttributeSystem.Collections.Generic.ListInTheHand.Net.Bluetooth.ServiceAttribute;
#else
using List_ServiceAttributeSystem.Collections.ArrayList;
#endif
using InTheHand.Net.Bluetooth.AttributeIds;

namespace InTheHand.Net.Bluetooth{
  /// <summary>
  /// Dummy SDP record into which we can insert the Guid and channel
  /// </summary>
  internal class SdpRecordTemp
  {
    byte[] m_data;
        ServiceRecord m_record;
        readonly int m_expectedRecordLength = 41;

    public SdpRecordTemp()
    {
      m_data = new byte[] {0x35,0x27,0x09,0x00,0x01,0x35,0x11,0x1c,
                  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
                  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
                  0x09,0x00,0x04,0x35,0x0c,0x35,0x03,0x19,
                  0x01,0x00,0x35,0x05,0x19,0x00,0x03,0x08,
                  0x00};
            m_record = CreateRecord();
            m_expectedRecordLength = 41;
        }

    public Guid Service
    {
      get
      {
                // HACK SdpRecordTemp.get_Service is not callable, it is effectively private!
                Guid uuid = GetRecordService(m_record);
                //old
                byte[] guidbytes = new byte[16];
                Buffer.BlockCopy(m_data, 8, guidbytes, 0, 16);
                Guid hostGuid = new Guid(guidbytes);
                Guid netGuid = Sockets.BluetoothListener.HostToNetworkOrder(hostGuid);
                if (uuid != netGuid) {
                    System.Diagnostics.Debug.Fail("Internal error--Service UUID not equal.");
                }
                //
                return netGuid;
      }
      set
      {
                SetRecordService(m_record, value);
                //old
                Guid hostGuid = Sockets.BluetoothListener.HostToNetworkOrder(value);
                Buffer.BlockCopy(hostGuid.ToByteArray(), 0, m_data, 8, 16);
      }
    }

    public byte Channel
    {
      get
      {
                // HACK SdpRecordTemp.get_Channel is not callable, it is effectively private!
                int value = ServiceRecordHelper.GetRfcommChannelNumber(m_record);
                byte channel = (byte)value;
                //old
                byte orig_channel = m_data[m_data.Length - 1];
                if (orig_channel != channel) {
                    System.Diagnostics.Debug.Fail("Internal error--Channel Number not equal.");
                }
                //
                return channel;
      }
      set
      {
                ServiceRecordHelper.SetRfcommChannelNumber(m_record, value);
                m_data[m_data.Length - 1] = value;
      }
    }

    public byte[] ToByteArray()
    {
            byte[] newRecordBytes = new byte[m_expectedRecordLength];
            int length = new ServiceRecordCreator().CreateServiceRecord(m_record, newRecordBytes);
            System.Diagnostics.Debug.Assert(length == m_expectedRecordLength);
            //old
            for (int i = 0; i < m_data.Length; ++i) {
                if (m_data[i] != newRecordBytes[i]) {
                    System.Diagnostics.Debug.Fail(String.Format(
                        "Internal error--Records different at index {0} was 0x{1} is 0x{2}.",
                        i, m_data[i], newRecordBytes[i]));
                }
            }//for
      return newRecordBytes;
    }

        //--------------------------------------------------------------
        private static ServiceRecord CreateRecord()
        {
            List_ServiceAttribute attrs = new List_ServiceAttribute();
            ServiceElement element;
            //
            element = new ServiceElement(ElementType.ElementSequence,
                new ServiceElement(ElementType.Uuid128, Guid.Empty));
            attrs.Add(new ServiceAttribute(UniversalAttributeId.ServiceClassIdList, element));
            //
            element = ServiceRecordHelper.CreateRfcommProtocolDescriptorList();
            attrs.Add(new ServiceAttribute(UniversalAttributeId.ProtocolDescriptorList, element));
            //
            ServiceRecord record = new ServiceRecord(attrs);
            return record;
        }

        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;
        }

    }//class
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.