- 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
+2 -3
View File
@@ -46,7 +46,7 @@ public:
ServiceRecord getRecord(Connection notifier); ServiceRecord getRecord(Connection notifier);
void updateRecord(ServiceRecord srvRecord); void updateRecord(ServiceRecord srvRecord);
*/ */
hci_id GetID(void) {return hid;} hci_id ID() const;
private: private:
LocalDevice(hci_id hid); LocalDevice(hci_id hid);
virtual ~LocalDevice(); virtual ~LocalDevice();
@@ -58,8 +58,7 @@ private:
static LocalDevice* RequestLocalDeviceID(BMessage* request); static LocalDevice* RequestLocalDeviceID(BMessage* request);
BMessenger* fMessenger; BMessenger* fMessenger;
hci_id fHid;
hci_id hid;
friend class DiscoveryAgent; friend class DiscoveryAgent;
friend class RemoteDevice; friend class RemoteDevice;
+3 -1
View File
@@ -193,7 +193,8 @@ DeviceClass::GetMinorDeviceClass(BString& minorClass)
break; break;
} }
break; break;
case 5: /* peripheral */ { case 5: /* peripheral */
{
switch(minor & 48) { switch(minor & 48) {
case 16: case 16:
minorClass << "Keyboard"; minorClass << "Keyboard";
@@ -237,6 +238,7 @@ DeviceClass::GetMinorDeviceClass(BString& minorClass)
minorClass << "(reserved)"; minorClass << "(reserved)";
break; break;
} }
break;
} }
case 6: /* imaging */ case 6: /* imaging */
if (minor & 4) if (minor & 4)
+8 -9
View File
@@ -1,22 +1,20 @@
/* /*
* Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com * Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
*
* All rights reserved. Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT License.
*
*/ */
#include <bluetooth/bluetooth_error.h>
#include <bluetooth/DiscoveryAgent.h> #include <bluetooth/DiscoveryAgent.h>
#include <bluetooth/DiscoveryListener.h> #include <bluetooth/DiscoveryListener.h>
#include <bluetooth/RemoteDevice.h>
#include <bluetooth/LocalDevice.h> #include <bluetooth/LocalDevice.h>
#include <bluetooth/bluetooth_error.h> #include <bluetooth/RemoteDevice.h>
#include <bluetooth/HCI/btHCI_command.h> #include <bluetooth/HCI/btHCI_command.h>
#include <bluetooth/HCI/btHCI_event.h> #include <bluetooth/HCI/btHCI_event.h>
#include <bluetoothserver_p.h> #include <bluetoothserver_p.h>
#include <CommandManager.h> #include <CommandManager.h>
#include "KitSupport.h" #include "KitSupport.h"
namespace Bluetooth { namespace Bluetooth {
@@ -25,7 +23,7 @@ namespace Bluetooth {
RemoteDevicesList RemoteDevicesList
DiscoveryAgent::RetrieveDevices(int option) DiscoveryAgent::RetrieveDevices(int option)
{ {
/* No inquiry process initiated */ // No inquiry process initiated
if (fLastUsedListener == NULL) if (fLastUsedListener == NULL)
return RemoteDevicesList(); return RemoteDevicesList();
@@ -64,7 +62,7 @@ DiscoveryAgent::StartInquiry(uint32 accessCode, DiscoveryListener* listener, big
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
BMessage reply; BMessage reply;
request.AddInt32("hci_id", fLocalDevice->GetID()); request.AddInt32("hci_id", fLocalDevice->ID());
startInquiryCommand = buildInquiry(accessCode, secs, BT_MAX_RESPONSES, &size); startInquiryCommand = buildInquiry(accessCode, secs, BT_MAX_RESPONSES, &size);
@@ -105,7 +103,7 @@ DiscoveryAgent::CancelInquiry(DiscoveryListener* listener)
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
BMessage reply; BMessage reply;
request.AddInt32("hci_id", fLocalDevice->GetID()); request.AddInt32("hci_id", fLocalDevice->ID());
cancelInquiryCommand = buildInquiryCancel(&size); cancelInquiryCommand = buildInquiryCancel(&size);
request.AddData("raw command", B_ANY_TYPE, cancelInquiryCommand, size); request.AddData("raw command", B_ANY_TYPE, cancelInquiryCommand, size);
@@ -121,12 +119,14 @@ DiscoveryAgent::CancelInquiry(DiscoveryListener* listener)
return B_ERROR; return B_ERROR;
} }
void void
DiscoveryAgent::SetLocalDeviceOwner(LocalDevice* ld) DiscoveryAgent::SetLocalDeviceOwner(LocalDevice* ld)
{ {
fLocalDevice = ld; fLocalDevice = ld;
} }
DiscoveryAgent::DiscoveryAgent(LocalDevice* ld) DiscoveryAgent::DiscoveryAgent(LocalDevice* ld)
{ {
fLocalDevice = ld; fLocalDevice = ld;
@@ -136,7 +136,6 @@ DiscoveryAgent::DiscoveryAgent(LocalDevice* ld)
DiscoveryAgent::~DiscoveryAgent() DiscoveryAgent::~DiscoveryAgent()
{ {
if (fMessenger)
delete fMessenger; delete fMessenger;
} }
+9 -20
View File
@@ -45,7 +45,8 @@ DiscoveryListener::InquiryCompleted(int discType)
/* private */ /* private */
/* A LocalDevice is always referenced in any request to the /* 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 void
DiscoveryListener::SetLocalDeviceOwner(LocalDevice* ld) DiscoveryListener::SetLocalDeviceOwner(LocalDevice* ld)
{ {
@@ -65,8 +66,7 @@ DiscoveryListener::MessageReceived(BMessage* message)
{ {
int8 status; int8 status;
switch (message->what) switch (message->what) {
{
case BT_MSG_INQUIRY_DEVICE: case BT_MSG_INQUIRY_DEVICE:
{ {
const struct inquiry_info* inquiryInfo; const struct inquiry_info* inquiryInfo;
@@ -75,14 +75,13 @@ DiscoveryListener::MessageReceived(BMessage* message)
bool duplicatedFound = false; bool duplicatedFound = false;
// TODO: Loop for all inquiryInfo! // 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 // Skip duplicated replies
for (int32 index = 0 ; index < fRemoteDevicesList.CountItems(); index++) { for (int32 index = 0 ; index < fRemoteDevicesList.CountItems(); index++) {
bdaddr_t b1 = fRemoteDevicesList.ItemAt(index)->GetBluetoothAddress(); 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 // update these values
fRemoteDevicesList.ItemAt(index)->fPageRepetitionMode = inquiryInfo->pscan_rep_mode; fRemoteDevicesList.ItemAt(index)->fPageRepetitionMode = inquiryInfo->pscan_rep_mode;
@@ -96,7 +95,6 @@ DiscoveryListener::MessageReceived(BMessage* message)
} }
if (!duplicatedFound) { if (!duplicatedFound) {
rd = new RemoteDevice(inquiryInfo->bdaddr, (uint8*)inquiryInfo->dev_class); rd = new RemoteDevice(inquiryInfo->bdaddr, (uint8*)inquiryInfo->dev_class);
fRemoteDevicesList.AddItem(rd); fRemoteDevicesList.AddItem(rd);
// keep all inquiry reported data // keep all inquiry reported data
@@ -109,41 +107,32 @@ DiscoveryListener::MessageReceived(BMessage* message)
DeviceDiscovered( rd, rd->GetDeviceClass()); DeviceDiscovered( rd, rd->GetDeviceClass());
} }
} }
}
break; break;
}
case BT_MSG_INQUIRY_STARTED: case BT_MSG_INQUIRY_STARTED:
if (message->FindInt8("status", &status) == B_OK){ if (message->FindInt8("status", &status) == B_OK) {
fRemoteDevicesList.MakeEmpty(); fRemoteDevicesList.MakeEmpty();
InquiryStarted(status); InquiryStarted(status);
} }
break; break;
case BT_MSG_INQUIRY_COMPLETED: case BT_MSG_INQUIRY_COMPLETED:
InquiryCompleted(BT_INQUIRY_COMPLETED); InquiryCompleted(BT_INQUIRY_COMPLETED);
break; break;
case BT_MSG_INQUIRY_TERMINATED: /* inquiry was cancelled */ case BT_MSG_INQUIRY_TERMINATED: /* inquiry was cancelled */
InquiryCompleted(BT_INQUIRY_TERMINATED); InquiryCompleted(BT_INQUIRY_TERMINATED);
break; break;
case BT_MSG_INQUIRY_ERROR: case BT_MSG_INQUIRY_ERROR:
InquiryCompleted(BT_INQUIRY_ERROR); InquiryCompleted(BT_INQUIRY_ERROR);
break; break;
default: default:
BLooper::MessageReceived(message); BLooper::MessageReceived(message);
break; break;
} }
} }
+45 -27
View File
@@ -9,15 +9,17 @@
#include <bluetooth/HCI/btHCI_command.h> #include <bluetooth/HCI/btHCI_command.h>
#include <bluetooth/HCI/btHCI_event.h> #include <bluetooth/HCI/btHCI_event.h>
#include <bluetooth/LocalDevice.h>
#include <bluetooth/RemoteDevice.h>
#include <bluetooth/DeviceClass.h> #include <bluetooth/DeviceClass.h>
#include <bluetooth/DiscoveryAgent.h> #include <bluetooth/DiscoveryAgent.h>
#include <bluetooth/LocalDevice.h>
#include <bluetooth/RemoteDevice.h>
#include <bluetooth/bdaddrUtils.h> #include <bluetooth/bdaddrUtils.h>
#include <bluetoothserver_p.h> #include <bluetoothserver_p.h>
#include <CommandManager.h> #include <CommandManager.h>
#include <new>
#include "KitSupport.h" #include "KitSupport.h"
@@ -40,7 +42,7 @@ LocalDevice::RequestLocalDeviceID(BMessage* request)
reply.FindInt32("hci_id", &hid) == B_OK ) { reply.FindInt32("hci_id", &hid) == B_OK ) {
if (hid >= 0) if (hid >= 0)
lDevice = new LocalDevice(hid); lDevice = new (std::nothrow)LocalDevice(hid);
} }
delete messenger; delete messenger;
@@ -109,7 +111,7 @@ DiscoveryAgent*
LocalDevice::GetDiscoveryAgent() LocalDevice::GetDiscoveryAgent()
{ {
/* TODO: Study a singleton here */ /* 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 request(BT_MSG_GET_PROPERTY);
BMessage reply; BMessage reply;
request.AddInt32("hci_id", hid); request.AddInt32("hci_id", fHid);
request.AddString("property", property); request.AddString("property", property);
if (fMessenger->SendMessage(&request, &reply) == B_OK) { if (fMessenger->SendMessage(&request, &reply) == B_OK) {
@@ -166,7 +168,7 @@ LocalDevice::SetDiscoverable(int mode)
int8 bt_status = BT_ERROR; int8 bt_status = BT_ERROR;
request.AddInt32("hci_id", hid); request.AddInt32("hci_id", fHid);
void* command = buildWriteScan(mode, &size); void* command = buildWriteScan(mode, &size);
@@ -177,7 +179,8 @@ LocalDevice::SetDiscoverable(int mode)
request.AddData("raw command", B_ANY_TYPE, command, size); request.AddData("raw command", B_ANY_TYPE, command, size);
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE); 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 (fMessenger->SendMessage(&request, &reply) == B_OK) {
if (reply.FindInt8("status", &bt_status ) == B_OK ) { if (reply.FindInt8("status", &bt_status ) == B_OK ) {
@@ -209,10 +212,11 @@ LocalDevice::GetBluetoothAddress()
ssize_t ssize; ssize_t ssize;
/* ADD ID */ /* ADD ID */
request.AddInt32("hci_id", hid); request.AddInt32("hci_id", fHid);
request.AddData("raw command", B_ANY_TYPE, command, size); request.AddData("raw command", B_ANY_TYPE, command, size);
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE); 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 (fMessenger->SendMessage(&request, &reply) == B_OK) {
if (reply.FindData("bdaddr", B_ANY_TYPE, 0, (const void**)&bdaddr, &ssize) == 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 BString
LocalDevice::GetFriendlyName() LocalDevice::GetFriendlyName()
{ {
@@ -239,10 +250,11 @@ LocalDevice::GetFriendlyName()
BMessage reply; BMessage reply;
request.AddInt32("hci_id", hid); request.AddInt32("hci_id", fHid);
request.AddData("raw command", B_ANY_TYPE, command, size); request.AddData("raw command", B_ANY_TYPE, command, size);
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE); 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 && if (fMessenger->SendMessage(&request, &reply) == B_OK &&
reply.FindString("friendlyname", &friendlyname) == B_OK){ reply.FindString("friendlyname", &friendlyname) == B_OK){
@@ -273,13 +285,15 @@ LocalDevice::GetDeviceClass()
const uint8* record; const uint8* record;
ssize_t ssize; ssize_t ssize;
request.AddInt32("hci_id", hid); request.AddInt32("hci_id", fHid);
request.AddData("raw command", B_ANY_TYPE, command, size); request.AddData("raw command", B_ANY_TYPE, command, size);
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE); 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 && if (fMessenger->SendMessage(&request, &reply) == B_OK
reply.FindData("devclass", B_ANY_TYPE, 0, (const void**)&record, &ssize) == B_OK) { && reply.FindData("devclass", B_ANY_TYPE, 0, (const void**)&record,
&ssize) == B_OK) {
fDeviceClass.SetRecord(*record); fDeviceClass.SetRecord(*record);
} }
@@ -301,10 +315,11 @@ LocalDevice::ReadLocalVersion()
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
BMessage reply; BMessage reply;
request.AddInt32("hci_id", hid); request.AddInt32("hci_id", fHid);
request.AddData("raw command", B_ANY_TYPE, localVersion.Data(), localVersion.Size()); request.AddData("raw command", B_ANY_TYPE, localVersion.Data(), localVersion.Size());
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE); 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) if (fMessenger->SendMessage(&request, &reply) == B_OK)
reply.FindInt8("status", &bt_status); reply.FindInt8("status", &bt_status);
@@ -324,10 +339,11 @@ LocalDevice::ReadBufferSize()
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
BMessage reply; BMessage reply;
request.AddInt32("hci_id", hid); request.AddInt32("hci_id", fHid);
request.AddData("raw command", B_ANY_TYPE, BufferSize.Data(), BufferSize.Size()); request.AddData("raw command", B_ANY_TYPE, BufferSize.Data(), BufferSize.Size());
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE); 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) if (fMessenger->SendMessage(&request, &reply) == B_OK)
reply.FindInt8("status", &bt_status); reply.FindInt8("status", &bt_status);
@@ -347,10 +363,11 @@ LocalDevice::Reset()
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
BMessage reply; BMessage reply;
request.AddInt32("hci_id", hid); request.AddInt32("hci_id", fHid);
request.AddData("raw command", B_ANY_TYPE, Reset.Data(), Reset.Size()); request.AddData("raw command", B_ANY_TYPE, Reset.Data(), Reset.Size());
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE); 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) if (fMessenger->SendMessage(&request, &reply) == B_OK)
reply.FindInt8("status", &bt_status); 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(); fMessenger = _RetrieveBluetoothMessenger();
ReadLocalVersion(); ReadLocalVersion();
@@ -388,10 +405,11 @@ LocalDevice::LocalDevice(hci_id hid) : hid(hid)
//#define BT_WRITE_BDADDR_FOR_BCM2035 //#define BT_WRITE_BDADDR_FOR_BCM2035
#ifdef 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; 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 request(BT_MSG_HANDLE_SIMPLE_REQUEST);
BMessage reply; BMessage reply;
@@ -402,10 +420,11 @@ LocalDevice::LocalDevice(hci_id hid) : hid(hid)
writeAddress->bdaddr.b[4] = 0x03; writeAddress->bdaddr.b[4] = 0x03;
writeAddress->bdaddr.b[5] = 0x00; 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.AddData("raw command", B_ANY_TYPE, writeAddress.Data(), writeAddress.Size());
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE); 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) if (fMessenger->SendMessage(&request, &reply) == B_OK)
reply.FindInt8("status", &bt_status); reply.FindInt8("status", &bt_status);
@@ -418,7 +437,6 @@ LocalDevice::LocalDevice(hci_id hid) : hid(hid)
LocalDevice::~LocalDevice() LocalDevice::~LocalDevice()
{ {
if (fMessenger)
delete fMessenger; delete fMessenger;
} }
+8 -7
View File
@@ -35,7 +35,6 @@ RemoteDevice::IsTrustedDevice(void)
BString BString
RemoteDevice::GetFriendlyName(bool alwaysAsk) RemoteDevice::GetFriendlyName(bool alwaysAsk)
{ {
if (!alwaysAsk) { if (!alwaysAsk) {
// Check if the name is already retrieved // Check if the name is already retrieved
// TODO: Check if It is known from a KnownDevicesList // 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 request(BT_MSG_HANDLE_SIMPLE_REQUEST);
BMessage reply; BMessage reply;
request.AddInt32("hci_id", fDiscovererLocalDevice->GetID()); request.AddInt32("hci_id", fDiscovererLocalDevice->ID());
// Fill the request // 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); 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); 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; BString name;
int8 status; int8 status;
if ((reply.FindInt8("status", &status) == B_OK) && (status == BT_OK)) { 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; return name;
} else { } else {
return BString(""); // should not happen return BString(""); // should not happen
@@ -113,8 +111,10 @@ RemoteDevice::Equals(RemoteDevice* obj)
return bdaddrUtils::Compare(&fBdaddr, &ba); return bdaddrUtils::Compare(&fBdaddr, &ba);
} }
// static RemoteDevice* GetRemoteDevice(Connection conn); // static RemoteDevice* GetRemoteDevice(Connection conn);
bool bool
RemoteDevice::Authenticate() RemoteDevice::Authenticate()
{ {
@@ -142,12 +142,14 @@ RemoteDevice::IsEncrypted()
return true; return true;
} }
LocalDevice* LocalDevice*
RemoteDevice::GetLocalDeviceOwner() RemoteDevice::GetLocalDeviceOwner()
{ {
return fDiscovererLocalDevice; return fDiscovererLocalDevice;
} }
/* Private */ /* Private */
void void
RemoteDevice::SetLocalDeviceOwner(LocalDevice* ld) RemoteDevice::SetLocalDeviceOwner(LocalDevice* ld)
@@ -175,7 +177,6 @@ RemoteDevice::RemoteDevice(const BString& address)
RemoteDevice::~RemoteDevice() RemoteDevice::~RemoteDevice()
{ {
if (fMessenger)
delete fMessenger; delete fMessenger;
} }
+5 -4
View File
@@ -22,6 +22,7 @@
#include <PincodeWindow.h> #include <PincodeWindow.h>
#include <stdio.h> #include <stdio.h>
#include <new>
#if 0 #if 0
@@ -33,10 +34,10 @@
LocalDeviceImpl* LocalDeviceImpl*
LocalDeviceImpl::CreateControllerAccessor(BPath* path) LocalDeviceImpl::CreateControllerAccessor(BPath* path)
{ {
HCIDelegate* hd = new HCIControllerAccessor(path); HCIDelegate* hd = new (std::nothrow)HCIControllerAccessor(path);
if (hd != NULL) if (hd != NULL)
return new LocalDeviceImpl(hd); return new (std::nothrow)LocalDeviceImpl(hd);
else else
return NULL; return NULL;
} }
@@ -45,10 +46,10 @@ LocalDeviceImpl::CreateControllerAccessor(BPath* path)
LocalDeviceImpl* LocalDeviceImpl*
LocalDeviceImpl::CreateTransportAccessor(BPath* path) LocalDeviceImpl::CreateTransportAccessor(BPath* path)
{ {
HCIDelegate* hd = new HCITransportAccessor(path); HCIDelegate* hd = new (std::nothrow)HCITransportAccessor(path);
if (hd != NULL) if (hd != NULL)
return new LocalDeviceImpl(hd); return new (std::nothrow)LocalDeviceImpl(hd);
else else
return NULL; return NULL;
} }