- Unregister the device when appears any error Issuing any command. Now at least we realize in userland when a dongle has been unplugged with the first problem appears.
- Move code between parent & children classes of the Accessors - a bit Styling git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31446 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
ff1a0e63f8
commit
ccf28e4dd1
|
@ -77,10 +77,10 @@ bool BluetoothServer::QuitRequested(void)
|
||||||
Output::Instance()->Lock();
|
Output::Instance()->Lock();
|
||||||
Output::Instance()->Quit();
|
Output::Instance()->Quit();
|
||||||
|
|
||||||
LocalDeviceImpl* ldi = NULL;
|
LocalDeviceImpl* lDeviceImpl = NULL;
|
||||||
while ((ldi = (LocalDeviceImpl *)fLocalDevicesList.RemoveItem((int32)0))
|
while ((lDeviceImpl = (LocalDeviceImpl *)fLocalDevicesList.RemoveItem((int32)0))
|
||||||
!= NULL)
|
!= NULL)
|
||||||
delete ldi;
|
delete lDeviceImpl;
|
||||||
|
|
||||||
printf("Accepting quitting of the application\n");
|
printf("Accepting quitting of the application\n");
|
||||||
return BApplication::QuitRequested();
|
return BApplication::QuitRequested();
|
||||||
|
@ -132,13 +132,13 @@ void BluetoothServer::MessageReceived(BMessage *message)
|
||||||
BPath path(str.String());
|
BPath path(str.String());
|
||||||
Output::Instance()->Postf(BLACKBOARD_GENERAL,
|
Output::Instance()->Postf(BLACKBOARD_GENERAL,
|
||||||
"Requested LocalDevice %s\n", str.String());
|
"Requested LocalDevice %s\n", str.String());
|
||||||
LocalDeviceImpl* ldi = LocalDeviceImpl::CreateTransportAccessor(&path);
|
LocalDeviceImpl* lDeviceImpl = LocalDeviceImpl::CreateTransportAccessor(&path);
|
||||||
|
|
||||||
if (ldi->GetID() >= 0) {
|
if (lDeviceImpl->GetID() >= 0) {
|
||||||
fLocalDevicesList.AddItem(ldi);
|
fLocalDevicesList.AddItem(lDeviceImpl);
|
||||||
Output::Instance()->AddTab("Local Device", BLACKBOARD_LD(ldi->GetID()));
|
Output::Instance()->AddTab("Local Device", BLACKBOARD_LD(lDeviceImpl->GetID()));
|
||||||
Output::Instance()->Postf(BLACKBOARD_LD(ldi->GetID()),
|
Output::Instance()->Postf(BLACKBOARD_LD(lDeviceImpl->GetID()),
|
||||||
"LocalDevice %s id=%x added\n", str.String(), ldi->GetID());
|
"LocalDevice %s id=%x added\n", str.String(), lDeviceImpl->GetID());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Output::Instance()->Post("Adding LocalDevice failed\n",
|
Output::Instance()->Post("Adding LocalDevice failed\n",
|
||||||
|
@ -147,16 +147,16 @@ void BluetoothServer::MessageReceived(BMessage *message)
|
||||||
|
|
||||||
status = B_WOULD_BLOCK;
|
status = B_WOULD_BLOCK;
|
||||||
/* TODO: This should be by user request only! */
|
/* TODO: This should be by user request only! */
|
||||||
ldi->Launch();
|
lDeviceImpl->Launch();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case BT_MSG_REMOVE_DEVICE:
|
case BT_MSG_REMOVE_DEVICE:
|
||||||
{
|
{
|
||||||
LocalDeviceImpl* ldi;
|
LocalDeviceImpl* lDeviceImpl = LocateDelegateFromMessage(message);
|
||||||
message->FindPointer("device", (void**)&ldi);
|
if (lDeviceImpl != NULL)
|
||||||
fLocalDevicesList.RemoveItem(ldi);
|
fLocalDevicesList.RemoveItem(lDeviceImpl);
|
||||||
delete ldi;
|
delete lDeviceImpl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,20 +212,20 @@ void BluetoothServer::MessageReceived(BMessage *message)
|
||||||
LocalDeviceImpl*
|
LocalDeviceImpl*
|
||||||
BluetoothServer::LocateDelegateFromMessage(BMessage* message)
|
BluetoothServer::LocateDelegateFromMessage(BMessage* message)
|
||||||
{
|
{
|
||||||
LocalDeviceImpl* ldi = NULL;
|
LocalDeviceImpl* lDeviceImpl = NULL;
|
||||||
hci_id hid;
|
hci_id hid;
|
||||||
|
|
||||||
if (message->FindInt32("hci_id", &hid) == B_OK) {
|
if (message->FindInt32("hci_id", &hid) == B_OK) {
|
||||||
/* Try to find out when a ID was specified */
|
/* Try to find out when a ID was specified */
|
||||||
int index;
|
int index;
|
||||||
for (index = 0; index < fLocalDevicesList.CountItems(); index ++) {
|
for (index = 0; index < fLocalDevicesList.CountItems(); index ++) {
|
||||||
ldi = fLocalDevicesList.ItemAt(index);
|
lDeviceImpl = fLocalDevicesList.ItemAt(index);
|
||||||
if (ldi->GetID() == hid)
|
if (lDeviceImpl->GetID() == hid)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ldi;
|
return lDeviceImpl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,9 +236,9 @@ BluetoothServer::LocateLocalDeviceImpl(hci_id hid)
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
for (index = 0; index < fLocalDevicesList.CountItems(); index ++) {
|
for (index = 0; index < fLocalDevicesList.CountItems(); index ++) {
|
||||||
LocalDeviceImpl* ldi = fLocalDevicesList.ItemAt(index);
|
LocalDeviceImpl* lDeviceImpl = fLocalDevicesList.ItemAt(index);
|
||||||
if (ldi->GetID() == hid)
|
if (lDeviceImpl->GetID() == hid)
|
||||||
return ldi;
|
return lDeviceImpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -262,14 +262,14 @@ BluetoothServer::HandleAcquireLocalDevice(BMessage* message, BMessage* reply)
|
||||||
hci_id hid;
|
hci_id hid;
|
||||||
ssize_t size;
|
ssize_t size;
|
||||||
bdaddr_t bdaddr;
|
bdaddr_t bdaddr;
|
||||||
LocalDeviceImpl* ldi = NULL;
|
LocalDeviceImpl* lDeviceImpl = NULL;
|
||||||
static int32 lastIndex = 0;
|
static int32 lastIndex = 0;
|
||||||
|
|
||||||
if (message->FindInt32("hci_id", &hid) == B_OK)
|
if (message->FindInt32("hci_id", &hid) == B_OK)
|
||||||
{
|
{
|
||||||
Output::Instance()->Post("GetLocalDevice requested with id\n",
|
Output::Instance()->Post("GetLocalDevice requested with id\n",
|
||||||
BLACKBOARD_KIT);
|
BLACKBOARD_KIT);
|
||||||
ldi = LocateDelegateFromMessage(message);
|
lDeviceImpl = LocateDelegateFromMessage(message);
|
||||||
|
|
||||||
} else if (message->FindData("bdaddr", B_ANY_TYPE, (const void**)&bdaddr, &size )
|
} else if (message->FindData("bdaddr", B_ANY_TYPE, (const void**)&bdaddr, &size )
|
||||||
== B_OK) {
|
== B_OK) {
|
||||||
|
@ -279,8 +279,8 @@ BluetoothServer::HandleAcquireLocalDevice(BMessage* message, BMessage* reply)
|
||||||
for (lastIndex = 0; lastIndex < fLocalDevicesList.CountItems(); lastIndex ++) {
|
for (lastIndex = 0; lastIndex < fLocalDevicesList.CountItems(); lastIndex ++) {
|
||||||
//TODO: Only possible if the property is available
|
//TODO: Only possible if the property is available
|
||||||
//bdaddr_t local;
|
//bdaddr_t local;
|
||||||
//ldi = fLocalDevicesList.ItemAt(lastIndex);
|
//lDeviceImpl = fLocalDevicesList.ItemAt(lastIndex);
|
||||||
//if ((ldi->GetAddress(&local, message) == B_OK)
|
//if ((lDeviceImpl->GetAddress(&local, message) == B_OK)
|
||||||
// && bacmp(&local, &bdaddr)) {
|
// && bacmp(&local, &bdaddr)) {
|
||||||
// break;
|
// break;
|
||||||
//}
|
//}
|
||||||
|
@ -291,24 +291,24 @@ BluetoothServer::HandleAcquireLocalDevice(BMessage* message, BMessage* reply)
|
||||||
Output::Instance()->Post("GetLocalDevice plain request\n", BLACKBOARD_KIT);
|
Output::Instance()->Post("GetLocalDevice plain request\n", BLACKBOARD_KIT);
|
||||||
// from last assigned till end
|
// from last assigned till end
|
||||||
for ( int index = lastIndex + 1; index < fLocalDevicesList.CountItems(); index ++) {
|
for ( int index = lastIndex + 1; index < fLocalDevicesList.CountItems(); index ++) {
|
||||||
ldi = fLocalDevicesList.ItemAt(index);
|
lDeviceImpl = fLocalDevicesList.ItemAt(index);
|
||||||
printf("Requesting local device %ld\n", ldi->GetID());
|
printf("Requesting local device %ld\n", lDeviceImpl->GetID());
|
||||||
if (ldi != NULL && ldi->Available())
|
if (lDeviceImpl != NULL && lDeviceImpl->Available())
|
||||||
{
|
{
|
||||||
Output::Instance()->Postf(BLACKBOARD_KIT, "Device available: %lx\n", ldi->GetID());
|
Output::Instance()->Postf(BLACKBOARD_KIT, "Device available: %lx\n", lDeviceImpl->GetID());
|
||||||
lastIndex = index;
|
lastIndex = index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// from starting till last assigned if not yet found
|
// from starting till last assigned if not yet found
|
||||||
if (ldi == NULL) {
|
if (lDeviceImpl == NULL) {
|
||||||
for ( int index = 0; index <= lastIndex ; index ++) {
|
for ( int index = 0; index <= lastIndex ; index ++) {
|
||||||
ldi = fLocalDevicesList.ItemAt(index);
|
lDeviceImpl = fLocalDevicesList.ItemAt(index);
|
||||||
printf("Requesting local device %ld\n", ldi->GetID());
|
printf("Requesting local device %ld\n", lDeviceImpl->GetID());
|
||||||
if (ldi != NULL && ldi->Available())
|
if (lDeviceImpl != NULL && lDeviceImpl->Available())
|
||||||
{
|
{
|
||||||
Output::Instance()->Postf(BLACKBOARD_KIT, "Device available: %lx\n", ldi->GetID());
|
Output::Instance()->Postf(BLACKBOARD_KIT, "Device available: %lx\n", lDeviceImpl->GetID());
|
||||||
lastIndex = index;
|
lastIndex = index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -316,9 +316,9 @@ BluetoothServer::HandleAcquireLocalDevice(BMessage* message, BMessage* reply)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastIndex <= fLocalDevicesList.CountItems() && ldi != NULL && ldi->Available()) {
|
if (lastIndex <= fLocalDevicesList.CountItems() && lDeviceImpl != NULL && lDeviceImpl->Available()) {
|
||||||
hid = ldi->GetID();
|
hid = lDeviceImpl->GetID();
|
||||||
ldi->Acquire();
|
lDeviceImpl->Acquire();
|
||||||
|
|
||||||
Output::Instance()->Postf(BLACKBOARD_KIT, "Device acquired %lx\n", hid);
|
Output::Instance()->Postf(BLACKBOARD_KIT, "Device acquired %lx\n", hid);
|
||||||
return reply->AddInt32("hci_id", hid);
|
return reply->AddInt32("hci_id", hid);
|
||||||
|
@ -332,24 +332,26 @@ BluetoothServer::HandleAcquireLocalDevice(BMessage* message, BMessage* reply)
|
||||||
status_t
|
status_t
|
||||||
BluetoothServer::HandleSimpleRequest(BMessage* message, BMessage* reply)
|
BluetoothServer::HandleSimpleRequest(BMessage* message, BMessage* reply)
|
||||||
{
|
{
|
||||||
LocalDeviceImpl* ldi = LocateDelegateFromMessage(message);
|
LocalDeviceImpl* lDeviceImpl = LocateDelegateFromMessage(message);
|
||||||
const char* propertyRequested;
|
const char* propertyRequested;
|
||||||
|
|
||||||
// Find out if there is a property being requested,
|
// Find out if there is a property being requested,
|
||||||
if (message->FindString("property", &propertyRequested) == B_OK) {
|
if (message->FindString("property", &propertyRequested) == B_OK) {
|
||||||
// Check if the property has been already retrieved
|
// Check if the property has been already retrieved
|
||||||
if (ldi->IsPropertyAvailable(propertyRequested)) {
|
if (lDeviceImpl->IsPropertyAvailable(propertyRequested)) {
|
||||||
// Dump everything
|
// Dump everything
|
||||||
reply->AddMessage("properties",ldi->GetPropertiesMessage());
|
reply->AddMessage("properties", lDeviceImpl->GetPropertiesMessage());
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// we are gonna need issue the command ...
|
// we are gonna need issue the command ...
|
||||||
if (ldi->ProcessSimpleRequest(DetachCurrentMessage()) == B_OK)
|
if (lDeviceImpl->ProcessSimpleRequest(DetachCurrentMessage()) == B_OK)
|
||||||
return B_WOULD_BLOCK;
|
return B_WOULD_BLOCK;
|
||||||
else
|
else {
|
||||||
|
lDeviceImpl->Unregister();
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,22 +363,22 @@ BluetoothServer::HandleGetProperty(BMessage* message, BMessage* reply)
|
||||||
* and will not care about status fields, therefore we return OK in all cases
|
* and will not care about status fields, therefore we return OK in all cases
|
||||||
*/
|
*/
|
||||||
|
|
||||||
LocalDeviceImpl* ldi = LocateDelegateFromMessage(message);
|
LocalDeviceImpl* lDeviceImpl = LocateDelegateFromMessage(message);
|
||||||
const char* propertyRequested;
|
const char* propertyRequested;
|
||||||
|
|
||||||
// Find out if there is a property being requested,
|
// Find out if there is a property being requested,
|
||||||
if (message->FindString("property", &propertyRequested) == B_OK) {
|
if (message->FindString("property", &propertyRequested) == B_OK) {
|
||||||
|
|
||||||
Output::Instance()->Postf(BLACKBOARD_LD(ldi->GetID()), "Searching %s property...\n",
|
Output::Instance()->Postf(BLACKBOARD_LD(lDeviceImpl->GetID()), "Searching %s property...\n",
|
||||||
propertyRequested);
|
propertyRequested);
|
||||||
|
|
||||||
// Check if the property has been already retrieved
|
// Check if the property has been already retrieved
|
||||||
if (ldi->IsPropertyAvailable(propertyRequested)) {
|
if (lDeviceImpl->IsPropertyAvailable(propertyRequested)) {
|
||||||
if (strcmp(propertyRequested, "hci_version") == 0
|
if (strcmp(propertyRequested, "hci_version") == 0
|
||||||
|| strcmp(propertyRequested, "lmp_version") == 0
|
|| strcmp(propertyRequested, "lmp_version") == 0
|
||||||
|| strcmp(propertyRequested, "sco_mtu") == 0) {
|
|| strcmp(propertyRequested, "sco_mtu") == 0) {
|
||||||
|
|
||||||
uint8 result = ldi->GetPropertiesMessage()->FindInt8(propertyRequested);
|
uint8 result = lDeviceImpl->GetPropertiesMessage()->FindInt8(propertyRequested);
|
||||||
reply->AddInt32("result", result);
|
reply->AddInt32("result", result);
|
||||||
|
|
||||||
} else if (strcmp(propertyRequested, "hci_revision") == 0
|
} else if (strcmp(propertyRequested, "hci_revision") == 0
|
||||||
|
@ -386,11 +388,11 @@ BluetoothServer::HandleGetProperty(BMessage* message, BMessage* reply)
|
||||||
|| strcmp(propertyRequested, "acl_max_pkt") == 0
|
|| strcmp(propertyRequested, "acl_max_pkt") == 0
|
||||||
|| strcmp(propertyRequested, "sco_max_pkt") == 0 ) {
|
|| strcmp(propertyRequested, "sco_max_pkt") == 0 ) {
|
||||||
|
|
||||||
uint16 result = ldi->GetPropertiesMessage()->FindInt16(propertyRequested);
|
uint16 result = lDeviceImpl->GetPropertiesMessage()->FindInt16(propertyRequested);
|
||||||
reply->AddInt32("result", result);
|
reply->AddInt32("result", result);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Output::Instance()->Postf(BLACKBOARD_LD(ldi->GetID()), "Property %s could not be satisfied\n",
|
Output::Instance()->Postf(BLACKBOARD_LD(lDeviceImpl->GetID()), "Property %s could not be satisfied\n",
|
||||||
propertyRequested);
|
propertyRequested);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +1,30 @@
|
||||||
/*
|
/*
|
||||||
* 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 "HCIControllerAccessor.h"
|
#include "HCIControllerAccessor.h"
|
||||||
|
|
||||||
HCIControllerAccessor::HCIControllerAccessor(BPath* path) : HCIDelegate(path)
|
HCIControllerAccessor::HCIControllerAccessor(BPath* path) : HCIDelegate(path)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
HCIControllerAccessor::~HCIControllerAccessor()
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
HCIControllerAccessor::IssueCommand(raw_command rc, size_t size)
|
HCIControllerAccessor::IssueCommand(raw_command rc, size_t size)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (GetID() < 0)
|
if (Id() < 0)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
return B_ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* 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.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef _HCICONTROLLER_ACCESSOR_H_
|
#ifndef _HCICONTROLLER_ACCESSOR_H_
|
||||||
#define _HCICONTROLLER_ACCESSOR_H_
|
#define _HCICONTROLLER_ACCESSOR_H_
|
||||||
|
|
||||||
|
@ -17,8 +12,12 @@ class HCIControllerAccessor : public HCIDelegate {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HCIControllerAccessor(BPath* path);
|
HCIControllerAccessor(BPath* path);
|
||||||
|
~HCIControllerAccessor();
|
||||||
status_t IssueCommand(raw_command rc, size_t size);
|
status_t IssueCommand(raw_command rc, size_t size);
|
||||||
status_t Launch();
|
status_t Launch();
|
||||||
|
private:
|
||||||
|
int fSocket;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
|
|
||||||
#include <bluetooth/HCI/btHCI_transport.h>
|
#include <bluetooth/HCI/btHCI_transport.h>
|
||||||
|
|
||||||
|
|
||||||
typedef void* raw_command;
|
typedef void* raw_command;
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,39 +21,20 @@ class HCIDelegate {
|
||||||
public:
|
public:
|
||||||
HCIDelegate(BPath* path)
|
HCIDelegate(BPath* path)
|
||||||
{
|
{
|
||||||
status_t status;
|
|
||||||
|
|
||||||
fFD = open (path->Path(), O_RDWR);
|
|
||||||
if (fFD > 0) {
|
|
||||||
// find out which ID was assigned
|
|
||||||
status = ioctl(fFD, GET_HCI_ID, &fHID, 0);
|
|
||||||
printf("%s: hid retrieved %lx status=%ld\n", __FUNCTION__,
|
|
||||||
fHID, status);
|
|
||||||
} else {
|
|
||||||
printf("%s: Device driver could not be opened %ld\n", __FUNCTION__,
|
|
||||||
fHID);
|
|
||||||
fHID = B_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO create such queue
|
//TODO create such queue
|
||||||
|
fIdentifier = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
hci_id GetID(void)
|
hci_id Id(void) const
|
||||||
{
|
{
|
||||||
return fHID;
|
return fIdentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual ~HCIDelegate()
|
virtual ~HCIDelegate()
|
||||||
{
|
{
|
||||||
if (fFD > 0)
|
|
||||||
{
|
|
||||||
close (fFD);
|
|
||||||
fFD = -1;
|
|
||||||
fHID = B_ERROR;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual status_t IssueCommand(raw_command rc, size_t size)=0;
|
virtual status_t IssueCommand(raw_command rc, size_t size)=0;
|
||||||
|
@ -77,12 +57,10 @@ class HCIDelegate {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
hci_id fHID;
|
hci_id fIdentifier;
|
||||||
int fFD;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -14,14 +14,38 @@
|
||||||
|
|
||||||
HCITransportAccessor::HCITransportAccessor(BPath* path) : HCIDelegate(path)
|
HCITransportAccessor::HCITransportAccessor(BPath* path) : HCIDelegate(path)
|
||||||
{
|
{
|
||||||
|
status_t status;
|
||||||
|
|
||||||
|
fDescriptor = open (path->Path(), O_RDWR);
|
||||||
|
if (fDescriptor > 0) {
|
||||||
|
// find out which ID was assigned
|
||||||
|
status = ioctl(fDescriptor, GET_HCI_ID, &fIdentifier, 0);
|
||||||
|
printf("%s: hid retrieved %lx status=%ld\n", __FUNCTION__,
|
||||||
|
fIdentifier, status);
|
||||||
|
} else {
|
||||||
|
printf("%s: Device driver could not be opened %ld\n", __FUNCTION__,
|
||||||
|
fIdentifier);
|
||||||
|
fIdentifier = B_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
HCITransportAccessor::~HCITransportAccessor()
|
||||||
|
{
|
||||||
|
if (fDescriptor > 0)
|
||||||
|
{
|
||||||
|
close(fDescriptor);
|
||||||
|
fDescriptor = -1;
|
||||||
|
fIdentifier = B_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
HCITransportAccessor::IssueCommand(raw_command rc, size_t size)
|
HCITransportAccessor::IssueCommand(raw_command rc, size_t size)
|
||||||
{
|
{
|
||||||
if (GetID() < 0 || fFD < 0)
|
if (Id() < 0 || fDescriptor < 0)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
printf("### Command going: len = %ld\n", size);
|
printf("### Command going: len = %ld\n", size);
|
||||||
|
@ -31,7 +55,7 @@ for (uint16 index = 0 ; index < size; index++ ) {
|
||||||
printf("### \n");
|
printf("### \n");
|
||||||
|
|
||||||
|
|
||||||
return ioctl(fFD, ISSUE_BT_COMMAND, rc, size);
|
return ioctl(fDescriptor, ISSUE_BT_COMMAND, rc, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,6 +63,6 @@ status_t
|
||||||
HCITransportAccessor::Launch() {
|
HCITransportAccessor::Launch() {
|
||||||
|
|
||||||
uint32 dummy;
|
uint32 dummy;
|
||||||
return ioctl(fFD, BT_UP, &dummy, sizeof(uint32));
|
return ioctl(fDescriptor, BT_UP, &dummy, sizeof(uint32));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,11 @@ class HCITransportAccessor : public HCIDelegate {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HCITransportAccessor(BPath* path);
|
HCITransportAccessor(BPath* path);
|
||||||
|
~HCITransportAccessor();
|
||||||
status_t IssueCommand(raw_command rc, size_t size);
|
status_t IssueCommand(raw_command rc, size_t size);
|
||||||
status_t Launch();
|
status_t Launch();
|
||||||
|
private:
|
||||||
|
int fDescriptor;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -16,6 +16,7 @@ LocalDeviceHandler::LocalDeviceHandler(HCIDelegate* hd)
|
||||||
|
|
||||||
LocalDeviceHandler::~LocalDeviceHandler()
|
LocalDeviceHandler::~LocalDeviceHandler()
|
||||||
{
|
{
|
||||||
|
delete fHCIDelegate;
|
||||||
delete fProperties;
|
delete fProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +24,7 @@ LocalDeviceHandler::~LocalDeviceHandler()
|
||||||
hci_id
|
hci_id
|
||||||
LocalDeviceHandler::GetID()
|
LocalDeviceHandler::GetID()
|
||||||
{
|
{
|
||||||
return fHCIDelegate->GetID();
|
return fHCIDelegate->Id();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -101,8 +102,8 @@ LocalDeviceHandler::ClearWantedEvent(BMessage* msg, uint16 event, uint16 opcode)
|
||||||
if (opcode != 0) {
|
if (opcode != 0) {
|
||||||
|
|
||||||
// The opcode matches
|
// The opcode matches
|
||||||
if ( (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK)
|
if ((msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK)
|
||||||
&& ((uint16)opcodeFound == opcode) ) {
|
&& ((uint16)opcodeFound == opcode)) {
|
||||||
|
|
||||||
// this should remove only the entry
|
// this should remove only the entry
|
||||||
printf("Removed event %#x and opcode %d from request %p\n",
|
printf("Removed event %#x and opcode %d from request %p\n",
|
||||||
|
@ -122,7 +123,7 @@ LocalDeviceHandler::ClearWantedEvent(BMessage* msg, uint16 event, uint16 opcode)
|
||||||
}
|
}
|
||||||
eventIndex++;
|
eventIndex++;
|
||||||
}
|
}
|
||||||
printf("%s:Nothing Found/Removed\n",__FUNCTION__);
|
printf("%s:Nothing Found/Removed\n", __FUNCTION__);
|
||||||
|
|
||||||
finish:
|
finish:
|
||||||
fEventsWanted.Unlock();
|
fEventsWanted.Unlock();
|
||||||
|
|
|
@ -70,6 +70,25 @@ LocalDeviceImpl::LocalDeviceImpl(HCIDelegate* hd) : LocalDeviceHandler(hd)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
LocalDeviceImpl::~LocalDeviceImpl()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
LocalDeviceImpl::Unregister()
|
||||||
|
{
|
||||||
|
BMessage* msg = new BMessage(BT_MSG_REMOVE_DEVICE);
|
||||||
|
|
||||||
|
msg->AddInt32("hci_id", fHCIDelegate->Id());
|
||||||
|
|
||||||
|
Output::Instance()->Postf(BLACKBOARD_DEVICEMANAGER, "Unregistering %x\n", fHCIDelegate->Id());
|
||||||
|
|
||||||
|
be_app_messenger.SendMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
#pragma mark - Event handling methods -
|
#pragma mark - Event handling methods -
|
||||||
#endif
|
#endif
|
||||||
|
@ -755,7 +774,9 @@ LocalDeviceImpl::ProcessSimpleRequest(BMessage* request)
|
||||||
== B_ERROR) {
|
== B_ERROR) {
|
||||||
// TODO: - Reply the request with error!
|
// TODO: - Reply the request with error!
|
||||||
// - Remove the just added request
|
// - Remove the just added request
|
||||||
(Output::Instance()->Post("Command issue error\n", BLACKBOARD_KIT));
|
(Output::Instance()->Post("## ERROR Command issue, REMOVING!\n", BLACKBOARD_KIT));
|
||||||
|
ClearWantedEvent(request);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,15 +28,17 @@ public:
|
||||||
// Factory methods
|
// Factory methods
|
||||||
static LocalDeviceImpl* CreateControllerAccessor(BPath* path);
|
static LocalDeviceImpl* CreateControllerAccessor(BPath* path);
|
||||||
static LocalDeviceImpl* CreateTransportAccessor(BPath* path);
|
static LocalDeviceImpl* CreateTransportAccessor(BPath* path);
|
||||||
|
~LocalDeviceImpl();
|
||||||
|
void Unregister();
|
||||||
|
|
||||||
void HandleEvent(struct hci_event_header* event);
|
void HandleEvent(struct hci_event_header* event);
|
||||||
|
|
||||||
/* Request handling */
|
// Request handling
|
||||||
status_t GetAddress(bdaddr_t* bdaddr, BMessage* request);
|
status_t GetAddress(bdaddr_t* bdaddr, BMessage* request);
|
||||||
status_t GetFriendlyName(BString str, BMessage* request);
|
status_t GetFriendlyName(BString str, BMessage* request);
|
||||||
status_t ProcessSimpleRequest(BMessage* request);
|
status_t ProcessSimpleRequest(BMessage* request);
|
||||||
|
|
||||||
/* Events handling */
|
// Events handling
|
||||||
void CommandComplete(struct hci_ev_cmd_complete* event, BMessage* request, int32 index);
|
void CommandComplete(struct hci_ev_cmd_complete* event, BMessage* request, int32 index);
|
||||||
void CommandStatus(struct hci_ev_cmd_status* event, BMessage* request, int32 index);
|
void CommandStatus(struct hci_ev_cmd_status* event, BMessage* request, int32 index);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue