Update LocalDevice class with basic bluetooth_server comunication. Server code still to come. Nothing except the driver tested at the moment... I hope after these nothing is broken

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23817 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Ruiz Dorantes 2008-02-01 21:24:17 +00:00
parent b06bf23fb5
commit 308050e89a
3 changed files with 211 additions and 107 deletions

View File

@ -52,7 +52,7 @@ DiscoveryListener::MessageReceived(BMessage* message)
case B_BT_INQUIRY_DEVICE_MSG:
/* TODO: Extract info from BMessage to create a
proper RemoteDevice, ¿¿¿message should be passed from Agent??? */
proper RemoteDevice, message should be passed from Agent??? */
/* - Instance to be stored/Registered in the Agent? */
//DeviceDiscovered( RemoteDevice(BString("00:00:00:00:00:00")), DeviceClass(0));

View File

@ -1,5 +1,7 @@
SubDir HAIKU_TOP src kits bluetooth ;
UsePrivateHeaders bluetooth ;
SharedLibrary libbluetooth.so :
LocalDevice.cpp
DiscoveryListener.cpp

View File

@ -5,123 +5,225 @@
*
*/
#include <bluetooth/LocalDevice.h>
#include <bluetooth/RemoteDevice.h>
#include <bluetooth/DeviceClass.h>
#include <bluetooth/DiscoveryAgent.h>
#include <bluetooth/RemoteDevice.h>
#include <bluetooth/bdaddrUtils.h>
#include "bluetoothserver_p.h"
namespace Bluetooth {
BMessenger* LocalDevice::sfMessenger = NULL;
LocalDevice*
LocalDevice::GetLocalDevice()
{
return NULL;
}
LocalDevice*
LocalDevice::GetLocalDevice(uint8 dev)
{
return NULL;
}
LocalDevice*
LocalDevice::GetLocalDevice(bdaddr_t bdaddr)
{
return NULL;
status_t
LocalDevice::SRetrieveBluetoothMessenger(void)
{
if (sfMessenger == NULL || !sfMessenger->IsValid() )
sfMessenger = new BMessenger();
return (sfMessenger != NULL)?B_OK:B_ERROR;
}
status_t LocalDevice::RetrieveBluetoothMessenger(void)
{
if (fMessenger == NULL || !fMessenger->IsValid())
fMessenger = new BMessenger();
return (fMessenger != NULL)?B_OK:B_ERROR;
}
LocalDevice*
LocalDevice::RequestLocalDeviceID(BMessage* request)
{
BMessage reply;
hci_id hid;
if (sfMessenger->SendMessage(request, &reply) == B_OK &&
reply.FindInt32("hci_id", &hid) == B_OK ){
if (hid > 0)
return new LocalDevice(hid);
}
return NULL;
}
#if 0
#pragma -
#endif
LocalDevice*
LocalDevice::GetLocalDevice()
{
if (SRetrieveBluetoothMessenger() != B_OK)
return NULL;
BMessage request(BT_MSG_ADQUIRE_LOCAL_DEVICE);
return RequestLocalDeviceID(&request);
}
LocalDevice*
LocalDevice::GetLocalDevice(hci_id hid)
{
if (SRetrieveBluetoothMessenger() != B_OK)
return NULL;
BMessage request(BT_MSG_ADQUIRE_LOCAL_DEVICE);
request.AddInt32("hci_id", hid);
return RequestLocalDeviceID(&request);
}
LocalDevice*
LocalDevice::GetLocalDevice(bdaddr_t bdaddr)
{
if (SRetrieveBluetoothMessenger() != B_OK)
return NULL;
BMessage request(BT_MSG_ADQUIRE_LOCAL_DEVICE);
request.AddData("bdaddr", B_ANY_TYPE, &bdaddr, sizeof(bdaddr_t));
return RequestLocalDeviceID(&request);
}
uint32
LocalDevice::GetLocalDeviceCount()
{
if (SRetrieveBluetoothMessenger() != B_OK)
return NULL;
BMessage request(BT_MSG_COUNT_LOCAL_DEVICES);
BMessage reply;
if (sfMessenger->SendMessage(&request, &reply) == B_OK)
return reply.FindInt32("count");
else
return B_ERROR;
}
}
DiscoveryAgent*
LocalDevice::GetDiscoveryAgent()
{
return NULL;
}
BString
LocalDevice::GetFriendlyName()
{
if (RetrieveBluetoothMessenger() != B_OK)
return NULL;
BString friendlyname;
BMessage request(BT_MSG_GET_FRIENDLY_NAME);
BMessage reply;
/* ADD ID */
request.AddInt32("hci_id", hid);
if (fMessenger->SendMessage(&request, &reply) == B_OK &&
reply.FindString("friendlyname", &friendlyname) == B_OK ){
return friendlyname;
}
DiscoveryAgent*
LocalDevice::GetDiscoveryAgent()
{
return NULL;
}
BString
LocalDevice::GetFriendlyName()
{
return NULL;
}
DeviceClass
LocalDevice::GetDeviceClass()
{
return NULL;
}
bool
LocalDevice::SetDiscoverable(int mode)
{
return false;
}
BString
LocalDevice::GetProperty(const char* property)
{
return NULL;
}
void
LocalDevice::GetProperty(const char* property, uint32* value)
{
*value = 0;
}
int
LocalDevice::GetDiscoverable()
{
return 0;
}
BString
LocalDevice::GetBluetoothAddress()
{
return NULL;
}
/*
ServiceRecord
LocalDevice::getRecord(Connection notifier) {
}
void
LocalDevice::updateRecord(ServiceRecord srvRecord) {
}
*/
LocalDevice::LocalDevice()
{
}
return BString("Unknown");
}
DeviceClass
LocalDevice::GetDeviceClass()
{
return NULL;
}
bool
LocalDevice::SetDiscoverable(int mode)
{
return false;
}
BString
LocalDevice::GetProperty(const char* property)
{
return NULL;
}
void
LocalDevice::GetProperty(const char* property, uint32* value)
{
*value = 0;
}
int
LocalDevice::GetDiscoverable()
{
return 0;
}
bdaddr_t
LocalDevice::GetBluetoothAddress()
{
if (RetrieveBluetoothMessenger() != B_OK)
return bdaddrUtils::NullAddress();
bdaddr_t bdaddr;
BMessage request(BT_MSG_GET_ADDRESS);
BMessage reply;
ssize_t size;
/* ADD ID */
request.AddInt32("hci_id", hid);
if (fMessenger->SendMessage(&request, &reply) == B_OK &&
reply.FindData("bdaddr", B_ANY_TYPE, 0, (const void**)&bdaddr, &size) == B_OK ){
return bdaddr;
}
return bdaddrUtils::NullAddress();
}
/*
ServiceRecord
LocalDevice::getRecord(Connection notifier) {
}
void
LocalDevice::updateRecord(ServiceRecord srvRecord) {
}
*/
LocalDevice::LocalDevice(hci_id hid) : hid(hid)
{
}
}