- Change LocalDevice getter for HCI id

- Fix some new some std::nothrow on critical allocations among kit and server
- Some styling



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30353 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Ruiz Dorantes 2009-04-23 18:47:01 +00:00
parent 072f1c320c
commit b9068dbf95
7 changed files with 210 additions and 201 deletions

View File

@ -46,7 +46,7 @@ public:
ServiceRecord getRecord(Connection notifier);
void updateRecord(ServiceRecord srvRecord);
*/
hci_id GetID(void) {return hid;}
hci_id ID() const;
private:
LocalDevice(hci_id hid);
virtual ~LocalDevice();
@ -58,8 +58,7 @@ private:
static LocalDevice* RequestLocalDeviceID(BMessage* request);
BMessenger* fMessenger;
hci_id hid;
hci_id fHid;
friend class DiscoveryAgent;
friend class RemoteDevice;

View File

@ -193,7 +193,8 @@ DeviceClass::GetMinorDeviceClass(BString& minorClass)
break;
}
break;
case 5: /* peripheral */ {
case 5: /* peripheral */
{
switch(minor & 48) {
case 16:
minorClass << "Keyboard";
@ -237,6 +238,7 @@ DeviceClass::GetMinorDeviceClass(BString& minorClass)
minorClass << "(reserved)";
break;
}
break;
}
case 6: /* imaging */
if (minor & 4)

View File

@ -1,22 +1,20 @@
/*
* Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
*
* All rights reserved. Distributed under the terms of the MIT License.
*
*/
#include <bluetooth/bluetooth_error.h>
#include <bluetooth/DiscoveryAgent.h>
#include <bluetooth/DiscoveryListener.h>
#include <bluetooth/RemoteDevice.h>
#include <bluetooth/LocalDevice.h>
#include <bluetooth/bluetooth_error.h>
#include <bluetooth/RemoteDevice.h>
#include <bluetooth/HCI/btHCI_command.h>
#include <bluetooth/HCI/btHCI_event.h>
#include <bluetoothserver_p.h>
#include <CommandManager.h>
#include "KitSupport.h"
namespace Bluetooth {
@ -25,7 +23,7 @@ namespace Bluetooth {
RemoteDevicesList
DiscoveryAgent::RetrieveDevices(int option)
{
/* No inquiry process initiated */
// No inquiry process initiated
if (fLastUsedListener == NULL)
return RemoteDevicesList();
@ -64,7 +62,7 @@ DiscoveryAgent::StartInquiry(uint32 accessCode, DiscoveryListener* listener, big
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
BMessage reply;
request.AddInt32("hci_id", fLocalDevice->GetID());
request.AddInt32("hci_id", fLocalDevice->ID());
startInquiryCommand = buildInquiry(accessCode, secs, BT_MAX_RESPONSES, &size);
@ -105,7 +103,7 @@ DiscoveryAgent::CancelInquiry(DiscoveryListener* listener)
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
BMessage reply;
request.AddInt32("hci_id", fLocalDevice->GetID());
request.AddInt32("hci_id", fLocalDevice->ID());
cancelInquiryCommand = buildInquiryCancel(&size);
request.AddData("raw command", B_ANY_TYPE, cancelInquiryCommand, size);
@ -121,12 +119,14 @@ DiscoveryAgent::CancelInquiry(DiscoveryListener* listener)
return B_ERROR;
}
void
DiscoveryAgent::SetLocalDeviceOwner(LocalDevice* ld)
{
fLocalDevice = ld;
}
DiscoveryAgent::DiscoveryAgent(LocalDevice* ld)
{
fLocalDevice = ld;
@ -136,7 +136,6 @@ DiscoveryAgent::DiscoveryAgent(LocalDevice* ld)
DiscoveryAgent::~DiscoveryAgent()
{
if (fMessenger)
delete fMessenger;
}

View File

@ -45,7 +45,8 @@ DiscoveryListener::InquiryCompleted(int discType)
/* private */
/* A LocalDevice is always referenced in any request to the
Bluetooth server therefore is going to be needed in any */
* Bluetooth server therefore is going to be needed in any
*/
void
DiscoveryListener::SetLocalDeviceOwner(LocalDevice* ld)
{
@ -65,8 +66,7 @@ DiscoveryListener::MessageReceived(BMessage* message)
{
int8 status;
switch (message->what)
{
switch (message->what) {
case BT_MSG_INQUIRY_DEVICE:
{
const struct inquiry_info* inquiryInfo;
@ -75,14 +75,13 @@ DiscoveryListener::MessageReceived(BMessage* message)
bool duplicatedFound = false;
// TODO: Loop for all inquiryInfo!
if (message->FindData("info", B_ANY_TYPE, 0, (const void**)&inquiryInfo, &size) == B_OK )
{
if (message->FindData("info", B_ANY_TYPE, 0, (const void**)&inquiryInfo, &size) == B_OK) {
// Skip duplicated replies
for (int32 index = 0 ; index < fRemoteDevicesList.CountItems(); index++) {
bdaddr_t b1 = fRemoteDevicesList.ItemAt(index)->GetBluetoothAddress();
if (bdaddrUtils::Compare( (bdaddr_t*) &inquiryInfo->bdaddr, &b1 )) {
if (bdaddrUtils::Compare((bdaddr_t*) &inquiryInfo->bdaddr, &b1)) {
// update these values
fRemoteDevicesList.ItemAt(index)->fPageRepetitionMode = inquiryInfo->pscan_rep_mode;
@ -96,7 +95,6 @@ DiscoveryListener::MessageReceived(BMessage* message)
}
if (!duplicatedFound) {
rd = new RemoteDevice(inquiryInfo->bdaddr, (uint8*)inquiryInfo->dev_class);
fRemoteDevicesList.AddItem(rd);
// keep all inquiry reported data
@ -109,41 +107,32 @@ DiscoveryListener::MessageReceived(BMessage* message)
DeviceDiscovered( rd, rd->GetDeviceClass());
}
}
}
break;
}
case BT_MSG_INQUIRY_STARTED:
if (message->FindInt8("status", &status) == B_OK){
if (message->FindInt8("status", &status) == B_OK) {
fRemoteDevicesList.MakeEmpty();
InquiryStarted(status);
}
break;
case BT_MSG_INQUIRY_COMPLETED:
InquiryCompleted(BT_INQUIRY_COMPLETED);
break;
case BT_MSG_INQUIRY_TERMINATED: /* inquiry was cancelled */
InquiryCompleted(BT_INQUIRY_TERMINATED);
break;
case BT_MSG_INQUIRY_ERROR:
InquiryCompleted(BT_INQUIRY_ERROR);
break;
default:
BLooper::MessageReceived(message);
break;
}
}

View File

@ -9,15 +9,17 @@
#include <bluetooth/HCI/btHCI_command.h>
#include <bluetooth/HCI/btHCI_event.h>
#include <bluetooth/LocalDevice.h>
#include <bluetooth/RemoteDevice.h>
#include <bluetooth/DeviceClass.h>
#include <bluetooth/DiscoveryAgent.h>
#include <bluetooth/LocalDevice.h>
#include <bluetooth/RemoteDevice.h>
#include <bluetooth/bdaddrUtils.h>
#include <bluetoothserver_p.h>
#include <CommandManager.h>
#include <new>
#include "KitSupport.h"
@ -40,7 +42,7 @@ LocalDevice::RequestLocalDeviceID(BMessage* request)
reply.FindInt32("hci_id", &hid) == B_OK ) {
if (hid >= 0)
lDevice = new LocalDevice(hid);
lDevice = new (std::nothrow)LocalDevice(hid);
}
delete messenger;
@ -109,7 +111,7 @@ DiscoveryAgent*
LocalDevice::GetDiscoveryAgent()
{
/* TODO: Study a singleton here */
return new DiscoveryAgent(this);
return new (std::nothrow)DiscoveryAgent(this);
}
@ -131,7 +133,7 @@ LocalDevice::GetProperty(const char* property, uint32* value)
BMessage request(BT_MSG_GET_PROPERTY);
BMessage reply;
request.AddInt32("hci_id", hid);
request.AddInt32("hci_id", fHid);
request.AddString("property", property);
if (fMessenger->SendMessage(&request, &reply) == B_OK) {
@ -166,7 +168,7 @@ LocalDevice::SetDiscoverable(int mode)
int8 bt_status = BT_ERROR;
request.AddInt32("hci_id", hid);
request.AddInt32("hci_id", fHid);
void* command = buildWriteScan(mode, &size);
@ -177,7 +179,8 @@ LocalDevice::SetDiscoverable(int mode)
request.AddData("raw command", B_ANY_TYPE, command, size);
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_WRITE_SCAN_ENABLE));
request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_CONTROL_BASEBAND,
OCF_WRITE_SCAN_ENABLE));
if (fMessenger->SendMessage(&request, &reply) == B_OK) {
if (reply.FindInt8("status", &bt_status ) == B_OK ) {
@ -209,10 +212,11 @@ LocalDevice::GetBluetoothAddress()
ssize_t ssize;
/* ADD ID */
request.AddInt32("hci_id", hid);
request.AddInt32("hci_id", fHid);
request.AddData("raw command", B_ANY_TYPE, command, size);
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_BD_ADDR));
request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_INFORMATIONAL_PARAM,
OCF_READ_BD_ADDR));
if (fMessenger->SendMessage(&request, &reply) == B_OK) {
if (reply.FindData("bdaddr", B_ANY_TYPE, 0, (const void**)&bdaddr, &ssize) == B_OK )
@ -223,6 +227,13 @@ LocalDevice::GetBluetoothAddress()
}
hci_id
LocalDevice::ID(void) const
{
return fHid;
}
BString
LocalDevice::GetFriendlyName()
{
@ -239,10 +250,11 @@ LocalDevice::GetFriendlyName()
BMessage reply;
request.AddInt32("hci_id", hid);
request.AddInt32("hci_id", fHid);
request.AddData("raw command", B_ANY_TYPE, command, size);
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_READ_LOCAL_NAME));
request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_CONTROL_BASEBAND,
OCF_READ_LOCAL_NAME));
if (fMessenger->SendMessage(&request, &reply) == B_OK &&
reply.FindString("friendlyname", &friendlyname) == B_OK){
@ -273,13 +285,15 @@ LocalDevice::GetDeviceClass()
const uint8* record;
ssize_t ssize;
request.AddInt32("hci_id", hid);
request.AddInt32("hci_id", fHid);
request.AddData("raw command", B_ANY_TYPE, command, size);
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_READ_CLASS_OF_DEV));
request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_CONTROL_BASEBAND,
OCF_READ_CLASS_OF_DEV));
if (fMessenger->SendMessage(&request, &reply) == B_OK &&
reply.FindData("devclass", B_ANY_TYPE, 0, (const void**)&record, &ssize) == B_OK) {
if (fMessenger->SendMessage(&request, &reply) == B_OK
&& reply.FindData("devclass", B_ANY_TYPE, 0, (const void**)&record,
&ssize) == B_OK) {
fDeviceClass.SetRecord(*record);
}
@ -301,10 +315,11 @@ LocalDevice::ReadLocalVersion()
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
BMessage reply;
request.AddInt32("hci_id", hid);
request.AddInt32("hci_id", fHid);
request.AddData("raw command", B_ANY_TYPE, localVersion.Data(), localVersion.Size());
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_LOCAL_VERSION));
request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_INFORMATIONAL_PARAM,
OCF_READ_LOCAL_VERSION));
if (fMessenger->SendMessage(&request, &reply) == B_OK)
reply.FindInt8("status", &bt_status);
@ -324,10 +339,11 @@ LocalDevice::ReadBufferSize()
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
BMessage reply;
request.AddInt32("hci_id", hid);
request.AddInt32("hci_id", fHid);
request.AddData("raw command", B_ANY_TYPE, BufferSize.Data(), BufferSize.Size());
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_BUFFER_SIZE));
request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_INFORMATIONAL_PARAM,
OCF_READ_BUFFER_SIZE));
if (fMessenger->SendMessage(&request, &reply) == B_OK)
reply.FindInt8("status", &bt_status);
@ -347,10 +363,11 @@ LocalDevice::Reset()
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
BMessage reply;
request.AddInt32("hci_id", hid);
request.AddInt32("hci_id", fHid);
request.AddData("raw command", B_ANY_TYPE, Reset.Data(), Reset.Size());
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_CONTROL_BASEBAND, OCF_RESET));
request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_CONTROL_BASEBAND,
OCF_RESET));
if (fMessenger->SendMessage(&request, &reply) == B_OK)
reply.FindInt8("status", &bt_status);
@ -372,7 +389,7 @@ LocalDevice::updateRecord(ServiceRecord srvRecord) {
*/
LocalDevice::LocalDevice(hci_id hid) : hid(hid)
LocalDevice::LocalDevice(hci_id hid) : fHid(hid)
{
fMessenger = _RetrieveBluetoothMessenger();
ReadLocalVersion();
@ -388,10 +405,11 @@ LocalDevice::LocalDevice(hci_id hid) : hid(hid)
//#define BT_WRITE_BDADDR_FOR_BCM2035
#ifdef BT_WRITE_BDADDR_FOR_BCM2035
// try the bcm stuff
// try write bdaddr to a bcm2035 -> will be moved to an addon
int8 bt_status = BT_ERROR;
BluetoothCommand<typed_command(hci_write_bcm2035_bdaddr)> writeAddress(OGF_VENDOR_CMD, OCF_WRITE_BCM2035_BDADDR);
BluetoothCommand<typed_command(hci_write_bcm2035_bdaddr)>
writeAddress(OGF_VENDOR_CMD, OCF_WRITE_BCM2035_BDADDR);
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
BMessage reply;
@ -402,10 +420,11 @@ LocalDevice::LocalDevice(hci_id hid) : hid(hid)
writeAddress->bdaddr.b[4] = 0x03;
writeAddress->bdaddr.b[5] = 0x00;
request.AddInt32("hci_id", hid);
request.AddInt32("hci_id", fHid);
request.AddData("raw command", B_ANY_TYPE, writeAddress.Data(), writeAddress.Size());
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_VENDOR_CMD, OCF_WRITE_BCM2035_BDADDR));
request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_VENDOR_CMD,
OCF_WRITE_BCM2035_BDADDR));
if (fMessenger->SendMessage(&request, &reply) == B_OK)
reply.FindInt8("status", &bt_status);
@ -418,7 +437,6 @@ LocalDevice::LocalDevice(hci_id hid) : hid(hid)
LocalDevice::~LocalDevice()
{
if (fMessenger)
delete fMessenger;
}

