Changeset 24699

Show
Ignore:
Timestamp:
03/30/08 17:48:17 (8 months ago)
Author:
oruizdorantes
Message:

- Implementation of the discovery classes & RemoteDevice
. Support for StartInquiry method

Location:
haiku/trunk/src/kits/bluetooth
Files:
1 added
3 modified

Legend:

Unmodified
Added
Removed
  • haiku/trunk/src/kits/bluetooth/DiscoveryAgent.cpp

    r24318 r24699  
    88#include <bluetooth/DiscoveryAgent.h> 
    99#include <bluetooth/DiscoveryListener.h> 
     10#include <bluetooth/RemoteDevice.h> 
     11#include <bluetooth/LocalDevice.h> 
    1012 
    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" 
    1223 
    1324namespace Bluetooth { 
    1425 
    1526 
    16 RemoteDevice** 
     27RemoteDevicesList 
    1728DiscoveryAgent::RetrieveDevices(int option) 
    1829{ 
    19         return NULL; 
     30    /* No inquiry process initiated */ 
     31    if (fLastUsedListener == NULL) 
     32        return NULL; 
     33 
     34    return fLastUsedListener->GetRemoteDevicesList(); 
     35} 
     36 
     37 
     38status_t 
     39DiscoveryAgent::StartInquiry(int accessCode, DiscoveryListener* listener) 
     40{ 
     41    return StartInquiry(accessCode, listener, BT_DEFAULT_INQUIRY_TIME); 
     42} 
     43 
     44 
     45status_t 
     46DiscoveryAgent::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; 
    2084 
    2185} 
    2286 
    2387 
    24 bool 
    25 DiscoveryAgent::StartInquiry(int accessCode, DiscoveryListener listener) 
     88status_t 
     89DiscoveryAgent::CancelInquiry(DiscoveryListener* listener) 
    2690{ 
    27         return false; 
     91    BMessenger* btsm = NULL; 
    2892 
     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 
     117void 
     118DiscoveryAgent::SetLocalDeviceOwner(LocalDevice* ld) 
     119{ 
     120    fLocalDevice = ld; 
     121} 
     122 
     123DiscoveryAgent::DiscoveryAgent() 
     124{ 
     125    fLocalDevice = NULL; 
    29126} 
    30127 
    31128 
    32 bool 
    33 DiscoveryAgent::CancelInquiry(DiscoveryListener listener) 
    34 { 
    35         return false; 
    36129} 
    37          
    38  
    39 DiscoveryAgent::DiscoveryAgent() 
    40 { 
    41  
    42 } 
    43  
    44 } 
  • haiku/trunk/src/kits/bluetooth/DiscoveryListener.cpp

    r24376 r24699  
    1010#include <bluetooth/DeviceClass.h> 
    1111 
     12#include <bluetooth/HCI/btHCI_event.h> 
     13 
    1214#include <bluetoothserver_p.h> 
    1315 
     
    1921/* hooks */ 
    2022void  
    21 DiscoveryListener::DeviceDiscovered(RemoteDevice btDevice, DeviceClass cod) 
     23DiscoveryListener::DeviceDiscovered(RemoteDevice* btDevice, DeviceClass cod) 
    2224{ 
    2325     
     
    4244 
    4345/* 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 */ 
     49void 
     50DiscoveryListener::SetLocalDeviceOwner(LocalDevice* ld) 
     51{ 
     52    fLocalDevice = ld; 
     53} 
     54 
     55 
     56RemoteDevicesList 
     57DiscoveryListener::GetRemoteDevicesList(void) 
     58{ 
     59        return fRemoteDevicesList; 
     60} 
     61 
     62 
     63void 
     64DiscoveryListener::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 
     121DiscoveryListener::DiscoveryListener() : BLooper() 
    45122{ 
    46123 
     
    48125 
    49126 
    50 void  
    51 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 a  
    58                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      
    89127} 
    90  
    91 } 
  • haiku/trunk/src/kits/bluetooth/Jamfile

    r24385 r24699  
    1010 
    1111SharedLibrary libbluetooth.so : 
     12SharedLibrary libbluetooth.so : 
    1213        LocalDevice.cpp 
     14        DiscoveryListener.cpp 
    1315        DiscoveryAgent.cpp 
    14         DiscoveryListener.cpp 
     16        RemoteDevice.cpp 
    1517        CommandManager.cpp 
    1618        KitSupport.cpp