Merge "Refactor LE scanning HAL (1/3)" am: f43056dc4d

am: 5b4676f9e0

Change-Id: Ib393b8399156ed6bafb419cce3fb8d7c96740d9c
This commit is contained in:
Jakub Pawlowski 2016-12-17 01:36:05 +00:00 committed by android-build-merger
commit 5aa9096f21
2 changed files with 68 additions and 60 deletions

View file

@ -19,107 +19,115 @@
#include <stdint.h> #include <stdint.h>
#include <vector> #include <vector>
#include "bt_gatt_types.h"
#include "bt_common_types.h" #include "bt_common_types.h"
#include "bt_gatt_client.h" #include "bt_gatt_client.h"
#include "bt_gatt_types.h"
/** Callback invoked in response to register_scanner */
typedef void (*register_scanner_callback)(int status, int scanner_id,
bt_uuid_t *app_uuid);
/** Callback invoked when batchscan storage config operation has completed */ /** Callback invoked when batchscan storage config operation has completed */
typedef void (*batchscan_cfg_storage_callback)(int client_if, int status); typedef void (*batchscan_cfg_storage_callback)(int client_if, int status);
/** Callback invoked when batchscan enable / disable operation has completed */ /** Callback invoked when batchscan enable / disable operation has completed */
typedef void (*batchscan_enable_disable_callback)(int action, int client_if, int status); typedef void (*batchscan_enable_disable_callback)(int action, int client_if,
int status);
/** Callback invoked when batchscan reports are obtained */ /** Callback invoked when batchscan reports are obtained */
typedef void (*batchscan_reports_callback)(int client_if, int status, int report_format, typedef void (*batchscan_reports_callback)(int client_if, int status,
int num_records, std::vector<uint8_t> data); int report_format, int num_records,
std::vector<uint8_t> data);
/** Callback invoked when batchscan storage threshold limit is crossed */ /** Callback invoked when batchscan storage threshold limit is crossed */
typedef void (*batchscan_threshold_callback)(int client_if); typedef void (*batchscan_threshold_callback)(int client_if);
/** Track ADV VSE callback invoked when tracked device is found or lost */ /** Track ADV VSE callback invoked when tracked device is found or lost */
typedef void (*track_adv_event_callback)(btgatt_track_adv_info_t *p_track_adv_info); typedef void (*track_adv_event_callback)(
btgatt_track_adv_info_t *p_track_adv_info);
/** Callback invoked when scan parameter setup has completed */ /** Callback invoked when scan parameter setup has completed */
typedef void (*scan_parameter_setup_completed_callback)(int client_if, typedef void (*scan_parameter_setup_completed_callback)(int client_if,
btgattc_error_t status); btgattc_error_t status);
/** Callback for scan results */ /** Callback for scan results */
typedef void (*scan_result_callback)(bt_bdaddr_t* bda, int rssi, std::vector<uint8_t> adv_data); typedef void (*scan_result_callback)(bt_bdaddr_t *bda, int rssi,
std::vector<uint8_t> adv_data);
/** Callback invoked when a scan filter configuration command has completed */ /** Callback invoked when a scan filter configuration command has completed */
typedef void (*scan_filter_cfg_callback)(int action, int client_if, int status, int filt_type, typedef void (*scan_filter_cfg_callback)(int action, int client_if, int status,
int avbl_space); int filt_type, int avbl_space);
/** Callback invoked when scan param has been added, cleared, or deleted */ /** Callback invoked when scan param has been added, cleared, or deleted */
typedef void (*scan_filter_param_callback)(int action, int client_if, int status, typedef void (*scan_filter_param_callback)(int action, int client_if,
int avbl_space); int status, int avbl_space);
/** Callback invoked when a scan filter configuration command has completed */ /** Callback invoked when a scan filter configuration command has completed */
typedef void (*scan_filter_status_callback)(int enable, int client_if, int status); typedef void (*scan_filter_status_callback)(int enable, int client_if,
int status);
typedef struct { typedef struct {
register_scanner_callback register_scanner_cb; scan_result_callback scan_result_cb;
scan_result_callback scan_result_cb; batchscan_cfg_storage_callback batchscan_cfg_storage_cb;
batchscan_cfg_storage_callback batchscan_cfg_storage_cb; batchscan_enable_disable_callback batchscan_enb_disable_cb;
batchscan_enable_disable_callback batchscan_enb_disable_cb; batchscan_reports_callback batchscan_reports_cb;
batchscan_reports_callback batchscan_reports_cb; batchscan_threshold_callback batchscan_threshold_cb;
batchscan_threshold_callback batchscan_threshold_cb; track_adv_event_callback track_adv_event_cb;
track_adv_event_callback track_adv_event_cb; scan_parameter_setup_completed_callback scan_parameter_setup_completed_cb;
scan_parameter_setup_completed_callback scan_parameter_setup_completed_cb; scan_filter_cfg_callback scan_filter_cfg_cb;
scan_filter_cfg_callback scan_filter_cfg_cb; scan_filter_param_callback scan_filter_param_cb;
scan_filter_param_callback scan_filter_param_cb; scan_filter_status_callback scan_filter_status_cb;
scan_filter_status_callback scan_filter_status_cb;
} btgatt_scanner_callbacks_t; } btgatt_scanner_callbacks_t;
typedef struct { class BleScannerInterface {
/** Registers a scanner with the stack */ public:
bt_status_t (*register_scanner)( bt_uuid_t *uuid ); virtual ~BleScannerInterface() = default;
/** Unregister a scanner from the stack */ using RegisterCallback =
bt_status_t (*unregister_scanner)(int scanner_id ); base::Callback<void(uint8_t /* scanner_id */, uint8_t /* status */)>;
/** Start or stop LE device scanning */ /** Registers a scanner with the stack */
bt_status_t (*scan)( bool start ); virtual void RegisterScanner(RegisterCallback) = 0;
/** Setup scan filter params */ /** Unregister a scanner from the stack */
bt_status_t (*scan_filter_param_setup)(btgatt_filt_param_setup_t filt_param); virtual void Unregister(int scanner_id) = 0;
/** Start or stop LE device scanning */
virtual void Scan(bool start) = 0;
/** Configure a scan filter condition */ /** Setup scan filter params */
bt_status_t (*scan_filter_add_remove)(int client_if, int action, int filt_type, virtual bt_status_t scan_filter_param_setup(
int filt_index, int company_id, btgatt_filt_param_setup_t filt_param) = 0;
int company_id_mask, const bt_uuid_t *p_uuid,
const bt_uuid_t *p_uuid_mask, const bt_bdaddr_t *bd_addr,
char addr_type, std::vector<uint8_t> data,
std::vector<uint8_t> p_mask);
/** Clear all scan filter conditions for specific filter index*/ /** Configure a scan filter condition */
bt_status_t (*scan_filter_clear)(int client_if, int filt_index); virtual bt_status_t scan_filter_add_remove(
int client_if, int action, int filt_type, int filt_index, int company_id,
int company_id_mask, const bt_uuid_t *p_uuid,
const bt_uuid_t *p_uuid_mask, const bt_bdaddr_t *bd_addr, char addr_type,
std::vector<uint8_t> data, std::vector<uint8_t> p_mask) = 0;
/** Enable / disable scan filter feature*/ /** Clear all scan filter conditions for specific filter index*/
bt_status_t (*scan_filter_enable)(int client_if, bool enable); virtual bt_status_t scan_filter_clear(int client_if, int filt_index) = 0;
/** Sets the LE scan interval and window in units of N*0.625 msec */ /** Enable / disable scan filter feature*/
bt_status_t (*set_scan_parameters)(int client_if, int scan_interval, int scan_window); virtual bt_status_t scan_filter_enable(int client_if, bool enable) = 0;
/* Configure the batchscan storage */ /** Sets the LE scan interval and window in units of N*0.625 msec */
bt_status_t (*batchscan_cfg_storage)(int client_if, int batch_scan_full_max, virtual bt_status_t set_scan_parameters(int client_if, int scan_interval,
int batch_scan_trunc_max, int batch_scan_notify_threshold); int scan_window) = 0;
/* Enable batchscan */ /* Configure the batchscan storage */
bt_status_t (*batchscan_enb_batch_scan)(int client_if, int scan_mode, virtual bt_status_t batchscan_cfg_storage(
int scan_interval, int scan_window, int addr_type, int discard_rule); int client_if, int batch_scan_full_max, int batch_scan_trunc_max,
int batch_scan_notify_threshold) = 0;
/* Disable batchscan */ /* Enable batchscan */
bt_status_t (*batchscan_dis_batch_scan)(int client_if); virtual bt_status_t batchscan_enb_batch_scan(int client_if, int scan_mode,
int scan_interval,
int scan_window, int addr_type,
int discard_rule) = 0;
/* Read out batchscan reports */ /* Disable batchscan */
bt_status_t (*batchscan_read_reports)(int client_if, int scan_mode); virtual bt_status_t batchscan_dis_batch_scan(int client_if) = 0;
} btgatt_scanner_interface_t; /* Read out batchscan reports */
virtual bt_status_t batchscan_read_reports(int client_if, int scan_mode) = 0;
};
#endif /* ANDROID_INCLUDE_BLE_SCANNER_H */ #endif /* ANDROID_INCLUDE_BLE_SCANNER_H */

View file

@ -61,7 +61,7 @@ typedef struct {
const btgatt_server_interface_t* server; const btgatt_server_interface_t* server;
/** Pointer to the LE scanner interface methods.*/ /** Pointer to the LE scanner interface methods.*/
const btgatt_scanner_interface_t* scanner; BleScannerInterface* scanner;
/** Pointer to the advertiser interface methods.*/ /** Pointer to the advertiser interface methods.*/
BleAdvertiserInterface* advertiser; BleAdvertiserInterface* advertiser;