diff --git a/src/servers/bluetooth/LocalDeviceHandler.cpp b/src/servers/bluetooth/LocalDeviceHandler.cpp index b2b89c06dc..33e7bf373d 100644 --- a/src/servers/bluetooth/LocalDeviceHandler.cpp +++ b/src/servers/bluetooth/LocalDeviceHandler.cpp @@ -74,50 +74,49 @@ LocalDeviceHandler::ClearWantedEvent(BMessage* msg) void -LocalDeviceHandler::ClearWantedEvent(BMessage* msg, uint16 event, uint16 opcode = 0) +LocalDeviceHandler::ClearWantedEvent(BMessage* msg, uint16 event, uint16 opcode) { // Remove the whole petition from queue fEventsWanted.Lock(); int16 eventFound; int16 opcodeFound; - int32 eventIndex; + int32 eventIndex = 0; - for (int32 index = 0 ; index < fEventsWanted.CountMessages() ; index++) { - - BMessage* msg = fEventsWanted.FindMessage(index); + // for each Event + while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) { - eventIndex = 0; - // for each Event - while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) { - if (eventFound == event) { - - // there is an opcode specified - if (opcode != 0) { + printf("@ Event expected found @%ld\n", eventIndex); + + if (eventFound == event) { + + printf("@ Event matches %ld\n", eventIndex); + // there is an opcode specified + if (opcode != 0) { - // The opcode matches - if ( (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK) && - ((uint16)opcodeFound != opcode) ) { - - // this should remove only the entry - (void)msg->RemoveData("eventExpected", eventIndex); - (void)msg->RemoveData("opcodeExpected", eventIndex); - goto bail; - } - } else { - // Event matches so far + // The opcode matches + if ( (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK) && + ((uint16)opcodeFound == opcode) ) { + + // this should remove only the entry + printf("@ Removed event %d and opcoce %d from message %p\n", event, opcode, msg); (void)msg->RemoveData("eventExpected", eventIndex); + (void)msg->RemoveData("opcodeExpected", eventIndex); goto bail; - } + } + } else { + // Event matches so far + printf("@ Removed event %d from message %p\n", event, msg); + (void)msg->RemoveData("eventExpected", eventIndex); + goto bail; + } - } - eventIndex++; - } + } + eventIndex++; } bail: - fEventsWanted.RemoveMessage(msg); fEventsWanted.Unlock(); } diff --git a/src/servers/bluetooth/LocalDeviceImpl.cpp b/src/servers/bluetooth/LocalDeviceImpl.cpp index 4d5215b025..46ebe806e5 100644 --- a/src/servers/bluetooth/LocalDeviceImpl.cpp +++ b/src/servers/bluetooth/LocalDeviceImpl.cpp @@ -95,7 +95,7 @@ printf("### \n"); } else if ( event->ecode == HCI_EVENT_CMD_STATUS ) { - (Output::Instance()->Post("Incoming Command Complete\n", BLACKBOARD_EVENTS)); + (Output::Instance()->Post("Incoming Command Status\n", BLACKBOARD_EVENTS)); request = FindPetition(event->ecode, ((struct hci_ev_cmd_status*)(event+1))->opcode ); } else @@ -346,17 +346,15 @@ LocalDeviceImpl::CommandStatus(struct hci_ev_cmd_status* event, BMessage* reques switch (opcodeExpected) { - case PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_BD_ADDR): - { - struct hci_ev_cmd_status* commandStatus = (struct hci_ev_cmd_status*)(event+1); - + case PACK_OPCODE(OGF_LINK_CONTROL, OCF_INQUIRY): + { reply.what = BT_MSG_INQUIRY_STARTED; - reply.AddInt8("status", commandStatus->status); + reply.AddInt8("status", event->status); - if (commandStatus->status == BT_OK) { - Output::Instance()->Post("Positive reply for inquiry\n", BLACKBOARD_KIT); + if (event->status == BT_OK) { + Output::Instance()->Post("Positive reply for inquiry status\n", BLACKBOARD_KIT); } else { - Output::Instance()->Post("Negative reply for friendly name\n", BLACKBOARD_KIT); + Output::Instance()->Post("Negative reply for inquiry status\n", BLACKBOARD_KIT); } printf("Sending reply ... %ld\n",request->SendReply(&reply)); @@ -384,7 +382,6 @@ LocalDeviceImpl::InquiryResult(struct inquiry_info* event, BMessage* request) printf("%s: Sending reply ... %ld\n",__FUNCTION__, request->SendReply(&reply)); - } @@ -393,9 +390,11 @@ LocalDeviceImpl::InquiryComplete(uint8* status, BMessage* request) { BMessage reply(BT_MSG_INQUIRY_COMPLETED); - reply.AddInt8("status", *status); + reply.AddInt8("status", *status); + printf("%s: Sending reply ... %ld\n",__FUNCTION__, request->SendReply(&reply)); - + + ClearWantedEvent(request); }