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
+174 -72
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() )
sfMessenger = new BMessenger();
return NULL; 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;
}
LocalDevice* #if 0
LocalDevice::GetLocalDevice(uint8 dev) #pragma -
{ #endif
return NULL;
}
LocalDevice* LocalDevice*
LocalDevice::GetLocalDevice(bdaddr_t bdaddr) LocalDevice::GetLocalDevice()
{ {
if (SRetrieveBluetoothMessenger() != B_OK)
return NULL;
return NULL; BMessage request(BT_MSG_ADQUIRE_LOCAL_DEVICE);
} return RequestLocalDeviceID(&request);
}
DiscoveryAgent* LocalDevice*
LocalDevice::GetDiscoveryAgent() LocalDevice::GetLocalDevice(hci_id hid)
{ {
if (SRetrieveBluetoothMessenger() != B_OK)
return NULL;
return NULL; BMessage request(BT_MSG_ADQUIRE_LOCAL_DEVICE);
} request.AddInt32("hci_id", hid);
return RequestLocalDeviceID(&request);
}
BString LocalDevice*
LocalDevice::GetFriendlyName() LocalDevice::GetLocalDevice(bdaddr_t bdaddr)
{ {
if (SRetrieveBluetoothMessenger() != B_OK)
return NULL;
return NULL; BMessage request(BT_MSG_ADQUIRE_LOCAL_DEVICE);
} request.AddData("bdaddr", B_ANY_TYPE, &bdaddr, sizeof(bdaddr_t));
DeviceClass return RequestLocalDeviceID(&request);
LocalDevice::GetDeviceClass() }
{
return NULL;
}
bool uint32
LocalDevice::SetDiscoverable(int mode) LocalDevice::GetLocalDeviceCount()
{ {
if (SRetrieveBluetoothMessenger() != B_OK)
return NULL;
return false; BMessage request(BT_MSG_COUNT_LOCAL_DEVICES);
} BMessage reply;
if (sfMessenger->SendMessage(&request, &reply) == B_OK)
return reply.FindInt32("count");
else
return B_ERROR;
}
BString DiscoveryAgent*
LocalDevice::GetProperty(const char* property) LocalDevice::GetDiscoveryAgent()
{ {
return NULL; return NULL;
}
}
void BString
LocalDevice::GetProperty(const char* property, uint32* value) LocalDevice::GetFriendlyName()
{ {
if (RetrieveBluetoothMessenger() != B_OK)
return NULL;
*value = 0; 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");
}
int DeviceClass
LocalDevice::GetDiscoverable() LocalDevice::GetDeviceClass()
{ {
return 0; return NULL;
} }
BString bool
LocalDevice::GetBluetoothAddress() LocalDevice::SetDiscoverable(int mode)
{ {
return NULL; return false;
} }
/* BString
ServiceRecord LocalDevice::GetProperty(const char* property)
LocalDevice::getRecord(Connection notifier) { {
} return NULL;
void }
LocalDevice::updateRecord(ServiceRecord srvRecord) {
}
*/
LocalDevice::LocalDevice()
{
} 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)
{
}
} }