- Add capability to the server to handle Command Status events

- Add capability to reply the inquiry started command status



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24700 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Ruiz Dorantes 2008-03-30 21:53:37 +00:00
parent d581ede6e2
commit fd223db5ad
4 changed files with 75 additions and 13 deletions

View File

@ -63,17 +63,21 @@ LocalDeviceHandler::AddWantedEvent(BMessage* msg)
fEventsWanted.Unlock();
}
void
LocalDeviceHandler::ClearWantedEvent(BMessage* msg)
{
fEventsWanted.Lock();
fEventsWanted.RemoveMessage(msg);
fEventsWanted.Unlock();
}
void
LocalDeviceHandler::ClearWantedEvent(BMessage* msg, uint16 event = 0, uint16 opcode = 0)
LocalDeviceHandler::ClearWantedEvent(BMessage* msg, uint16 event, uint16 opcode = 0)
{
// Remove the whole petition from queue
fEventsWanted.Lock();
/*
if (event == 0) {
fEventsWanted.RemoveMessage(msg);
goto bail;
}
fEventsWanted.Lock();
int16 eventFound;
int16 opcodeFound;
@ -89,17 +93,19 @@ LocalDeviceHandler::ClearWantedEvent(BMessage* msg, uint16 event = 0, uint16 opc
if (eventFound == event) {
// there is an opcode specified
if (opcde != 0)
if (opcode != 0) {
// The opcode matches
if ( (msg->FindInt16("opcodeExpected", eventIndex, &opcodeFound) == B_OK) &&
((uint16)opcodeFound != opcode) ) {
// FIX: this should remove only the entry
fEventsWanted.RemoveMessage(msg);
goto bail;
}
} else {
// Event matches so far
// FIX: this should remove only the entry
fEventsWanted.RemoveMessage(msg);
goto bail;
}
@ -109,9 +115,9 @@ LocalDeviceHandler::ClearWantedEvent(BMessage* msg, uint16 event = 0, uint16 opc
}
}
bail: */
fEventsWanted.RemoveMessage(msg);
bail:
fEventsWanted.RemoveMessage(msg);
fEventsWanted.Unlock();
}

View File

@ -37,7 +37,9 @@ protected:
BMessage* fProperties;
void AddWantedEvent(BMessage* msg);
void ClearWantedEvent(BMessage* msg, uint16 code, uint16 opcode = 0);
void ClearWantedEvent(BMessage* msg, uint16 event, uint16 opcode = 0);
void ClearWantedEvent(BMessage* msg);
BMessage* FindPetition(uint16 event, uint16 opcode = 0);
private:

View File

@ -15,6 +15,8 @@
#include <bluetooth/bluetooth_error.h>
#include <bluetooth/HCI/btHCI_event.h>
#include <bluetoothserver_p.h>
#include <stdio.h>
@ -91,8 +93,12 @@ printf("### \n");
(Output::Instance()->Post("Incoming Command Complete\n", BLACKBOARD_EVENTS));
request = FindPetition(event->ecode, ((struct hci_ev_cmd_complete*)(event+1))->opcode );
} else if ( event->ecode == HCI_EVENT_CMD_STATUS ) {
(Output::Instance()->Post("Incoming Command Complete\n", BLACKBOARD_EVENTS));
request = FindPetition(event->ecode, ((struct hci_ev_cmd_status*)(event+1))->opcode );
} else
// TODO: Command status should also be considered
{
request = FindPetition(event->ecode);
}
@ -145,6 +151,7 @@ printf("### \n");
break;
case HCI_EVENT_CMD_STATUS:
CommandStatus((struct hci_ev_cmd_status*)(event+1), request);
break;
case HCI_EVENT_FLUSH_OCCUR:
@ -313,6 +320,52 @@ LocalDeviceImpl::CommandComplete(struct hci_ev_cmd_complete* event, BMessage* re
}
void
LocalDeviceImpl::CommandStatus(struct hci_ev_cmd_status* event, BMessage* request) {
int16 opcodeExpected;
BMessage reply;
Output::Instance()->Post(__FUNCTION__, BLACKBOARD_LD_OFFSET + GetID());
Output::Instance()->Post("\n", BLACKBOARD_LD_OFFSET + GetID());
// Handle command complete information
request->FindInt16("opcodeExpected", 0 /*REVIEW!*/, &opcodeExpected);
if (request->IsSourceWaiting() == false)
Output::Instance()->Post("Nobody waiting for the event\n", BLACKBOARD_KIT);
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);
reply.what = BT_MSG_INQUIRY_STARTED;
reply.AddInt8("status", commandStatus->status);
if (commandStatus->status == BT_OK) {
Output::Instance()->Post("Positive reply for inquiry\n", BLACKBOARD_KIT);
} else {
Output::Instance()->Post("Negative reply for friendly name\n", BLACKBOARD_KIT);
}
printf("Sending reply ... %ld\n",request->SendReply(&reply));
reply.PrintToStream();
ClearWantedEvent(request, PACK_OPCODE(OGF_LINK_CONTROL, OCF_INQUIRY));
}
break;
default:
Output::Instance()->Post("Command Status not handled\n", BLACKBOARD_KIT);
break;
}
}
#if 0
#pragma mark - Request Methods -
#endif

View File

@ -38,6 +38,7 @@ public:
/* Events handling */
void CommandComplete(struct hci_ev_cmd_complete* event, BMessage* request);
void CommandStatus(struct hci_ev_cmd_status* event, BMessage* request);
};