Cleapups, Fix memory leaks,
Patch by Mika Lindqvist. Could we give give him Commit access? I am getting daily patches from him with fixes and new features. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26227 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
765ae3a785
commit
9bfe62f9aa
@ -25,7 +25,7 @@ namespace Bluetooth {
|
||||
class DiscoveryAgent;
|
||||
|
||||
class LocalDevice : public BluetoothDevice {
|
||||
|
||||
|
||||
public:
|
||||
/* Possible throwing */
|
||||
static LocalDevice* GetLocalDevice();
|
||||
@ -49,17 +49,18 @@ class LocalDevice : public BluetoothDevice {
|
||||
ServiceRecord getRecord(Connection notifier);
|
||||
void updateRecord(ServiceRecord srvRecord);
|
||||
*/
|
||||
|
||||
|
||||
private:
|
||||
LocalDevice(hci_id hid);
|
||||
virtual ~LocalDevice();
|
||||
|
||||
hci_id GetID(void) {return hid;}
|
||||
static LocalDevice* RequestLocalDeviceID(BMessage* request);
|
||||
|
||||
static BMessenger* sfMessenger;
|
||||
BMessenger* fMessenger;
|
||||
|
||||
BMessenger* fMessenger;
|
||||
|
||||
hci_id hid;
|
||||
|
||||
|
||||
friend class DiscoveryAgent;
|
||||
friend class RemoteDevice;
|
||||
friend class PincodeWindow;
|
||||
|
@ -28,6 +28,8 @@ class RemoteDevice : public BluetoothDevice {
|
||||
static const int WAIT = B_BT_WAIT;
|
||||
static const int SUCCEEDED = B_BT_SUCCEEDED;
|
||||
|
||||
virtual ~RemoteDevice();
|
||||
|
||||
bool IsTrustedDevice();
|
||||
BString GetFriendlyName(bool alwaysAsk); /* Throwing */
|
||||
BString GetFriendlyName(void); /* Throwing */
|
||||
@ -52,6 +54,8 @@ class RemoteDevice : public BluetoothDevice {
|
||||
RemoteDevice(BString address);
|
||||
RemoteDevice(bdaddr_t address);
|
||||
|
||||
|
||||
|
||||
/* Instances of this class only would be instantiated by Discovery[Listener|Agent] */
|
||||
friend class DiscoveryListener;
|
||||
void SetLocalDeviceOwner(LocalDevice* ld);
|
||||
@ -59,6 +63,7 @@ class RemoteDevice : public BluetoothDevice {
|
||||
private:
|
||||
|
||||
LocalDevice* fDiscovererLocalDevice;
|
||||
BMessenger* fMessenger;
|
||||
|
||||
uint8 fPageRepetitionMode;
|
||||
uint8 fScanPeriodMode;
|
||||
|
@ -27,7 +27,7 @@ DiscoveryAgent::RetrieveDevices(int option)
|
||||
{
|
||||
/* No inquiry process initiated */
|
||||
if (fLastUsedListener == NULL)
|
||||
return NULL; // xxx: Fix me
|
||||
return RemoteDevicesList();
|
||||
|
||||
return fLastUsedListener->GetRemoteDevicesList();
|
||||
}
|
||||
|
@ -22,29 +22,31 @@
|
||||
|
||||
#include "KitSupport.h"
|
||||
|
||||
/* TODO: remove me */
|
||||
#include <stdio.h>
|
||||
|
||||
namespace Bluetooth {
|
||||
|
||||
BMessenger* LocalDevice::sfMessenger = NULL;
|
||||
|
||||
|
||||
LocalDevice*
|
||||
LocalDevice::RequestLocalDeviceID(BMessage* request)
|
||||
{
|
||||
{
|
||||
BMessage reply;
|
||||
hci_id hid;
|
||||
|
||||
if (sfMessenger->SendMessage(request, &reply) == B_OK &&
|
||||
reply.FindInt32("hci_id", &hid) == B_OK ){
|
||||
|
||||
if (hid >= 0) {
|
||||
return new LocalDevice(hid);
|
||||
}
|
||||
}
|
||||
LocalDevice* lDevice = NULL;
|
||||
|
||||
return NULL;
|
||||
BMessenger* messenger = _RetrieveBluetoothMessenger();
|
||||
|
||||
if (messenger == NULL)
|
||||
return NULL;
|
||||
|
||||
if (messenger->SendMessage(request, &reply) == B_OK &&
|
||||
reply.FindInt32("hci_id", &hid) == B_OK ) {
|
||||
|
||||
if (hid >= 0)
|
||||
lDevice = new LocalDevice(hid);
|
||||
}
|
||||
|
||||
delete messenger;
|
||||
return lDevice;
|
||||
}
|
||||
|
||||
|
||||
@ -55,57 +57,52 @@ LocalDevice::RequestLocalDeviceID(BMessage* request)
|
||||
|
||||
LocalDevice*
|
||||
LocalDevice::GetLocalDevice()
|
||||
{
|
||||
if ((sfMessenger = _RetrieveBluetoothMessenger()) == NULL)
|
||||
return NULL;
|
||||
|
||||
BMessage request(BT_MSG_ACQUIRE_LOCAL_DEVICE);
|
||||
|
||||
{
|
||||
BMessage request(BT_MSG_ACQUIRE_LOCAL_DEVICE);
|
||||
|
||||
return RequestLocalDeviceID(&request);
|
||||
}
|
||||
|
||||
|
||||
LocalDevice*
|
||||
LocalDevice::GetLocalDevice(hci_id hid)
|
||||
{
|
||||
if ((sfMessenger = _RetrieveBluetoothMessenger()) == NULL)
|
||||
return NULL;
|
||||
|
||||
BMessage request(BT_MSG_ACQUIRE_LOCAL_DEVICE);
|
||||
{
|
||||
BMessage request(BT_MSG_ACQUIRE_LOCAL_DEVICE);
|
||||
request.AddInt32("hci_id", hid);
|
||||
|
||||
return RequestLocalDeviceID(&request);
|
||||
|
||||
return RequestLocalDeviceID(&request);
|
||||
}
|
||||
|
||||
|
||||
LocalDevice*
|
||||
LocalDevice::GetLocalDevice(bdaddr_t bdaddr)
|
||||
{
|
||||
if ((sfMessenger = _RetrieveBluetoothMessenger()) == NULL)
|
||||
return NULL;
|
||||
|
||||
BMessage request(BT_MSG_ACQUIRE_LOCAL_DEVICE);
|
||||
request.AddData("bdaddr", B_ANY_TYPE, &bdaddr, sizeof(bdaddr_t));
|
||||
|
||||
|
||||
return RequestLocalDeviceID(&request);
|
||||
|
||||
BMessage request(BT_MSG_ACQUIRE_LOCAL_DEVICE);
|
||||
request.AddData("bdaddr", B_ANY_TYPE, &bdaddr, sizeof(bdaddr_t));
|
||||
|
||||
return RequestLocalDeviceID(&request);
|
||||
}
|
||||
|
||||
|
||||
uint32
|
||||
LocalDevice::GetLocalDeviceCount()
|
||||
{
|
||||
if ((sfMessenger = _RetrieveBluetoothMessenger()) == NULL)
|
||||
return 0;
|
||||
BMessenger* messenger = _RetrieveBluetoothMessenger();
|
||||
uint32 count = 0;
|
||||
|
||||
BMessage request(BT_MSG_COUNT_LOCAL_DEVICES);
|
||||
BMessage reply;
|
||||
if (messenger != NULL) {
|
||||
|
||||
if (sfMessenger->SendMessage(&request, &reply) == B_OK)
|
||||
return reply.FindInt32("count");
|
||||
else
|
||||
return 0;
|
||||
BMessage request(BT_MSG_COUNT_LOCAL_DEVICES);
|
||||
BMessage reply;
|
||||
|
||||
if (messenger->SendMessage(&request, &reply) == B_OK)
|
||||
count = reply.FindInt32("count");
|
||||
|
||||
delete messenger;
|
||||
}
|
||||
|
||||
return count;
|
||||
|
||||
}
|
||||
|
||||
@ -146,7 +143,7 @@ LocalDevice::GetDiscoverable()
|
||||
status_t
|
||||
LocalDevice::SetDiscoverable(int mode)
|
||||
{
|
||||
if ((fMessenger = _RetrieveBluetoothMessenger()) == NULL)
|
||||
if (fMessenger == NULL)
|
||||
return B_ERROR;
|
||||
|
||||
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
|
||||
@ -162,7 +159,7 @@ LocalDevice::SetDiscoverable(int mode)
|
||||
void* command = buildWriteScan(mode, &size);
|
||||
|
||||
if (command == NULL) {
|
||||
return B_NO_MEMORY;
|
||||
return B_NO_MEMORY;
|
||||
}
|
||||
|
||||
request.AddData("raw command", B_ANY_TYPE, command, size);
|
||||
@ -184,8 +181,8 @@ LocalDevice::SetDiscoverable(int mode)
|
||||
bdaddr_t
|
||||
LocalDevice::GetBluetoothAddress()
|
||||
{
|
||||
if ((fMessenger = _RetrieveBluetoothMessenger()) == NULL)
|
||||
return bdaddrUtils::NullAddress();
|
||||
if (fMessenger == NULL)
|
||||
return bdaddrUtils::NullAddress();
|
||||
|
||||
const bdaddr_t* bdaddr;
|
||||
BMessage request(BT_MSG_GET_ADDRESS);
|
||||
@ -214,8 +211,8 @@ LocalDevice::GetBluetoothAddress()
|
||||
BString
|
||||
LocalDevice::GetFriendlyName()
|
||||
{
|
||||
if ((fMessenger = _RetrieveBluetoothMessenger()) == NULL)
|
||||
return NULL;
|
||||
if (fMessenger == NULL)
|
||||
return NULL;
|
||||
|
||||
BString friendlyname;
|
||||
BMessage request(BT_MSG_GET_FRIENDLY_NAME);
|
||||
@ -258,7 +255,14 @@ LocalDevice::updateRecord(ServiceRecord srvRecord) {
|
||||
|
||||
LocalDevice::LocalDevice(hci_id hid) : hid(hid)
|
||||
{
|
||||
fMessenger = _RetrieveBluetoothMessenger();
|
||||
}
|
||||
|
||||
|
||||
LocalDevice::~LocalDevice()
|
||||
{
|
||||
if (fMessenger)
|
||||
delete fMessenger;
|
||||
}
|
||||
|
||||
|
||||
|
@ -38,21 +38,18 @@ RemoteDevice::GetFriendlyName(bool alwaysAsk)
|
||||
|
||||
if (!alwaysAsk) {
|
||||
// Check if the name is already retrieved
|
||||
return BString("Not implemented");
|
||||
|
||||
// TODO: Check if It is known from a KnownDevicesList
|
||||
return BString("Not implemented");
|
||||
}
|
||||
|
||||
if (fDiscovererLocalDevice == NULL)
|
||||
return BString("#NoOwnerError#Not Valid name");
|
||||
|
||||
BMessenger* btsm = NULL;
|
||||
size_t size;
|
||||
|
||||
if ((btsm = _RetrieveBluetoothMessenger()) == NULL)
|
||||
if (fMessenger == NULL)
|
||||
return BString("#ServerNotReady#Not Valid name");
|
||||
|
||||
void* remoteNameCommand = NULL;
|
||||
size_t size;
|
||||
|
||||
/* Issue inquiry command */
|
||||
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
|
||||
@ -71,7 +68,7 @@ RemoteDevice::GetFriendlyName(bool alwaysAsk)
|
||||
request.AddInt16("eventExpected", HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE);
|
||||
|
||||
|
||||
if (btsm->SendMessage(&request, &reply) == B_OK)
|
||||
if (fMessenger->SendMessage(&request, &reply) == B_OK)
|
||||
{
|
||||
BString name;
|
||||
int8 status;
|
||||
@ -155,12 +152,21 @@ RemoteDevice::SetLocalDeviceOwner(LocalDevice* ld)
|
||||
RemoteDevice::RemoteDevice(bdaddr_t address)
|
||||
{
|
||||
fBdaddr = address;
|
||||
fMessenger = _RetrieveBluetoothMessenger();
|
||||
}
|
||||
|
||||
|
||||
RemoteDevice::RemoteDevice(BString address)
|
||||
{
|
||||
fBdaddr = bdaddrUtils::FromString((const char *)address.String());
|
||||
fMessenger = _RetrieveBluetoothMessenger();
|
||||
}
|
||||
|
||||
|
||||
RemoteDevice::~RemoteDevice()
|
||||
{
|
||||
if (fMessenger)
|
||||
delete fMessenger;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user