- Modify API be more be like

- Polish a bit the classes composing the Discovery process




git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24697 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Ruiz Dorantes 2008-03-30 21:42:22 +00:00
parent dca967073f
commit b426fc0487
6 changed files with 86 additions and 54 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2007 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
* Copyright 2007-2008 Oliver Ruiz Dorantes, oliver.ruiz.dorantes_at_gmail.com
*
* All rights reserved. Distributed under the terms of the MIT License.
*
@ -9,13 +9,19 @@
#define _DISCOVERY_AGENT_H
#include <bluetooth/bluetooth.h>
#include <bluetooth/DiscoveryListener.h>
#define B_BT_CACHED 0x00
#define B_BT_PREKNOWN 0x01
#define B_BT_NOT_DISCOVERABLE 0x01
#define B_BT_GIAC 0x9E8B33
#define B_BT_LIAC 0x9E8B00
#define BT_CACHED 0x00
#define BT_PREKNOWN 0x01
#define BT_NOT_DISCOVERABLE 0x01
#define BT_GIAC 0x9E8B33
#define BT_LIAC 0x9E8B00
#define BT_MAX_RESPONSES (32)
#define BT_BASE_INQUIRY_TIME (1.28)
#define BT_DEFAULT_INQUIRY_TIME (0x15*BT_BASE_INQUIRY_TIME) /* TODO: REVIEW SPECS! */
namespace Bluetooth {
@ -26,16 +32,17 @@ class DiscoveryAgent {
public:
static const int GIAC = B_BT_GIAC;
static const int LIAC = B_BT_LIAC;
static const int GIAC = BT_GIAC;
static const int LIAC = BT_LIAC;
static const int PREKNOWN = B_BT_PREKNOWN;
static const int CACHED = B_BT_CACHED;
static const int NOT_DISCOVERABLE = B_BT_NOT_DISCOVERABLE;
static const int PREKNOWN = BT_PREKNOWN;
static const int CACHED = BT_CACHED;
static const int NOT_DISCOVERABLE = BT_NOT_DISCOVERABLE;
RemoteDevice** RetrieveDevices(int option); /* TODO */
bool StartInquiry(int accessCode, DiscoveryListener listener); /* Throwing */
bool CancelInquiry(DiscoveryListener listener);
RemoteDevicesList RetrieveDevices(int option); /* TODO */
status_t StartInquiry(int accessCode, DiscoveryListener* listener); /* Throwing */
status_t StartInquiry(uint32 accessCode, DiscoveryListener* listener, bigtime_t secs);
status_t CancelInquiry(DiscoveryListener* listener);
/*
int searchServices(int[] attrSet,
@ -49,7 +56,11 @@ class DiscoveryAgent {
private:
DiscoveryAgent();
void SetLocalDeviceOwner(LocalDevice* ld);
DiscoveryListener* fLastUsedListener;
LocalDevice* fLocalDevice;
};
}

View File

@ -9,26 +9,31 @@
#define _DISCOVERY_LISTENER_H
#include <Looper.h>
#include <ObjectList.h>
#include <bluetooth/RemoteDevice.h>
#define B_BT_INQUIRY_COMPLETED 0x01 // HCI_EVENT_X check specs
#define B_BT_INQUIRY_TERMINATED 0x02 // HCI_EVENT_X
#define B_BT_INQUIRY_ERROR 0x03 // HCI_EVENT_X
#define BT_INQUIRY_COMPLETED 0x01 // HCI_EVENT_X check specs
#define BT_INQUIRY_TERMINATED 0x02 // HCI_EVENT_X
#define BT_INQUIRY_ERROR 0x03 // HCI_EVENT_X
namespace Bluetooth {
typedef BObjectList<RemoteDevice> RemoteDevicesList;
class RemoteDevice;
class DeviceClass;
class LocalDevice;
class DiscoveryListener : BLooper {
class DiscoveryListener : public BLooper {
public:
static const int INQUIRY_COMPLETED = B_BT_INQUIRY_COMPLETED;
static const int INQUIRY_TERMINATED = B_BT_INQUIRY_TERMINATED;
static const int INQUIRY_ERROR = B_BT_INQUIRY_ERROR;
static const int INQUIRY_COMPLETED = BT_INQUIRY_COMPLETED;
static const int INQUIRY_TERMINATED = BT_INQUIRY_TERMINATED;
static const int INQUIRY_ERROR = BT_INQUIRY_ERROR;
static const int SERVICE_SEARCH_COMPLETED = 0x01;
static const int SERVICE_SEARCH_TERMINATED = 0x02;
@ -36,7 +41,7 @@ class DiscoveryListener : BLooper {
static const int SERVICE_SEARCH_NO_RECORDS = 0x04;
static const int SERVICE_SEARCH_DEVICE_NOT_REACHABLE = 0x06;
virtual void DeviceDiscovered(RemoteDevice btDevice, DeviceClass cod);
virtual void DeviceDiscovered(RemoteDevice* btDevice, DeviceClass cod);
/*
virtual void servicesDiscovered(int transID, ServiceRecord[] servRecord);
virtual void serviceSearchCompleted(int transID, int respCode);
@ -48,8 +53,15 @@ class DiscoveryListener : BLooper {
private:
DiscoveryListener();
void SetLocalDeviceOwner(LocalDevice* ld);
RemoteDevicesList GetRemoteDevicesList(void);
void MessageReceived(BMessage* msg);
LocalDevice* fLocalDevice;
RemoteDevicesList fRemoteDevicesList;
friend class DiscoveryAgent;
};
}

View File

@ -181,6 +181,16 @@ struct hci_command_header {
/* Link Control Command definition */
#define OGF_LINK_CONTROL 0x01
#define OCF_INQUIRY 0x0001
struct hci_cp_inquiry {
uint8 lap[3];
uint8 length;
uint8 num_rsp;
} __attribute__ ((packed));
#define OCF_INQUIRY_CANCEL 0x0002
#define OCF_CREATE_CONN 0x0005
struct hci_cp_create_conn {
bdaddr_t bdaddr;
@ -190,19 +200,7 @@ struct hci_command_header {
uint16 clock_offset;
uint8 role_switch;
} __attribute__ ((packed));
#define OCF_ACCEPT_CONN_REQ 0x0009
struct hci_cp_accept_conn_req {
bdaddr_t bdaddr;
uint8 role;
} __attribute__ ((packed));
#define OCF_REJECT_CONN_REQ 0x000a
struct hci_cp_reject_conn_req {
bdaddr_t bdaddr;
uint8 reason;
} __attribute__ ((packed));
#define OCF_DISCONNECT 0x0006
struct hci_disconnect {
uint16 handle;
@ -214,19 +212,19 @@ struct hci_command_header {
uint16 handle;
uint16 pkt_type;
} __attribute__ ((packed));
#define OCF_INQUIRY 0x0001
struct hci_cp_inquiry {
uint8 lap[3];
/* Constants related the inquiry process */
#define B_BT_GIAC 0x9E8B33
#define B_BT_LIAC 0x9E8B00
uint8 length;
uint8 num_rsp;
#define OCF_ACCEPT_CONN_REQ 0x0009
struct hci_cp_accept_conn_req {
bdaddr_t bdaddr;
uint8 role;
} __attribute__ ((packed));
#define OCF_INQUIRY_CANCEL 0x0002
#define OCF_REJECT_CONN_REQ 0x000a
struct hci_cp_reject_conn_req {
bdaddr_t bdaddr;
uint8 reason;
} __attribute__ ((packed));
#define OCF_LINK_KEY_REPLY 0x000B
struct hci_cp_link_key_reply {
bdaddr_t bdaddr;

View File

@ -9,6 +9,7 @@
#define _BTHCI_EVENT_H_
#include <bluetooth/bluetooth.h>
#include <bluetooth/HCI/btHCI.h>
#define HCI_EVENT_HDR_SIZE 2

View File

@ -49,7 +49,7 @@ class LocalDevice {
void updateRecord(ServiceRecord srvRecord);
*/
private:
LocalDevice(hci_id hid);
LocalDevice(hci_id hid);
static LocalDevice* RequestLocalDeviceID(BMessage* request);
@ -57,6 +57,9 @@ class LocalDevice {
BMessenger* fMessenger;
hci_id hid;
hci_id GetID(void) {return hid;}
friend class DiscoveryAgent;
};
}

View File

@ -19,6 +19,7 @@
namespace Bluetooth {
class Connection;
class LocalDevice;
class RemoteDevice {
@ -32,12 +33,12 @@ class RemoteDevice {
BString GetBluetoothAddress();
bool Equals(RemoteDevice* obj);
static RemoteDevice* GetRemoteDevice(Connection conn); /* Throwing */
/*static RemoteDevice* GetRemoteDevice(Connection conn); Throwing */
bool Authenticate(); /* Throwing */
bool Authorize(Connection conn); /* Throwing */
bool Encrypt(Connection conn, bool on); /* Throwing */
/* bool Authorize(Connection conn); Throwing */
/*bool Encrypt(Connection conn, bool on); Throwing */
bool IsAuthenticated(); /* Throwing */
bool IsAuthorized(Connection conn); /* Throwing */
/*bool IsAuthorized(Connection conn); Throwing */
bool IsEncrypted(); /* Throwing */
protected:
@ -46,6 +47,12 @@ class RemoteDevice {
/* Instances of this class only will be done by Discovery[Listener|Agent] TODO */
friend class DiscoveryListener;
private:
void SetLocalDeviceOwner(LocalDevice* ld);
bdaddr_t fBdaddr;
LocalDevice* fDiscovererLocalDevice;
};