diff --git a/src/servers/bluetooth/LocalDeviceHandler.cpp b/src/servers/bluetooth/LocalDeviceHandler.cpp index 413234c974..eb835a762b 100644 --- a/src/servers/bluetooth/LocalDeviceHandler.cpp +++ b/src/servers/bluetooth/LocalDeviceHandler.cpp @@ -82,39 +82,39 @@ LocalDeviceHandler::ClearWantedEvent(BMessage* msg, uint16 event, uint16 opcode) int16 eventFound; int16 opcodeFound; int32 eventIndex = 0; - + // for each Event while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) { - printf("@ Event expected found @%ld\n", eventIndex); + printf("@ Event expected found @%ld\n", eventIndex); if (eventFound == event) { - printf("@ Event matches %ld\n", eventIndex); + 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 printf("@ Removed event %d and opcoce %d from message %p\n", event, opcode, msg); (void)msg->RemoveData("eventExpected", eventIndex); - (void)msg->RemoveData("opcodeExpected", eventIndex); + (void)msg->RemoveData("opcodeExpected", eventIndex); goto bail; - } - } else { + } + } else { // Event matches so far printf("@ Removed event %d from message %p\n", event, msg); (void)msg->RemoveData("eventExpected", eventIndex); goto bail; } - + } eventIndex++; } - + bail: fEventsWanted.Unlock(); @@ -123,45 +123,48 @@ bail: BMessage* -LocalDeviceHandler::FindPetition(uint16 event, uint16 opcode) +LocalDeviceHandler::FindPetition(uint16 event, uint16 opcode, int32* indexFound) { int16 eventFound; int16 opcodeFound; int32 eventIndex; - - fEventsWanted.Lock(); + + fEventsWanted.Lock(); // for each Petition for (int32 index = 0 ; index < fEventsWanted.CountMessages() ; index++) { BMessage* msg = fEventsWanted.FindMessage(index); printf("Petition %ld ... of %ld msg #%p\n", index, fEventsWanted.CountMessages(), msg); msg->PrintToStream(); - eventIndex = 0; - // for each Event + eventIndex = 0; + + // for each Event while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) { if (eventFound == event) { - printf("Event found %ld\n", eventIndex); + printf("Event found %ld\n", eventIndex); // there is an opcode specified.. if (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK) { - + // ensure the opcode if ((uint16)opcodeFound != opcode) { - printf("opcode does not match %d\n", opcode); + printf("opcode does not match %d\n", opcode); break; } - printf("Opcdodes match %d %d \n", opcode , opcodeFound); + printf("Opcdodes match %d %d \n", opcode , opcodeFound); } - + fEventsWanted.Unlock(); + if (indexFound != NULL) + *indexFound = eventIndex; return msg; - + } eventIndex++; } } - + fEventsWanted.Unlock(); return NULL; } diff --git a/src/servers/bluetooth/LocalDeviceHandler.h b/src/servers/bluetooth/LocalDeviceHandler.h index a676542edc..8ddc18da70 100644 --- a/src/servers/bluetooth/LocalDeviceHandler.h +++ b/src/servers/bluetooth/LocalDeviceHandler.h @@ -40,7 +40,7 @@ protected: void ClearWantedEvent(BMessage* msg, uint16 event, uint16 opcode = 0); void ClearWantedEvent(BMessage* msg); - BMessage* FindPetition(uint16 event, uint16 opcode = 0); + BMessage* FindPetition(uint16 event, uint16 opcode = 0, int32* indexFound = NULL); private: diff --git a/src/servers/bluetooth/LocalDeviceImpl.cpp b/src/servers/bluetooth/LocalDeviceImpl.cpp index a5c46314c0..bf91cfc826 100644 --- a/src/servers/bluetooth/LocalDeviceImpl.cpp +++ b/src/servers/bluetooth/LocalDeviceImpl.cpp @@ -98,17 +98,18 @@ printf("### \n"); BMessage* request = NULL; + int32 eventIndexLocation; // Check if its a requested one if ( event->ecode == HCI_EVENT_CMD_COMPLETE ) { (Output::Instance()->Post("Incoming Command Complete\n", BLACKBOARD_EVENTS)); - request = FindPetition(event->ecode, ((struct hci_ev_cmd_complete*)(event+1))->opcode ); + request = FindPetition(event->ecode, ((struct hci_ev_cmd_complete*)(event+1))->opcode, &eventIndexLocation ); } else if ( event->ecode == HCI_EVENT_CMD_STATUS ) { (Output::Instance()->Post("Incoming Command Status\n", BLACKBOARD_EVENTS)); - request = FindPetition(event->ecode, ((struct hci_ev_cmd_status*)(event+1))->opcode ); + request = FindPetition(event->ecode, ((struct hci_ev_cmd_status*)(event+1))->opcode, &eventIndexLocation ); } else { @@ -160,11 +161,11 @@ printf("### \n"); break; case HCI_EVENT_CMD_COMPLETE: - CommandComplete((struct hci_ev_cmd_complete*)(event+1), request); + CommandComplete((struct hci_ev_cmd_complete*)(event+1), request, eventIndexLocation); break; - + case HCI_EVENT_CMD_STATUS: - CommandStatus((struct hci_ev_cmd_status*)(event+1), request); + CommandStatus((struct hci_ev_cmd_status*)(event+1), request, eventIndexLocation); break; case HCI_EVENT_FLUSH_OCCUR: @@ -230,7 +231,7 @@ printf("### \n"); void -LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, BMessage* request) { +LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, BMessage* request, int32 index) { int16 opcodeExpected; BMessage reply; @@ -241,11 +242,11 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, BMessage* re // Handle command complete information // FIX ME! the expected code might me in another // index as is relative to the event not the request - request->FindInt16("opcodeExpected", 0 /*REVIEW!*/, &opcodeExpected); + request->FindInt16("opcodeExpected", index, &opcodeExpected); if (request->IsSourceWaiting() == false) - Output::Instance()->Post("Nobody waiting for the event\n", BLACKBOARD_KIT); + Output::Instance()->Post("Nobody waiting for the event\n", BLACKBOARD_KIT); switch (opcodeExpected) { @@ -332,7 +333,7 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, BMessage* re void -LocalDeviceImpl::CommandStatus(struct hci_ev_cmd_status* event, BMessage* request) { +LocalDeviceImpl::CommandStatus(struct hci_ev_cmd_status* event, BMessage* request, int32 index) { int16 opcodeExpected; BMessage reply; @@ -341,31 +342,30 @@ LocalDeviceImpl::CommandStatus(struct hci_ev_cmd_status* event, BMessage* reques Output::Instance()->Post("\n", BLACKBOARD_LD_OFFSET + GetID()); // Handle command complete information - request->FindInt16("opcodeExpected", 0 /*REVIEW!*/, &opcodeExpected); + request->FindInt16("opcodeExpected", index, &opcodeExpected); if (request->IsSourceWaiting() == false) - Output::Instance()->Post("Nobody waiting for the event\n", BLACKBOARD_KIT); - - + Output::Instance()->Post("Nobody waiting for the event\n", BLACKBOARD_KIT); + switch (opcodeExpected) { - + case PACK_OPCODE(OGF_LINK_CONTROL, OCF_INQUIRY): - { + { reply.what = BT_MSG_INQUIRY_STARTED; reply.AddInt8("status", event->status); - - if (event->status == BT_OK) { + + if (event->status == BT_OK) { Output::Instance()->Post("Positive reply for inquiry status\n", BLACKBOARD_KIT); } else { - Output::Instance()->Post("Negative reply for inquiry status\n", BLACKBOARD_KIT); + Output::Instance()->Post("Negative reply for inquiry status\n", BLACKBOARD_KIT); } - printf("Sending reply ... %ld\n", request->SendReply(&reply)); + printf("Sending reply ... %ld\n", request->SendReply(&reply)); reply.PrintToStream(); - + ClearWantedEvent(request, HCI_EVENT_CMD_STATUS, PACK_OPCODE(OGF_LINK_CONTROL, OCF_INQUIRY)); - } + } break; case PACK_OPCODE(OGF_LINK_CONTROL, OCF_REMOTE_NAME_REQUEST): @@ -374,7 +374,7 @@ LocalDeviceImpl::CommandStatus(struct hci_ev_cmd_status* event, BMessage* reques } break; default: - Output::Instance()->Post("Command Status not handled\n", BLACKBOARD_KIT); + Output::Instance()->Post("Command Status not handled\n", BLACKBOARD_KIT); break; } @@ -415,21 +415,21 @@ void LocalDeviceImpl::RemoteNameRequestComplete(struct hci_remote_name_request_complete_reply* remotename, BMessage* request) { BMessage reply; - - reply.AddInt8("status", remotename->status); - + + reply.AddInt8("status", remotename->status); + if (remotename->status == BT_OK) { - - reply.AddString("friendlyname", (const char*)remotename->remote_name ); + + reply.AddString("friendlyname", (const char*)remotename->remote_name ); Output::Instance()->Post("Positive reply for remote friendly name\n", BLACKBOARD_KIT); } else { - Output::Instance()->Post("Negative reply for remote friendly name\n", BLACKBOARD_KIT); + Output::Instance()->Post("Negative reply for remote friendly name\n", BLACKBOARD_KIT); } - printf("Sending reply ... %ld\n", request->SendReply(&reply)); + printf("Sending reply ... %ld\n", request->SendReply(&reply)); reply.PrintToStream(); // This request is not genna be used anymore diff --git a/src/servers/bluetooth/LocalDeviceImpl.h b/src/servers/bluetooth/LocalDeviceImpl.h index a5ed210f77..406f7d631f 100644 --- a/src/servers/bluetooth/LocalDeviceImpl.h +++ b/src/servers/bluetooth/LocalDeviceImpl.h @@ -37,8 +37,8 @@ public: status_t ProcessSimpleRequest(BMessage* request); /* Events handling */ - void CommandComplete(struct hci_ev_cmd_complete* event, BMessage* request); - void CommandStatus(struct hci_ev_cmd_status* event, BMessage* request); + void CommandComplete(struct hci_ev_cmd_complete* event, BMessage* request, int32 index); + void CommandStatus(struct hci_ev_cmd_status* event, BMessage* request, int32 index); // Inquiry void InquiryResult(uint8* numberOfResponses, BMessage* request);