some cleanups and styling by Mika and me
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28915 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -21,28 +21,14 @@ static inline void bacpy(bdaddr_t* dst, bdaddr_t* src)
|
||||
}
|
||||
|
||||
|
||||
static inline void baswap(bdaddr_t* dst, bdaddr_t* src) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
static inline char* batostr(bdaddr_t *ba)
|
||||
static inline void baswap(bdaddr_t* dst, bdaddr_t* src)
|
||||
{
|
||||
return "00:00:00:00:00:00";
|
||||
register uint8* d = (uint8*)dst;
|
||||
register uint8* s = (uint8*)src;
|
||||
register int i;
|
||||
|
||||
}
|
||||
for(i=0; i<6; i++) d[i] = s[5-i];
|
||||
|
||||
|
||||
static inline void strtoba(const char *str, bdaddr_t *ba)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* Link key Management */
|
||||
static inline char* lktostr( uint8 link_key[16] )
|
||||
{
|
||||
return "00:00:00:00:00:00";
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
|
||||
*
|
||||
* Copyright 2007-2009 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
|
||||
* Copyright 2008 Mika Lindqvist, monni1995_at_gmail.com
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*
|
||||
*/
|
||||
@@ -9,14 +9,12 @@
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#include <Entry.h>
|
||||
#include <Path.h>
|
||||
#include <Message.h>
|
||||
#include <Directory.h>
|
||||
#include <String.h>
|
||||
#include <Message.h>
|
||||
#include <Path.h>
|
||||
#include <Roster.h>
|
||||
|
||||
#include <String.h>
|
||||
|
||||
#include <TypeConstants.h>
|
||||
#include <syslog.h>
|
||||
@@ -40,15 +38,14 @@ BluetoothServer::BluetoothServer() : BApplication(BLUETOOTH_SIGNATURE)
|
||||
Output::Instance()->AddTab("Events", BLACKBOARD_EVENTS);
|
||||
Output::Instance()->AddTab("Kit", BLACKBOARD_KIT);
|
||||
|
||||
|
||||
ShowWindow(Output::Instance());
|
||||
|
||||
fDeviceManager = new DeviceManager();
|
||||
fLocalDevicesList.MakeEmpty();
|
||||
|
||||
// TODO: Some events should be handled faster than in KL...
|
||||
fEventListener = spawn_thread(notification_Thread, "BT port listener" , B_URGENT_DISPLAY_PRIORITY , this);
|
||||
|
||||
fEventListener = spawn_thread(notification_Thread, "BT port listener" ,
|
||||
B_URGENT_DISPLAY_PRIORITY , this);
|
||||
|
||||
}
|
||||
|
||||
@@ -58,36 +55,29 @@ bool BluetoothServer::QuitRequested(void)
|
||||
Output::Instance()->Lock();
|
||||
Output::Instance()->Quit();
|
||||
|
||||
|
||||
/* HCIDelegate *hd = NULL;
|
||||
while ((hd = (HCIDelegate *)fDelegatesList.RemoveItem((int32)0)) !=NULL)
|
||||
delete hd;
|
||||
*/
|
||||
LocalDeviceImpl* ldi = NULL;
|
||||
while ((ldi = (LocalDeviceImpl *)fLocalDevicesList.RemoveItem((int32)0))
|
||||
!= NULL)
|
||||
delete ldi;
|
||||
|
||||
printf("Accepting quitting of the application\n");
|
||||
return BApplication::QuitRequested();
|
||||
}
|
||||
|
||||
|
||||
void BluetoothServer::ArgvReceived(int32 argc, char **argv)
|
||||
{
|
||||
if (argc>1) {
|
||||
if (strcmp(argv[1], "--finish") == 0)
|
||||
PostMessage(B_QUIT_REQUESTED);
|
||||
|
||||
else {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void BluetoothServer::ReadyToRun(void) {
|
||||
|
||||
void BluetoothServer::ReadyToRun(void)
|
||||
{
|
||||
fDeviceManager->StartMonitoringDevice("bluetooth/h2generic");
|
||||
|
||||
|
||||
// Launch the notifier thread
|
||||
if ( resume_thread(fEventListener) != B_OK )
|
||||
{
|
||||
@@ -97,52 +87,49 @@ void BluetoothServer::ReadyToRun(void) {
|
||||
Output::Instance()->Post("Bluetooth server Ready\n", BLACKBOARD_GENERAL);
|
||||
}
|
||||
|
||||
void BluetoothServer::AppActivated(bool act) {
|
||||
|
||||
void BluetoothServer::AppActivated(bool act)
|
||||
{
|
||||
printf("Activated %d\n",act);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BluetoothServer::MessageReceived(BMessage *message)
|
||||
{
|
||||
BMessage reply;
|
||||
status_t status = B_WOULD_BLOCK; // mark somehow.. do not reply anything
|
||||
status_t status = B_WOULD_BLOCK;
|
||||
// mark somehow.. do not reply anything
|
||||
|
||||
switch(message->what)
|
||||
{
|
||||
|
||||
case BT_MSG_ADD_DEVICE:
|
||||
{
|
||||
BString str;
|
||||
message->FindString("name", &str);
|
||||
BPath path(str.String());
|
||||
|
||||
(Output::Instance()->Postf(BLACKBOARD_GENERAL, "Requested LocalDevice %s\n", str.String()));
|
||||
|
||||
Output::Instance()->Postf(BLACKBOARD_GENERAL,
|
||||
"Requested LocalDevice %s\n", str.String());
|
||||
LocalDeviceImpl* ldi = LocalDeviceImpl::CreateTransportAccessor(&path);
|
||||
|
||||
if (ldi->GetID() >= 0) {
|
||||
fLocalDevicesList.AddItem(ldi);
|
||||
Output::Instance()->AddTab("Local Device", BLACKBOARD_LD(ldi->GetID()));
|
||||
(Output::Instance()->Postf(BLACKBOARD_LD(ldi->GetID()), "LocalDevice %s id=%x added\n", str.String(), ldi->GetID()));
|
||||
|
||||
|
||||
Output::Instance()->Postf(BLACKBOARD_LD(ldi->GetID()),
|
||||
"LocalDevice %s id=%x added\n",
|
||||
str.String(), ldi->GetID());
|
||||
} else {
|
||||
(Output::Instance()->Post("Adding LocalDevice failed\n", BLACKBOARD_GENERAL));
|
||||
Output::Instance()->Post("Adding LocalDevice failed\n",
|
||||
BLACKBOARD_GENERAL);
|
||||
}
|
||||
|
||||
status = B_WOULD_BLOCK;
|
||||
|
||||
/* TODO: This should be by user request only! */
|
||||
ldi->Launch();
|
||||
}
|
||||
|
||||
break;
|
||||
case BT_MSG_COUNT_LOCAL_DEVICES:
|
||||
status = HandleLocalDevicesCount(message, &reply);
|
||||
break;
|
||||
|
||||
case BT_MSG_ACQUIRE_LOCAL_DEVICE:
|
||||
status = HandleAcquireLocalDevice(message, &reply);
|
||||
break;
|
||||
@@ -150,8 +137,6 @@ void BluetoothServer::MessageReceived(BMessage *message)
|
||||
case BT_MSG_HANDLE_SIMPLE_REQUEST:
|
||||
status = HandleSimpleRequest(message, &reply);
|
||||
break;
|
||||
|
||||
|
||||
/* Handle if the bluetooth preferences is running?? */
|
||||
case B_SOME_APP_LAUNCHED:
|
||||
{
|
||||
@@ -166,7 +151,6 @@ void BluetoothServer::MessageReceived(BMessage *message)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
default:
|
||||
BApplication::MessageReceived(message);
|
||||
break;
|
||||
@@ -179,7 +163,6 @@ void BluetoothServer::MessageReceived(BMessage *message)
|
||||
message->SendReply(&reply);
|
||||
printf("Sending reply message\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#if 0
|
||||
@@ -192,37 +175,31 @@ BluetoothServer::LocateDelegateFromMessage(BMessage* message)
|
||||
LocalDeviceImpl* ldi = NULL;
|
||||
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 */
|
||||
int index;
|
||||
|
||||
for (index = 0; index < fLocalDevicesList.CountItems(); index ++) {
|
||||
|
||||
ldi = fLocalDevicesList.ItemAt(index);
|
||||
if (ldi->GetID() == hid) {
|
||||
if (ldi->GetID() == hid)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ldi;
|
||||
|
||||
}
|
||||
|
||||
LocalDeviceImpl*
|
||||
BluetoothServer::LocateLocalDeviceImpl(hci_id hid)
|
||||
{
|
||||
|
||||
/* Try to find out when a ID was specified */
|
||||
int index;
|
||||
|
||||
for (index = 0; index < fLocalDevicesList.CountItems(); index ++) {
|
||||
|
||||
LocalDeviceImpl* ldi = fLocalDevicesList.ItemAt(index);
|
||||
if (ldi->GetID() == hid) {
|
||||
if (ldi->GetID() == hid)
|
||||
return ldi;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -250,29 +227,29 @@ BluetoothServer::HandleAcquireLocalDevice(BMessage* message, BMessage* reply)
|
||||
|
||||
if (message->FindInt32("hci_id", &hid) == B_OK)
|
||||
{
|
||||
Output::Instance()->Post("GetLocalDevice requested with id\n", BLACKBOARD_KIT);
|
||||
Output::Instance()->Post("GetLocalDevice requested with id\n",
|
||||
BLACKBOARD_KIT);
|
||||
ldi = LocateDelegateFromMessage(message);
|
||||
|
||||
} else if (message->FindData("bdaddr", B_ANY_TYPE, (const void**)&bdaddr, &size ) == B_OK)
|
||||
{
|
||||
} else if (message->FindData("bdaddr", B_ANY_TYPE, (const void**)&bdaddr, &size )
|
||||
== B_OK) {
|
||||
/* Try to find out when the user specified the address */
|
||||
Output::Instance()->Post("GetLocalDevice requested with bdaddr\n", BLACKBOARD_KIT);
|
||||
Output::Instance()->Post("GetLocalDevice requested with bdaddr\n",
|
||||
BLACKBOARD_KIT);
|
||||
for (index = 0; index < fLocalDevicesList.CountItems(); index ++) {
|
||||
|
||||
bdaddr_t local;
|
||||
ldi = fLocalDevicesList.ItemAt(index);
|
||||
// TODO: Only if the property is available
|
||||
//if ((ldi->GetAddress(&local, message) == B_OK) && bacmp(&local, &bdaddr)) {
|
||||
//if ((ldi->GetAddress(&local, message) == B_OK)
|
||||
// && bacmp(&local, &bdaddr)) {
|
||||
// break;
|
||||
//}
|
||||
}
|
||||
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
/* Careless, any device not performing operations will be fine */
|
||||
Output::Instance()->Post("GetLocalDevice requested\n", BLACKBOARD_KIT);
|
||||
for (index = 0; index < fLocalDevicesList.CountItems(); index ++) {
|
||||
|
||||
ldi = fLocalDevicesList.ItemAt(index);
|
||||
printf("Requesting local device %ld\n", ldi->GetID());
|
||||
if (ldi != NULL && ldi->Available())
|
||||
@@ -280,12 +257,10 @@ BluetoothServer::HandleAcquireLocalDevice(BMessage* message, BMessage* reply)
|
||||
printf("dev ours %ld\n", ldi->GetID());
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (index <= fLocalDevicesList.CountItems() && ldi != NULL && ldi->Available())
|
||||
{
|
||||
if (index <= fLocalDevicesList.CountItems() && ldi != NULL && ldi->Available()) {
|
||||
Output::Instance()->Post("Device acquired\n", BLACKBOARD_KIT);
|
||||
ldi->Acquire();
|
||||
return reply->AddInt32("hci_id", hid);
|
||||
@@ -299,26 +274,21 @@ BluetoothServer::HandleAcquireLocalDevice(BMessage* message, BMessage* reply)
|
||||
status_t
|
||||
BluetoothServer::HandleSimpleRequest(BMessage* message, BMessage* reply)
|
||||
{
|
||||
|
||||
LocalDeviceImpl* ldi = LocateDelegateFromMessage(message);
|
||||
BString propertyRequested;
|
||||
|
||||
// Find out if there is a property being requested,
|
||||
if (message->FindString("property", &propertyRequested) == B_OK) {
|
||||
// Check if the property has been already retrieved
|
||||
|
||||
if (ldi->IsPropertyAvailable(propertyRequested)) {
|
||||
|
||||
// Dump everything
|
||||
reply->AddMessage("properties",ldi->GetPropertiesMessage());
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// we are gonna need issue the command ...
|
||||
if (ldi->ProcessSimpleRequest(DetachCurrentMessage()) == B_OK)
|
||||
// if (ldi->ProcessSimpleRequest(message) == B_OK)
|
||||
return B_WOULD_BLOCK;
|
||||
else
|
||||
return B_ERROR;
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
/*
|
||||
* Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
|
||||
*
|
||||
* Copyright 2008 Mika Lindqvist, monni1995_at_gmail.com
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _HCIDELEGATE_H_
|
||||
#define _HCIDELEGATE_H_
|
||||
|
||||
@@ -30,10 +28,12 @@ class HCIDelegate {
|
||||
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);
|
||||
printf("%s: hid retrieved %lx status=%ld\n", __FUNCTION__,
|
||||
fHID, status);
|
||||
}
|
||||
else {
|
||||
printf("%s: Device driver could not be opened %ld\n", __FUNCTION__, fHID);
|
||||
printf("%s: Device driver could not be opened %ld\n", __FUNCTION__,
|
||||
fHID);
|
||||
fHID = B_ERROR;
|
||||
}
|
||||
|
||||
@@ -47,23 +47,37 @@ class HCIDelegate {
|
||||
return fHID;
|
||||
}
|
||||
|
||||
virtual status_t IssueCommand(raw_command rc, size_t size)=0; // TODO means to be private
|
||||
|
||||
virtual ~HCIDelegate()
|
||||
{
|
||||
if (fFD > 0)
|
||||
{
|
||||
close (fFD);
|
||||
fFD = -1;
|
||||
fHID = B_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
virtual status_t IssueCommand(raw_command rc, size_t size)=0;
|
||||
// TODO means to be private use QueueCommand
|
||||
virtual status_t Launch()=0;
|
||||
|
||||
void FreeWindow(uint8 slots) { // TODO: hci control flow
|
||||
|
||||
void FreeWindow(uint8 slots)
|
||||
{
|
||||
// TODO: hci control flow
|
||||
}
|
||||
|
||||
|
||||
status_t QueueCommand(raw_command rc, size_t size)
|
||||
{
|
||||
// TODO: this is suposed to queue the command in a queue so all are actually send to HW
|
||||
// TODO: this is suposed to queue the command in a queue so all
|
||||
// are actually send to HW
|
||||
return IssueCommand(rc, size);
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
hci_id fHID;
|
||||
int fFD;
|
||||
|
||||
|
||||
@@ -1,25 +1,22 @@
|
||||
/*
|
||||
* Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
|
||||
*
|
||||
* Copyright 2007-2009 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
|
||||
* Copyright 2008 Mika Lindqvist, monni1995_at_gmail.com
|
||||
* All rights reserved. Distributed under the terms of the MIT License.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "LocalDeviceHandler.h"
|
||||
|
||||
|
||||
|
||||
LocalDeviceHandler::LocalDeviceHandler(HCIDelegate* hd)
|
||||
{
|
||||
fHCIDelegate = hd;
|
||||
fProperties = new BMessage();
|
||||
|
||||
}
|
||||
|
||||
|
||||
LocalDeviceHandler::~LocalDeviceHandler()
|
||||
{
|
||||
|
||||
delete fProperties;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +26,7 @@ LocalDeviceHandler::GetID()
|
||||
return fHCIDelegate->GetID();
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
LocalDeviceHandler::Launch(void)
|
||||
{
|
||||
@@ -37,26 +35,27 @@ LocalDeviceHandler::Launch(void)
|
||||
|
||||
|
||||
bool
|
||||
LocalDeviceHandler::Available() {
|
||||
LocalDeviceHandler::Available()
|
||||
{
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
LocalDeviceHandler::Acquire(void) {
|
||||
LocalDeviceHandler::Acquire(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
LocalDeviceHandler::IsPropertyAvailable(const BString& property) {
|
||||
|
||||
LocalDeviceHandler::IsPropertyAvailable(const BString& property)
|
||||
{
|
||||
type_code typeFound;
|
||||
int32 countFound;
|
||||
|
||||
return (fProperties->GetInfo(property.String(), &typeFound, &countFound) == B_OK );
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -70,13 +69,13 @@ LocalDeviceHandler::AddWantedEvent(BMessage* msg)
|
||||
fEventsWanted.Unlock();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
LocalDeviceHandler::ClearWantedEvent(BMessage* msg)
|
||||
{
|
||||
fEventsWanted.Lock();
|
||||
fEventsWanted.RemoveMessage(msg);
|
||||
fEventsWanted.Unlock();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -102,11 +101,12 @@ LocalDeviceHandler::ClearWantedEvent(BMessage* msg, uint16 event, uint16 opcode)
|
||||
if (opcode != 0) {
|
||||
|
||||
// The opcode matches
|
||||
if ( (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK) &&
|
||||
((uint16)opcodeFound == opcode) ) {
|
||||
if ( (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK)
|
||||
&& ((uint16)opcodeFound == opcode) ) {
|
||||
|
||||
// this should remove only the entry
|
||||
printf("Removed event %#x and opcode %d from request %p\n", event, opcode, msg);
|
||||
printf("Removed event %#x and opcode %d from request %p\n",
|
||||
event, opcode, msg);
|
||||
(void)msg->RemoveData("eventExpected", eventIndex);
|
||||
(void)msg->RemoveData("opcodeExpected", eventIndex);
|
||||
goto finish;
|
||||
@@ -141,8 +141,8 @@ LocalDeviceHandler::FindPetition(uint16 event, uint16 opcode, int32* indexFound)
|
||||
// for each Petition
|
||||
for (int32 index = 0 ; index < fEventsWanted.CountMessages() ; index++) {
|
||||
BMessage* msg = fEventsWanted.FindMessage(index);
|
||||
|
||||
printf("%s:Petition %ld ... of %ld msg #%p\n", __FUNCTION__, index, fEventsWanted.CountMessages(), msg);
|
||||
printf("%s:Petition %ld ... of %ld msg #%p\n", __FUNCTION__, index,
|
||||
fEventsWanted.CountMessages(), msg);
|
||||
//msg->PrintToStream();
|
||||
eventIndex = 0;
|
||||
|
||||
@@ -152,24 +152,23 @@ LocalDeviceHandler::FindPetition(uint16 event, uint16 opcode, int32* indexFound)
|
||||
|
||||
printf("%s:Event found@%ld...", __FUNCTION__, eventIndex);
|
||||
// there is an opcode specified..
|
||||
if (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK) {
|
||||
|
||||
if (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound)
|
||||
== B_OK) {
|
||||
// ensure the opcode
|
||||
if ((uint16)opcodeFound != opcode) {
|
||||
printf("%s:opcode does not match %d\n",__FUNCTION__, opcode);
|
||||
printf("%s:opcode does not match %d\n",
|
||||
__FUNCTION__, opcode);
|
||||
break;
|
||||
}
|
||||
printf("opcode match %d\n", opcode);
|
||||
printf("Opcode matches %d\n", opcode);
|
||||
} else {
|
||||
printf("no opcode specified\n");
|
||||
printf("No opcode specified\n");
|
||||
}
|
||||
|
||||
fEventsWanted.Unlock();
|
||||
if (indexFound != NULL)
|
||||
*indexFound = eventIndex;
|
||||
return msg;
|
||||
|
||||
|
||||
}
|
||||
eventIndex++;
|
||||
}
|
||||
@@ -178,4 +177,5 @@ LocalDeviceHandler::FindPetition(uint16 event, uint16 opcode, int32* indexFound)
|
||||
|
||||
fEventsWanted.Unlock();
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
@@ -82,23 +82,18 @@ printf("### \n");
|
||||
case HCI_EVENT_CONN_REQUEST:
|
||||
ConnectionRequest((struct hci_ev_conn_request*)(event+1), NULL);
|
||||
return;
|
||||
|
||||
case HCI_EVENT_CONN_COMPLETE:
|
||||
// should belong to a request? can be sporadic or initiated by us¿?...
|
||||
ConnectionComplete((struct hci_ev_conn_complete*)(event+1), NULL);
|
||||
return;
|
||||
|
||||
case HCI_EVENT_PIN_CODE_REQ:
|
||||
PinCodeRequest((struct hci_ev_pin_code_req*)(event+1), NULL);
|
||||
return;
|
||||
|
||||
default:
|
||||
// lets go on
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
BMessage* request = NULL;
|
||||
int32 eventIndexLocation;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user