Changeset 24699
- Timestamp:
- 03/30/08 17:48:17 (8 months ago)
- Location:
- haiku/trunk/src/kits/bluetooth
- Files:
-
- 1 added
- 3 modified
-
DiscoveryAgent.cpp (modified) (1 diff)
-
DiscoveryListener.cpp (modified) (4 diffs)
-
Jamfile (modified) (1 diff)
-
RemoteDevice.cpp (added)
Legend:
- Unmodified
- Added
- Removed
-
haiku/trunk/src/kits/bluetooth/DiscoveryAgent.cpp
r24318 r24699 8 8 #include <bluetooth/DiscoveryAgent.h> 9 9 #include <bluetooth/DiscoveryListener.h> 10 #include <bluetooth/RemoteDevice.h> 11 #include <bluetooth/LocalDevice.h> 10 12 11 #include <bluetooth/RemoteDevice.h> 13 #include <bluetooth/bluetooth_error.h> 14 15 #include <bluetooth/bluetoothserver_p.h> 16 #include <bluetooth/CommandManager.h> 17 18 #include <bluetooth/HCI/btHCI_command.h> 19 #include <bluetooth/HCI/btHCI_event.h> 20 21 22 #include "KitSupport.h" 12 23 13 24 namespace Bluetooth { 14 25 15 26 16 RemoteDevice **27 RemoteDevicesList 17 28 DiscoveryAgent::RetrieveDevices(int option) 18 29 { 19 return NULL; 30 /* No inquiry process initiated */ 31 if (fLastUsedListener == NULL) 32 return NULL; 33 34 return fLastUsedListener->GetRemoteDevicesList(); 35 } 36 37 38 status_t 39 DiscoveryAgent::StartInquiry(int accessCode, DiscoveryListener* listener) 40 { 41 return StartInquiry(accessCode, listener, BT_DEFAULT_INQUIRY_TIME); 42 } 43 44 45 status_t 46 DiscoveryAgent::StartInquiry(uint32 accessCode, DiscoveryListener* listener, bigtime_t secs) 47 { 48 BMessenger* btsm = NULL; 49 size_t size; 50 51 if ((btsm = _RetrieveBluetoothMessenger()) == NULL) 52 return B_ERROR; 53 54 if (secs < 1 || secs > 61 ) 55 return B_TIMED_OUT; 56 57 void* startInquiryCommand = NULL; 58 int8 bt_status = BT_ERROR; 59 60 // keep the listener whats the current listener for our inquiry state 61 fLastUsedListener = listener; 62 63 // Inform the listener who is gonna be its owner LocalDevice 64 // and its discovered devices 65 listener->SetLocalDeviceOwner(fLocalDevice); 66 67 /* Issue inquiry command */ 68 BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); 69 BMessage reply; 70 71 request.AddInt32("hci_id", fLocalDevice->GetID()); 72 73 startInquiryCommand = buildInquiry(accessCode, secs, BT_MAX_RESPONSES, &size); 74 request.AddData("raw command", B_ANY_TYPE, startInquiryCommand, size); 75 request.AddInt16("eventExpected", HCI_EVENT_CMD_STATUS); 76 request.AddInt16("opcodeExpected", PACK_OPCODE(OGF_LINK_CONTROL, OCF_INQUIRY)); 77 78 if (btsm->SendMessage(&request, listener) == B_OK) 79 { 80 return B_OK; 81 } 82 83 return B_ERROR; 20 84 21 85 } 22 86 23 87 24 bool 25 DiscoveryAgent:: StartInquiry(int accessCode, DiscoveryListenerlistener)88 status_t 89 DiscoveryAgent::CancelInquiry(DiscoveryListener* listener) 26 90 { 27 return false;91 BMessenger* btsm = NULL; 28 92 93 if ((btsm = _RetrieveBluetoothMessenger()) == NULL) 94 return B_ERROR; 95 96 void* cancelInquiryCommand = NULL; 97 int8 bt_status = BT_ERROR; 98 99 /* Issue inquiry command */ 100 BMessage request(BT_MSG_HANDLE_SIMPLE_REQUEST); 101 BMessage reply; 102 103 request.AddInt32("hci_id", fLocalDevice->GetID()); 104 // TODO: Add the raw command to the BMessage + expected event(s) 105 106 107 108 if (btsm->SendMessage(&request, listener) == B_OK) { 109 if (reply.FindInt8("status", &bt_status ) == B_OK ) { 110 return bt_status; 111 } 112 } 113 114 return B_ERROR; 115 } 116 117 void 118 DiscoveryAgent::SetLocalDeviceOwner(LocalDevice* ld) 119 { 120 fLocalDevice = ld; 121 } 122 123 DiscoveryAgent::DiscoveryAgent() 124 { 125 fLocalDevice = NULL; 29 126 } 30 127 31 128 32 bool33 DiscoveryAgent::CancelInquiry(DiscoveryListener listener)34 {35 return false;36 129 } 37 38 39 DiscoveryAgent::DiscoveryAgent()40 {41 42 }43 44 } -
haiku/trunk/src/kits/bluetooth/DiscoveryListener.cpp
r24376 r24699 10 10 #include <bluetooth/DeviceClass.h> 11 11 12 #include <bluetooth/HCI/btHCI_event.h> 13 12 14 #include <bluetoothserver_p.h> 13 15 … … 19 21 /* hooks */ 20 22 void 21 DiscoveryListener::DeviceDiscovered(RemoteDevice btDevice, DeviceClass cod)23 DiscoveryListener::DeviceDiscovered(RemoteDevice* btDevice, DeviceClass cod) 22 24 { 23 25 … … 42 44 43 45 /* private */ 44 DiscoveryListener::DiscoveryListener() 46 47 /* A LocalDevice is always referenced in any request to the 48 Bluetooth server therefore is going to be needed in any */ 49 void 50 DiscoveryListener::SetLocalDeviceOwner(LocalDevice* ld) 51 { 52 fLocalDevice = ld; 53 } 54 55 56 RemoteDevicesList 57 DiscoveryListener::GetRemoteDevicesList(void) 58 { 59 return fRemoteDevicesList; 60 } 61 62 63 void 64 DiscoveryListener::MessageReceived(BMessage* message) 65 { 66 int8 status; 67 68 switch (message->what) 69 { 70 case BT_MSG_INQUIRY_DEVICE: 71 { 72 const struct inquiry_info* inquiryInfo; 73 ssize_t size; 74 75 if (message->FindData("info", B_ANY_TYPE, 0, (const void**)&inquiryInfo, &size) == B_OK ) 76 { 77 RemoteDevice* rd = new RemoteDevice(inquiryInfo->bdaddr); 78 // DeviceClass(inquiryInfo->dev_class[0] | inquiryInfo->dev_class[1]<<8 | inquiryInfo->dev_class[2]<<16 ) 79 // fRemoteDevicesList.AddItem(rd); 80 rd->SetLocalDeviceOwner(fLocalDevice); 81 DeviceDiscovered( rd, DeviceClass(inquiryInfo->dev_class[0] | inquiryInfo->dev_class[1]<<8 | inquiryInfo->dev_class[2]<<16 )); 82 83 } 84 } 85 break; 86 87 case BT_MSG_INQUIRY_STARTED: 88 if (message->FindInt8("status", &status) == B_OK){ 89 InquiryStarted(status); 90 } 91 92 break; 93 94 case BT_MSG_INQUIRY_COMPLETED: 95 96 InquiryCompleted(BT_INQUIRY_COMPLETED); 97 98 break; 99 case BT_MSG_INQUIRY_TERMINATED: /* inquiry was cancelled */ 100 101 InquiryCompleted(BT_INQUIRY_TERMINATED); 102 103 break; 104 case BT_MSG_INQUIRY_ERROR: 105 106 InquiryCompleted(BT_INQUIRY_ERROR); 107 108 break; 109 110 default: 111 112 BLooper::MessageReceived(message); 113 114 break; 115 116 } 117 118 } 119 120 121 DiscoveryListener::DiscoveryListener() : BLooper() 45 122 { 46 123 … … 48 125 49 126 50 void51 DiscoveryListener::MessageReceived(BMessage* message)52 {53 switch (message->what)54 {55 case BT_MSG_INQUIRY_DEVICE:56 57 /* TODO: Extract info from BMessage to create a58 proper RemoteDevice, message should be passed from Agent??? */59 60 /* - Instance to be stored/Registered in the Agent? */61 //DeviceDiscovered( RemoteDevice(BString("00:00:00:00:00:00")), DeviceClass(0));62 63 break;64 65 case BT_MSG_INQUIRY_COMPLETED:66 67 InquiryCompleted(B_BT_INQUIRY_COMPLETED);68 69 break;70 case BT_MSG_INQUIRY_TERMINATED:71 72 InquiryCompleted(B_BT_INQUIRY_TERMINATED);73 74 break;75 case BT_MSG_INQUIRY_ERROR:76 77 InquiryCompleted(B_BT_INQUIRY_ERROR);78 79 break;80 81 default:82 83 BLooper::MessageReceived(message);84 85 break;86 87 }88 89 127 } 90 91 } -
haiku/trunk/src/kits/bluetooth/Jamfile
r24385 r24699 10 10 11 11 SharedLibrary libbluetooth.so : 12 SharedLibrary libbluetooth.so : 12 13 LocalDevice.cpp 14 DiscoveryListener.cpp 13 15 DiscoveryAgent.cpp 14 DiscoveryListener.cpp16 RemoteDevice.cpp 15 17 CommandManager.cpp 16 18 KitSupport.cpp
