- Fix correct handling of the command status event

- Fix Removal of specifil event wanted in a given request



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24971 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Ruiz Dorantes
2008-04-15 17:17:47 +00:00
parent 088fb3cd47
commit 717c9b00f2
2 changed files with 38 additions and 40 deletions
+27 -28
View File
@@ -74,50 +74,49 @@ LocalDeviceHandler::ClearWantedEvent(BMessage* msg)
void void
LocalDeviceHandler::ClearWantedEvent(BMessage* msg, uint16 event, uint16 opcode = 0) LocalDeviceHandler::ClearWantedEvent(BMessage* msg, uint16 event, uint16 opcode)
{ {
// Remove the whole petition from queue // Remove the whole petition from queue
fEventsWanted.Lock(); fEventsWanted.Lock();
int16 eventFound; int16 eventFound;
int16 opcodeFound; int16 opcodeFound;
int32 eventIndex; int32 eventIndex = 0;
for (int32 index = 0 ; index < fEventsWanted.CountMessages() ; index++) { // for each Event
while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) {
BMessage* msg = fEventsWanted.FindMessage(index);
eventIndex = 0; printf("@ Event expected found @%ld\n", eventIndex);
// for each Event
while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) { if (eventFound == event) {
if (eventFound == event) {
printf("@ Event matches %ld\n", eventIndex);
// there is an opcode specified // there is an opcode specified
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
(void)msg->RemoveData("eventExpected", eventIndex); printf("@ Removed event %d and opcoce %d from message %p\n", event, opcode, msg);
(void)msg->RemoveData("opcodeExpected", eventIndex);
goto bail;
}
} else {
// Event matches so far
(void)msg->RemoveData("eventExpected", eventIndex); (void)msg->RemoveData("eventExpected", eventIndex);
(void)msg->RemoveData("opcodeExpected", eventIndex);
goto bail; 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: bail:
fEventsWanted.RemoveMessage(msg);
fEventsWanted.Unlock(); fEventsWanted.Unlock();
} }
+11 -12
View File
@@ -95,7 +95,7 @@ printf("### \n");
} else if ( event->ecode == HCI_EVENT_CMD_STATUS ) { } 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 ); request = FindPetition(event->ecode, ((struct hci_ev_cmd_status*)(event+1))->opcode );
} else } else
@@ -346,17 +346,15 @@ LocalDeviceImpl::CommandStatus(struct hci_ev_cmd_status* event, BMessage* reques
switch (opcodeExpected) { switch (opcodeExpected) {
case PACK_OPCODE(OGF_INFORMATIONAL_PARAM, OCF_READ_BD_ADDR): case PACK_OPCODE(OGF_LINK_CONTROL, OCF_INQUIRY):
{ {
struct hci_ev_cmd_status* commandStatus = (struct hci_ev_cmd_status*)(event+1);
reply.what = BT_MSG_INQUIRY_STARTED; reply.what = BT_MSG_INQUIRY_STARTED;
reply.AddInt8("status", commandStatus->status); reply.AddInt8("status", event->status);
if (commandStatus->status == BT_OK) { if (event->status == BT_OK) {
Output::Instance()->Post("Positive reply for inquiry\n", BLACKBOARD_KIT); Output::Instance()->Post("Positive reply for inquiry status\n", BLACKBOARD_KIT);
} else { } 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)); 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)); 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); BMessage reply(BT_MSG_INQUIRY_COMPLETED);
reply.AddInt8("status", *status); reply.AddInt8("status", *status);
printf("%s: Sending reply ... %ld\n",__FUNCTION__, request->SendReply(&reply)); printf("%s: Sending reply ... %ld\n",__FUNCTION__, request->SendReply(&reply));
ClearWantedEvent(request);
} }