Fix a serious TODO,
Report the index where the event opcode pair has been found. Currently server was expecting them to be the first entry of the request git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26198 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
5c5b7a5760
commit
480cccf67b
@ -82,39 +82,39 @@ LocalDeviceHandler::ClearWantedEvent(BMessage* msg, uint16 event, uint16 opcode)
|
|||||||
int16 eventFound;
|
int16 eventFound;
|
||||||
int16 opcodeFound;
|
int16 opcodeFound;
|
||||||
int32 eventIndex = 0;
|
int32 eventIndex = 0;
|
||||||
|
|
||||||
// for each Event
|
// for each Event
|
||||||
while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) {
|
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) {
|
if (eventFound == event) {
|
||||||
|
|
||||||
printf("@ Event matches %ld\n", eventIndex);
|
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
|
||||||
printf("@ Removed event %d and opcoce %d from message %p\n", event, opcode, msg);
|
printf("@ Removed event %d and opcoce %d from message %p\n", event, opcode, msg);
|
||||||
(void)msg->RemoveData("eventExpected", eventIndex);
|
(void)msg->RemoveData("eventExpected", eventIndex);
|
||||||
(void)msg->RemoveData("opcodeExpected", eventIndex);
|
(void)msg->RemoveData("opcodeExpected", eventIndex);
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Event matches so far
|
// 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);
|
(void)msg->RemoveData("eventExpected", eventIndex);
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
eventIndex++;
|
eventIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
|
|
||||||
fEventsWanted.Unlock();
|
fEventsWanted.Unlock();
|
||||||
@ -123,45 +123,48 @@ bail:
|
|||||||
|
|
||||||
|
|
||||||
BMessage*
|
BMessage*
|
||||||
LocalDeviceHandler::FindPetition(uint16 event, uint16 opcode)
|
LocalDeviceHandler::FindPetition(uint16 event, uint16 opcode, int32* indexFound)
|
||||||
{
|
{
|
||||||
int16 eventFound;
|
int16 eventFound;
|
||||||
int16 opcodeFound;
|
int16 opcodeFound;
|
||||||
int32 eventIndex;
|
int32 eventIndex;
|
||||||
|
|
||||||
fEventsWanted.Lock();
|
fEventsWanted.Lock();
|
||||||
// for each Petition
|
// for each Petition
|
||||||
for (int32 index = 0 ; index < fEventsWanted.CountMessages() ; index++) {
|
for (int32 index = 0 ; index < fEventsWanted.CountMessages() ; index++) {
|
||||||
BMessage* msg = fEventsWanted.FindMessage(index);
|
BMessage* msg = fEventsWanted.FindMessage(index);
|
||||||
|
|
||||||
printf("Petition %ld ... of %ld msg #%p\n", index, fEventsWanted.CountMessages(), msg);
|
printf("Petition %ld ... of %ld msg #%p\n", index, fEventsWanted.CountMessages(), msg);
|
||||||
msg->PrintToStream();
|
msg->PrintToStream();
|
||||||
eventIndex = 0;
|
eventIndex = 0;
|
||||||
// for each Event
|
|
||||||
|
// for each Event
|
||||||
while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) {
|
while (msg->FindInt16("eventExpected", eventIndex, &eventFound) == B_OK ) {
|
||||||
if (eventFound == event) {
|
if (eventFound == event) {
|
||||||
|
|
||||||
printf("Event found %ld\n", eventIndex);
|
printf("Event found %ld\n", eventIndex);
|
||||||
// there is an opcode specified..
|
// there is an opcode specified..
|
||||||
if (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK) {
|
if (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK) {
|
||||||
|
|
||||||
// ensure the opcode
|
// ensure the opcode
|
||||||
if ((uint16)opcodeFound != opcode) {
|
if ((uint16)opcodeFound != opcode) {
|
||||||
printf("opcode does not match %d\n", opcode);
|
printf("opcode does not match %d\n", opcode);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
printf("Opcdodes match %d %d \n", opcode , opcodeFound);
|
printf("Opcdodes match %d %d \n", opcode , opcodeFound);
|
||||||
}
|
}
|
||||||
|
|
||||||
fEventsWanted.Unlock();
|
fEventsWanted.Unlock();
|
||||||
|
if (indexFound != NULL)
|
||||||
|
*indexFound = eventIndex;
|
||||||
return msg;
|
return msg;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
eventIndex++;
|
eventIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fEventsWanted.Unlock();
|
fEventsWanted.Unlock();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ protected:
|
|||||||
void ClearWantedEvent(BMessage* msg, uint16 event, uint16 opcode = 0);
|
void ClearWantedEvent(BMessage* msg, uint16 event, uint16 opcode = 0);
|
||||||
void ClearWantedEvent(BMessage* msg);
|
void ClearWantedEvent(BMessage* msg);
|
||||||
|
|
||||||
BMessage* FindPetition(uint16 event, uint16 opcode = 0);
|
BMessage* FindPetition(uint16 event, uint16 opcode = 0, int32* indexFound = NULL);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -98,17 +98,18 @@ printf("### \n");
|
|||||||
|
|
||||||
|
|
||||||
BMessage* request = NULL;
|
BMessage* request = NULL;
|
||||||
|
int32 eventIndexLocation;
|
||||||
|
|
||||||
// Check if its a requested one
|
// Check if its a requested one
|
||||||
if ( event->ecode == HCI_EVENT_CMD_COMPLETE ) {
|
if ( event->ecode == HCI_EVENT_CMD_COMPLETE ) {
|
||||||
|
|
||||||
(Output::Instance()->Post("Incoming Command Complete\n", BLACKBOARD_EVENTS));
|
(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 ) {
|
} else if ( event->ecode == HCI_EVENT_CMD_STATUS ) {
|
||||||
|
|
||||||
(Output::Instance()->Post("Incoming Command Status\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, &eventIndexLocation );
|
||||||
|
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
@ -160,11 +161,11 @@ printf("### \n");
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case HCI_EVENT_CMD_COMPLETE:
|
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;
|
break;
|
||||||
|
|
||||||
case HCI_EVENT_CMD_STATUS:
|
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;
|
break;
|
||||||
|
|
||||||
case HCI_EVENT_FLUSH_OCCUR:
|
case HCI_EVENT_FLUSH_OCCUR:
|
||||||
@ -230,7 +231,7 @@ printf("### \n");
|
|||||||
|
|
||||||
|
|
||||||
void
|
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;
|
int16 opcodeExpected;
|
||||||
BMessage reply;
|
BMessage reply;
|
||||||
@ -241,11 +242,11 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, BMessage* re
|
|||||||
// Handle command complete information
|
// Handle command complete information
|
||||||
// FIX ME! the expected code might me in another
|
// FIX ME! the expected code might me in another
|
||||||
// index as is relative to the event not the request
|
// 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)
|
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) {
|
switch (opcodeExpected) {
|
||||||
|
|
||||||
@ -332,7 +333,7 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, BMessage* re
|
|||||||
|
|
||||||
|
|
||||||
void
|
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;
|
int16 opcodeExpected;
|
||||||
BMessage reply;
|
BMessage reply;
|
||||||
@ -341,31 +342,30 @@ LocalDeviceImpl::CommandStatus(struct hci_ev_cmd_status* event, BMessage* reques
|
|||||||
Output::Instance()->Post("\n", BLACKBOARD_LD_OFFSET + GetID());
|
Output::Instance()->Post("\n", BLACKBOARD_LD_OFFSET + GetID());
|
||||||
|
|
||||||
// Handle command complete information
|
// Handle command complete information
|
||||||
request->FindInt16("opcodeExpected", 0 /*REVIEW!*/, &opcodeExpected);
|
request->FindInt16("opcodeExpected", index, &opcodeExpected);
|
||||||
|
|
||||||
|
|
||||||
if (request->IsSourceWaiting() == false)
|
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) {
|
switch (opcodeExpected) {
|
||||||
|
|
||||||
case PACK_OPCODE(OGF_LINK_CONTROL, OCF_INQUIRY):
|
case PACK_OPCODE(OGF_LINK_CONTROL, OCF_INQUIRY):
|
||||||
{
|
{
|
||||||
reply.what = BT_MSG_INQUIRY_STARTED;
|
reply.what = BT_MSG_INQUIRY_STARTED;
|
||||||
reply.AddInt8("status", event->status);
|
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);
|
Output::Instance()->Post("Positive reply for inquiry status\n", BLACKBOARD_KIT);
|
||||||
} else {
|
} 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();
|
reply.PrintToStream();
|
||||||
|
|
||||||
ClearWantedEvent(request, HCI_EVENT_CMD_STATUS, PACK_OPCODE(OGF_LINK_CONTROL, OCF_INQUIRY));
|
ClearWantedEvent(request, HCI_EVENT_CMD_STATUS, PACK_OPCODE(OGF_LINK_CONTROL, OCF_INQUIRY));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PACK_OPCODE(OGF_LINK_CONTROL, OCF_REMOTE_NAME_REQUEST):
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
Output::Instance()->Post("Command Status not handled\n", BLACKBOARD_KIT);
|
Output::Instance()->Post("Command Status not handled\n", BLACKBOARD_KIT);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -415,21 +415,21 @@ void
|
|||||||
LocalDeviceImpl::RemoteNameRequestComplete(struct hci_remote_name_request_complete_reply* remotename, BMessage* request)
|
LocalDeviceImpl::RemoteNameRequestComplete(struct hci_remote_name_request_complete_reply* remotename, BMessage* request)
|
||||||
{
|
{
|
||||||
BMessage reply;
|
BMessage reply;
|
||||||
|
|
||||||
reply.AddInt8("status", remotename->status);
|
reply.AddInt8("status", remotename->status);
|
||||||
|
|
||||||
if (remotename->status == BT_OK) {
|
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);
|
Output::Instance()->Post("Positive reply for remote friendly name\n", BLACKBOARD_KIT);
|
||||||
|
|
||||||
} else {
|
} 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();
|
reply.PrintToStream();
|
||||||
|
|
||||||
// This request is not genna be used anymore
|
// This request is not genna be used anymore
|
||||||
|
@ -37,8 +37,8 @@ public:
|
|||||||
status_t ProcessSimpleRequest(BMessage* request);
|
status_t ProcessSimpleRequest(BMessage* request);
|
||||||
|
|
||||||
/* Events handling */
|
/* Events handling */
|
||||||
void CommandComplete(struct hci_ev_cmd_complete* 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);
|
void CommandStatus(struct hci_ev_cmd_status* event, BMessage* request, int32 index);
|
||||||
|
|
||||||
// Inquiry
|
// Inquiry
|
||||||
void InquiryResult(uint8* numberOfResponses, BMessage* request);
|
void InquiryResult(uint8* numberOfResponses, BMessage* request);
|
||||||
|
Loading…
Reference in New Issue
Block a user