From e5da0ec57e7e7de6640b4cfc98eab2c7856951dc Mon Sep 17 00:00:00 2001 From: Oliver Ruiz Dorantes Date: Fri, 16 Jan 2009 20:32:19 +0000 Subject: [PATCH] some cleanups and styling by Mika and me git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28915 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/bluetooth/LinkKeyUtils.h | 14 +- headers/os/bluetooth/bdaddrUtils.h | 2 +- headers/os/bluetooth/bluetooth_util.h | 24 +- src/servers/bluetooth/BluetoothServer.cpp | 284 +++++++++---------- src/servers/bluetooth/HCIDelegate.h | 42 ++- src/servers/bluetooth/LocalDeviceHandler.cpp | 128 ++++----- src/servers/bluetooth/LocalDeviceImpl.cpp | 25 +- src/servers/bluetooth/LocalDeviceImpl.h | 2 +- 8 files changed, 243 insertions(+), 278 deletions(-) diff --git a/headers/os/bluetooth/LinkKeyUtils.h b/headers/os/bluetooth/LinkKeyUtils.h index ff3d82ff11..5009735140 100644 --- a/headers/os/bluetooth/LinkKeyUtils.h +++ b/headers/os/bluetooth/LinkKeyUtils.h @@ -30,10 +30,10 @@ public: static char str[50]; sprintf(str, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:" - "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", - lk.l[0], lk.l[1], lk.l[2], lk.l[3], lk.l[4], lk.l[5], - lk.l[6], lk.l[7], lk.l[8], lk.l[9], lk.l[10], lk.l[11], - lk.l[12], lk.l[13], lk.l[14], lk.l[15]); + "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", + lk.l[0], lk.l[1], lk.l[2], lk.l[3], lk.l[4], lk.l[5], + lk.l[6], lk.l[7], lk.l[8], lk.l[9], lk.l[10], lk.l[11], + lk.l[12], lk.l[13], lk.l[14], lk.l[15]); return str; } @@ -43,9 +43,9 @@ public: if (lkstr != NULL) { int l0, l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15; size_t count = sscanf(lkstr, "%2X:%2X:%2X:%2X:%2X:%2X:%2X:%2X:" - "%2X:%2X:%2X:%2X:%2X:%2X:%2X:%2X", &l0, &l1, &l2, &l3, - &l4, &l5, &l6, &l7, &l8, &l9, &l10, &l11, &l12, &l13, - &l14, &l15); + "%2X:%2X:%2X:%2X:%2X:%2X:%2X:%2X", &l0, &l1, &l2, &l3, + &l4, &l5, &l6, &l7, &l8, &l9, &l10, &l11, &l12, &l13, + &l14, &l15); if (count == 16) { return (linkkey_t){{l0, l1, l2, l3, l4, l5, l6, l7, l8, diff --git a/headers/os/bluetooth/bdaddrUtils.h b/headers/os/bluetooth/bdaddrUtils.h index 9fcb3f6bb6..19079c9520 100644 --- a/headers/os/bluetooth/bdaddrUtils.h +++ b/headers/os/bluetooth/bdaddrUtils.h @@ -58,7 +58,7 @@ public: if (addr != NULL) { size_t count = sscanf(addr, "%2X:%2X:%2X:%2X:%2X:%2X", - &b0, &b1, &b2, &b3, &b4, &b5); + &b0, &b1, &b2, &b3, &b4, &b5); if (count == 6) return ((bdaddr_t) {{b0, b1, b2, b3, b4, b5}}); diff --git a/headers/os/bluetooth/bluetooth_util.h b/headers/os/bluetooth/bluetooth_util.h index 874418057b..896c5cc514 100644 --- a/headers/os/bluetooth/bluetooth_util.h +++ b/headers/os/bluetooth/bluetooth_util.h @@ -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"; } diff --git a/src/servers/bluetooth/BluetoothServer.cpp b/src/servers/bluetooth/BluetoothServer.cpp index 0225035b40..e2248de5a2 100644 --- a/src/servers/bluetooth/BluetoothServer.cpp +++ b/src/servers/bluetooth/BluetoothServer.cpp @@ -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 #include - #include -#include -#include #include -#include +#include +#include #include - +#include #include #include @@ -31,7 +29,7 @@ BluetoothServer::BluetoothServer() : BApplication(BLUETOOTH_SIGNATURE) -{ +{ Output::Instance()->Run(); Output::Instance()->SetTitle("Bluetooth message gathering"); @@ -40,16 +38,15 @@ BluetoothServer::BluetoothServer() : BApplication(BLUETOOTH_SIGNATURE) Output::Instance()->AddTab("Events", BLACKBOARD_EVENTS); Output::Instance()->AddTab("Kit", BLACKBOARD_KIT); - ShowWindow(Output::Instance()); - fDeviceManager = new DeviceManager(); + 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); - } bool BluetoothServer::QuitRequested(void) @@ -58,128 +55,114 @@ 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) { - - fDeviceManager->StartMonitoringDevice("bluetooth/h2generic"); - - +void BluetoothServer::ReadyToRun(void) +{ + fDeviceManager->StartMonitoringDevice("bluetooth/h2generic"); // Launch the notifier thread if ( resume_thread(fEventListener) != B_OK ) { Output::Instance()->Post("Bluetooth port listener failed\n", BLACKBOARD_GENERAL); } - - Output::Instance()->Post("Bluetooth server Ready\n", BLACKBOARD_GENERAL); + + 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); + message->FindString("name", &str); BPath path(str.String()); + Output::Instance()->Postf(BLACKBOARD_GENERAL, + "Requested LocalDevice %s\n", str.String()); + LocalDeviceImpl* ldi = LocalDeviceImpl::CreateTransportAccessor(&path); - (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()); + } else { + Output::Instance()->Post("Adding LocalDevice failed\n", + BLACKBOARD_GENERAL); + } - 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())); - - - } else { - (Output::Instance()->Post("Adding LocalDevice failed\n", BLACKBOARD_GENERAL)); - } - - status = B_WOULD_BLOCK; - - /* TODO: This should be by user request only! */ - ldi->Launch(); - } - + 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; - + break; case BT_MSG_ACQUIRE_LOCAL_DEVICE: status = HandleAcquireLocalDevice(message, &reply); break; - case BT_MSG_HANDLE_SIMPLE_REQUEST: - status = HandleSimpleRequest(message, &reply); - break; - - + case BT_MSG_HANDLE_SIMPLE_REQUEST: + status = HandleSimpleRequest(message, &reply); + break; /* Handle if the bluetooth preferences is running?? */ case B_SOME_APP_LAUNCHED: { const char *signature; // TODO: what's this for? - if (message->FindString("be:signature", &signature)==B_OK) { + if (message->FindString("be:signature", &signature) == B_OK) { printf("input_server : %s\n", signature); - if (strcmp(signature, "application/x-vnd.Be-TSKB")==0) { + if (strcmp(signature, "application/x-vnd.Be-TSKB") == 0) { } } return; } - default: BApplication::MessageReceived(message); break; } - // Can we reply right now? + // Can we reply right now? // TOD: review this condition - if (status != B_WOULD_BLOCK) { - reply.AddInt32("status", status); - message->SendReply(&reply); - printf("Sending reply message\n"); + if (status != B_WOULD_BLOCK) { + reply.AddInt32("status", status); + message->SendReply(&reply); + printf("Sending reply message\n"); } - } #if 0 @@ -189,42 +172,36 @@ void BluetoothServer::MessageReceived(BMessage *message) LocalDeviceImpl* BluetoothServer::LocateDelegateFromMessage(BMessage* message) { - LocalDeviceImpl* ldi = NULL; - hci_id hid; - - 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 ++) { + LocalDeviceImpl* ldi = NULL; + hci_id hid; + 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; + } + } + + return ldi; + } LocalDeviceImpl* BluetoothServer::LocateLocalDeviceImpl(hci_id hid) { + /* Try to find out when a ID was specified */ + int index; - /* Try to find out when a ID was specified */ - int index; - - for (index = 0; index < fLocalDevicesList.CountItems() ; index ++) { + for (index = 0; index < fLocalDevicesList.CountItems(); index ++) { + LocalDeviceImpl* ldi = fLocalDevicesList.ItemAt(index); + if (ldi->GetID() == hid) + return ldi; + } - LocalDeviceImpl* ldi = fLocalDevicesList.ItemAt(index); - if (ldi->GetID() == hid) { - return ldi; - } - } - - return NULL; + return NULL; } @@ -246,52 +223,50 @@ BluetoothServer::HandleAcquireLocalDevice(BMessage* message, BMessage* reply) ssize_t size; bdaddr_t bdaddr; LocalDeviceImpl* ldi = NULL; - int32 index = 0; + int32 index = 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", BLACKBOARD_KIT); - ldi = LocateDelegateFromMessage(message); - - } 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); - 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)) { - // break; - //} - } - - } 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()) - { - printf("dev ours %ld\n", ldi->GetID()); - break; - } - - } - } + Output::Instance()->Post("GetLocalDevice requested with id\n", + BLACKBOARD_KIT); + ldi = LocateDelegateFromMessage(message); - if (index <= fLocalDevicesList.CountItems() && ldi != NULL && ldi->Available()) - { - Output::Instance()->Post("Device acquired\n", BLACKBOARD_KIT); - ldi->Acquire(); - return reply->AddInt32("hci_id", hid); - } + } 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); + 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)) { + // break; + //} + } - return B_ERROR; + } 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()) + { + printf("dev ours %ld\n", ldi->GetID()); + break; + } + } + } + + if (index <= fLocalDevicesList.CountItems() && ldi != NULL && ldi->Available()) { + Output::Instance()->Post("Device acquired\n", BLACKBOARD_KIT); + ldi->Acquire(); + return reply->AddInt32("hci_id", hid); + } + + return B_ERROR; } @@ -299,26 +274,21 @@ BluetoothServer::HandleAcquireLocalDevice(BMessage* message, BMessage* reply) status_t BluetoothServer::HandleSimpleRequest(BMessage* message, BMessage* reply) { - - LocalDeviceImpl* ldi = LocateDelegateFromMessage(message); + 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; - } - - } + + // 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; @@ -334,7 +304,7 @@ BluetoothServer::HandleSimpleRequest(BMessage* message, BMessage* reply) int32 BluetoothServer::notification_Thread(void* data) { - BPortNot notifierd( (BluetoothServer*) data , BT_USERLAND_PORT_NAME); + BPortNot notifierd((BluetoothServer*)data, BT_USERLAND_PORT_NAME); notifierd.loop(); return B_NO_ERROR; @@ -367,7 +337,7 @@ BluetoothServer::ShowWindow(BWindow* pWindow) int main(int /*argc*/, char** /*argv*/) { - setbuf(stdout,NULL); + setbuf(stdout, NULL); BluetoothServer* bluetoothServer = new BluetoothServer; diff --git a/src/servers/bluetooth/HCIDelegate.h b/src/servers/bluetooth/HCIDelegate.h index 36c02ebdf0..e3c2e55a0c 100644 --- a/src/servers/bluetooth/HCIDelegate.h +++ b/src/servers/bluetooth/HCIDelegate.h @@ -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,43 +28,59 @@ 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; } - - //TODO create such queue + + //TODO create such queue } - + hci_id GetID(void) { 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; - + private: diff --git a/src/servers/bluetooth/LocalDeviceHandler.cpp b/src/servers/bluetooth/LocalDeviceHandler.cpp index bc84acc6b1..e0aabc12fd 100644 --- a/src/servers/bluetooth/LocalDeviceHandler.cpp +++ b/src/servers/bluetooth/LocalDeviceHandler.cpp @@ -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(); - + 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,28 +69,28 @@ LocalDeviceHandler::AddWantedEvent(BMessage* msg) fEventsWanted.Unlock(); } + void LocalDeviceHandler::ClearWantedEvent(BMessage* msg) { fEventsWanted.Lock(); - fEventsWanted.RemoveMessage(msg); + fEventsWanted.RemoveMessage(msg); fEventsWanted.Unlock(); - } void LocalDeviceHandler::ClearWantedEvent(BMessage* msg, uint16 event, uint16 opcode) -{ - // Remove the whole petition from queue - fEventsWanted.Lock(); +{ + // Remove the whole petition from queue + fEventsWanted.Lock(); - int16 eventFound; - int16 opcodeFound; + int16 eventFound; + int16 opcodeFound; int32 eventIndex = 0; - // for each Event - while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) { + // for each Event + while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK) { printf("%s:Event expected@%ld...\n", __FUNCTION__, eventIndex); @@ -102,19 +101,20 @@ 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; } - } else { + } else { // Event matches so far - printf("Removed event %d from message %p\n", event, msg); + printf("Removed event %d from message %p\n", event, msg); (void)msg->RemoveData("eventExpected", eventIndex); goto finish; } @@ -133,49 +133,49 @@ finish: BMessage* LocalDeviceHandler::FindPetition(uint16 event, uint16 opcode, int32* indexFound) { - int16 eventFound; - int16 opcodeFound; + int16 eventFound; + int16 opcodeFound; int32 eventIndex; - fEventsWanted.Lock(); - // 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); + fEventsWanted.Lock(); + // 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); //msg->PrintToStream(); eventIndex = 0; - // for each Event - while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) { - if (eventFound == event) { - - printf("%s:Event found@%ld...", __FUNCTION__, eventIndex); - // there is an opcode specified.. - 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); - break; - } - printf("opcode match %d\n", opcode); - } else { - printf("no opcode specified\n"); - } - - fEventsWanted.Unlock(); + // for each Event + while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) { + if (eventFound == event) { + + printf("%s:Event found@%ld...", __FUNCTION__, eventIndex); + // there is an opcode specified.. + 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); + break; + } + printf("Opcode matches %d\n", opcode); + } else { + printf("No opcode specified\n"); + } + + fEventsWanted.Unlock(); if (indexFound != NULL) *indexFound = eventIndex; - return msg; + return msg; + } + eventIndex++; + } + } + printf("%s:Nothing found\n", __FUNCTION__); + fEventsWanted.Unlock(); + return NULL; - } - eventIndex++; - } - } - printf("%s:Nothing found\n",__FUNCTION__); - - fEventsWanted.Unlock(); - return NULL; } diff --git a/src/servers/bluetooth/LocalDeviceImpl.cpp b/src/servers/bluetooth/LocalDeviceImpl.cpp index fdd66f083d..2cb3dc5d4c 100644 --- a/src/servers/bluetooth/LocalDeviceImpl.cpp +++ b/src/servers/bluetooth/LocalDeviceImpl.cpp @@ -34,7 +34,7 @@ LocalDeviceImpl* LocalDeviceImpl::CreateControllerAccessor(BPath* path) { HCIDelegate* hd = new HCIControllerAccessor(path); - + if ( hd != NULL) return new LocalDeviceImpl(hd); else @@ -46,11 +46,11 @@ LocalDeviceImpl* LocalDeviceImpl::CreateTransportAccessor(BPath* path) { HCIDelegate* hd = new HCITransportAccessor(path); - + if ( hd != NULL) - return new LocalDeviceImpl(hd); + return new LocalDeviceImpl(hd); else - return NULL; + return NULL; } @@ -75,30 +75,25 @@ printf("### \n"); // Events here might have not been initated by us // TODO: ML mark as handled pass a reply by parameter and reply in common - switch (event->ecode) { - case HCI_EVENT_HARDWARE_ERROR: + switch (event->ecode) { + case HCI_EVENT_HARDWARE_ERROR: //HardwareError(event); - return; + return; 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; + default: + // lets go on + break; } - - BMessage* request = NULL; int32 eventIndexLocation; diff --git a/src/servers/bluetooth/LocalDeviceImpl.h b/src/servers/bluetooth/LocalDeviceImpl.h index b0bcc6cc4c..54ec98bddb 100644 --- a/src/servers/bluetooth/LocalDeviceImpl.h +++ b/src/servers/bluetooth/LocalDeviceImpl.h @@ -48,7 +48,7 @@ public: // Connection void ConnectionComplete(struct hci_ev_conn_complete* event, BMessage* request); void ConnectionRequest(struct hci_ev_conn_request* event, BMessage* request); - void DisconnectionComplete(struct hci_ev_disconnection_complete_reply* event, BMessage *request); + void DisconnectionComplete(struct hci_ev_disconnection_complete_reply* event, BMessage* request); // Pairing void PinCodeRequest(struct hci_ev_pin_code_req* event, BMessage* request);