View File

@ -35,7 +35,6 @@ RemoteDevice::IsTrustedDevice(void)
BString
RemoteDevice::GetFriendlyName(bool alwaysAsk)
{
if (!alwaysAsk) {
// Check if the name is already retrieved
// TODO: Check if It is known from a KnownDevicesList
@ -55,10 +54,10 @@ RemoteDevice::GetFriendlyName(bool alwaysAsk)
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
BMessage reply;
request.AddInt32("hci_id", fDiscovererLocalDevice->GetID());
request.AddInt32("hci_id", fDiscovererLocalDevice->ID());
// Fill the request
remoteNameCommand = buildRemoteNameRequest(fBdaddr, fPageRepetitionMode, fClockOffset, &size); // Fill correctily
remoteNameCommand = buildRemoteNameRequest(fBdaddr, fPageRepetitionMode, fClockOffset, &size);
request.AddData("raw command", B_ANY_TYPE, remoteNameCommand, size);
@ -68,14 +67,13 @@ RemoteDevice::GetFriendlyName(bool alwaysAsk)
request.AddInt16("eventExpected", HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE);
if (fMessenger->SendMessage(&request, &reply) == B_OK)
{
if (fMessenger->SendMessage(&request, &reply) == B_OK) {
BString name;
int8 status;
if ((reply.FindInt8("status", &status) == B_OK) && (status == BT_OK)) {
if ((reply.FindString("friendlyname", &name) == B_OK ) ) {
if ((reply.FindString("friendlyname", &name) == B_OK )) {
return name;
} else {
return BString(""); // should not happen
@ -113,8 +111,10 @@ RemoteDevice::Equals(RemoteDevice* obj)
return bdaddrUtils::Compare(&fBdaddr, &ba);
}
// static RemoteDevice* GetRemoteDevice(Connection conn);
bool
RemoteDevice::Authenticate()
{
@ -142,12 +142,14 @@ RemoteDevice::IsEncrypted()
return true;
}
LocalDevice*
RemoteDevice::GetLocalDeviceOwner()
{
return fDiscovererLocalDevice;
}
/* Private */
void
RemoteDevice::SetLocalDeviceOwner(LocalDevice* ld)
@ -175,7 +177,6 @@ RemoteDevice::RemoteDevice(const BString& address)
RemoteDevice::~RemoteDevice()
{
if (fMessenger)
delete fMessenger;
}

View File

@ -22,6 +22,7 @@
#include <PincodeWindow.h>
#include <stdio.h>
#include <new>
#if 0
@ -33,10 +34,10 @@
LocalDeviceImpl*
LocalDeviceImpl::CreateControllerAccessor(BPath* path)
{
HCIDelegate* hd = new HCIControllerAccessor(path);
HCIDelegate* hd = new (std::nothrow)HCIControllerAccessor(path);
if (hd != NULL)
return new LocalDeviceImpl(hd);
return new (std::nothrow)LocalDeviceImpl(hd);
else
return NULL;
}
@ -45,10 +46,10 @@ LocalDeviceImpl::CreateControllerAccessor(BPath* path)
LocalDeviceImpl*
LocalDeviceImpl::CreateTransportAccessor(BPath* path)
{
HCIDelegate* hd = new HCITransportAccessor(path);
HCIDelegate* hd = new (std::nothrow)HCITransportAccessor(path);
if (hd != NULL)
return new LocalDeviceImpl(hd);
return new (std::nothrow)LocalDeviceImpl(hd);
else
return NULL;
}