⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 btcon_sdpmanager.cpp

📁 C++实现的BlueTooth
💻 CPP
字号:
/*****************************************************************************

 COPYRIGHT All rights reserved Sony Ericsson Mobile Communications AB 2005.



 The software is the copyrighted work of Sony Ericsson Mobile Communications AB.

 The use of the software is subject to the terms of the end-user license

 agreement which accompanies or is included with the software. The software is

 provided "as is" and Sony Ericsson specifically disclaim any warranty or

 condition whatsoever regarding merchantability or fitness for a specific

 purpose, title or non-infringement. No warranty of any kind is made in

 relation to the condition, suitability, availability, accuracy, reliability,

 merchantability and/or non-infringement of the software provided herein.



 *****************************************************************************/


#include <bt_sock.h>

#include "BTCon_Application.h"
#include "BTCon_AppView.h"
#include "BTCon_MsgServer.h"
#include "BTCon_SdpManager.h"


_LIT(KServerTransportName,"RFCOMM");

const TInt KServiceClass = 0x1101;

CSdpManager* CSdpManager::NewL()
  {
  CSdpManager* self = NewLC();
  CleanupStack::Pop(self);
  return self;
  }

CSdpManager* CSdpManager::NewLC()
  {
  CSdpManager* self = new (ELeave) CSdpManager();
  CleanupStack::PushL(self);
  self->ConstructL();
  return self;
  }

CSdpManager::~CSdpManager()
  {
  if( IsAdvertising() ) 
    {
    TRAPD( err, StopConnectionToSdpL() );
    if( err != KErrNone )
      User::Panic(_L("CSdpManager Destructor"), err);
    }

  iSdpDatabase.Close();
  iSdp.Close();
  }

void CSdpManager::ConnectAndSetToSdpL(TInt aChannel)
  {
  StopConnectionToSdpL(); 
  
  if(!iIsConnected)
    {
// SDK: "How to connect to the service discovery database"

    // Create and open session to the database
    User::LeaveIfError(iSdp.Connect());
    // Create and open a subsession
    User::LeaveIfError(iSdpDatabase.Open(iSdp));
    iIsConnected = ETrue;
    }

// SDK: "How to register a service in the database"

  // Enter record into the sdp database
  iSdpDatabase.CreateServiceRecordL(KServiceClass, iRecordHandle);

  // Create a list of service class UUIDs
  CSdpAttrValueDES* UUIDlist = CSdpAttrValueDES::NewDESL(NULL);
  CleanupStack::PushL(UUIDlist);
  TBuf8<1> tb_channel;
  tb_channel.Append((TChar)aChannel);
  UUIDlist
    ->StartListL()
      ->BuildDESL()
      ->StartListL()
        ->BuildUUIDL(KRFCOMM)
        ->BuildUintL(tb_channel)
      ->EndListL()
    ->EndListL();

  // set an attribute in a service record
  iSdpDatabase.UpdateAttributeL(iRecordHandle,
                                KSdpAttrIdProtocolDescriptorList,
                                *UUIDlist);

  CleanupStack::PopAndDestroy(UUIDlist);
  }

void CSdpManager::StopConnectionToSdpL()
  {
  if( IsAdvertising() )
    {
    iSdpDatabase.DeleteRecordL(iRecordHandle);
    iRecordHandle = 0;
    }
  }

void CSdpManager::UpdateAvailabilityL(TBool aIsAvailable)
  {
  TUint state;
  if(aIsAvailable)
    {
    state = 0xFF;  //  Fully unused
    }
  else
    {
    state = 0x00;  //  Fully used -> can't connect
    }

  //  Update the availibility attribute field
  iSdpDatabase.UpdateAttributeL(iRecordHandle,
                                KSdpAttrIdServiceAvailability,
                                state);

  //  Mark the record as changed - by increasing its state number (version)
  iSdpDatabase.UpdateAttributeL(iRecordHandle,
                                KSdpAttrIdServiceRecordState,
                                ++iRecordState);
  }

CSdpManager::CSdpManager() : iIsConnected(EFalse), iRecordHandle(0)
  {
  }

void CSdpManager::ConstructL()
  {
  }


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -