- Implement RemoteDevice::GetFriendlyName() in kit and handle the required reply in the server.
- Now a discovery process is nicer. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25053 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -60,6 +60,7 @@ class LocalDevice {
|
||||
hci_id GetID(void) {return hid;}
|
||||
|
||||
friend class DiscoveryAgent;
|
||||
friend class RemoteDevice;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -9,9 +9,19 @@
|
||||
#include <bluetooth/DiscoveryAgent.h>
|
||||
#include <bluetooth/DiscoveryListener.h>
|
||||
#include <bluetooth/bdaddrUtils.h>
|
||||
#include <bluetooth/LocalDevice.h>
|
||||
|
||||
#include <bluetooth/RemoteDevice.h>
|
||||
|
||||
#include <bluetoothserver_p.h>
|
||||
#include <bluetooth/HCI/btHCI_command.h>
|
||||
#include <bluetooth/HCI/btHCI_event.h>
|
||||
#include <CommandManager.h>
|
||||
|
||||
#include "KitSupport.h"
|
||||
|
||||
|
||||
|
||||
namespace Bluetooth {
|
||||
|
||||
|
||||
@@ -21,11 +31,54 @@ RemoteDevice::IsTrustedDevice(void)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
BString
|
||||
RemoteDevice::GetFriendlyName(bool alwaysAsk)
|
||||
{
|
||||
return BString("Not implemented");
|
||||
|
||||
if (!alwaysAsk) {
|
||||
// Check if the name is already retrieved
|
||||
return BString("Not implemented");
|
||||
|
||||
// TODO: Check if It is known from a KnownDevicesList
|
||||
}
|
||||
|
||||
if (fDiscovererLocalDevice == NULL)
|
||||
return BString("#NoOwnerError#Not Valid name");
|
||||
|
||||
BMessenger* btsm = NULL;
|
||||
size_t size;
|
||||
|
||||
if ((btsm = _RetrieveBluetoothMessenger()) == NULL)
|
||||
return BString("#ServerNotReady#Not Valid name");
|
||||
|
||||
void* remoteNameCommand = NULL;
|
||||
|
||||
/* Issue inquiry command */
|
||||
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
|
||||
BMessage reply;
|
||||
|
||||
request.AddInt32("hci_id", fDiscovererLocalDevice->GetID());
|
||||
|
||||
// Fill the request
|
||||
remoteNameCommand = buildRemoteNameRequest(fBdaddr, fPageRepetitionMode, fClockOffset, &size); // Fill correctily
|
||||
|
||||
request.AddData("raw command", B_ANY_TYPE, remoteNameCommand, size);
|
||||
|
||||
request.AddInt16("eventExpected", HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE);
|
||||
//request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_REMOTE_NAME_REQUEST));
|
||||
|
||||
if (btsm->SendMessage(&request, &reply) == B_OK)
|
||||
{
|
||||
BString name;
|
||||
int8 status;
|
||||
|
||||
if (reply.FindInt8("status", &status) == B_OK &&
|
||||
reply.FindString("friendlyname", &name) == B_OK ) {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
return BString("#NotCompletedRequestr#Not Valid name");
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +92,9 @@ RemoteDevice::GetBluetoothAddress()
|
||||
bool
|
||||
RemoteDevice::Equals(RemoteDevice* obj)
|
||||
{
|
||||
return true;
|
||||
bdaddr_t ba = obj->GetBluetoothAddress();
|
||||
|
||||
return bdaddrUtils::Compare(&fBdaddr, &ba);
|
||||
}
|
||||
|
||||
// static RemoteDevice* GetRemoteDevice(Connection conn);
|
||||
@@ -87,7 +142,7 @@ RemoteDevice::RemoteDevice(bdaddr_t address)
|
||||
RemoteDevice::RemoteDevice(BString address)
|
||||
{
|
||||
/* TODO */
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -128,6 +128,7 @@ printf("### \n");
|
||||
break;
|
||||
|
||||
case HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE:
|
||||
RemoteNameRequestComplete((struct hci_remote_name_request_complete_reply*)(event+1), request);
|
||||
break;
|
||||
|
||||
case HCI_EVENT_ENCRYPT_CHANGE:
|
||||
@@ -149,11 +150,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);
|
||||
break;
|
||||
|
||||
case HCI_EVENT_CMD_STATUS:
|
||||
CommandStatus((struct hci_ev_cmd_status*)(event+1), request);
|
||||
CommandStatus((struct hci_ev_cmd_status*)(event+1), request);
|
||||
break;
|
||||
|
||||
case HCI_EVENT_FLUSH_OCCUR:
|
||||
@@ -402,6 +403,34 @@ LocalDeviceImpl::InquiryComplete(uint8* status, BMessage* request)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
LocalDeviceImpl::RemoteNameRequestComplete(struct hci_remote_name_request_complete_reply* remotename, BMessage* request)
|
||||
{
|
||||
BMessage reply;
|
||||
|
||||
reply.AddInt8("status", remotename->status);
|
||||
|
||||
if (remotename->status == BT_OK) {
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
printf("Sending reply ... %ld\n", request->SendReply(&reply));
|
||||
reply.PrintToStream();
|
||||
|
||||
// This request is not genna be used anymore
|
||||
// Although there are many middle events that should be tracked
|
||||
ClearWantedEvent(request);
|
||||
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
#pragma mark - Request Methods -
|
||||
#endif
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
// Inquiry
|
||||
void InquiryResult(uint8* numberOfResponses, BMessage* request);
|
||||
void InquiryComplete(uint8* status, BMessage* request);
|
||||
|
||||
void RemoteNameRequestComplete(struct hci_remote_name_request_complete_reply* remotename, BMessage* request);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user