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
+1 -1
View File
@@ -52,7 +52,7 @@ DiscoveryListener::MessageReceived(BMessage* message)
case B_BT_INQUIRY_DEVICE_MSG: case B_BT_INQUIRY_DEVICE_MSG:
/* TODO: Extract info from BMessage to create a /* 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? */ /* - Instance to be stored/Registered in the Agent? */
//DeviceDiscovered( RemoteDevice(BString("00:00:00:00:00:00")), DeviceClass(0)); //DeviceDiscovered( RemoteDevice(BString("00:00:00:00:00:00")), DeviceClass(0));
+2
View File
@@ -1,5 +1,7 @@
SubDir HAIKU_TOP src kits bluetooth ; SubDir HAIKU_TOP src kits bluetooth ;
UsePrivateHeaders bluetooth ;
SharedLibrary libbluetooth.so : SharedLibrary libbluetooth.so :
LocalDevice.cpp LocalDevice.cpp
DiscoveryListener.cpp DiscoveryListener.cpp
+208 -106
View File
@@ -5,123 +5,225 @@
* *
*/ */
#include <bluetooth/LocalDevice.h> #include <bluetooth/LocalDevice.h>
#include <bluetooth/RemoteDevice.h>
#include <bluetooth/DeviceClass.h> #include <bluetooth/DeviceClass.h>
#include <bluetooth/DiscoveryAgent.h> #include <bluetooth/DiscoveryAgent.h>
#include <bluetooth/RemoteDevice.h>
#include <bluetooth/bdaddrUtils.h> #include <bluetooth/bdaddrUtils.h>
#include "bluetoothserver_p.h"
namespace Bluetooth { namespace Bluetooth {
BMessenger* LocalDevice::sfMessenger = NULL;
LocalDevice* status_t
LocalDevice::GetLocalDevice() LocalDevice::SRetrieveBluetoothMessenger(void)
{ {
if (sfMessenger == NULL || !sfMessenger->IsValid() )
return NULL; sfMessenger = new BMessenger();
}
return (sfMessenger != NULL)?B_OK:B_ERROR;
}
LocalDevice*
LocalDevice::GetLocalDevice(uint8 dev) status_t LocalDevice::RetrieveBluetoothMessenger(void)
{ {
if (fMessenger == NULL || !fMessenger->IsValid())
return NULL; fMessenger = new BMessenger();
} return (fMessenger != NULL)?B_OK:B_ERROR;
}
LocalDevice* LocalDevice*
LocalDevice::GetLocalDevice(bdaddr_t bdaddr) LocalDevice::RequestLocalDeviceID(BMessage* request)
{ {
BMessage reply;
return NULL; 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;
}
return BString("Unknown");
DiscoveryAgent* }
LocalDevice::GetDiscoveryAgent()
{
DeviceClass
return NULL; LocalDevice::GetDeviceClass()
} {
return NULL;
BString }
LocalDevice::GetFriendlyName()
{
bool
return NULL; LocalDevice::SetDiscoverable(int mode)
} {
return false;
DeviceClass }
LocalDevice::GetDeviceClass()
{
BString
return NULL; LocalDevice::GetProperty(const char* property)
} {
return NULL;
bool
LocalDevice::SetDiscoverable(int mode) }
{
return false; void
} LocalDevice::GetProperty(const char* property, uint32* value)
{
BString *value = 0;
LocalDevice::GetProperty(const char* property) }
{
return NULL; int
LocalDevice::GetDiscoverable()
} {
return 0;
void }
LocalDevice::GetProperty(const char* property, uint32* value)
{
bdaddr_t
*value = 0; LocalDevice::GetBluetoothAddress()
} {
if (RetrieveBluetoothMessenger() != B_OK)
return bdaddrUtils::NullAddress();
int
LocalDevice::GetDiscoverable() bdaddr_t bdaddr;
{ BMessage request(BT_MSG_GET_ADDRESS);
BMessage reply;
return 0; ssize_t size;
} /* ADD ID */
request.AddInt32("hci_id", hid);
BString if (fMessenger->SendMessage(&request, &reply) == B_OK &&
LocalDevice::GetBluetoothAddress() reply.FindData("bdaddr", B_ANY_TYPE, 0, (const void**)&bdaddr, &size) == B_OK ){
{
return bdaddr;
return NULL; }
}
return bdaddrUtils::NullAddress();
}
/*
ServiceRecord
LocalDevice::getRecord(Connection notifier) { /*
ServiceRecord
} LocalDevice::getRecord(Connection notifier) {
void }
LocalDevice::updateRecord(ServiceRecord srvRecord) {
void
} LocalDevice::updateRecord(ServiceRecord srvRecord) {
*/
LocalDevice::LocalDevice() }
{ */
LocalDevice::LocalDevice(hci_id hid) : hid(hid)
} {
}
} }