- Add method in LocalDevice class to write its class to the dongle

- Rework and style the DeviceClass class
- Implement option "Identify host as..." in preferences with mentioned method, this should allow us to be visible to more RemoteDevices



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31502 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Ruiz Dorantes
2009-07-10 14:19:17 +00:00
parent 2a3b755cbe
commit 981f1b1135
5 changed files with 147 additions and 51 deletions
+23 -16
View File
@@ -10,8 +10,7 @@
namespace Bluetooth { namespace Bluetooth {
#define UNKNOWN_CLASS_OF_DEVICE 0x00 #define UNKNOWN_CLASS_OF_DEVICE 0x000000
class DeviceClass { class DeviceClass {
@@ -26,45 +25,53 @@ public:
} }
DeviceClass(uint32 record) DeviceClass(uint8 major, uint8 minor, uint16 service)
{ {
SetRecord(record); SetRecord(major, minor, service);
} }
DeviceClass(void) DeviceClass(void)
{ {
this->record = UNKNOWN_CLASS_OF_DEVICE; fRecord = UNKNOWN_CLASS_OF_DEVICE;
} }
void SetRecord(uint8 record[3]) void SetRecord(uint8 record[3])
{ {
this->record = record[0]|record[1]<<8|record[2]<<16; fRecord = record[0]|record[1]<<8|record[2]<<16;
} }
void SetRecord(uint32 record) void SetRecord(uint8 major, uint8 minor, uint16 service)
{ {
this->record = record; fRecord = (minor & 0x3F) << 2;
fRecord |= (major & 0x1F) << 8;
fRecord |= (service & 0x7FF) << 13;
} }
uint GetServiceClass()
uint16 ServiceClass()
{ {
return (record & 0x00FFE000) >> 13; return (fRecord & 0x00FFE000) >> 13;
} }
uint GetMajorDeviceClass() uint8 MajorDeviceClass()
{ {
return (record & 0x00001F00) >> 8; return (fRecord & 0x00001F00) >> 8;
} }
uint GetMinorDeviceClass() uint8 MinorDeviceClass()
{ {
return (record & 0x000000FF) >> 2; return (fRecord & 0x000000FF) >> 2;
}
uint32 Record()
{
return fRecord;
} }
bool IsUnknownDeviceClass() bool IsUnknownDeviceClass()
{ {
return (record == UNKNOWN_CLASS_OF_DEVICE); return (fRecord == UNKNOWN_CLASS_OF_DEVICE);
} }
void GetServiceClass(BString&); void GetServiceClass(BString&);
@@ -76,7 +83,7 @@ public:
void Draw(BView* view, const BPoint& point); void Draw(BView* view, const BPoint& point);
private: private:
uint32 record; uint32 fRecord;
}; };
+2
View File
@@ -34,6 +34,8 @@ public:
DiscoveryAgent* GetDiscoveryAgent(); DiscoveryAgent* GetDiscoveryAgent();
BString GetFriendlyName(); BString GetFriendlyName();
DeviceClass GetDeviceClass(); DeviceClass GetDeviceClass();
status_t SetDeviceClass(DeviceClass deviceClass);
/* Possible throwing */ /* Possible throwing */
status_t SetDiscoverable(int mode); status_t SetDiscoverable(int mode);
+16 -11
View File
@@ -14,18 +14,23 @@ DeviceClass::GetServiceClass(BString& serviceClass)
"Rendering", "Capturing", "Object Transfer", "Rendering", "Capturing", "Object Transfer",
"Audio", "Telephony", "Information" }; "Audio", "Telephony", "Information" };
if (GetServiceClass() != 0) { if (ServiceClass() != 0) {
bool first = true;
for (uint s = 0; s < (sizeof(services) / sizeof(*services)); s++) { for (uint s = 0; s < (sizeof(services) / sizeof(*services)); s++) {
if (GetServiceClass() & (1 << s)) { if (ServiceClass() & (1 << s)) {
serviceClass << services[s]; if (first) {
if (s != 0) first = false;
serviceClass << ", "; serviceClass << services[s];
} else {
serviceClass << ", " << services[s];
}
} }
} }
} else } else
serviceClass << "Unspecified"; serviceClass << "Unspecified";
} }
@@ -36,10 +41,10 @@ DeviceClass::GetMajorDeviceClass(BString& majorClass)
static const char *major_devices[] = { "Miscellaneous", "Computer", "Phone", static const char *major_devices[] = { "Miscellaneous", "Computer", "Phone",
"LAN Access", "Audio/Video", "Peripheral", "Imaging", "Uncategorized" }; "LAN Access", "Audio/Video", "Peripheral", "Imaging", "Uncategorized" };
if (GetMajorDeviceClass() >= sizeof(major_devices) / sizeof(*major_devices)) if (MajorDeviceClass() >= sizeof(major_devices) / sizeof(*major_devices))
majorClass << "Invalid Device Class!\n"; majorClass << "Invalid Device Class!\n";
else else
majorClass << major_devices[GetMajorDeviceClass()]; majorClass << major_devices[MajorDeviceClass()];
} }
@@ -47,8 +52,8 @@ DeviceClass::GetMajorDeviceClass(BString& majorClass)
void void
DeviceClass::GetMinorDeviceClass(BString& minorClass) DeviceClass::GetMinorDeviceClass(BString& minorClass)
{ {
uint major = GetMajorDeviceClass(); uint major = MajorDeviceClass();
uint minor = GetMinorDeviceClass(); uint minor = MinorDeviceClass();
switch (major) { switch (major) {
case 0: /* misc */ case 0: /* misc */
@@ -327,7 +332,7 @@ DeviceClass::Draw(BView* view, const BPoint& point)
view->SetHighColor(kWhite); view->SetHighColor(kWhite);
switch (GetMajorDeviceClass()) { switch (MajorDeviceClass()) {
case 2: // phone case 2: // phone
view->StrokeRoundRect(BRect(point.x + IconInsets + uint(PixelsForIcon/4), view->StrokeRoundRect(BRect(point.x + IconInsets + uint(PixelsForIcon/4),
+39 -9
View File
@@ -211,7 +211,6 @@ LocalDevice::GetBluetoothAddress()
BMessage reply; BMessage reply;
ssize_t ssize; ssize_t ssize;
/* ADD ID */
request.AddInt32("hci_id", fHid); request.AddInt32("hci_id", fHid);
request.AddData("raw command", B_ANY_TYPE, command, size); request.AddData("raw command", B_ANY_TYPE, command, size);
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE); request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
@@ -270,7 +269,7 @@ DeviceClass
LocalDevice::GetDeviceClass() LocalDevice::GetDeviceClass()
{ {
if (fDeviceClass.IsUnknownDeviceClass()) { // if (fDeviceClass.IsUnknownDeviceClass()) {
if (fMessenger == NULL) if (fMessenger == NULL)
return fDeviceClass; return fDeviceClass;
@@ -282,7 +281,7 @@ LocalDevice::GetDeviceClass()
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
BMessage reply; BMessage reply;
const uint8* record; const uint8* bufferRecord;
ssize_t ssize; ssize_t ssize;
request.AddInt32("hci_id", fHid); request.AddInt32("hci_id", fHid);
@@ -292,26 +291,57 @@ LocalDevice::GetDeviceClass()
OCF_READ_CLASS_OF_DEV)); OCF_READ_CLASS_OF_DEV));
if (fMessenger->SendMessage(&request, &reply) == B_OK if (fMessenger->SendMessage(&request, &reply) == B_OK
&& reply.FindData("devclass", B_ANY_TYPE, 0, (const void**)&record, && reply.FindData("devclass", B_ANY_TYPE, 0, (const void**)&bufferRecord,
&ssize) == B_OK) { &ssize) == B_OK) {
uint8 record[3] = { bufferRecord[0], bufferRecord[1], bufferRecord[2] };
fDeviceClass.SetRecord(*record); fDeviceClass.SetRecord(record);
} }
} // }
return fDeviceClass; return fDeviceClass;
} }
status_t
LocalDevice::SetDeviceClass(DeviceClass deviceClass)
{
int8 bt_status = BT_ERROR;
if (fMessenger == NULL)
return bt_status;
BluetoothCommand<typed_command(hci_write_dev_class)>
setDeviceClass(OGF_CONTROL_BASEBAND, OCF_WRITE_CLASS_OF_DEV);
setDeviceClass->dev_class[0] = deviceClass.Record() & 0xFF;
setDeviceClass->dev_class[1] = (deviceClass.Record() & 0xFF00) >> 8;
setDeviceClass->dev_class[2] = (deviceClass.Record() & 0xFF0000) >> 16;
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
BMessage reply;
request.AddInt32("hci_id", fHid);
request.AddData("raw command", B_ANY_TYPE, setDeviceClass.Data(), setDeviceClass.Size());
request.AddInt16("eventExpected", HCI_EVENT_CMD_COMPLETE);
request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_CONTROL_BASEBAND,
OCF_WRITE_CLASS_OF_DEV));
if (fMessenger->SendMessage(&request, &reply) == B_OK)
reply.FindInt8("status", &bt_status);
return bt_status;
}
status_t status_t
LocalDevice::ReadLocalVersion() LocalDevice::ReadLocalVersion()
{ {
int8 bt_status = BT_ERROR; int8 bt_status = BT_ERROR;
BluetoothCommand<> localVersion(OGF_INFORMATIONAL_PARAM,OCF_READ_LOCAL_VERSION); BluetoothCommand<> localVersion(OGF_INFORMATIONAL_PARAM,OCF_READ_LOCAL_VERSION);
BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST);
BMessage reply; BMessage reply;
@@ -25,7 +25,12 @@
#include "BluetoothWindow.h" #include "BluetoothWindow.h"
static const int32 kMsgSetAntialiasing = 'anti'; static const int32 kMsgSetAntialiasing = 'anti';
static const int32 kMsgSetHinting = 'hint'; static const int32 kMsgSetDeviceClassDesktop = 'sDCd';
static const int32 kMsgSetDeviceClassServer = 'sDCs';
static const int32 kMsgSetDeviceClassLaptop = 'sDCl';
static const int32 kMsgSetDeviceClassNetbook = 'sDCn';
static const int32 kMsgSetDeviceClassSmartPhone = 'sDCp';
static const int32 kMsgSetAverageWeight = 'afEa'; static const int32 kMsgSetAverageWeight = 'afEa';
static const int32 kMsgLocalSwitched = 'lDsW'; static const int32 kMsgLocalSwitched = 'lDsW';
@@ -34,8 +39,10 @@ static const char* kTrustedLabel = "Only from Trusted devices";
static const char* kAlwaysLabel = "Always ask"; static const char* kAlwaysLabel = "Always ask";
static const char* kDesktopLabel = "Desktop"; static const char* kDesktopLabel = "Desktop";
static const char* kServerLabel = "Server";
static const char* kLaptopLabel = "Laptop"; static const char* kLaptopLabel = "Laptop";
static const char* kPhoneLabel = "Haiku Phone"; static const char* kNetBookLabel = "NetBook";
static const char* kPhoneLabel = "Smart Phone";
// #pragma mark - // #pragma mark -
@@ -119,6 +126,9 @@ BluetoothSettingsView::AttachedToWindow()
void void
BluetoothSettingsView::MessageReceived(BMessage *msg) BluetoothSettingsView::MessageReceived(BMessage *msg)
{ {
DeviceClass devClass;
switch (msg->what) { switch (msg->what) {
case kMsgLocalSwitched: case kMsgLocalSwitched:
{ {
@@ -131,6 +141,42 @@ BluetoothSettingsView::MessageReceived(BMessage *msg)
} }
} }
break; break;
case kMsgSetDeviceClassDesktop:
{
devClass.SetRecord(1, 1, 0x72);
ActiveLocalDevice->SetDeviceClass(devClass);
break;
}
case kMsgSetDeviceClassServer:
{
devClass.SetRecord(1, 2, 0x72);
ActiveLocalDevice->SetDeviceClass(devClass);
break;
}
case kMsgSetDeviceClassLaptop:
{
devClass.SetRecord(1, 3, 0x72);
ActiveLocalDevice->SetDeviceClass(devClass);
break;
}
case kMsgSetDeviceClassNetbook:
{
devClass.SetRecord(1, 4, 0x72);
ActiveLocalDevice->SetDeviceClass(devClass);
break;
}
case kMsgSetDeviceClassSmartPhone:
{
devClass.SetRecord(2, 3, 0x72);
ActiveLocalDevice->SetDeviceClass(devClass);
break;
}
case kMsgRefresh: case kMsgRefresh:
_BuildLocalDevicesMenu(); _BuildLocalDevicesMenu();
fLocalDevicesMenu->SetTargetForItems(this); fLocalDevicesMenu->SetTargetForItems(this);
@@ -169,25 +215,31 @@ BluetoothSettingsView::_BuildConnectionPolicy()
void void
BluetoothSettingsView::_BuildHintingMenu() BluetoothSettingsView::_BuildHintingMenu()
{ {
fHintingMenu = new BPopUpMenu("Identify us as..."); fHintingMenu = new BPopUpMenu("Identify us as...");
BMessage* message;
BMessage* message = new BMessage(kMsgSetHinting);
message->AddBool("hinting", false); message = new BMessage(kMsgSetDeviceClassDesktop);
BMenuItem* item = new BMenuItem(kDesktopLabel, message); BMenuItem* item = new BMenuItem(kDesktopLabel, message);
fHintingMenu->AddItem(item); fHintingMenu->AddItem(item);
message = new BMessage(kMsgSetAverageWeight); message = new BMessage(kMsgSetDeviceClassServer);
message->AddBool("hinting", true); item = new BMenuItem(kServerLabel, message);
fHintingMenu->AddItem(item);
item = new BMenuItem(kLaptopLabel, message);
message = new BMessage(kMsgSetDeviceClassLaptop);
item = new BMenuItem(kLaptopLabel, message);
fHintingMenu->AddItem(item);
message = new BMessage(kMsgSetDeviceClassNetbook);
item = new BMenuItem(kNetBookLabel, message);
fHintingMenu->AddItem(item);
message = new BMessage(kMsgSetDeviceClassSmartPhone);
item = new BMenuItem(kPhoneLabel, message);
fHintingMenu->AddItem(item); fHintingMenu->AddItem(item);
BMenuItem* item2 = new BMenuItem(kPhoneLabel, NULL);
fHintingMenu->AddItem(item2);
} }